def createCSV(resvs, req): results=[['URL', 'id', 'start date', 'end date', 'name', 'site', 'building', 'floor', 'roomNr', 'IP', 'H323 IP', 'uses VC equipment' ]] for collision in resvs: resv = collision.withReservation if resv.usesAVC: usesAVC = 1 else: usesAVC = 0 results.append([str(UHRoomBookingBookingDetails.getURL(resv)), str(resv.id), collision.startDT.strftime("%Y-%m-%d %H:%M:%S"), collision.endDT.strftime("%Y-%m-%d %H:%M:%S"), resv.room.name or "", resv.room.site, str(resv.room.building), resv.room.floor, str(resv.room.roomNr), resv.room.customAtts.get('IP') or "", resv.room.customAtts.get('H323 IP') or "", usesAVC ]) #################### create temp file ################### cfg = Config.getInstance() tempPath = cfg.getUploadedFilesTempDir() tempFileName = tempfile.mkstemp( prefix="Bookings", suffix=".csv", dir = tempPath )[1] #################### write the results in the temp file ################### fd=open(tempFileName, 'w') writer = csv.writer(fd, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL) for i in results: writer.writerow(i) fd.close() #################### return the CSV file ################### req.headers_out["Content-Length"] = "%s"%int(os.stat(tempFileName)[stat.ST_SIZE]) mimetype = cfg.getFileTypeMimeType( cfg.getFileType("CSV") ) req.content_type = """%s"""%(mimetype) req.headers_out["Content-Disposition"] = """inline; filename="%s\""""%cleanHTMLHeaderFilename(os.path.basename(tempFileName)) fr = open(tempFileName, "rb") data = fr.read() fr.close() return data
class IReservationFossil(IFossil): """ Fossil inteface for reservation """ def id(self): """ Id of the reservation """ def bookedForName(self): """ Name of the reservation owner """ def getBookingUrl(self): """ URL to reservation details webpage """ getBookingUrl.produce = lambda s: str(UHRoomBookingBookingDetails.getURL( s )) def reason(self): """ Reason of the reservation """
class IReservationMetadataFossilBase(IFossil): def id(self): pass def startDT(self): pass startDT.convert = Conversion.naive def endDT(self): pass endDT.convert = Conversion.naive def repeatability(self): pass # None or a nice short name repeatability.convert = lambda r: RepeatabilityEnum.rep2shortname[r] if r is not None else None def bookedForName(self): pass def getBookingUrl(self): pass getBookingUrl.produce = lambda s: str(UHRoomBookingBookingDetails.getURL(s)) def reason(self): pass def usesAVC(self): pass def needsAVCSupport(self): pass def useVC(self): pass def isConfirmed(self): pass def isValid(self): pass useVC.name = 'vcList' useVC.produce = lambda x: x.useVC if hasattr(x, 'useVC') else None
def _produce_booking_url(resv): if resv.id is None: # Booking is not saved yet return None return str(UHRoomBookingBookingDetails.getURL(resv))