daily pastebin goal
41%
SHARE
TWEET

Untitled

a guest Jan 23rd, 2018 47 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # -*- coding: utf-8 -*-
  2. # $Id$
  3. # Basic implementation of FlexibleAssignTo ValidOwnerProvider for trac,
  4. # that uses trac users but displays their fullname in the assign <select>
  5.  
  6. ## trac imports
  7. from trac.core import *
  8. from trac.util.compat import sorted
  9.  
  10. ## FlexibleAssignTo imports
  11. from flexibleassignto import IValidOwnerProvider, SimpleUser
  12.  
  13. __version__ = '0.1'
  14. __revision__ = "2"
  15. version = __version__
  16. fullversion = ".".join([__version__, __revision__])
  17.  
  18. class BasicFullNameOwnerProvider(Component):
  19.     implements(IValidOwnerProvider)
  20.    
  21.     def getUsers(self, next_action_obj):
  22.         known_users = list(self.env.get_known_users())  
  23.         # get_known_users() returns a list of tuples with:
  24.         # [(u'username', u'Full Name', u'email'), (u'username', u'Full Name', u'email')... ]
  25.         user_objs = []
  26.         for userinfo in known_users:
  27.             u = BasicFullNameUser()
  28.             u.username = u.userlogin = userinfo[0]
  29.             try:
  30.                 u.firstname, u.lastname = userinfo[1].split(' ', 1)
  31.             except (ValueError, AttributeError):
  32.                 u.firstname = userinfo[1]
  33.                 u.lastname = ""
  34.             u.email = userinfo[2]
  35.             u.setOptionValue("%s" % u.username)
  36.             u.setOptionDisplay("%s %s  (%s)" % (u.firstname, u.lastname, u.username))
  37.             user_objs.append(u)
  38.         return [EmptyFullNameUser()] + sorted(user_objs)
  39.  
  40. class BasicFullNameUser(SimpleUser):
  41.     def __cmp__(self, other):
  42.         return cmp(self.lastname, other.lastname)
  43.        
  44. class EmptyFullNameUser(BasicFullNameUser):
  45.     def __init__(self):
  46.         self.firstname = ""
  47.         self.lastname = ""
  48.         self.fullname = ""
  49.         self.userlogin = ""
  50.         self.email = ""
  51.         self.username = ""
  52.         self.option_value = ""
  53.         self.option_display = ""
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top