Пример #1
0
 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)
Пример #2
0
    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()
Пример #3
0
    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")
Пример #4
0
    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)