PonyConf/accounts/utils.py
Élie Bouttier 61d0372bfd use is_orga
2016-07-09 23:44:52 +02:00

20 lines
729 B
Python

from django.contrib.sites.shortcuts import get_current_site
from django.utils.crypto import get_random_string
def generate_user_uid():
return get_random_string(length=12, allowed_chars='abcdefghijklmnopqrstuvwxyz0123456789')
def is_orga(request, user):
return user.is_authenticated() and user.participation_set.get(site=get_current_site(request)).is_orga()
def is_staff(request, user):
return user.is_authenticated() and user.participation_set.get(site=get_current_site(request)).is_staff()
def can_edit_profile(request, profile):
editor = request.user.participation_set.get(site=get_current_site(request))
return editor.is_orga() or editor.user.topic_set.filter(talk__speakers=profile.user).exists()