Coverage for lino/modlib/users/models.py : 78%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# Copyright 2011-2015 Luc Saffre # License: BSD (see file COPYING for details)
.. autosummary::
See also :doc:`/dev/users`
"""
check_password, make_password, is_password_usable)
"""Dialog action to change the password of a user.
""" current=dd.PasswordField(_("Current password"), blank=True), new1=dd.PasswordField(_("New password"), blank=True), new2=dd.PasswordField(_("New password again"), blank=True) ) current new1 new2 """
ar.error("New passwords didn't match!") return or obj.check_password(pv.current): else: ar.info("Incorrect current password for %s." % obj)
"""Represents a user of this site.
.. attribute:: username
The primary key.
.. attribute:: profile
The profile of a user is what defines her or his permissions.
Users with an empty `profile` field are considered inactive and cannot log in.
.. attribute:: partner
Pointer to the :class:`lino.modlib.contacts.models.Partner` instance related to this user.
This is a DummyField when :mod:`lino.modlib.contacts` is not installed.
"""
"""This is always `True`. See also :attr:`lino.modlib.users.utils.AnonymousUser.authenticated`. """
_('Username'), max_length=30, unique=True, help_text=_("""Required. Must be unique."""))
blank=True, help_text=_("Users with an empty `profile` field are considered " "inactive and cannot log in."))
'contacts.Partner', blank=True, null=True, on_delete=models.PROTECT)
else:
"Returns the first_name plus the last_name, with a space in between."
def name_column(self, request): #~ return join_words(self.last_name.upper(),self.first_name)
return self.partner.get_mti_child('person') else: return None
""" Only system managers may edit other users. See also :meth:`User.disabled_fields`. """ #~ print 20120621, self, user, state, action if not ba.action.readonly: user = ar.get_user() if user != self: if not isinstance(user.profile.role, dd.SiteAdmin): return False return super(User, self).get_row_permission(ar, state, ba) #~ return False
""" Only System admins may change the `profile` of users. See also :meth:`Users.get_row_permission`. """ rv = super(User, self).disabled_fields(ar) if not isinstance(ar.get_user().profile.role, dd.SiteAdmin): rv.add('profile') return rv
for n in ('first_name', 'last_name', 'email', 'language'): if not getattr(self, n): setattr(self, n, getattr(p, n)) #~ self.language = p.language #~ self.language = settings.SITE.DEFAULT_LANGUAGE.django_code self.set_unusable_password() self.initials = self.first_name[0] + self.last_name[0]
#~ return [ [u.id,_("as %s")%u] for u in self.__class__.objects.all()] return [[u.id, str(u)] for u in self.__class__.objects.all()] #~ return self.__class__.objects.all()
# the following methods are unchanged copies from Django's User # model
""" Returns a boolean of whether the raw_password was correct. Handles hashing formats behind the scenes. """ self.set_password(raw_password) self.save()
# Sets a value that will never be a valid hash self.password = make_password(None)
if settings.SITE.is_demo_site: p = "'{0}', '{1}'".format(self.username, '1234') else: p = "'{0}'".format(self.username) url = "javascript:Lino.show_login_window(null, {0})".format(p) return E.li(E.a(self.username, href=url), ' : ', str(self), ', ', str(self.profile), ', ', E.strong(settings.SITE.LANGUAGE_DICT.get(self.language)))
""" `User.get_by_username(x)` is equivalent to `User.objects.get(username=x)` except that the text of the DoesNotExist exception is more useful. """ try: return cls.objects.get(username=username) except cls.DoesNotExist: if default is models.NOT_PROVIDED: raise cls.DoesNotExist( "No %s with username %r" % ( str(cls._meta.verbose_name), username)) return default
username profile:20 partner first_name last_name initials email language timezone id created modified """
box1 #MembershipsByUser:20 remarks:40 AuthoritiesGiven:20 """
username email first_name last_name partner language profile """
#~ debug_actions = True #~ order_by = "last_name first_name".split()
#~ column_names = 'username first_name last_name is_active is_staff is_expert is_superuser *'
#~ @classmethod #~ def get_row_permission(cls,action,user,obj): #~ """ #~ Only system managers may edit other users. #~ See also :meth:`User.disabled_fields`. #~ """ #~ if not super(Users,cls).get_row_permission(action,user,obj): #~ return False #~ if user.level >= UserLevel.manager: return True #~ if action.readonly: return True #~ if user is not None and user == obj: return True #~ return False
def get_default_action(cls):
"""A variant of :ddref:`users.Users` showing only active users and only some fields. This is used on demo sites in :xfile:`admin_main.html` to display the list of available users.
"""
""" An Authority is when a User gives another User the right to "represent him"
:user: points to the user who gives the right of representation. author of this Authority :authorized: points to the user who gets the right to represent the author
"""
#~ quick_search_fields = ('user__username','user__first_name','user__last_name')
settings.SITE.user_model, help_text=_("The user who gets authority to act in your name."))
def authorized_choices(cls, user): qs = settings.SITE.user_model.objects.exclude( profile=None) #~ profile=UserProfiles.blank_item) 20120829 if user is not None: qs = qs.exclude(id=user.id) #~ .exclude(level__gte=UserLevels.admin) return qs
|