web/views/cwuser.py
changeset 7993 aa0addce4dae
parent 7990 a673d1d9a738
child 8083 3db2f3317d15
equal deleted inserted replaced
7992:4ff9f25cb06e 7993:aa0addce4dae
   110 class CWGroupMainTab(tabs.PrimaryTab):
   110 class CWGroupMainTab(tabs.PrimaryTab):
   111     __regid__ = 'cwgroup-main'
   111     __regid__ = 'cwgroup-main'
   112     __select__ = tabs.PrimaryTab.__select__ & is_instance('CWGroup')
   112     __select__ = tabs.PrimaryTab.__select__ & is_instance('CWGroup')
   113 
   113 
   114     def render_entity_attributes(self, entity):
   114     def render_entity_attributes(self, entity):
   115         _ = self._cw._
   115         rset = self._cw.execute(
   116         rql = 'Any U, FN, LN, CD, LL ORDERBY L WHERE U in_group G, ' \
   116             'Any U, FN, LN, CD, LL ORDERBY L WHERE U in_group G, '
   117               'U login L, U firstname FN, U surname LN, U creation_date CD, ' \
   117             'U login L, U firstname FN, U surname LN, U creation_date CD, '
   118               'U last_login_time LL, G eid %(x)s'
   118             'U last_login_time LL, G eid %(x)s', {'x': entity.eid})
   119         rset = self._cw.execute(rql, {'x': entity.eid})
   119         self.wview('cwgroup.users', rset, 'null')
   120         headers = (_(u'user'), _(u'first name'), _(u'last name'),
   120 
   121                    _(u'creation date'), _(u'last login time'))
   121 class CWGroupUsersTable(tableview.RsetTableView):
   122         self.wview('editable-table', rset, 'null', displayfilter=True,
   122     __regid__ = 'cwgroup.users'
   123                    displaycols=range(5), mainindex=0, headers=headers)
   123     __select__ = is_instance('CWUser')
       
   124     headers = (_(u'user'), _(u'first name'), _(u'last name'),
       
   125                _(u'creation date'), _(u'last login time'))
       
   126     layout_args = {'display_filter': 'top'}
       
   127     finalvid = 'editable-final'
   124 
   128 
   125 
   129 
   126 class CWGroupPermTab(EntityView):
   130 class CWGroupPermTab(EntityView):
   127     __regid__ = 'cwgroup-permissions'
   131     __regid__ = 'cwgroup-permissions'
   128     __select__ = is_instance('CWGroup')
   132     __select__ = is_instance('CWGroup')
   192            'U in_state US, US name USN, '
   196            'U in_state US, US name USN, '
   193            'U primary_email UA?, UA address UAA, '
   197            'U primary_email UA?, UA address UAA, '
   194            'U cw_source UDS, US name UDSN')
   198            'U cw_source UDS, US name UDSN')
   195 
   199 
   196     def call(self, **kwargs):
   200     def call(self, **kwargs):
   197         self.w(add_etype_button(self._cw, 'CWGroup'))
   201         self.w(add_etype_button(self._cw, 'CWUser'))
   198         self.w(u'<div class="clear"></div>')
   202         self.w(u'<div class="clear"></div>')
   199         self.wview('cw.users-table', self._cw.execute(self.rql))
   203         self.wview('cw.users-table', self._cw.execute(self.rql))
       
   204 
       
   205 
       
   206 class CWUsersTable(tableview.EntityTableView):
       
   207     __regid__ = 'cw.users-table'
       
   208     __select__ = is_instance('CWUser')
       
   209     columns = ['user', 'in_state', 'firstname', 'surname',
       
   210                'in_group', 'primary_email', 'cw_source']
       
   211     layout_args = {'display_filter': 'top'}
       
   212     finalvid = 'editable-final'
       
   213 
       
   214     column_renderers = {
       
   215         'user': tableview.EntityTableColRenderer(
       
   216             renderfunc=lambda w,x: w(tags.a(x.login, href=x.absolute_url())),
       
   217             sortfunc=lambda x: x.login),
       
   218         'in_state': tableview.EntityTableColRenderer(
       
   219             renderfunc=lambda w,x: w(x.cw_adapt_to('IWorkflowable').printable_state),
       
   220             sortfunc=lambda x: x.cw_adapt_to('IWorkflowable').printable_state),
       
   221         'in_group': tableview.EntityTableColRenderer(
       
   222             renderfunc=lambda w,x: x.view('reledit', rtype='in_group', role='subject', w=w)),
       
   223         'primary_email': tableview.RelatedEntityColRenderer(
       
   224             getrelated=lambda x:x.primary_email and x.primary_email[0]),
       
   225         'cw_source': tableview.RelatedEntityColRenderer(
       
   226             getrelated=lambda x: x.cw_source[0]),
       
   227         }
   200 
   228 
   201 
   229 
   202 class CWGroupsManagementView(StartupView):
   230 class CWGroupsManagementView(StartupView):
   203     __regid__ = 'cw.groups-management'
   231     __regid__ = 'cw.groups-management'
   204     __select__ = StartupView.__select__ & match_user_groups('managers')
   232     __select__ = StartupView.__select__ & match_user_groups('managers')
   205     cache_max_age = 0 # disable caching
   233     cache_max_age = 0 # disable caching
   206     rql = ('Any G,COUNT(U), GN GROUPBY G,GN ORDERBY GN '
   234     rql = ('Any G,GN ORDERBY GN WHERE G is CWGroup, G name GN, NOT G name "owners"')
   207            'WHERE G is CWGroup, U? in_group G, G name GN, NOT G name "owners"')
       
   208     headers = [None, None]
       
   209     cellvids = {}
       
   210 
   235 
   211     def call(self, **kwargs):
   236     def call(self, **kwargs):
   212         self.w('<h1>%s</h1>' % self._cw._(self.title))
   237         self.w(add_etype_button(self._cw, 'CWGroup'))
   213         self.w(add_etype_button(self._cw, 'CWUser'))
       
   214         self.w(u'<div class="clear"></div>')
   238         self.w(u'<div class="clear"></div>')
   215         self.wview('editable-table', self._cw.execute(self.rql),
   239         self.wview('cw.groups-table', self._cw.execute(self.rql))
   216                    headers=self.headers, cellvids=self.cellvids)
   240 
   217 
   241 
   218 
   242 class CWGroupsTable(tableview.EntityTableView):
   219 class CWUsersTable(tableview.EditableTableView):
   243     __regid__ = 'cw.groups-table'
   220     __regid__ = 'cw.users-table'
   244     __select__ = is_instance('CWGroup')
   221     __select__ = is_instance('CWUser')
   245     columns = ['group', 'nb_users']
   222 
   246     layout_args = {'display_filter': 'top'}
   223     def call(self, **kwargs):
   247 
   224         headers = (display_name(self._cw, 'CWUser', 'plural'),
   248     column_renderers = {
   225                    display_name(self._cw, 'in_state'),
   249         'group': tableview.MainEntityColRenderer(),
   226                    self._cw._('firstname'), self._cw._('surname'),
   250         'nb_users': tableview.EntityTableColRenderer(
   227                    display_name(self._cw, 'CWGroup', 'plural'),
   251             header=_('num. users'),
   228                    display_name(self._cw, 'primary_email'),
   252             renderfunc=lambda w,x: w(unicode(x.num_users())),
   229                    display_name(self._cw, 'CWSource'))
   253             sortfunc=lambda x: x.num_users()),
   230         super(CWUsersTable, self).call(
   254         }
   231             paginate=True, displayfilter=True,
       
   232             cellvids={0: 'cw.user.login',
       
   233                       4: 'cw.users-table.group-cell'},
       
   234             headers=headers, **kwargs)
       
   235 
       
   236 
       
   237 class CWUserGroupCell(EntityView):
       
   238     __regid__ = 'cw.users-table.group-cell'
       
   239     __select__ = is_instance('CWUser')
       
   240 
       
   241     def entity_call(self, entity, **kwargs):
       
   242         self.w(entity.view('reledit', rtype='in_group', role='subject'))
       
   243 
       
   244 
       
   245 class CWUserLoginCell(EntityView):
       
   246     __regid__ = 'cw.user.login'
       
   247     __select__ = is_instance('CWUser')
       
   248 
       
   249     def entity_call(self, entity, **kwargs):
       
   250         self.w(tags.a(entity.login, href=entity.absolute_url()))