~ubuntu-branches/ubuntu/trusty/schooltool/trusty

« back to all changes in this revision

Viewing changes to src/schooltool/basicperson/person.py

  • Committer: Gediminas Paulauskas
  • Date: 2013-10-10 16:53:33 UTC
  • mfrom: (1.1.27)
  • Revision ID: menesis@pov.lt-20131010165333-knsk88i2od7b8o70
Tags: 1:2.6.0-0ubuntu1
* New upstream release.
* debian/redis.conf: save redis databases less often.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
from zope.interface import implements
24
24
from zope.component import adapts
25
25
 
 
26
from schooltool.app.interfaces import ISchoolToolApplication
 
27
from schooltool.app.interfaces import IApplicationPreferences
26
28
from schooltool.person.person import Person
27
29
from schooltool.person.interfaces import IPersonFactory
28
30
from schooltool.course.section import PersonInstructorsCrowd
53
55
 
54
56
    @property
55
57
    def title(self):
56
 
        return "%s, %s" % (self.last_name, self.first_name)
 
58
        return "%s %s" % (self.first_name, self.last_name)
57
59
 
58
60
    advisors = RelationshipProperty(rel_type=URIAdvising,
59
61
                                    my_role=URIStudent,
68
70
 
69
71
    implements(IPersonFactory)
70
72
 
 
73
    @property
 
74
    def name_sorting(self):
 
75
        app = ISchoolToolApplication(None)
 
76
        preferences = IApplicationPreferences(app)
 
77
        return preferences.name_sorting
 
78
 
 
79
    @property
 
80
    def columns_order(self):
 
81
        result = ['last_name', 'first_name']
 
82
        if self.name_sorting == 'first_name':
 
83
            result = list(reversed(result))
 
84
        return result
 
85
 
71
86
    def columns(self):
72
87
        first_name = IndexedLocaleAwareGetterColumn(
73
88
            index='first_name',
83
98
            title=_(u'Last Name'),
84
99
            getter=lambda i, f: i.last_name,
85
100
            subsort=True)
86
 
 
87
 
        return [first_name, last_name]
88
 
 
89
 
    def createManagerUser(self, username, system_name):
90
 
        return self(username, system_name, "Administrator")
 
101
        result = []
 
102
        for column_name in self.columns_order:
 
103
            result.append(locals()[column_name])
 
104
        return result
 
105
 
 
106
    def createManagerUser(self, username):
 
107
        return self(username, "Default", "Manager")
91
108
 
92
109
    def sortOn(self):
93
 
        return (("last_name", False),)
 
110
        result = []
 
111
        for column_name in self.columns_order:
 
112
            result.append((column_name, False))
 
113
        return tuple(result)
94
114
 
95
115
    def groupBy(self):
96
116
        return (("grade", False),)
99
119
        result = BasicPerson(*args, **kw)
100
120
        return result
101
121
 
 
122
    def getSortingKey(self, person, collator):
 
123
        result = []
 
124
        for column_name in self.columns_order:
 
125
            attr = getattr(person, column_name)
 
126
            result.append(collator.key(attr))
 
127
        return tuple(result)
 
128
 
102
129
 
103
130
class BasicPersonCalendarCrowd(PersonCalendarCrowd):
104
131
    """Crowd that allows instructor of a person access persons calendar.
114
141
 
115
142
class PersonCatalog(AttributeCatalog):
116
143
 
117
 
    version = '2 - added text index'
 
144
    version = '3 - updated title'
118
145
    interface = IBasicPerson
119
146
    attributes = ('__name__', 'title', 'first_name', 'last_name')
120
147