Changeset 8651 for main/waeup.kofa/trunk/src/waeup/kofa
- Timestamp:
- 8 Jun 2012, 11:42:58 (13 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa/browser
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/browser/pages.py
r8573 r8651 931 931 return reader.next() 932 932 933 def getPreviewBody(self): 934 """Get the first 5 rows of attached CSV file. 933 def getPreviewTable(self): 934 """Get transposed table with 3 sample records. 935 936 The first column contains the headers. 935 937 """ 936 result = [] 938 if not self.reader: 939 return 940 header = self.getPreviewHeader() 937 941 num = 0 938 if not self.reader: 939 return 940 for row in self.reader: 941 if num > 4: 942 data = [] 943 for line in self.reader: 944 if num > 2: 942 945 break 943 946 num += 1 944 row = row.items() 945 # Sort fields in headerfield order 946 row = sorted(row, 947 key=lambda k: self.reader.fieldnames.index(k[0])) 948 row = [x[1] for x in row] 949 result.append(row) 950 result.append(len(result[0]) * ['...']) 947 data.append(line) 948 result = [] 949 for name in header: 950 result_line = [] 951 result_line.append(name) 952 for d in data: 953 result_line.append(d[name]) 954 result.append(result_line) 951 955 return result 952 956 … … 1056 1060 return reader.next() 1057 1061 1058 def getPreviewBody(self): 1059 """Get the first 5 rows of attached CSV file. 1062 def getPreviewTable(self): 1063 """Get transposed table with 1 sample record. 1064 1065 The first column contains the headers. 1060 1066 """ 1061 result = [] 1067 if not self.reader: 1068 return 1069 header = self.getPreviewHeader() 1062 1070 num = 0 1063 for row in self.reader: 1064 if num > 4: 1071 data = [] 1072 for line in self.reader: 1073 if num > 0: 1065 1074 break 1066 1075 num += 1 1067 row = row.items() 1068 # Sort fields in headerfield order 1069 row = sorted(row, 1070 key=lambda k: self.reader.fieldnames.index(k[0])) 1071 row = [x[1] for x in row] 1072 result.append(row) 1073 result.append(len(result[0]) * ['...']) 1076 data.append(line) 1077 result = [] 1078 for name in header: 1079 result_line = [] 1080 result_line.append(name) 1081 for d in data: 1082 result_line.append(d[name]) 1083 result.append(result_line) 1074 1084 return result 1075 1085 … … 1106 1116 1107 1117 def update(self, headerfield=None, back2=None, cancel=None, proceed=None): 1118 datatable.need() 1108 1119 session = ISession(self.request)['waeup.kofa'] 1109 1120 self.filename = session.get('import_filename', None) -
main/waeup.kofa/trunk/src/waeup/kofa/browser/templates/datacenterimport2page.pt
r7811 r8651 10 10 </p> 11 11 <div> 12 <table 13 tal:define="body view/getPreviewBody; 14 headers view/getPreviewHeader; 15 fieldnum python: len(headers)"> 12 <table tal:define="prev_table view/getPreviewTable;"> 16 13 <thead> 17 14 <tr> 18 <th tal:repeat="headerfield headers" 19 tal:content="headerfield"> headerfield 20 </th> 15 <th i18n:translate="">Header</th> 16 <th i18n:translate="">Sample Record 1</th> 17 <th i18n:translate="">Sample Record 2</th> 18 <th i18n:translate="">Sample Record 3</th> 21 19 </tr> 22 20 </thead> 23 21 <tbody> 24 <tr tal:repeat="row body">22 <tr tal:repeat="row prev_table"> 25 23 <td tal:repeat="value row" 26 24 tal:content="value"> value -
main/waeup.kofa/trunk/src/waeup/kofa/browser/templates/datacenterimport3page.pt
r7811 r8651 29 29 30 30 <div> 31 <table class="condensed-table" 32 tal:define="body view/getPreviewBody; 33 headers view/headerfields;34 fieldnum python: len(headers)">31 32 33 <table tal:define="prev_table view/getPreviewTable; 34 headers view/headerfields;"> 35 35 <thead> 36 36 <tr> 37 <th tal:repeat="headerfield headers" 38 tal:content="headerfield"> 39 headerfield 40 </th> 37 <th i18n:translate="">Header</th> 38 <th i18n:translate="">change to</th> 39 <th i18n:translate="">Sample Record</th> 41 40 </tr> 42 <tr> 43 <th tal:repeat="headerfield headers"> 44 <i i18n:translate="">change to:</i> 45 </th> 46 </tr> 47 <tr> 48 <th tal:repeat="headerfield headers"> 49 <select name="headerfield"> 41 </thead> 42 <tbody> 43 <tr tal:repeat="row prev_table"> 44 <td tal:content="python:row[0]"> value 45 </td> 46 <td> 47 <select class="span4" name="python:row[0]"> 50 48 <option tal:repeat="opt view/getPossibleHeaders" 51 49 tal:attributes="value opt/value; 52 selected python: opt['value']== headerfieldand 'selected' or '';"50 selected python: opt['value']==row[0] and 'selected' or '';" 53 51 tal:content="opt/title"> 54 52 new_header_name 55 53 </option> 56 54 </select> 57 </th> 58 </tr> 59 </thead> 60 <tbody> 61 <tr tal:repeat="row body"> 62 <td tal:repeat="value row" 63 tal:content="value"> 64 value 55 </td> 56 <td tal:repeat="value python:row[1:]" 57 tal:content="value"> value 65 58 </td> 66 59 </tr>
Note: See TracChangeset for help on using the changeset viewer.