Changeset 12957
- Timestamp:
- 17 May 2015, 08:03:11 (10 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa/browser
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/browser/pages.py
r12955 r12957 244 244 entries.append(new_entry) 245 245 return entries 246 247 def getImporters(context): 248 importers = getAllUtilitiesRegisteredFor(IBatchProcessor) 249 importer_props = [] 250 for x in importers: 251 # Skip User Processor if user isn't allowed to manage users. 252 if x.util_name == 'userprocessor' and not checkPermission( 253 'waeup.manageUsers', context): 254 continue 255 iface_fields = schema.getFields(x.iface) 256 available_fields = [] 257 for key in iface_fields.keys(): 258 iface_fields[key] = (iface_fields[key].__class__.__name__, 259 iface_fields[key].required) 260 for value in x.available_fields: 261 available_fields.append( 262 dict(f_name=value, 263 f_type=iface_fields.get(value, (None, False))[0], 264 f_required=iface_fields.get(value, (None, False))[1] 265 ) 266 ) 267 available_fields = sorted(available_fields, key=lambda k: k[ 268 'f_name']) 269 importer_props.append( 270 dict(title=x.name, name=x.util_name, fields=available_fields)) 271 return sorted(importer_props, key=lambda k: k['title']) 246 272 247 273 class LocalRoleAssignmentUtilityView(object): … … 579 605 self._set_payment_cats() 580 606 self._set_sex() 607 return 608 609 class ProcessorsOverview(KofaPage): 610 grok.context(IUniversity) 611 grok.name('processors') 612 grok.require('waeup.Public') 613 label = _(u'Available Processors (Importers)') 614 pnav = 0 615 616 def getImporters(self): 617 return getImporters(self.context) 618 619 class SkeletonDownloadView(UtilityView, grok.View): 620 grok.context(IUniversity) 621 grok.name('skeleton') 622 grok.require('waeup.Public') 623 624 def update(self, processorname=None): 625 self.processorname = self.request.form['name'] 626 self.filename = ('%s_000.csv' % 627 self.processorname.replace('processor','import')) 628 return 629 630 def render(self): 631 #ob_class = self.__implemented__.__name__.replace('waeup.kofa.','') 632 #self.context.logger.info( 633 # '%s - skeleton downloaded: %s' % (ob_class, self.filename)) 634 self.response.setHeader( 635 'Content-Type', 'text/csv; charset=UTF-8') 636 self.response.setHeader( 637 'Content-Disposition:', 'attachment; filename="%s' % self.filename) 638 processor = getUtility(IBatchProcessor, name=self.processorname) 639 csv_data = processor.get_csv_skeleton() 640 return csv_data 581 641 582 642 class AdministrationPage(KofaPage): … … 1047 1107 upload_button =_(u'Upload') 1048 1108 cancel_button =_(u'Back to Data Center') 1109 doclink = DOCLINK + '/datacenter/import_stages.html#stage-1-file-upload' 1049 1110 1050 1111 def getPreviewHeader(self): … … 1195 1256 1196 1257 def getImporters(self): 1197 importers = getAllUtilitiesRegisteredFor(IBatchProcessor) 1198 importer_props = [] 1199 for x in importers: 1200 # Skip User Processor if user isn't allowed to manage users. 1201 if x.util_name == 'userprocessor' and not checkPermission( 1202 'waeup.manageUsers', self.context): 1203 continue 1204 iface_fields = schema.getFields(x.iface) 1205 available_fields = [] 1206 for key in iface_fields.keys(): 1207 iface_fields[key] = (iface_fields[key].__class__.__name__, 1208 iface_fields[key].required) 1209 for value in x.available_fields: 1210 available_fields.append( 1211 dict(f_name=value, 1212 f_type=iface_fields.get(value, (None, False))[0], 1213 f_required=iface_fields.get(value, (None, False))[1] 1214 ) 1215 ) 1216 available_fields = sorted(available_fields, key=lambda k: k[ 1217 'f_name']) 1218 importer_props.append( 1219 dict(title=x.name, name=x.util_name, fields=available_fields)) 1220 return sorted(importer_props, key=lambda k: k['title']) 1258 return getImporters(self.context) 1221 1259 1222 1260 class FileDownloadView(UtilityView, grok.View): … … 1240 1278 fullpath = os.path.join(self.context.storage, self.filename) 1241 1279 return open(fullpath, 'rb').read() 1242 1243 class SkeletonDownloadView(UtilityView, grok.View):1244 grok.context(IDataCenter)1245 grok.name('skeleton')1246 grok.require('waeup.manageDataCenter')1247 1248 def update(self, processorname=None):1249 self.processorname = self.request.form['name']1250 self.filename = ('%s_000.csv' %1251 self.processorname.replace('processor','import'))1252 return1253 1254 def render(self):1255 #ob_class = self.__implemented__.__name__.replace('waeup.kofa.','')1256 #self.context.logger.info(1257 # '%s - skeleton downloaded: %s' % (ob_class, self.filename))1258 self.response.setHeader(1259 'Content-Type', 'text/csv; charset=UTF-8')1260 self.response.setHeader(1261 'Content-Disposition:', 'attachment; filename="%s' % self.filename)1262 processor = getUtility(IBatchProcessor, name=self.processorname)1263 csv_data = processor.get_csv_skeleton()1264 return csv_data1265 1280 1266 1281 class DatacenterImportStep1(KofaPage): -
main/waeup.kofa/trunk/src/waeup/kofa/browser/templates/datacenteruploadpage.pt
r12867 r12957 1 1 <p i18n:translate=""> 2 Before uploading a file check that your file header corresponds2 Before uploading a file, check that your file header corresponds 3 3 with header format of the selected processor. All available headers 4 4 are listed below. … … 65 65 The data will be imported according to the information given. 66 66 </p> 67 68 <br /><br />69 70 <h2 i18n:translate="">Available Processors (Importers)</h2>71 72 <table i18n:domain="waeup.kofa" class="table table-condensed">73 <thead>74 <tr>75 <th i18n:translate="">Processor</th>76 <th i18n:translate="">Required Schema Fields</th>77 <th i18n:translate="">Optional Schema Fields</th>78 <th i18n:translate="">Non-Schema Fields</th>79 </tr>80 </thead>81 <tr tal:repeat="importer view/getImporters">82 <td>83 <span tal:content="importer/title">TITLE</span><br /><br />84 <a i18n:translate="" class="btn btn-primary btn-xs"85 tal:attributes="href python: 'skeleton?name=' + importer['name']">86 Download CSV File Template87 </a>88 </td>89 <td nowrap>90 <span tal:repeat="field importer/fields">91 <tal:schemafield condition="field/f_type">92 <tal:required condition="field/f_required">93 <span tal:replace="field/f_name"></span>94 (<span tal:replace="field/f_type"></span>)95 <br />96 </tal:required>97 </tal:schemafield>98 </span>99 </td>100 <td nowrap>101 <span tal:repeat="field importer/fields">102 <tal:schemafield condition="field/f_type">103 <tal:notrequired condition="not:field/f_required">104 <span tal:replace="field/f_name"></span>105 (<span tal:replace="field/f_type"></span>)106 <br />107 </tal:notrequired>108 </tal:schemafield>109 </span>110 </td>111 <td>112 <span tal:repeat="field importer/fields">113 <tal:extrafield condition="not:field/f_type">114 <span tal:replace="field/f_name"></span>115 <br />116 </tal:extrafield>117 </span>118 </td>119 120 </tr>121 </table> -
main/waeup.kofa/trunk/src/waeup/kofa/browser/tests/test_browser.py
r12932 r12957 371 371 return 372 372 373 def test_skeleton_download(self):374 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')375 self.browser.open(self.datacenter_path)376 self.browser.getLink("Upload data").click()377 self.browser.getLink(url='skeleton?name=facultyprocessor').click()378 self.assertEqual(self.browser.headers['Status'], '200 Ok')379 self.assertEqual(self.browser.headers['Content-Type'],380 'text/csv; charset=UTF-8')381 self.assertEqual(self.browser.contents,382 'code,local_roles,title,title_prefix\r\n')383 return384 385 373 def test_user_data_import_permission(self): 386 374 upload_path = 'http://localhost/app/datacenter/upload' … … 505 493 self.assertEqual(self.browser.headers['Status'], '200 Ok') 506 494 self.assertTrue('id="headingStudentStates"' in self.browser.contents) 495 496 def test_processors_overview(self): 497 self.browser.open('http://localhost/app/processors') 498 self.assertEqual(self.browser.headers['Status'], '200 Ok') 499 self.browser.getLink(url='skeleton?name=facultyprocessor').click() 500 self.assertEqual(self.browser.headers['Status'], '200 Ok') 501 self.assertEqual(self.browser.headers['Content-Type'], 502 'text/csv; charset=UTF-8') 503 self.assertEqual(self.browser.contents, 504 'code,local_roles,title,title_prefix\r\n') 505 return
Note: See TracChangeset for help on using the changeset viewer.