Changeset 1410
- Timestamp:
- 12 Feb 2007, 19:24:42 (18 years ago)
- Location:
- WAeUP_SRP/trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
WAeUP_SRP/trunk/Accommodation.py
r1393 r1410 11 11 from Products.CPSCore.CPSBase import CPSBaseBTreeFolder as BaseBTreeFolder 12 12 from Products.WAeUP_SRP.WAeUPTables import AccommodationTable 13 import logging 14 import csv,re,os 13 15 import Globals 14 16 import DateTime … … 90 92 ###) 91 93 94 security.declareProtected(ModifyPortalContent,"importReservedBeds")###( 95 def importReservedBeds(self): 96 """load Reserved Beds from CSV""" 97 import transaction 98 import random 99 current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S") 100 students_folder = self.portal_url.getPortalObject().campus.students 101 acco_folder = self.portal_url.getPortalObject().campus.accommodation 102 tr_count = 1 103 total = 0 104 name = 'ReservedBeds' 105 accommodation = self.portal_accommodation 106 students_cat = self.students_catalog 107 no_import = [] 108 imported = [] 109 logger = logging.getLogger('Import.%s' % name) 110 try: 111 beds = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) 112 except: 113 logger.error('Error reading %s.csv' % name) 114 return 115 halls = {} 116 start = True 117 for bed in beds: 118 if start: 119 start = False 120 logger.info('start loading from %s.csv' % name) 121 s = ','.join(['"%s"' % fn for fn in bed.keys()]) 122 imported.append(s) 123 no_import.append('%s,"Error"' % s) 124 format = ','.join(['"%%(%s)s"' % fn for fn in bed.keys()]) 125 format_error = format + ',"%(Error)s"' 126 no_certificate = "no certificate %s" % format 127 matric_no = bed.get('matric_no') 128 jamb_reg_no = bed.get('jamb_reg_no') 129 if matric_no != '': 130 res = students_cat(matric_no = matric_no) 131 if not res: 132 bed['Error'] = "No such student" 133 no_import.append( format_error % bed) 134 continue 135 student = res[0] 136 elif jamb_reg_no != '': 137 res = students_cat(jamb_reg_no = jamb_reg_no) 138 if not res: 139 bed['Error'] = "No such student" 140 no_import.append( format_error % bed) 141 continue 142 student = res[0] 143 else: 144 bed['Error'] = "No such student" 145 no_import.append( format_error % bed) 146 continue 147 sid = student.id 148 names = bed.get('name').split() 149 n = 0 150 for na in names: 151 if na.endswith(','): 152 names[n] = na[:-1] 153 n += 1 154 s_names = student.name.split() 155 found = False 156 for sn in s_names: 157 if sn.upper() in names: 158 found = True 159 break 160 if not found: 161 bed['Error'] = "Name mismatch %s %s" % (str(names),str(s_names)) 162 no_import.append( format_error % bed) 163 continue 164 hall = bed.get('hall') 165 if hall not in halls.keys(): 166 hall_object = getattr(acco_folder,hall, None) 167 if hall_object is None: 168 bed['Error'] = "No such hall" 169 no_import.append( format_error % bed) 170 continue 171 halls[hall] = hall_doc = hall_object.getContent() 172 bid = "%(hall)s_%(block)s_%(room)s_%(bed)s" % bed 173 res = accommodation(bed = bid) 174 psm = '' 175 while True: 176 if not res: 177 psm = "No bed with this id" 178 break 179 bed_brain = res[0] 180 if not bed_brain.bed_type.endswith("reserved"): 181 psm = "Not a reserved bed" 182 break 183 if bed_brain.student: 184 psm = "Bed %s already reserved for %s" % (bid,bed_brain.student) 185 break 186 if student.sex and not bed.get('block') in hall_doc.blocks_for_female: 187 psm = "Sex does not match %s" % bid 188 break 189 break 190 if psm != '': 191 bed['Error'] = psm 192 no_import.append( format_error % bed) 193 continue 194 accommodation.modifyRecord(bed = bid, student = sid) 195 imported.append( format % bed) 196 tr_count += 1 197 if tr_count > 1000: 198 if len(no_import) > 0: 199 open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write( 200 '\n'.join(no_import) + '\n') 201 no_import = [] 202 open("%s/import/%simported%s.csv" % (i_home,name,current),"a").write( 203 '\n'.join(no_import) + "\n") 204 imported = [] 205 em = '%d transactions commited total %s\n' % (tr_count,total) 206 transaction.commit() 207 regs = [] 208 logger.info(em) 209 total += tr_count 210 tr_count = 0 211 #from pdb import set_trace;set_trace() 212 open("%s/import/%simported%s.csv" % (i_home,name,current),"a").write( 213 '\n'.join(imported)) 214 open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write( 215 '\n'.join(no_import)) 216 return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) 217 218 92 219 InitializeClass(AccoFolder) 93 220 -
WAeUP_SRP/trunk/profiles/default/accommodation.xml
r1062 r1410 1 1 <?xml version="1.0"?> 2 <?xml-stylesheet type="text/xsl" href="catalog.xsl"?> 2 3 <object name="portal_catalog" meta_type="WAeUP Table"> 3 4 <column value="bed"/> -
WAeUP_SRP/trunk/profiles/default/catalog.xsl
r1403 r1410 23 23 <xsl:sort select="@value" 24 24 order="ascending" /> 25 <tr> 25 <xsl:variable name="color"> 26 <xsl:choose> 27 <xsl:when test="position() mod 2 = 0"> 28 <xsl:text>#ffffff</xsl:text> 29 </xsl:when> 30 <xsl:otherwise> 31 <xsl:text>#eeeeee</xsl:text> 32 </xsl:otherwise> 33 </xsl:choose> 34 </xsl:variable> 35 <tr style="background-color:{$color}"> 26 36 <td colspan=""> 27 37 <xsl:value-of select="@value"/> … … 40 50 <xsl:sort select="@name" 41 51 order="ascending" /> 42 <tr> 52 <xsl:variable name="color"> 53 <xsl:choose> 54 <xsl:when test="position() mod 2 = 0"> 55 <xsl:text>#ffffff</xsl:text> 56 </xsl:when> 57 <xsl:otherwise> 58 <xsl:text>#eeeeee</xsl:text> 59 </xsl:otherwise> 60 </xsl:choose> 61 </xsl:variable> 62 <tr style="background-color:{$color}"> 43 63 <td colspan=""> 44 64 <xsl:value-of select="@name"/> -
WAeUP_SRP/trunk/profiles/default/courses_catalog.xml
r1403 r1410 1 1 <?xml version="1.0"?> 2 2 <?xml-stylesheet type="text/xsl" href="catalog.xsl"?> 3 <object name="courses_catalog" meta_type=" CMF Catalog">3 <object name="courses_catalog" meta_type="WAeUP Table"> 4 4 <column value="code"/> 5 5 <column value="faculty"/> … … 8 8 <column value="level"/> 9 9 <column value="credits"/> 10 <column value="passmark"/> 10 11 <column value="semester"/> 11 12 <index name="code" meta_type="FieldIndex"> -
WAeUP_SRP/trunk/profiles/default/schemas/certificate_course.xml
r1399 r1410 2 2 <?xml-stylesheet type="text/xsl" href="schema.xsl"?> 3 3 <object name="certificate_course" meta_type="CPS Schema"> 4 <field name="admin_status" meta_type="CPS String Field"/> 5 <field name="certificate_code" meta_type="CPS String Field"/> 6 <field name="certificate_code_org" meta_type="CPS String Field"/> 7 <field name="code" meta_type="CPS String Field"> 8 <property name="is_searchabletext">False</property> 9 </field> 4 <field name="code" meta_type="CPS String Field" /> 10 5 <field name="core_or_elective" meta_type="CPS Boolean Field"/> 11 <field name="semester" meta_type="CPS String Field"/>12 <field name="department" meta_type="CPS String Field"/>13 <field name="level" meta_type="CPS String Field">14 <property name="is_searchabletext">True</property>15 </field>16 <field name="session" meta_type="CPS String Field"/>17 6 </object> -
WAeUP_SRP/trunk/profiles/default/types/types.xsl
r1404 r1410 101 101 </td> 102 102 <td> 103 <xsl:for-each select="permission"> 104 <xsl:value-of select="@value"/> 105 </xsl:for-each> 106 </td> 107 <td> 103 108 <xsl:value-of select="@category"/> 104 109 </td> -
WAeUP_SRP/trunk/skins/waeup_accommodation/book_reserved_bed.py
r1393 r1410 54 54 bl = ds.get('bed_letter') 55 55 bid = "%s_%s_%s" % (hall_id,br,bl) 56 res = acco_cat(bed = b ed)56 res = acco_cat(bed = bid) 57 57 psm = '' 58 58 while True: … … 79 79 button = "reserve bed", 80 80 ) 81 acco_cat.modifyRecord(bed = b ed, student = sid)81 acco_cat.modifyRecord(bed = bid, student = sid) 82 82 logger.info('"%s","booked reserved bed %s for","%s"' % (member,bed,sid)) 83 83 return context.book_reserved_bed_form(rendered = res,
Note: See TracChangeset for help on using the changeset viewer.