Changeset 9322 for main/waeup.kofa/trunk/src
- Timestamp:
- 9 Oct 2012, 10:29:49 (12 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
r9311 r9322 67 67 from waeup.kofa.utils.helpers import get_user_account 68 68 from waeup.kofa.mandates.mandate import PasswordMandate 69 from waeup.kofa.datacenter import DataCenterFile 69 70 70 71 grok.context(IKofaObject) … … 154 155 view.redirect(view.url(view.context, redirect)) 155 156 return 157 158 def getPreviewTable(view, n): 159 """Get transposed table with n sample record. 160 161 The first column contains the headers. 162 """ 163 if not view.reader: 164 return 165 header = view.getPreviewHeader() 166 num = 0 167 data = [] 168 for line in view.reader: 169 if num > n-1: 170 break 171 num += 1 172 data.append(line) 173 result = [] 174 for name in header: 175 result_line = [] 176 result_line.append(name) 177 for d in data: 178 result_line.append(d[name]) 179 result.append(result_line) 180 return result 156 181 157 182 # Save function used for save methods in pages … … 838 863 cancel_button =_(u'Cancel') 839 864 840 def _notifyImportManagers(self, normalized_filename): 865 def getPreviewHeader(self): 866 """Get the header fields of uploaded CSV file. 867 """ 868 reader = csv.reader(open(self.fullpath, 'rb')) 869 return reader.next() 870 871 def getImporters(self): 872 importers = getAllUtilitiesRegisteredFor(IBatchProcessor) 873 importers = sorted( 874 [dict(title=x.name, name=x.util_name) for x in importers]) 875 return importers 876 877 def _notifyImportManagers(self, normalized_filename, importer, import_mode): 841 878 """Send email to Import Managers 842 879 """ 880 # Get information about file 881 self.fullpath = os.path.join(self.context.storage, normalized_filename) 882 uploadfile = DataCenterFile(self.fullpath) 883 self.reader = csv.DictReader(open(self.fullpath, 'rb')) 884 table = getPreviewTable(self, 3) 885 mail_table = '' 886 for line in table: 887 header = line[0] 888 data = str(line[1:]).strip('[').strip(']') 889 mail_table += '%s: %s\n' % (line[0], data) 890 # Collect all recipient addresses 843 891 kofa_utils = getUtility(IKofaUtils) 844 892 import_managers = get_users_with_role( … … 862 910 'waeup.kofa', 863 911 target_language=kofa_utils.PORTAL_LANGUAGE) 864 text = _('File ${a} uploaded.', mapping = {'a':normalized_filename}) 912 text = _("""File: ${a} 913 Processor: ${b} 914 Import Mode: ${c} 915 Datasets: ${d} 916 917 ${e} 918 919 """, mapping = {'a':normalized_filename, 920 'b':importer, 921 'c':import_mode, 922 'd':uploadfile.lines - 1, 923 'e':mail_table}) 865 924 success = kofa_utils.sendContactForm( 866 925 fullname,email, … … 875 934 return 876 935 877 def update(self, uploadfile=None, CANCEL=None, SUBMIT=None): 936 def update(self, uploadfile=None, import_mode=None, 937 importer=None, CANCEL=None, SUBMIT=None): 878 938 if CANCEL is not None: 879 939 self.redirect(self.url(self.context)) … … 903 963 ob_class = self.__implemented__.__name__.replace('waeup.kofa.','') 904 964 logger.info('%s - uploaded: %s' % (ob_class, target)) 905 self._notifyImportManagers(normalized_filename) 965 self._notifyImportManagers( 966 normalized_filename, importer, import_mode) 906 967 907 968 except IOError: … … 1050 1111 1051 1112 def getPreviewTable(self): 1052 """Get transposed table with 3 sample records. 1053 1054 The first column contains the headers. 1055 """ 1056 if not self.reader: 1057 return 1058 header = self.getPreviewHeader() 1059 num = 0 1060 data = [] 1061 for line in self.reader: 1062 if num > 2: 1063 break 1064 num += 1 1065 data.append(line) 1066 result = [] 1067 for name in header: 1068 result_line = [] 1069 result_line.append(name) 1070 for d in data: 1071 result_line.append(d[name]) 1072 result.append(result_line) 1073 return result 1113 return getPreviewTable(self, 3) 1074 1114 1075 1115 def getImporters(self): -
main/waeup.kofa/trunk/src/waeup/kofa/browser/templates/datacenteruploadpage.pt
r9311 r9322 1 1 <form method="post" enctype="multipart/form-data"> 2 <input type="file" name="uploadfile:file" /> 3 <br /><br /> 4 <div> 5 <input class="btn primary" type="submit" name="SUBMIT" 6 tal:attributes="value view/upload_button" /> 7 <input class="btn" type="submit" name="CANCEL" 8 tal:attributes="value view/cancel_button"/> 9 </div> 2 <br /> 3 <table class="form-table"> 4 <tr> 5 <td i18n:translate=""> 6 File: 7 </td> 8 <td> 9 <input type="file" size=47 name="uploadfile:file" /> 10 </td> 11 </tr> 12 <tr> 13 <td i18n:translate=""> 14 Processor: 15 </td> 16 <td> 17 <select name="importer"> 18 <option tal:repeat="importer view/getImporters" 19 tal:attributes="value importer/title" 20 tal:content="importer/title"> Some Importer 21 </option> 22 </select> 23 </td> 24 </tr> 25 <tr> 26 <td i18n:translate=""> 27 Import Mode: 28 </td> 29 <td> 30 <select name="import_mode"> 31 <option value='Create'>Create</option> 32 <option value='Update'>Update</option> 33 <option value='Remove'>Remove</option> 34 </select> 35 </td> 36 </tr> 37 <tr> 38 <td i18n:translate=""> 39 <input class="btn primary" type="submit" name="SUBMIT" 40 tal:attributes="value view/upload_button" /> 41 <input class="btn" type="submit" name="CANCEL" 42 tal:attributes="value view/cancel_button"/> 43 </td> 44 <td> 45 </td> 46 </tr> 47 </table> 10 48 </form> 11 49 12 50 <p i18n:translate=""> 13 51 Import managers will be automatically informed by email after file upload. 14 There is no need for assigning trac tickets anymore. 52 There is no need for assigning trac tickets or sending emails anymore. 53 The data will be imported according to the information given. 15 54 </p> 16 55
Note: See TracChangeset for help on using the changeset viewer.