Changeset 10541


Ignore:
Timestamp:
27 Aug 2013, 20:32:12 (11 years ago)
Author:
Henrik Bettermann
Message:

Reuse code by defining a mixin view.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/browser/pages.py

    r10540 r10541  
    234234    return entries
    235235
     236class LocalRoleAssignmentUtilityView(object):
     237    """A view mixin with useful methods for local role assignment.
     238
     239    """
     240
     241    def getLocalRoles(self):
     242        roles = ILocalRolesAssignable(self.context)
     243        return roles()
     244
     245    def getUsers(self):
     246        return get_all_users()
     247
     248    def getUsersWithLocalRoles(self):
     249        return get_users_with_local_roles(self.context)
     250
    236251#
    237252# Login/logout and language switch pages...
     
    17731788        return _('Departments')
    17741789
    1775 class FacultyManageFormPage(KofaEditFormPage):
     1790class FacultyManageFormPage(KofaEditFormPage,
     1791                            LocalRoleAssignmentUtilityView):
    17761792    """Manage the basic properties of a `Faculty` instance.
    17771793    """
     
    18041820        return super(FacultyManageFormPage, self).update()
    18051821
    1806     def getLocalRoles(self):
    1807         roles = ILocalRolesAssignable(self.context)
    1808         return roles()
    1809 
    1810     def getUsers(self):
    1811         return get_all_users()
    1812 
    1813     def getUsersWithLocalRoles(self):
    1814         return get_users_with_local_roles(self.context)
    1815 
    18161822    @jsaction(_('Remove selected'))
    18171823    def delDepartments(self, **data):
     
    19081914            yield(dict(url=url, name=key, container=val))
    19091915
    1910 class DepartmentManageFormPage(KofaEditFormPage):
     1916class DepartmentManageFormPage(KofaEditFormPage,
     1917                               LocalRoleAssignmentUtilityView):
    19111918    """Manage the basic properties of a `Department` instance.
    19121919    """
     
    19541961        super(DepartmentManageFormPage, self).update()
    19551962        return
    1956 
    1957     def getLocalRoles(self):
    1958         roles = ILocalRolesAssignable(self.context)
    1959         return roles()
    1960 
    1961     def getUsers(self):
    1962         return get_all_users()
    1963 
    1964     def getUsersWithLocalRoles(self):
    1965         return get_users_with_local_roles(self.context)
    19661963
    19671964    @action(_('Save'), style='primary')
     
    21052102        return '%s (%s)' % (self.context.title, self.context.code)
    21062103
    2107 class CourseManageFormPage(KofaEditFormPage):
     2104class CourseManageFormPage(KofaEditFormPage,
     2105                           LocalRoleAssignmentUtilityView):
    21082106    """Edit form page for courses.
    21092107    """
     
    21402138        return
    21412139
    2142     def getLocalRoles(self):
    2143         roles = ILocalRolesAssignable(self.context)
    2144         return roles()
    2145 
    2146     def getUsers(self):
    2147         return get_all_users()
    2148 
    2149     def getUsersWithLocalRoles(self):
    2150         return get_users_with_local_roles(self.context)
    2151 
    21522140    @action(_('Add local role'), validator=NullValidator)
    21532141    def addLocalRole(self, **data):
     
    21792167        return super(CertificatePage, self).update()
    21802168
    2181 class CertificateManageFormPage(KofaEditFormPage):
     2169class CertificateManageFormPage(KofaEditFormPage,
     2170                                LocalRoleAssignmentUtilityView):
    21822171    """Manage the properties of a `Certificate` instance.
    21832172    """
     
    22312220        self.redirect(self.url(self.context))
    22322221        return
    2233 
    2234     def getLocalRoles(self):
    2235         roles = ILocalRolesAssignable(self.context)
    2236         return roles()
    2237 
    2238     def getUsers(self):
    2239         return get_all_users()
    2240 
    2241     def getUsersWithLocalRoles(self):
    2242         return get_users_with_local_roles(self.context)
    22432222
    22442223    @action(_('Add local role'), validator=NullValidator)
Note: See TracChangeset for help on using the changeset viewer.