Changeset 8366 for main/waeup.kofa
- Timestamp:
- 6 May 2012, 08:28:32 (13 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa/browser
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/browser/pages.py
r8361 r8366 749 749 # 750 750 751 class DatacenterPage(Kofa Page):751 class DatacenterPage(KofaEditFormPage): 752 752 grok.context(IDataCenter) 753 753 grok.name('index') 754 grok.require('waeup.manage University')754 grok.require('waeup.manageDataCenter') 755 755 label = _(u'Data Center') 756 756 pnav = 0 757 758 def update(self): 759 datatable.need() 760 warning.need() 761 return super(DatacenterPage, self).update() 762 763 @jsaction(_('Remove selected')) 764 def delFiles(self, **data): 765 form = self.request.form 766 logger = self.context.logger 767 if form.has_key('val_id'): 768 child_id = form['val_id'] 769 else: 770 self.flash(_('No item selected.')) 771 return 772 if not isinstance(child_id, list): 773 child_id = [child_id] 774 deleted = [] 775 for id in child_id: 776 fullpath = os.path.join(self.context.storage, id) 777 try: 778 os.remove(fullpath) 779 deleted.append(id) 780 except OSError: 781 self.flash(_('OSError: The file could not be deleted.')) 782 return 783 if len(deleted): 784 self.flash(_('Successfully deleted: ${a}', 785 mapping = {'a': ', '.join(deleted)})) 786 logger.info('%s: Deleted files %s' % ( 787 self.request.principal.id, ', '.join(deleted))) 788 return 757 789 758 790 class DatacenterUploadPage(KofaPage): 759 791 grok.context(IDataCenter) 760 792 grok.name('upload') 761 grok.require('waeup.manage University')793 grok.require('waeup.manageDataCenter') 762 794 label = _(u'Upload file') 763 795 pnav = 0 … … 773 805 try: 774 806 filename = uploadfile.filename 807 if 'pending' in filename: 808 self.flash(_("You can't re-upload pending data files.")) 809 return 810 if not filename.endswith('.csv'): 811 self.flash(_("Only csv files are allowed.")) 812 return 775 813 target = os.path.join(self.context.storage, 776 814 self.getNormalizedFileName(filename)) 777 815 open(target, 'wb').write(uploadfile.read()) 778 816 logger = self.context.logger 779 logger.info('%s: Uploaded file "%s"' % (817 logger.info('%s: Uploaded file %s' % ( 780 818 self.request.principal.id, target)) 781 819 except IOError: … … 801 839 return '%s_%s%s' % (base, filtered_username, ext.lower()) 802 840 841 class FileDownloadView(UtilityView, grok.View): 842 grok.context(IDataCenter) 843 grok.name('download') 844 grok.require('waeup.manageDataCenter') 845 846 def update(self, filename=None): 847 self.filename = self.request.form['filename'] 848 return 849 850 def render(self): 851 self.response.setHeader( 852 'Content-Type', 'text/csv; charset=UTF-8') 853 self.response.setHeader( 854 'Content-Disposition:', 'attachment; filename="%s.csv' % 855 self.filename.replace('.csv','')) 856 fullpath = os.path.join(self.context.storage, self.filename) 857 return open(fullpath, 'rb').read() 858 803 859 class DatacenterImportStep1(KofaPage): 804 860 """Manual import step 1: choose file … … 807 863 grok.name('import1') 808 864 grok.template('datacenterimport1page') 809 grok.require('waeup.manage University')865 grok.require('waeup.manageDataCenter') 810 866 label = _(u'Process CSV file') 811 867 pnav = 0 … … 837 893 grok.name('import2') 838 894 grok.template('datacenterimport2page') 839 grok.require('waeup.manage University')895 grok.require('waeup.manageDataCenter') 840 896 label = _(u'Process CSV file') 841 897 pnav = 0 … … 957 1013 grok.name('import3') 958 1014 grok.template('datacenterimport3page') 959 grok.require('waeup.manage University')1015 grok.require('waeup.manageDataCenter') 960 1016 label = _(u'Process CSV file') 961 1017 pnav = 0 … … 1065 1121 grok.name('import4') 1066 1122 grok.template('datacenterimport4page') 1067 grok.require('waeup.manage University')1123 grok.require('waeup.manageDataCenter') 1068 1124 label = _(u'Process CSV file') 1069 1125 pnav = 0 … … 1183 1239 grok.name('manage') 1184 1240 grok.template('datacentermanagepage') 1185 grok.require('waeup.manage University')1241 grok.require('waeup.manageDataCenter') 1186 1242 label = _('Edit data center settings') 1187 1243 pnav = 0 -
main/waeup.kofa/trunk/src/waeup/kofa/browser/templates/datacenterpage.pt
r7811 r8366 9 9 </p> 10 10 11 <table i18n:domain="waeup.kofa"> 12 <thead> 13 <tr> 14 <th i18n:translate="">File</th> 15 <th i18n:translate="">Size</th> 16 <th i18n:translate="">Upload Date</th> 17 </tr> 18 </thead> 19 <tbody> 20 <tr tal:repeat="file context/getFiles"> 21 <td tal:content="file/name">FILENAME</td> 22 <td tal:content="file/size">12 k</td> 23 <td tal:content="file/uploaddate">Mar 12, 2008</td> 24 </tr> 25 </tbody> 26 </table> 11 <form action="." tal:attributes="action request/URL" method="post" 12 i18n:domain="waeup.kofa" enctype="multipart/form-data"> 13 <table i18n:domain="waeup.kofa" class="display dataTableManage"> 14 <thead> 15 <tr> 16 <th></th> 17 <th i18n:translate="">File</th> 18 <th i18n:translate="">Size</th> 19 <th i18n:translate="">Upload Date</th> 20 </tr> 21 </thead> 22 <tbody> 23 <tr tal:repeat="file context/getFiles" class="gradeC"> 24 <td> 25 <input type="checkbox" name="val_id" 26 tal:attributes="value file/name" /> 27 </td> 28 <td><a tal:attributes="href python: 'download?filename=' + file.name" 29 tal:content="file/name">FILENAME</a></td> 30 <td tal:content="file/size">12 k</td> 31 <td tal:content="file/uploaddate">Mar 12, 2008</td> 32 </tr> 33 </tbody> 34 </table> 35 <div tal:condition="view/availableActions"> 36 <span tal:repeat="action view/actions" tal:omit-tag=""> 37 <input tal:replace="structure action/render"/> 38 </span> 39 </div> 40 </form>
Note: See TracChangeset for help on using the changeset viewer.