admingroup.py 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # -*- coding: utf-8 -*-
  2. from pod import model as pm
  3. from tgext.crud import CrudRestController
  4. from sprox.tablebase import TableBase
  5. from sprox.formbase import EditableForm, AddRecordForm
  6. from sprox.fillerbase import TableFiller, EditFormFiller
  7. from pod.model import auth as pma
  8. from tw2 import forms as tw2f
  9. import tg
  10. from sprox.widgets import PropertyMultipleSelectField
  11. from sprox._compat import unicode_text
  12. from formencode import Schema
  13. from formencode.validators import FieldsMatch
  14. from pod.lib import dbapi as pld
  15. class AdminGroupController(CrudRestController):
  16. model = pma.Group
  17. substring_filters = True
  18. class new_form_type(AddRecordForm):
  19. __model__ = pma.Group
  20. __require_fields__ = ['group_name', 'display_name', 'users', 'personnal_group']
  21. __omit_fields__ = ['created', 'permissions', '_lRights']
  22. __field_order__ = ['group_name', 'display_name', 'users']
  23. __headers__ = dict(group_name='Unique name', display_name='Visible name')
  24. group_name = tw2f.TextField('group_name')
  25. display_name = tw2f.TextField('display_name')
  26. personnal_group = tw2f.HiddenField('personnal_group', value='off')
  27. class edit_form_type(EditableForm):
  28. __model__ = pma.Group
  29. __require_fields__ = ['group_name', 'display_name', 'users']
  30. __omit_fields__ = ['personnal_group', 'created', 'permissions', '_lRights']
  31. __field_order__ = ['group_name', 'display_name']
  32. __headers__ = dict(group_name='Unique name', display_name='Visible name')
  33. class edit_filler_type(EditFormFiller):
  34. __model__ = pma.Group
  35. class table_type(TableBase):
  36. __model__ = pma.Group
  37. __limit_fields__ = ['group_id', 'group_name', 'display_name', 'users']
  38. __headers__ = dict(group_id='id', group_name='Unique name', display_name='Visible name', users='Users')
  39. __xml_fields__ = ['users']
  40. class table_filler_type(TableFiller):
  41. __model__ = pma.Group
  42. __limit_fields__ = ['group_id', 'group_name', 'display_name', 'users']
  43. #__add_fields__ = {'associated_users':None}
  44. def _do_get_provider_count_and_objs(self, groups=None, **kw):
  45. groups = pm.DBSession.query(pma.Group).\
  46. filter(pma.Group.group_id>0).\
  47. filter(pma.Group.group_id != pma.Group.GROUP_ID_ALL_USERS).\
  48. filter(pma.Group.group_id != pma.Group.GROUP_ID_MANAGERS).\
  49. all()
  50. return len(groups), groups
  51. def users(self, obj):
  52. users = ''.join(['<li>{0}</li>'.format(user.getDisplayName()) for user in obj.users])
  53. return users.join(('<ul>', '</ul>'))