- Timestamp:
- 19 May 2011, 16:49:36 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/browser/pages.py
r6150 r6151 113 113 # 114 114 115 class ContainerManageFormPage(WAeUPEditFormPage): 116 """Manage the basic properties of a container instance with local roles 117 and contents This is the base class for faculty and department containers 118 """ 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 deletion 126 @grok.action('Remove selected') 127 def delSubobjects(self, **data): 128 form = self.request.form 129 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 return 135 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 return 149 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 return 165 166 @grok.action('Cancel', validator=NullValidator) 167 def cancel(self, **data): 168 self.redirect(self.url(self.context)) 169 return 170 171 @grok.action('Add subunit', validator=NullValidator) 172 def addSubunit(self, **data): 173 self.redirect(self.url(self.context, '@@add')) 174 return 175 176 @grok.action('Add local role', validator=NullValidator) 177 def addLocalRole(self, **data): 178 form = self.request.form 179 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 return 186 115 187 class UniversityPage(WAeUPDisplayFormPage): 116 188 """ The main university page. … … 934 1006 return 'Departments' 935 1007 936 class FacultyManageFormPage( WAeUPEditFormPage):1008 class FacultyManageFormPage(ContainerManageFormPage): 937 1009 """Manage the basic properties of a `Faculty` instance. 938 1010 """ 939 1011 grok.context(IFaculty) 940 grok.name('manage')941 grok.require('waeup.manageUniversity')942 1012 grok.template('facultymanagepage') 943 1013 pnav = 1 944 taboneactions = ['Save','Cancel']945 tabtwoactions = ['Add department', 'Remove selected','Cancel']946 tabthreeactions = ['Add local role', 'Remove local roles selected']947 1014 subunits = 'Departments' 948 1015 … … 956 1023 def title(self): 957 1024 return self.context.longtitle() 958 959 def getLocalRoles(self):960 roles = ILocalRolesAssignable(self.context)961 return roles()962 963 def getUsers(self):964 """Get a list of all users.965 """966 for key, val in grok.getSite()['users'].items():967 url = self.url(val)968 #import pdb; pdb.set_trace()969 yield(dict(url=url, name=key, val=val))970 1025 971 1026 def update(self): … … 973 1028 #warning.need() 974 1029 return super(FacultyManageFormPage, self).update() 975 976 @grok.action('Save')977 def save(self, **data):978 self.applyData(self.context, **data)979 return980 981 # ToDo: Show warning message before deletion982 @grok.action('Remove selected')983 def delDepartments(self, **data):984 form = self.request.form985 child_id = form['val_id']986 if not isinstance(child_id, list):987 child_id = [child_id]988 deleted = []989 for id in child_id:990 try:991 del self.context[id]992 deleted.append(id)993 except:994 self.flash('Could not delete %s: %s: %s' % (995 id, sys.exc_info()[0], sys.exc_info()[1]))996 if len(deleted):997 self.flash('Successfully removed: %s' % ', '.join(deleted))998 self.redirect(self.url(self.context, u'@@manage')+'#tab-2')999 return1000 1001 @grok.action('Add department', validator=NullValidator)1002 def addDepartment(self, **data):1003 self.redirect(self.url(self.context, '@@add'))1004 return1005 1006 @grok.action('Cancel', validator=NullValidator)1007 def cancel(self, **data):1008 self.redirect(self.url(self.context))1009 return1010 1011 @grok.action('Add local role', validator=NullValidator)1012 def addLocalRole(self, **data):1013 form = self.request.form1014 localrole = form['local_role']1015 user = form['user']1016 role_manager = IPrincipalRoleManager(self.context)1017 role_map = IPrincipalRoleMap(self.context)1018 #import pdb; pdb.set_trace()1019 role_manager.assignRoleToPrincipal(localrole, user)1020 self.redirect(self.url(self.context, u'@@manage')+'#tab-3')1021 return1022 1030 1023 1031 class DepartmentAddFormPage(WAeUPAddFormPage):
Note: See TracChangeset for help on using the changeset viewer.