Changeset 6152 for main/waeup.sirp
- Timestamp:
- 19 May 2011, 19:40:10 (13 years ago)
- Location:
- main/waeup.sirp/trunk/src/waeup/sirp
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/browser/pages.py
r6151 r6152 48 48 grok.templatedir('templates') 49 49 50 def addLocalRole(view, tab, **data): 51 form = view.request.form 52 localrole = form['local_role'] 53 user = form['user'] 54 role_manager = IPrincipalRoleManager(view.context) 55 role_map = IPrincipalRoleMap(view.context) 56 role_manager.assignRoleToPrincipal(localrole, user) 57 view.redirect(view.url(view.context, u'@@manage')+'#tab-%s' % tab) 58 return 59 50 60 # 51 61 # Login/logout pages... … … 76 86 self.flash('You entered wrong credentials!') 77 87 78 79 88 class LoginStaffPage(LoginPage): 80 89 """A login page for staff members. … … 84 93 grok.require('waeup.Public') 85 94 title = u'Staff Login' 86 87 95 88 96 class LoginStudentPage(LoginPage): … … 108 116 self.redirect(self.url(self.context)) 109 117 110 111 118 # 112 119 # University related pages... 113 120 # 114 115 class ContainerManageFormPage(WAeUPEditFormPage):116 """Manage the basic properties of a container instance with local roles117 and contents This is the base class for faculty and department containers118 """119 grok.name('manage')120 grok.require('waeup.manageUniversity')121 taboneactions = ['Save','Cancel']122 tabtwoactions = ['Add subunit', 'Remove selected','Cancel']123 tabthreeactions = ['Add local role', 'Remove local roles selected']124 125 # ToDo: Show warning message before deletion126 @grok.action('Remove selected')127 def delSubobjects(self, **data):128 form = self.request.form129 if form.has_key('val_id'):130 child_id = form['val_id']131 else:132 self.flash('No subunit selected!')133 self.redirect(self.url(self.context, '@@manage')+'#tab-2')134 return135 if not isinstance(child_id, list):136 child_id = [child_id]137 deleted = []138 for id in child_id:139 try:140 del self.context[id]141 deleted.append(id)142 except:143 self.flash('Could not delete %s: %s: %s' % (144 id, sys.exc_info()[0], sys.exc_info()[1]))145 if len(deleted):146 self.flash('Successfully removed: %s' % ', '.join(deleted))147 self.redirect(self.url(self.context, '@@manage')+'#tab-1')148 return149 150 def getLocalRoles(self):151 roles = ILocalRolesAssignable(self.context)152 return roles()153 154 def getUsers(self):155 """Get a list of all users.156 """157 for key, val in grok.getSite()['users'].items():158 url = self.url(val)159 yield(dict(url=url, name=key, val=val))160 161 @grok.action('Save')162 def save(self, **data):163 self.applyData(self.context, **data)164 return165 166 @grok.action('Cancel', validator=NullValidator)167 def cancel(self, **data):168 self.redirect(self.url(self.context))169 return170 171 @grok.action('Add subunit', validator=NullValidator)172 def addSubunit(self, **data):173 self.redirect(self.url(self.context, '@@add'))174 return175 176 @grok.action('Add local role', validator=NullValidator)177 def addLocalRole(self, **data):178 form = self.request.form179 localrole = form['local_role']180 user = form['user']181 role_manager = IPrincipalRoleManager(self.context)182 role_map = IPrincipalRoleMap(self.context)183 role_manager.assignRoleToPrincipal(localrole, user)184 self.redirect(self.url(self.context, u'@@manage')+'#tab-3')185 return186 121 187 122 class UniversityPage(WAeUPDisplayFormPage): … … 1006 941 return 'Departments' 1007 942 1008 class FacultyManageFormPage( ContainerManageFormPage):943 class FacultyManageFormPage(WAeUPEditFormPage): 1009 944 """Manage the basic properties of a `Faculty` instance. 1010 945 """ 1011 946 grok.context(IFaculty) 947 grok.name('manage') 948 grok.require('waeup.manageUniversity') 1012 949 grok.template('facultymanagepage') 1013 950 pnav = 1 1014 951 subunits = 'Departments' 952 taboneactions = ['Save','Cancel'] 953 tabtwoactions = ['Add department', 'Remove selected','Cancel'] 954 tabthreeactions = ['Add local role', 'Remove local roles selected'] 1015 955 1016 956 form_fields = grok.AutoFields(IFaculty) … … 1028 968 #warning.need() 1029 969 return super(FacultyManageFormPage, self).update() 970 971 def getLocalRoles(self): 972 roles = ILocalRolesAssignable(self.context) 973 return roles() 974 975 def getUsers(self): 976 """Get a list of all users. 977 """ 978 for key, val in grok.getSite()['users'].items(): 979 url = self.url(val) 980 yield(dict(url=url, name=key, val=val)) 981 982 # ToDo: Show warning message before deletion 983 @grok.action('Remove selected') 984 def delSubobjects(self, **data): 985 form = self.request.form 986 if form.has_key('val_id'): 987 child_id = form['val_id'] 988 else: 989 self.flash('No subunit selected!') 990 self.redirect(self.url(self.context, '@@manage')+'#tab-%s' % tab) 991 return 992 if not isinstance(child_id, list): 993 child_id = [child_id] 994 deleted = [] 995 for id in child_id: 996 try: 997 del self.context[id] 998 deleted.append(id) 999 except: 1000 self.flash('Could not delete %s: %s: %s' % ( 1001 id, sys.exc_info()[0], sys.exc_info()[1])) 1002 if len(deleted): 1003 self.flash('Successfully removed: %s' % ', '.join(deleted)) 1004 self.redirect(self.url(self.context, '@@manage')+'#tab-2') 1005 return 1006 1007 @grok.action('Save') 1008 def save(self, **data): 1009 self.applyData(self.context, **data) 1010 return 1011 1012 @grok.action('Cancel', validator=NullValidator) 1013 def cancel(self, **data): 1014 self.redirect(self.url(self.context)) 1015 return 1016 1017 @grok.action('Add department', validator=NullValidator) 1018 def addSubunit(self, **data): 1019 self.redirect(self.url(self.context, '@@add')) 1020 return 1021 1022 @grok.action('Add local role', validator=NullValidator) 1023 def addLocalRole(self, **data): 1024 return addLocalRole(self, '3', **data) 1030 1025 1031 1026 class DepartmentAddFormPage(WAeUPAddFormPage): … … 1110 1105 tabtwoactions = ['Add course', 'Remove selected courses','Cancel'] 1111 1106 tabthreeactions = ['Add certificate', 'Remove selected certificates', 'Cancel'] 1107 tabfouractions = ['Add local role', 'Remove local roles selected'] 1108 1109 form_fields = grok.AutoFields(IDepartment) 1112 1110 1113 1111 @property … … 1138 1136 super(DepartmentManageFormPage, self).update() 1139 1137 return 1140 1141 form_fields = grok.AutoFields(IDepartment) 1138 1139 def getLocalRoles(self): 1140 roles = ILocalRolesAssignable(self.context) 1141 return roles() 1142 1143 def getUsers(self): 1144 """Get a list of all users. 1145 """ 1146 for key, val in grok.getSite()['users'].items(): 1147 url = self.url(val) 1148 yield(dict(url=url, name=key, val=val)) 1142 1149 1143 1150 @grok.action('Save') … … 1199 1206 self.redirect(self.url(self.context)) 1200 1207 return 1208 1209 @grok.action('Add local role', validator=NullValidator) 1210 def addLocalRole(self, **data): 1211 return addLocalRole(self, 4, **data) 1201 1212 1202 1213 class CourseAddFormPage(WAeUPAddFormPage): -
main/waeup.sirp/trunk/src/waeup/sirp/browser/templates/departmentmanagepage.pt
r6025 r6152 27 27 <li><a href="#tab-2">Courses</a></li> 28 28 <li><a href="#tab-3">Certificates</a></li> 29 <li><a href="#tab-4">Local Roles</a></li> 29 30 </ul> 30 31 … … 146 147 </div> 147 148 </div> 149 150 <div id="tab-4"> 151 <h3>Manage local roles</h3> 152 <table class="zebra"> 153 <tr> 154 <td> 155 <label>User:</label> 156 </td> 157 <td> 158 <select id="user" name="user" tal:repeat="user view/getUsers"> 159 <option tal:attributes="value user/name"> 160 <span tal:replace="user/val/description">USERTITLE</span> 161 </option> 162 </select> 163 </td> 164 </tr> 165 <tr> 166 <td> 167 <label>Local Role:</label> 168 </td> 169 <td> 170 <select id="local_role" name="local_role" tal:repeat="localrole view/getLocalRoles"> 171 <option tal:attributes="value localrole/name"> 172 <span tal:replace="localrole/title">LOCALROLETITLE</span> 173 </option> 174 </select> 175 </td> 176 </tr> 177 </table> 178 179 <div id="actionsView"> 180 <span class="actionButtons" tal:condition="view/availableActions"> 181 <span tal:repeat="action view/actions" 182 tal:omit-tag=""> 183 <input tal:condition="python:action.label in view.tabfouractions" 184 tal:replace="structure action/render"/> 185 </span> 186 </span> 187 </div> 188 </div> 148 189 149 190 </div> -
main/waeup.sirp/trunk/src/waeup/sirp/university/department.py
r5988 r6152 13 13 grok.implements(IDepartment, IDepartmentAdd) 14 14 15 @property # Make this method read_only and looking like an attr. 16 def local_roles(cls): 17 return [ 18 {'name':'waeup.local.DepartmentOfficer', 19 'title':'Department Officer'}, 20 ] 21 15 22 # A simple counter for ids. 16 23 next_id = 0L 17 24 18 25 def __init__(self, 19 26 title=u'Unnamed Department',
Note: See TracChangeset for help on using the changeset viewer.