Changeset 6069
- Timestamp:
- 13 May 2011, 15:25:22 (14 years ago)
- Location:
- main/waeup.sirp/trunk/src/waeup/sirp/applicants
- Files:
-
- 1 added
- 1 deleted
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/applicants/browser.py
r6067 r6069 27 27 from hurry.jquery import jquery 28 28 from hurry.jqueryui import jqueryui 29 from zope.component import getUtility, getAllUtilitiesRegisteredFor 29 from zope.component import getUtility, getAllUtilitiesRegisteredFor, createObject 30 30 from zope.formlib.widgets import FileWidget, DateWidget 31 31 from zope.securitypolicy.interfaces import IPrincipalRoleManager … … 44 44 IApplicant, IApplicantPrincipal, IApplicantPDEEditData, 45 45 IApplicantsRoot, IApplicantsContainer, IApplicantsContainerProvider, 46 IApplicantsContainerAdd 46 47 ) 47 48 from waeup.sirp.widgets.passportwidget import ( … … 84 85 grok.name('index') 85 86 title = 'Applicants' 87 label = 'Application Section' 86 88 pnav = 3 87 89 … … 101 103 grok.context(IApplicantsRoot) 102 104 grok.view(ApplicantsRootPage) 103 text = 'Manage applicant containers' 104 105 class ApplicantsRootEditPage(WAeUPPage): 105 grok.require('waeup.manageUniversity') 106 text = 'Manage application section' 107 108 class ApplicantsRootManageFormPage(WAeUPEditFormPage): 106 109 grok.context(IApplicantsRoot) 107 110 grok.name('manage') 108 111 grok.template('applicantsrooteditpage') 109 title = 'Edit applicants containers' 110 pnav = 3 111 112 def update(self, entries=None, DELETE=None, CANCEL=None): 113 if CANCEL is not None: 114 self.redirect(self.url(self.context)) 115 return 116 if DELETE is None: 117 return 118 if entries is None: 119 return 120 if not isinstance(entries, list): 121 entries = [entries] 122 for name in entries: 123 del self.context[name] 124 self.flash('Deleted "%s"' % name) 125 return 126 127 def getApplications(self): 128 """Get a list of all stored applicant containers. 129 """ 130 for key, val in self.context.items(): 131 url = self.url(val) 132 yield(dict(url=url, name=key)) 133 134 class AddApplicantsContainerActionButton(AddActionButton): 112 title = 'Applicants' 113 label = 'Manage application section' 114 pnav = 3 115 grok.require('waeup.manageUniversity') 116 taboneactions = ['Add applicants container', 'Remove selected','Cancel'] 117 subunits = 'Applicants Containers' 118 119 def update(self): 120 tabs.need() 121 #warning.need() 122 return super(ApplicantsRootManageFormPage, self).update() 123 124 # ToDo: Show warning message before deletion 125 @grok.action('Remove selected') 126 def delApplicantsContainers(self, **data): 127 form = self.request.form 128 child_id = form['val_id'] 129 if not isinstance(child_id, list): 130 child_id = [child_id] 131 deleted = [] 132 for id in child_id: 133 try: 134 del self.context[id] 135 deleted.append(id) 136 except: 137 self.flash('Could not delete %s: %s: %s' % ( 138 id, sys.exc_info()[0], sys.exc_info()[1])) 139 if len(deleted): 140 self.flash('Successfully removed: %s' % ', '.join(deleted)) 141 self.redirect(self.url(self.context, '@@manage')+'#tab-1') 142 return 143 144 @grok.action('Add applicants container', validator=NullValidator) 145 def addApplicantsContainer(self, **data): 146 self.redirect(self.url(self.context, '@@add')) 147 return 148 149 @grok.action('Cancel', validator=NullValidator) 150 def cancel(self, **data): 151 self.redirect(self.url(self.context)) 152 return 153 154 class ApplicantsContainerAddFormPage(WAeUPAddFormPage): 135 155 grok.context(IApplicantsRoot) 136 grok.view(ApplicantsRootEditPage) 137 text = 'Add applicants container' 138 139 class AddApplicantsContainer(WAeUPPage): 140 grok.context(IApplicantsRoot) 156 grok.require('waeup.manageUniversity') 141 157 grok.name('add') 142 grok.template('addcontainer') 143 title = 'Add applicants container' 144 pnav = 3 145 146 def update(self, providername=None, name=None, title=None, 147 description=None, ADD=None, CANCEL=None): 148 if CANCEL is not None: 149 self.redirect(self.url(self.context)) 150 return 151 if ADD is None: 152 return 153 if not name: 154 self.flash('Error: you must give a name') 155 return 156 if name in self.context.keys(): 157 self.flash('A container of the given name already exists') 158 grok.template('applicantscontaineraddformpage') 159 title = 'Applicants' 160 label = 'Add applicants container' 161 pnav = 3 162 form_fields = grok.AutoFields(IApplicantsContainerAdd) 163 # hier muessen noch die widgets fuer die Datumsfelder rein 164 165 @grok.action('Add applicants container') 166 def addApplicantsContainer(self, **data): 167 if data['code'] in self.context.keys(): 168 self.status = Invalid('The name chosen already exists ' 169 'in the database') 158 170 return 159 171 # Add new applicants container... 160 172 provider = getUtility(IApplicantsContainerProvider, 161 name=providername) 173 name=getattr(data['provider'], 174 'grokcore.component.directive.name')) 162 175 container = provider.factory() 163 if title: 164 container.title = title 165 if description: 166 container.description = description 167 self.context[name] = container 168 self.flash('Added "%s".' % name) 169 self.redirect(self.url(self.context)) 176 self.applyData(container, **data) 177 self.context[data['code']] = container 178 self.flash('Added "%s".' % data['code']) 179 self.redirect(self.url(self.context, u'@@manage')+'#tab-1') 170 180 return 171 181 172 def getContainerProviders(self): 173 """Get a list of applicants container providers. 174 175 Applicants container providers are named utilities that help 176 to create applicants containers of different types 177 (JAMB-based, non-JAMB-based, etc.). 178 179 The list returned contains dicts:: 180 181 {'name': <utility_name>, 182 'provider': <provider instance>} 183 184 where `utility_name` is the name under which the respective 185 provider utility is registered and `provider` is the real 186 provider instance. 187 188 The `utility_name` can be used to lookup the utility anew (for 189 instance after submitting a form) and the `provider` instance 190 can be used to create new instances of the respective 191 applicants container type. 192 """ 193 providers = getAllUtilitiesRegisteredFor(IApplicantsContainerProvider) 194 result = [ 195 {'name': getattr(x, 'grokcore.component.directive.name'), 196 'provider': x} 197 for x in providers 198 ] 199 return result 182 @grok.action('Cancel') 183 def cancel(self, **data): 184 self.redirect(self.url(self.context)) 185 186 #def getContainerProviders(self): 187 # """Get a list of applicants container providers. 188 # 189 # Applicants container providers are named utilities that help 190 # to create applicants containers of different types 191 # (JAMB-based, non-JAMB-based, etc.). 192 # 193 # The list returned contains dicts:: 194 # 195 # {'name': <utility_name>, 196 # 'provider': <provider instance>} 197 # 198 # where `utility_name` is the name under which the respective 199 # provider utility is registered and `provider` is the real 200 # provider instance. 201 # 202 # The `utility_name` can be used to lookup the utility anew (for 203 # instance after submitting a form) and the `provider` instance 204 # can be used to create new instances of the respective 205 # applicants container type. 206 # """ 207 # providers = getAllUtilitiesRegisteredFor(IApplicantsContainerProvider) 208 # result = [ 209 # {'name': getattr(x, 'grokcore.component.directive.name'), 210 # 'provider': x} 211 # for x in providers 212 # ] 213 # return result 200 214 201 215 class ApplicantsRootBreadcrumb(Breadcrumb): … … 213 227 """Faculties-tab in primary navigation. 214 228 """ 229 215 230 grok.context(IWAeUPObject) 216 231 grok.order(3) 217 grok.require('waeup. View')232 grok.require('waeup.manageUniversity') 218 233 grok.template('primarynavtab') 219 234 … … 253 268 # else: 254 269 # return 270 271 255 272 256 273 class ManageApplicantsContainerActionButton(ManageActionButton): -
main/waeup.sirp/trunk/src/waeup/sirp/applicants/browser_templates/applicantscontainerpage.pt
r6063 r6069 7 7 <table class="zebra"> 8 8 <tbody> 9 <tr>10 <td class="fieldname">11 Type (Code):12 </td>13 <td class="field">14 <input tal:replace="context/__name__" />15 </td>16 </tr>17 9 <tal:block repeat="widget view/widgets"> 18 10 <tal:condition condition="python:widget.name not in ['form.description','form.title']"> -
main/waeup.sirp/trunk/src/waeup/sirp/applicants/browser_templates/applicantsrooteditpage.pt
r5860 r6069 1 <form method="POST"> 2 <table> 1 <h2 i18n:translate="" 2 tal:condition="view/label" 3 tal:content="view/label">Label</h2> 4 5 <div class="form-status" 6 tal:define="status view/status" 7 tal:condition="status"> 8 9 <div i18n:translate="" tal:content="view/status"> 10 Form status summary 11 </div> 12 13 <ul class="errors" tal:condition="view/errors"> 14 <li tal:repeat="error view/error_views"> 15 <span tal:replace="structure error">Error Type</span> 16 </li> 17 </ul> 18 </div> 19 20 21 <form action="." tal:attributes="action request/URL" method="POST" 22 class="edit-form" enctype="multipart/form-data"> 23 24 <div id="tabs"> 25 <ul> 26 <li><a href="#tab-1"><span tal:content="view/subunits">Contents</span></a></li> 27 </ul> 28 29 <div id="tab-1"> 30 <h3 tal:content="view/subunits">Applicants Containers</h3> 31 <table class="zebra"> 3 32 <thead> 4 33 <tr> 5 <th> </th><th>Name</th><th>Title</th>34 <th> </th><th>Code</th><th>Title</th> 6 35 </tr> 7 36 </thead> 8 37 <tbody> 9 <tr tal:repeat=" entry view/getApplications"10 tal:attributes="class python: repeat['entry'].odd() and 'odd' or 'even'">11 <td> 12 <input type="checkbox" name="entries"13 tal:attributes="value entry/name" />14 15 16 <a href=""17 tal:attributes="href entry/url" 18 tal:content="entry/name" 19 >Some Entry</a>20 21 22 <span tal:define="name entry/name">23 <span tal:content="python: context[name].title">Title</span> 24 25 38 <tr tal:repeat="ac context/values"> 39 <td> 40 <input type="checkbox" 41 name="val_id" 42 tal:attributes="value ac/__name__" /> 43 </td> 44 <td> 45 <a tal:attributes="href python: view.url(ac)" 46 tal:content="ac/__name__"> 47 ID 48 </a> 49 </td> 50 <td> 51 <span tal:content="ac/title"> 52 ID 53 </span> 54 </td> 26 55 </tr> 27 56 </tbody> 28 57 </table> 29 <input type="submit" name="DELETE" value="Delete selected" /> 30 <input type="reset" name="RESET" value="Reset" /> 31 <input type="submit" name="CANCEL" value="Cancel" /> 32 </form> 58 59 <div id="actionsView"> 60 <span class="actionButtons" tal:condition="view/availableActions"> 61 <span tal:repeat="action view/actions" 62 tal:omit-tag=""> 63 <input tal:condition="python:action.label in view.taboneactions" 64 tal:replace="structure action/render"/> 65 </span> 66 </span> 67 </div> 68 69 </div> 70 </div> 71 </form> -
main/waeup.sirp/trunk/src/waeup/sirp/applicants/browser_templates/applicantsrootpage.pt
r6067 r6069 1 <h2 i18n:translate="" 2 tal:condition="view/label" 3 tal:content="view/label">Label</h2> 4 1 5 <table class="display dataTable"> 2 6 <thead> 3 7 <tr> 4 <th> Name</th><th>Title</th>8 <th>Code</th><th>Title</th> 5 9 </tr> 6 10 </thead> … … 11 15 <a href="" 12 16 tal:attributes="href python:view.url(entry)" 13 tal:content="entry/ name"17 tal:content="entry/__name__" 14 18 >Name</a> 15 19 </td> -
main/waeup.sirp/trunk/src/waeup/sirp/applicants/container.py
r5884 r6069 25 25 import grok 26 26 from waeup.sirp.applicants.interfaces import ( 27 IApplicantsContainer, IApplicantsContainerProvider, 27 IApplicantsContainer, IApplicantsContainerAdd, 28 IApplicantsContainerProvider, 28 29 ) 30 from zope.schema.fieldproperty import FieldProperty 29 31 30 32 class ApplicantsContainer(grok.Container): 31 33 """An applicants container contains university applicants. 32 34 """ 33 grok.implements(IApplicantsContainer) 35 grok.implements(IApplicantsContainer,IApplicantsContainerAdd) 36 #grok.provides(IApplicantsContainer) 34 37 35 38 title = u'Simple applicant container' … … 38 41 enddate = None 39 42 strict_deadline = True 40 41 @property 42 def name(self): 43 return getattr(self, '__name__', None) 43 provider = None 44 code = None 44 45 45 46 def archive(self, app_ids=None): … … 74 75 """ 75 76 raise NotImplemented() 76 77 77 78 class ApplicantsContainerProvider(grok.GlobalUtility): 78 79 """A utility that provides basic applicants containers. -
main/waeup.sirp/trunk/src/waeup/sirp/applicants/interfaces.py
r6039 r6069 33 33 from waeup.sirp.image.image import WAeUPImageFile 34 34 from waeup.sirp.interfaces import IWAeUPObject, SimpleWAeUPVocabulary 35 from zope.component import getAllUtilitiesRegisteredFor 35 36 36 37 IMAGE_PATH = os.path.join( … … 80 81 if value == 'f': 81 82 return 'female' 83 84 class ApplicantContainerProviderSource(BasicSourceFactory): 85 """ 86 """ 87 def getValues(self): 88 providers = getAllUtilitiesRegisteredFor(IApplicantsContainerProvider) 89 return providers 90 91 def getToken(self, value): 92 return getattr(value, 'grokcore.component.directive.name') 93 94 def getTitle(self, value): 95 return "%s - %s" % (value.factory.title, value.factory.description) 82 96 83 97 class IResultEntry(IWAeUPObject): … … 97 111 """ 98 112 pass 113 99 114 100 115 class IApplicantsContainer(IWAeUPObject): … … 102 117 103 118 """ 119 120 code = schema.TextLine( 121 title = u'Code', 122 description = u'Abbreviated code of applicants container', 123 default = u'NA', 124 required = True, 125 readonly = True, 126 ) 127 128 provider = schema.Choice( 129 title = u'Type of applicants stored here.', 130 required = True, 131 default = None, 132 source = ApplicantContainerProviderSource(), 133 ) 134 104 135 title = schema.TextLine( 105 136 title = u'Title of the type of applicants stored here.', … … 161 192 database. 162 193 """ 194 195 class IApplicantsContainerAdd(IApplicantsContainer): 196 """An applicants container contains university applicants. 197 """ 198 code = schema.TextLine( 199 title = u'Code', 200 description = u'Abbreviated code of applicants container', 201 default = u'NA', 202 required = True, 203 readonly = False, 204 ) 205 206 IApplicantsContainerAdd['code'].order = IApplicantsContainer['code'].order 207 163 208 class IApplicantBaseData(IWAeUPObject): 164 209 """The data for an applicant. -
main/waeup.sirp/trunk/src/waeup/sirp/applicants/root.py
r5867 r6069 29 29 30 30 class ApplicantsRoot(grok.Container): 31 """The root of applicants-related components. It contains primarily31 """The root of applicants-related components. It contains only 32 32 containers for applicants. 33 33 """
Note: See TracChangeset for help on using the changeset viewer.