Esempio n. 1
0
    def __init__(self, model):
        super(SubmitEventResource, self).__init__(model)
        self.allowedMethods = frozenset(("GET", "POST"))

        self.startTimeTypecast = Typecasts.PriyomTimestamp()
        self.endTimeTypecast = Typecasts.AllowBoth(Typecasts.PriyomTimestamp(),
                                                   Typecasts.EmptyString())
Esempio n. 2
0
    def buildDoc(self, trans, elements):
        super(SubmitEventResource, self).buildDoc(trans, elements)

        self.station = self.getQueryValue("station",
                                          Typecasts.ValidStormObject(
                                              Station, self.store),
                                          defaultKey=None)
        self.eventClass = self.getQueryValue("eventClass",
                                             Typecasts.AllowBoth(
                                                 Typecasts.ValidStormObject(
                                                     EventClass, self.store),
                                                 Typecasts.EmptyString()),
                                             defaultKey=None)
        if self.eventClass == u"":
            self.eventClass = None
        self.startTime = self.getQueryValue("startTime",
                                            Typecasts.PriyomTimestamp(),
                                            defaultKey=TimeUtils.nowDate())
        self.endTime = self.getQueryValue("endTime",
                                          Typecasts.AllowBoth(
                                              Typecasts.PriyomTimestamp(),
                                              Typecasts.EmptyString()),
                                          defaultKey=None)
        if self.endTime == u"":
            self.endTime = None
        self.description = self.query.get("description", u"")
        if len(self.description) < 10:
            self.error = u"Description must be at least 10 characters long."

        self.link(u"/css/submit.css")
        self.setTitle(u"Submit event")

        submitted = False
        if "submit" in self.query and self.error is None:
            try:
                self.insert()
                submitted = True
            except SubmitParameterError:
                submitted = False

        if not submitted:
            self.SubElement(self.body,
                            u"pre").text = self.recursiveDict(self.query)
            if self.error is not None:
                self.SubElement(self.body, u"div", attrib={
                    u"class": u"error"
                }).text = self.error

            form = self.SubElement(self.body,
                                   u"form",
                                   name=u"logform",
                                   method=u"POST")

            self._eventInformationTree(self.section(form,
                                                    u"Event information"))
            self._descriptionTree(self.section(form, u"Description"))

            self.input(form, type=u"submit", name=u"submit", value=u"Submit")

            self._noteTree(self.section(self.body, u"Notes"))
Esempio n. 3
0
    def insert(self):
        self.station = self.getQueryValue(
            "station", Typecasts.ValidStormObject(Station, self.store))

        if self.error is not None:
            self.setError(self.error)

        event = Event()
        try:
            event.Station = self.station
            event.StartTime = TimeUtils.toTimestamp(self.startTime)
            event.EndTime = TimeUtils.toTimestamp(
                self.endTime) if self.endTime is not None else None
            event.Description = self.description
            event.EventClass = self.eventClass
        except BaseException as e:
            del event
            self.setError(unicode(e))
        self.store.add(event)
        self.store.commit()

        self.SubElement(self.body, u"pre").text = u"""Added new event
Station: {0}
Event (#{2}): {1}""".format(unicode(event.Station), unicode(event),
                            unicode(event.ID))
Esempio n. 4
0
 def __init__(self, rows=None, cols=None, fullWidth=False, typecast=Typecasts.NoneAsEmpty(), **kwargs):
     if cols is not None and fullWidth:
         raise ValueError(u"Cannot specify both cols= and fullWidth=True for a TextArea")
     super(TextArea, self).__init__(typecast=typecast, **kwargs)
     self.rows = int(rows) if rows is not None else None
     self.cols = int(cols) if cols is not None else None
     self.fullWidth = bool(fullWidth)
Esempio n. 5
0
 def renderEditor(self, parent, path):
     h1 = HTMLIntf.SubElement(HTMLIntf.SubElement(parent, u"header"), u"h1")
     
     if self.table is None:
         h1.text = u"Welcome to the API table editor"
         HTMLIntf.SubElement(parent, u"p").text = u"Please select a table from the left to start editing contents."
         return
     
     if not self.table in UITree.virtualTables:
         h1.text = u"""Table "{0}" not found!""".format(self.table)
         HTMLIntf.SubElement(parent, u"p").text = u"The table you are trying to access does not exist!"
         return
     
     virtualTable = UITree.virtualTables[self.table]
     if len(path) == 0:
         # show the table
         self.renderTable(parent, virtualTable, h1)
     elif len(path) == 1:
         # show item editor
         try:
             if path[0] == "new":
                 obj = virtualTable.cls()
             else:
                 obj = Typecasts.ValidStormObject(virtualTable.cls, self.store)(path[0])
         except:
             self.redirectUpwards()
         else:
             self.renderObjectEditor(parent, virtualTable, obj, h1)
     elif len(path) == 2:
         # show table of related objects
         if path[0] == "new":
             self.redirectUpwards()
         obj = Typecasts.ValidStormObject(virtualTable.cls, self.store)(path[0])
         try:
             referencingTable = virtualTable.referencingTableMap[path[1]]
             referencedVirtualTable = UITree.virtualTables[referencingTable.name]
         except KeyError:
             self.redirectUpwards()
         else:
             self.renderReferencedTable(parent, virtualTable, obj, referencingTable, referencedVirtualTable, h1)
Esempio n. 6
0
    def __init__(self, model):
        super(SubmitLogResource, self).__init__(model)
        self.allowedMethods = frozenset(["GET", "POST"])

        self.stationValidator = Typecasts.ValidStormObject(Station, self.store)
        self.timestampValidator = Typecasts.PriyomTimestamp()
        self.durationValidator = float
        self.unicodeValidator = unicode

        self.broadcastValidator = Typecasts.AllowBoth(
            Typecasts.ValidStormObject(Broadcast, self.store),
            Typecasts.EmptyString())

        self.transmissionClassValidator = Typecasts.ValidStormObject(
            TransmissionClass, self.store)
Esempio n. 7
0
def get_site_map(priyomInterface):
    rootPath = application["root"]

    model = WebModel(priyomInterface)

    for table in virtualTables.itervalues():
        table.Model = model

    apiMap = MapSelector(
        "calls", {
            "getUpcomingBroadcasts":
            UpcomingBroadcastsAPI(model),
            "import":
            AuthorizationSelector(ImportAPI(model), "transaction"),
            "listStations":
            ListAPI(model, libPriyom.Station),
            "listBroadcasts":
            AuthorizationSelector(ListAPI(model, libPriyom.Broadcast, "list"),
                                  "list"),
            "listTransmissionClasses":
            ListAPI(model, libPriyom.TransmissionClass),
            "listTransmissions":
            AuthorizationSelector(
                ListAPI(model, libPriyom.Transmission, "list"), "list"),
            "listModulations":
            ListModulationsAPI(model),
            "getSession":
            SessionAPI(model),
            "getTransmissionStats":
            TransmissionStatsAPI(model),
            "getTransmissionsByMonth":
            TransmissionsByMonthAPI(model),
            "getCloseBroadcasts":
            CloseBroadcastsAPI(model),
            "getStationFrequencies":
            StationFrequenciesAPI(model),
            "instanciateSchedules":
            AuthorizationSelector(InstanciateSchedulesAPI(model),
                                  "instanciate"),
            "getTransmissionsByYear":
            TransmissionsByYearAPI(model),
            "getDuplicatedTransmissionItems":
            DuplicatedTransmissionItemsAPI(model),
            "plot":
            MapSelector(
                "plots", {
                    "station":
                    MapSelector(
                        "station", {
                            "hourWeekPunchCard":
                            PlotAPI(
                                model,
                                PlotDataSources.PlotDataWeekHourPunch(
                                    model.store), Plots.PlotPunchCard(),
                                [("station", Typecasts.ValidStation(
                                    model.store), "station")],
                                u"punchcard-hw"),
                            "hourMonthPunchCard":
                            PlotAPI(
                                model,
                                PlotDataSources.PlotDataMonthHourPunch(
                                    model.store), Plots.PlotPunchCard(),
                                [("station", Typecasts.ValidStation(
                                    model.store), "station")],
                                u"punchcard-mw"),
                            "hourWeekColourCard":
                            PlotAPI(
                                model,
                                PlotDataSources.PlotDataWeekHourPunch(
                                    model.store),
                                Plots.PlotColourCard(),
                                [("station", Typecasts.ValidStation(
                                    model.store), "station")],
                                u"colourcard-hw",
                                subdivision=32,
                                levels=23,
                                mirrored=2),
                            "hourMonthColourCard":
                            PlotAPI(
                                model,
                                PlotDataSources.PlotDataMonthHourPunch(
                                    model.store),
                                Plots.PlotColourCard(),
                                [("station", Typecasts.ValidStation(
                                    model.store), "station")],
                                u"colourcard-mw",
                                subdivision=32,
                                levels=23,
                                mirrored=2)
                        }),
                    "uptime":
                    PlotAPI(model,
                            PlotDataSources.PlotDataUptime(model.store),
                            Plots.PlotStackedGraph(),
                            [("station", Typecasts.ValidStation(
                                model.store), "station", None),
                             ("years", Typecasts.RangeCheck(int, 1,
                                                            10), "years", 5)],
                            u"uptime",
                            years=5)
                })
        })
    apiMap[""] = apiMap

    apiRoot = MapSelector(
        "API root", {
            "station":
            StationResource(model),
            "broadcast":
            IDResource(model, libPriyom.Broadcast),
            "transmission":
            IDResource(model, libPriyom.Transmission),
            "transmissionClass":
            IDResource(model, libPriyom.TransmissionClass),
            "schedule":
            IDResource(model, libPriyom.Schedule),
            "submit":
            AuthorizationSelector(
                MapSelector(
                    u"submit", {
                        "log": SubmitLogResource(model),
                        "event": SubmitEventResource(model)
                    }), ["log", "log-moderated"]),
            "admin":
            AuthorizationSelector(
                MapSelector(
                    u"admin", {
                        "":
                        AdminHomeResource(model),
                        "tables":
                        AuthorizationSelector(AdminTablesResource(model),
                                              ["admin"]),
                    }), ["moderate", "admin"]),
            "call":
            apiMap,
            "doc":
            DocumentationSelector(apiMap),
            "":
            HomeResource(model),
            "css":
            MapResource({
                "home.css":
                FileResource(os.path.join(rootPath, "www-files/css/home.css"),
                             ContentType("text/css", "utf-8")),
                "error.css":
                FileResource(os.path.join(rootPath, "www-files/css/error.css"),
                             ContentType("text/css", "utf-8")),
                "submit.css":
                FileResource(
                    os.path.join(rootPath, "www-files/css/submit.css"),
                    ContentType("text/css", "utf-8")),
                "admin.css":
                FileResource(os.path.join(rootPath, "www-files/css/admin.css"),
                             ContentType("text/css", "utf-8"))
            }),
            "js":
            MapResource({
                "jquery.js":
                FileResource(os.path.join(rootPath, "www-files/js/jquery.js"),
                             ContentType("text/javascript", "utf-8"))
            })
        })
    apiRoot["submit"][""] = apiRoot["submit"].resource

    return ContinueSelector(
        CompressionSelector(
            ExceptionSelector(
                CatchDisconnectSelector(
                    ResetSelector(model,
                                  AuthenticationSelector(model.store,
                                                         apiRoot)),
                    model.store), model)))
Esempio n. 8
0
 def __init__(self, allowNone=False, **kwargs):
     super(Timestamp, self).__init__(type=Input.TEXT, typecast=Typecasts.PriyomTimestamp(allowNone=allowNone, asDate=False), **kwargs)