def addboat(self): payload = {} id = string.upper(self.request.get("id")) name = self.request.get("name") passcode = self.request.get("passcode") action = self.request.get("action") boat = None bpayload = {} if action == "edit" or action == "store": boat = Boat.get_by_key_name(id, parent=self.dbuser) if boat != None: payload["id"] = boat.key().name() payload["name"] = boat.boat_name payload["passcode"] = boat.passcode payload["action"] = "store" bpayload = boat.getPayload() for param in [ "yotreps_enabled", "yotreps_email", "reports_enabled", "reports_email", "reports_body", "facebook_enabled", "facebook_email", ]: if self.request.get(param) != "": payload[param] = self.request.get(param) elif boat != None: if bpayload.has_key(param): payload[param] = bpayload[param] # TODO: enable checkboxes in form if appropriate _enabled is on if action == "edit" or name == "" or id == "" or passcode == "": if action != "edit": for param in ["yotreps_email", "reports_email", "facebook_email"]: if self.request.get(param) == "": payload[param] = self.user.email() return self.render("addboat", payload) if action != "store": logging.info("Adding " + name) boat = Boat(key_name=id, parent=self.dbuser) else: logging.info("Edited " + name) boat.boat_name = name boat.passcode = passcode boat.active = True boat.setPayload(payload) logging.info(boat.payload) boat.put() # TODO: Boat with this boat_id needs to be unique! return self.handler.redirect("/list")
def persist(self,reportd,mail_message): boats = Boat.all() boats.filter("passcode = ", reportd['passcode']) boats.filter("active =", True) emaillog=EmailLog() emaillog.rawemail=db.Text(mail_message.original.as_string()) #TODO: I don't like this way of figuring out if we got any rows count=0 for boat in boats: if (boat.key().name()==string.upper(reportd['boat'])): count=count+1 break # Return the first one else: boat=None if (count <1 or boats == None or boat == None): logging.error("Unable to persist report could not find boat "+string.upper(reportd['boat'])+":"+reportd['passcode']) else: report=Report(parent=boat) report.lat=reportd['lat'] report.lon=reportd['lon'] payload={ 'comment' : reportd['comment'] } report.setPayload(payload) report.put() emaillog.report_ref=report reportd['time']=strftime("%Y/%m/%d %H:%M", gmtime()) self.outbound(boat,reportd) emaillog.put()
def download(self): lines = [] id = string.upper(self.request.get("id")) boat = Boat.get_by_key_name(id, parent=self.dbuser) lines.append('<?xml version="1.0" encoding="utf-8" ?>') lines.append( '<gpx version="1.1" creator="sailtrack" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.topografix.com/GPX/1/1" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">' ) if boat != None: reports = Report.all() reports.ancestor(boat) reports.order("created") for report in reports: comment = "" if report.payload != None and report.payload != "": comment = report.getPayload()["comment"] lines.append(' <wpt lat="%f" lon="%f">' % (report.lat, report.lon)) lines.append(" <time>%s</time>" % (report.created.strftime("%Y-%m-%dT%H:%M:%SZ"))) lines.append(" <name>%s</name>" % (escape(comment))) lines.append(" <sym>circle</sym>") lines.append(" <type>WPT</type>") lines.append(" </wpt>") self.setContentType("text/plain") lines.append("</gpx>") return "\n".join(lines)
def importc(self): datere = re.compile(r"([0-9\-]+) ([0-9:]+)") reports = Report.all() for report in reports: report.delete() imp = csv.reader(open("doc/import.csv", "rb")) boat = None for row in imp: boatid = string.upper(row[1]) if boat == None: boat = Boat.get_by_key_name(boatid, parent=self.dbuser) # logging.error(row[0]) report = Report(parent=boat) parsedate = datere.match(row[0]) date = parsedate.group(1) + " " + parsedate.group(2) tm = time.strptime(date, "%Y-%m-%d %H:%M:%S") report.created = datetime.datetime.utcfromtimestamp(time.mktime(tm)) report.lat = float(row[2]) report.lon = float(row[3]) payload = {"comment": row[4].replace("</b>", "")} # logging.error(payload) report.setPayload(payload) report.put()
def upload(self): values = {} boatid = string.upper(self.request.get("boat")) boat = Boat.get_by_key_name(boatid, parent=self.dbuser) if boat != None: upload = Upload(parent=boat) upload.data = self.request.POST.get("myfile").file.read() upload.put() values["output"] = "File was uploaded" else: values["output"] = "Error - no valid boat!" return self.render("main", values)
def map(self): track=[] marker=None boatid=string.upper(self.request.get('boat')) showmarkers=string.upper(self.request.get('markers')) showinfo=string.upper(self.request.get('popup')) zoom=self.request.get('zoom') #TODO: Validate input if (zoom==''): zoom=6 if (showmarkers==''): showmarkers='true' if (showinfo==''): showinfo='false' boats=Boat.all() # TODO: Is there a better way to filter this? We can't use key_name because we don't know ancestor for boat in boats: logging.error(boat.key().name() + " vs " + boatid) if (boat.key().name()!=boatid): boat=None; else: break if (boats != None and boat!=None): reports=Report.all() reports.ancestor(boat) reports.order("created") for report in reports: #logging.error(report.payload) entry={} entry['date']=report.created.strftime("%Y-%m-%d %H:%M:%S") entry['lat']='%.2f' % (report.lat) entry['lon']='%.2f' % (report.lon) entry['boat']=boat.key().name() comment='' if (report.payload!=None and report.payload!=''): comment=report.getPayload()['comment'] entry['comment']=comment track.append(entry) marker=entry # This is the last one values={} values['marker']=marker values['track']=track values['zoom']=zoom values['showmarkers']=string.lower(showmarkers) values['showinfo']=string.lower(showinfo) return self.render('map',values)
def list(self): values = {} boats = Boat.all() boats.ancestor(self.dbuser) boats.filter("active =", True) boats.order("created") list = [] count = 0 for boat in boats: count = count + 1 logging.info(boat.payload) tmp = { "id": boat.key().name(), "name": boat.boat_name, "passcode": boat.passcode, "payload": boat.getPayload(), } list.append(tmp) values["count"] = count values["boats"] = list return self.render("list", values)