niwla23
I want to make a webapp with a secret page. I have a table with the user and an access bool. whats the easiest way to check in views.py if the user is in access and the boolis 1/True?
Alexey
If request.user....
niwla23
and then? I need something like is in access and access == true
Mirco
niwla23
how?
Mirco
how?
Official docs , permissions section 😁
niwla23
Mirco
in which file are they defined?
permissions.py for example , but you can choose by yourself
https://docs.djangoproject.com/en/2.2/topics/auth/default/#permissions-and-authorization
niwla23
Sorry, i cant find it in the doc. So i just have to create permissions.py at the main app or at the functional app?
Alexey
Or https://www.django-rest-framework.org/api-guide/permissions/ ? :)
Mirco
niwla23
ok, is contenttype required?
Mirco
niwla23
there is a field content–type and i dont understand it
Mirco
niwla23
whats drf?
Mirco
Django Rest Framework
Anyway you're not using it
niwla23
right
Mirco
right
https://docs.djangoproject.com/en/2.2/topics/auth/default/#django.contrib.auth.decorators.user_passes_test
Even better
niwla23
ok
niwla23
class T21Turma(models.Model):
class Meta:
permissions = (("can_view_boletim", "Can view boletim"),
("can_view_mensalidades", "Can view mensalidades"),)
niwla23
So I can just paste this in a permissions.py file and i will see the permissions in the admin panel?
Mirco
niwla23
how then?????
Alexey
Create new permissions.py in app dir
niwla23
ok and then? I want "global permissions"
niwla23
webapp
Mirco
Mirco
With that decorator on the view you wanna block, you can also redirect a user to a view when he tries to visit that page and he doesn't match your rules
niwla23
I want to CREATE A PERMISSION
niwla23
and: whats content_type?
Mirco
I want to CREATE A PERMISSION
In your opinion what am I telling you ?
But if you don't wanna read documentation and try to understand, I cannot do so much more
niwla23
and how can i manage it? Which rule?
Mirco
Django still hasn't can_view permission related to a view , just for admin panel at the moment
niwla23
Again: I want to allow a few specific users the access to a site what does a email cor username check help there? And i read the doc, theres an @permission_requiered decorator. My onliest Problem is actually that i dont know how to create a permission
niwla23
and my problem is content_type
niwla23
yes, but id still like to understand content_type
Mirco
If into the future you wanna use a permission, content_type will be used to understand what model is
niwla23
so is it requiered?
Mirco
niwla23
but i dont have a model...
niwla23
I want to have a permiision and use the perm decorator to check if a user has it.
niwla23
A kind of "stand-alone permission"
inchidi
Hello.
Can anyone come across this?
Trying to get email sent to admins on server errors.
my settings.py:
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'simple': {
'format': '%(levelname)s %(message)s'
},
},
'handlers': {
'file': {
'level': 'ERROR',
'class': 'logging.FileHandler',
'filename': 'debug.log',
'formatter': 'simple'
},
'mail_admins': {
'level': 'ERROR',
'class': 'django.utils.log.AdminEmailHandler',
'formatter': 'simple'
},
},
'loggers': {
'django': {
'handlers': ['file', 'mail_admins'],
'level': 'ERROR',
'propagate': True,
},
},
}
With 500 errors, letters do not arrive, but logs are written to the file.
Separately, I checked sending email through the console - everything is in order, I receive letters:
send_mail('Subject here', 'Here is the message.', EMAIL_HOST_USER, ADMINS, fail_silently=False)
I tried debug = True and False
did you set SERVER_EMAIL already?
inchidi
godmode
Not... My mistake
godmode
I got two apps , and the urls of the seccond are not being loaded
godmode
Why cannot be... Whats do ypu do when you want yo registrer another app?
inchidi
godmode
I already did this and it's not working
inchidi
godmode
ok, let me make a push to github
Murshid
If entry_time between 1:00 to 2:00 and exit_time graterthan 5:00 how to query this
niwla23
Murshid
Is there any option for between
inchidi
godmode
@Inchidi https://github.com/Godm0de/uec.git
godmode
it should be an easy problem
godmode
just adding another app and trying to solve this anytime i do 127.0.0.1:8000/dashboard
godmode
i should see... Hello or something
inchidi
godmode
how? it's private
godmode
but it should be posible to share
godmode
hold on
Murshid
inchidi
you can use range then
Albert
did you set SERVER_EMAIL already?
Yes. My config:
EMAIL_HOST = 'smtp.yandex.ru'
EMAIL_HOST_USER = 'notifications81818@ya.ru'
EMAIL_HOST_PASSWORD = '*****'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = 'notifications81818@ya.ru'
SERVER_EMAIL = 'notifications81818@ya.ru'
ADMINS = [
('Albert', 'alb.sult@gmail.com'),
]
MANAGERS = ADMINS
godmode
@Inchidi https://github.com/Godm0de/uec.git
godmode
Now it should be work
inchidi
inchidi
you can give it a shot
godmode
@Inchidi have you seen my code?