本文整理汇总了Python中userena.utils.get_profile_model函数的典型用法代码示例。如果您正苦于以下问题:Python get_profile_model函数的具体用法?Python get_profile_model怎么用?Python get_profile_model使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_profile_model函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_no_profile
def test_no_profile(self):
""" Check for warning when there is no profile """
# TODO: Dirty! Currently we check for the warning by getting a 100%
# test coverage, meaning that it dit output some warning.
user = UserenaSignup.objects.create_user(**self.user_info)
# remove the profile of this user
get_profile_model().objects.get(user=user).delete()
# run the command to check for the warning.
call_command('check_permissions', test=True)
示例2: check_permissions
def check_permissions(self):
"""
Checks that all permissions are set correctly for the users.
:return: A set of users whose permissions was wrong.
"""
# Variable to supply some feedback
changed_permissions = []
changed_users = []
warnings = []
# Check that all the permissions are available.
for model, perms in ASSIGNED_PERMISSIONS.items():
if model == 'profile':
model_obj = get_profile_model()
else: model_obj = get_user_model()
model_content_type = ContentType.objects.get_for_model(model_obj)
for perm in perms:
try:
Permission.objects.get(codename=perm[0],
content_type=model_content_type)
except Permission.DoesNotExist:
changed_permissions.append(perm[1])
Permission.objects.create(name=perm[1],
codename=perm[0],
content_type=model_content_type)
# it is safe to rely on settings.ANONYMOUS_USER_ID since it is a
# requirement of django-guardian
for user in get_user_model().objects.exclude(id=settings.ANONYMOUS_USER_ID):
try:
user_profile = user.get_profile()
except get_profile_model().DoesNotExist:
warnings.append(_("No profile found for %(username)s") \
% {'username': user.username})
else:
all_permissions = get_perms(user, user_profile) + get_perms(user, user)
for model, perms in ASSIGNED_PERMISSIONS.items():
if model == 'profile':
perm_object = user.get_profile()
else: perm_object = user
for perm in perms:
if perm[0] not in all_permissions:
assign(perm[0], user, perm_object)
changed_users.append(user)
return (changed_permissions, changed_users, warnings)
示例3: create_profile_and_userdetail
def create_profile_and_userdetail(self, user):
userDetail = UserDetail()
userDetail.user = user
userDetail.save()
userena_profile = UserenaSignup.objects.create_userena_profile(user)
# All users have an empty profile
profile_model = get_profile_model()
try:
new_profile = user.get_profile()
except profile_model.DoesNotExist:
new_profile = profile_model(user=user)
new_profile.save(using=self._db)
# Give permissions to view and change profile
for perm in ASSIGNED_PERMISSIONS['profile']:
assign(perm[0], user, new_profile)
# Give permissions to view and change itself
for perm in ASSIGNED_PERMISSIONS['user']:
assign(perm[0], user, user)
if settings.USERENA_ACTIVATION_REQUIRED:
userena_profile.send_activation_email()
return user
示例4: create_inactive_user
def create_inactive_user(self, username, email, password):
"""
A simple wrapper that creates a new ``User``.
"""
now = datetime.datetime.now()
new_user = User.objects.create_user(username, email, password)
new_user.is_active = False
new_user.save()
userena_profile = self.create_userena_profile(new_user)
# All users have an empty profile
profile_model = get_profile_model()
new_profile = profile_model(user=new_user)
new_profile.save(using=self._db)
# Give permissions to view and change profile
for perm in PERMISSIONS['profile']:
assign(perm, new_user, new_profile)
# Give permissinos to view and change itself
for perm in PERMISSIONS['user']:
assign(perm, new_user, new_user)
userena_profile.send_activation_email()
return new_user
示例5: get_context_data
def get_context_data(self, username, extra_context=None, *args, **kwargs):
context = super(ProfileDetailView, self).get_context_data(*args, **kwargs)
user = get_object_or_404(get_user_model(),
username__iexact=username)
# Get profile
profile_model = get_profile_model()
try:
profile = user.get_profile()
except profile_model.DoesNotExist:
profile = profile_model.objects.create(user=user)
# Lookup badges
services = profile.services.all()
services_detailed = profile.service_detailed.all()
badges = ServiceBadge.objects.filter(services__in=services).distinct().order_by('category')
for b in badges:
b.user_services = []
for service_detailed in services_detailed:
if service_detailed.service in b.services.all():
b.user_services.append(service_detailed)
# Check perms
if not profile.can_view_profile(self.request.user):
return HttpResponseForbidden(_("You don't have permission to view this profile."))
# context
context['profile'] = profile
context['hide_email'] = userena_settings.USERENA_HIDE_EMAIL
context['badges'] = badges
return context
示例6: check_permissions
def check_permissions(self):
"""
Checks that all permissions are set correctly for the users.
:return: A set of users whose permissions was wrong.
"""
# Variable to supply some feedback
changed_permissions = []
changed_users = []
warnings = []
# Check that all the permissions are available.
for model, perms in ASSIGNED_PERMISSIONS.items():
if model == "profile":
model_obj = get_profile_model()
else:
model_obj = User
model_content_type = ContentType.objects.get_for_model(model_obj)
for perm in perms:
try:
Permission.objects.get(codename=perm[0], content_type=model_content_type)
except Permission.DoesNotExist:
changed_permissions.append(perm[1])
Permission.objects.create(name=perm[1], codename=perm[0], content_type=model_content_type)
for user in User.objects.all():
if not user.username == "AnonymousUser":
try:
user_profile = user.get_profile()
except get_profile_model().DoesNotExist:
warnings.append(_("No profile found for %(username)s") % {"username": user.username})
else:
all_permissions = get_perms(user, user_profile) + get_perms(user, user)
for model, perms in ASSIGNED_PERMISSIONS.items():
if model == "profile":
perm_object = user.get_profile()
else:
perm_object = user
for perm in perms:
if perm[0] not in all_permissions:
assign(perm[0], user, perm_object)
changed_users.append(user)
return (changed_permissions, changed_users, warnings)
示例7: create_user
def create_user(self, username, email, password, active=False,
send_email=True, firstname=''):
"""
A simple wrapper that creates a new :class:`User`.
:param username:
String containing the username of the new user.
:param email:
String containing the email address of the new user.
:param password:
String containing the password for the new user.
:param active:
Boolean that defines if the user requires activation by clicking
on a link in an e-mail. Defauts to ``True``.
:param send_email:
Boolean that defines if the user should be send an email. You could
set this to ``False`` when you want to create a user in your own
code, but don't want the user to activate through email.
:return: :class:`User` instance representing the new user.
"""
now = timezone.now()
new_user = User.objects.create_user(username, email, password)
new_user.first_name = firstname
new_user.is_active = active
new_user.save()
userena_profile = self.create_userena_profile(new_user)
# All users have an empty profile
profile_model = get_profile_model()
try:
new_profile = new_user.get_profile()
except profile_model.DoesNotExist:
new_profile = profile_model(user=new_user)
new_profile.save(using=self._db)
# Give permissions to view and change profile
for perm in ASSIGNED_PERMISSIONS['profile']:
assign(perm[0], new_user, new_profile)
# Give permissions to view and change itself
for perm in ASSIGNED_PERMISSIONS['user']:
assign(perm[0], new_user, new_user)
if send_email:
userena_profile.send_activation_email()
# Send the signup complete signal
userena_signals.signup_complete.send(sender=None,
user=new_user)
return new_user
示例8: get_queryset
def get_queryset(self):
logging.error(get_user_profile(self.request.user).__dict__)
profile_model = get_profile_model()
logging.error(profile_model.__dict__)
logging.error(profile_model.objects.all())
logging.error(profile_model.__doc__)
## logging.error(self.__dict__)
## logging.error(self.request.__dict__)
queryset = profile_model.objects.get_visible_profiles(self.request.user).select_related()
return queryset
示例9: create_user
def create_user(self, form_data, active=False,
send_email=True):
"""
A simple wrapper that creates a new :class:`User`.
:param username:
String containing the username of the new user.
:param email:
String containing the email address of the new user.
:param password:
String containing the password for the new user.
:param active:
Boolean that defines if the user requires activation by clicking
on a link in an e-mail. Defauts to ``True``.
:param send_email:
Boolean that defines if the user should be send an email. You could
set this to ``False`` when you want to create a user in your own
code, but don't want the user to activate through email.
:return: :class:`User` instance representing the new user.
"""
username, email, password = (form_data['username'],
form_data['email'],
form_data['password1'])
now = datetime.datetime.now()
new_user = User.objects.create_user(username, email, password)
new_user.is_active = active
new_user.save()
userena_profile = self.create_userena_profile(new_user)
# All users have an empty profile
profile_model = get_profile_model()
try:
new_profile = new_user.get_profile()
except profile_model.DoesNotExist:
profile_model.objects.create_profile(new_user=new_user, form_data=form_data)
# Give permissions to view and change itself
for perm in ASSIGNED_PERMISSIONS['user']:
assign(perm[0], new_user, new_user)
if send_email:
userena_profile.send_activation_email()
return new_user
示例10: create_inactive_user
def create_inactive_user(self, username, email, password=None, send_email=True):
"""
A simple wrapper that creates a new :class:`User`.
:param username:
String containing the username of the new user.
:param email:
String containing the email address of the new user.
:param password:
String containing the password for the new user.
:param send_email:
Boolean that defines if the user should be send an email. You could
set this to ``False`` when you want to create a user in your own
code, but don't want the user to activate through email.
:return: :class:`User` instance representing the new user.
"""
now = datetime.datetime.now()
if password:
new_user = User.objects.create_user(username, email, password)
else:
new_user = User.objects.create_user(username, email)
new_user.is_active = False
new_user.save()
userena_profile = self.create_userena_profile(new_user)
# All users have an empty profile
profile_model = get_profile_model()
new_profile = profile_model(user=new_user)
new_profile.save(using=self._db)
# Give permissions to view and change profile
for perm in PERMISSIONS['profile']:
assign(perm, new_user, new_profile)
# Give permissinos to view and change itself
for perm in PERMISSIONS['user']:
assign(perm, new_user, new_user)
if send_email:
userena_profile.send_activation_email()
# Send the signup complete signal
userena_signals.signup_complete.send(sender=None,
user=new_user)
return new_user
示例11: has_profile
def has_profile(user):
"""Test utility function to check if user has profile"""
profile_model = get_profile_model()
try:
profile = user.get_profile()
except AttributeError:
related_name = profile_model._meta.get_field('user')\
.related_query_name()
profile = getattr(user, related_name, None)
except profile_model.DoesNotExist:
profile = None
return bool(profile)
示例12: profile_detail
def profile_detail(request, username,extra_context=None, **kwargs):
template_name = 'userena/profile_detail.html'
user = get_object_or_404(get_user_model(),
username__iexact=username)
profile_model = get_profile_model()
try:
profile = user.get_profile()
except profile_model.DoesNotExist:
profile = profile_model.objects.create(user=user)
if not profile.can_view_profile(request.user):
raise PermissionDenied
return render(request, template_name, {'profile': profile,'bulletins' : Post.objects.filter(tag1='announcement').order_by("-time")})
示例13: profile_detail
def profile_detail(request, username,
template_name=userena_settings.USERENA_PROFILE_DETAIL_TEMPLATE,
extra_context=None, **kwargs):
"""
Detailed view of an user.
:param username:
String of the username of which the profile should be viewed.
:param template_name:
String representing the template name that should be used to display
the profile.
:param extra_context:
Dictionary of variables which should be supplied to the template. The
``profile`` key is always the current profile.
**Context**
``profile``
Instance of the currently viewed ``Profile``.
"""
user = get_object_or_404(get_user_model(),
username__iexact=username)
if Pago.objects.filter(user=user).exists():
last_pago = Pago.objects.filter(user=user).order_by('-fecha_expiracion').get()
else:
last_pago = None
today = date.today()
profile_model = get_profile_model()
try:
profile = user.get_profile()
except profile_model.DoesNotExist:
profile = profile_model.objects.create(user=user)
if not profile.can_view_profile(request.user):
return HttpResponseForbidden(_("You don't have permission to view this profile."))
if not extra_context: extra_context = dict()
extra_context['profile'] = user.get_profile()
extra_context['hide_email'] = userena_settings.USERENA_HIDE_EMAIL
if last_pago is None or last_pago.fecha_expiracion < today:
extra_context['suscripcion_status'] = "Inactiva"
return ExtraContextTemplateView.as_view(template_name=template_name,
extra_context=extra_context)(request)
示例14: profile_detail
def profile_detail(request, username, template_name=userena_settings.USERENA_PROFILE_DETAIL_TEMPLATE, extra_context=None, **kwargs):
"""
Detailed view of an user.
:param username:
String of the username of which the profile should be viewed.
:param template_name:
String representing the template name that should be used to display
the profile.
:param extra_context:
Dictionary of variables which should be supplied to the template. The
``profile`` key is always the current profile.
**Context**
``profile``
Instance of the currently viewed ``Profile``.
"""
user = get_object_or_404(get_user_model(),
username__iexact=username)
profile_model = get_profile_model()
try:
profile = user.get_profile()
except profile_model.DoesNotExist:
profile = profile_model.objects.create(user=user)
if not profile.can_view_profile(request.user):
return HttpResponseForbidden(_("You don't have permission to view this profile."))
if not extra_context:
extra_context = dict()
extra_context['profile'] = user.get_profile()
extra_context['hide_email'] = userena_settings.USERENA_HIDE_EMAIL
extra_context['location'] = request.user_location["user_location_lat_lon"]
extra_context['is_admin'] = user.is_superuser
extra_context['per_page'] = int(request.GET.get('per_page', 6))
tabs_page = "profile-detail"
active_tab = request.session.get(tabs_page, "account-events")
extra_context['active_tab'] = active_tab
return ExtraContextTemplateView.as_view(
template_name=template_name,
extra_context=extra_context
)(request)
示例15: profile_detail
def profile_detail(request, username,
template_name=userena_settings.USERENA_PROFILE_DETAIL_TEMPLATE,
extra_context=None, **kwargs):
"""
Detailed view of an user.
:param username:
String of the username of which the profile should be viewed.
:param template_name:
String representing the template name that should be used to display
the profile.
:param extra_context:
Dictionary of variables which should be supplied to the template. The
``profile`` key is always the current profile.
**Context**
``profile``
Instance of the currently viewed ``Profile``.
"""
user = get_object_or_404(get_user_model(),
username__iexact=username)
ganaderia = 'Sin asignar'
if Ganaderia.objects.all():
if Ganaderia.objects.filter(perfil=user.id):
ganaderia = Ganaderia.objects.get(perfil=user.id)
profile_model = get_profile_model()
try:
profile = user.get_profile()
except profile_model.DoesNotExist:
profile = profile_model.objects.create(user=user)
if not profile.can_view_profile(request.user):
raise PermissionDenied
if not extra_context: extra_context = dict()
extra_context['profile'] = user.get_profile()
extra_context['hide_email'] = userena_settings.USERENA_HIDE_EMAIL
extra_context['ganaderia'] = ganaderia
return ExtraContextTemplateView.as_view(template_name=template_name,
extra_context=extra_context)(request)