Beispiel #1
0
 def toTree(self, parent):
     table = HTMLIntf.SubElement(parent,
                                 u"table",
                                 attrib={u"class": u"editors"})
     tbody = HTMLIntf.SubElement(table, u"tbody")
     for child in self:
         child.toTable(tbody)
Beispiel #2
0
 def renderObjectEditor(self, parent, virtualTable, obj, h1):
     virtualTable.Model = self.model
     virtualTable.Instance = obj
     validated = virtualTable.validate(self.postQuery)
     
     form = HTMLIntf.SubElement(parent, u"form", method="POST", name="editor")
     virtualTable.toTree(form)
     validate = HTMLIntf.SubElement(form, u"input", name="submit", value="Validate", type="submit")
     if "submit" in self.query and validated:
         if self.query["submit"] == "Save":
             if Store.of(obj) is None:
                 self.store.add(obj)
                 isNew = True
             else:
                 isNew = False
             virtualTable.apply(self.query)
             obj.touch()
             self.store.commit()
             self.store.flush()
             self.store.invalidate(obj)
             if isNew:
                 self.redirect(self.getUpwardsPath(unicode(obj.ID), 1))
         HTMLIntf.SubElement(form, u"input", name="submit", value="Save", type="submit")
     else:
         validate.tail = u" Please check your input."
     if Store.of(obj) is None:
         h1.text = u"Add new object"
     else:
         h1.text = u"Editing: {0}".format(unicode(obj))
         
     if Store.of(obj) is not None:
         self.renderObjectNavbar(self.navbar, virtualTable, obj)
Beispiel #3
0
 def toTree(self, parent):
     self.descriptionToTree(
         HTMLIntf.SubElement(parent,
                             u"div",
                             attrib={u"class": u"edit-description"}))
     self.editorToTree(
         HTMLIntf.SubElement(parent,
                             u"div",
                             attrib={u"class": u"edit-editor"}))
Beispiel #4
0
 def renderNavbar(self, parent, path):
     sec = HTMLIntf.SubElement(parent, u"section")
     HTMLIntf.SubElement(sec, u"h2").text = u"Available tables"
     ul = HTMLIntf.SubElement(sec, u"ul")
     basePath = self.getUpwardsPath(u"", removeSegments=len(path)+1)
     for tableName, table in UITree.virtualTables.iteritems():
         href = basePath + tableName
         a = HTMLIntf.SubElement(HTMLIntf.SubElement(ul, u"li"), u"a", href=href, title=table.description)
         a.text = tableName
Beispiel #5
0
 def renderObjectNavbar(self, navbar, virtualTable, obj):
     if len(virtualTable.referencingTables) > 0:
         section = HTMLIntf.SubElement(navbar, u"section")
         HTMLIntf.SubElement(section, u"h2").text = u"Related table views"
         ul = HTMLIntf.SubElement(section, u"ul")
         for table in virtualTable.referencingTables:
             li = HTMLIntf.SubElement(ul, u"li")
             a = HTMLIntf.SubElement(li, u"a", href=self.referencingTableHref(virtualTable, obj, table))
             a.text = table.displayName
Beispiel #6
0
 def technologyListToTree(self, parent, node):
     ul = HTMLIntf.SubElement(parent, u"ul")
     for item in node:
         li = HTMLIntf.SubElement(ul, u"li")
         a = HTMLIntf.SubElement(li, u"a", href=item[0])
         a.text = item[1]
         a.tail = item[2]
         if len(item) == 4:
             self.technologyListToTree(li, item[3])
     return ul
Beispiel #7
0
 def descriptionToTree(self, parent):
     HTMLIntf.SubElement(parent, u"p", attrib={
         u"class": u"caption"
     }).text = self.caption
     if self.description is not None:
         HTMLIntf.SubElement(parent,
                             u"p",
                             attrib={
                                 u"class": u"description"
                             }).text = self.description
Beispiel #8
0
 def modSelect(self, parent, name, selected):
     select = HTMLIntf.SubElement(parent, u"select", attrib={
         u"name": name
     })
     for modulation in self.store.find(libPriyom.Modulation).order_by(Asc(libPriyom.Modulation.Name)):
         option = HTMLIntf.SubElement(select, u"option")
         option.set(u"value", modulation.Name)
         option.text = modulation.Name
         if modulation.Name == selected:
             option.set(u"selected", u"selected")
     return select
Beispiel #9
0
 def toTable(self, tbody):
     tr = HTMLIntf.SubElement(tbody, u"tr")
     th = HTMLIntf.SubElement(tr,
                              u"th",
                              attrib={
                                  u"colspan": 2,
                                  u"class": "group"
                              })
     th.text = self.title
     for child in self:
         child.toTable(tbody)
Beispiel #10
0
 def editorToTree(self, parent):
     area = HTMLIntf.SubElement(parent, u"textarea", name=self.name)
     area.text = self.Value
     if self.rows:
         area.set(u"rows", unicode(self.rows))
     if self.cols:
         area.set(u"cols", unicode(self.cols))
     elif self.fullWidth:
         wrapper = HTMLIntf.SubElement(parent, u"div", style=u"padding-right: 1em")
         parent.remove(area)
         wrapper.append(area)
         area.set(u"style", u"width: 100%")
     super(TextArea, self).editorToTree(parent)
Beispiel #11
0
 def editorToTree(self, parent):
     super(ForeignInput, self).editorToTree(parent)
     HTMLIntf.SubElement(parent, u"br").tail = u"Foreign data (langcode / contents): "
     HTMLIntf.SubElement(parent, u"input", attrib={
         u"name": self.foreignLangName,
         u"type": u"text",
         u"value": self._foreignLang
     }).tail = u" / "
     HTMLIntf.SubElement(parent, u"input", attrib={
         u"name": self.foreignName,
         u"type": u"text",
         u"value": self._foreignValue
     })
Beispiel #12
0
 def notFound(self):
     #self.trans.rollback()
     self.trans.set_response_code(404)
     #self.trans.set_content_type(ContentType("text/plain", self.encoding))
     #print >>self.out, )
     #raise EndOfResponse
     HTMLIntf.SubElement(self.body, u"p").text = u"Table not found: \"{1}\"".format(self.trans.get_processed_virtual_path_info(), self.trans.get_virtual_path_info())
Beispiel #13
0
 def editorToTree(self, parent):
     select = HTMLIntf.SubElement(parent, u"select", attrib={
         u"name": self.name
     })
     if self.withNone is not False:
         HTMLIntf.SubElement(select, u"option", value=u"").text = self.withNone
     if self.where is not None:
         query = self.store.find(self.stormClass, self.where)
     else:
         query = self.store.find(self.stormClass)
     for item in query:
         option = HTMLIntf.SubElement(select, u"option", value=item.ID)
         option.text = unicode(item)
         if item is self.Value:
             option.set(u"selected", u"selected")
     super(SelectStormObject, self).editorToTree(parent)
Beispiel #14
0
 def editorToTree(self, parent):
     self.input = HTMLIntf.SubElement(parent, u"input", attrib={
         u"type": self.type,
         u"name": self.name,
         u"value": self.Value
     })
     if self.Disabled:
         self.input.set(u"disabled", u"disabled")
     super(Input, self).editorToTree(parent)
Beispiel #15
0
 def editorToTree(self, parent):
     super(CheckBox, self).editorToTree(parent)
     if self.label is not None:
         id = id(self)
         self.input.set(u"id", id)
         
         HTMLIntf.SubElement(parent, u"label", attrib={
             u"for": id
         }).text = self.label
Beispiel #16
0
 def __init__(self, items=[], **kwargs):
     if len(items) == 0:
         raise ValueError(u"Must have more than zero items for a Select.")
     super(Select, self).__init__(**kwargs)
     self.items = items
     self.hasDynamicItems = False
     self.reference = HTMLIntf.Element(u"select", name=self.name)
     for value, caption, enabled in self.items:
         if not callable(enabled):
             enabledCall = None
             if not enabled:
                 continue
         else:
             self.hasDynamicItems = True
             enabledCall = enabled
         option = HTMLIntf.SubElement(self.reference, u"option", value=value)
         option.text = caption
         option.enabled = enabledCall
Beispiel #17
0
 def __init__(self, priyomInterface):
     self.priyomInterface = priyomInterface
     self.store = self.priyomInterface.store
     self.serializer = XMLIntf.Serializer()
     self.xhtmlSerializer = HTMLIntf.Serializer()
     self.currentFlags = None
     self.limit = None
     self.offset = None
     self.distinct = False
     self.resetStore()
Beispiel #18
0
 def buildDoc(self, trans, elements):
     sec = HTMLIntf.SubElement(self.body, u"section")
     head = HTMLIntf.SubElement(sec, u"header")
     HTMLIntf.SubElement(head, u"h1").text = u"priyom.org/admin"
     HTMLIntf.SubElement(
         sec, u"p"
     ).text = u"Welcome to the administration area of api.priyom.org. Here you can more or less directly modify database contents."
     HTMLIntf.SubElement(
         sec, u"p"
     ).text = u"Choose which section of the admin area you want to use:"
     ul = HTMLIntf.SubElement(sec, u"ul")
     li = HTMLIntf.SubElement(ul, u"li")
     a = HTMLIntf.SubElement(HTMLIntf.SubElement(li, u"p"),
                             u"a",
                             href="tables/")
     a.text = u"Table editor"
     HTMLIntf.SubElement(
         li, u"p"
     ).text = u"This tool allows you to edit database contents in a safe manner (that is, with consistency checks etc.)"
Beispiel #19
0
 def editorToTree(self, parent):
     # super(EditorComponent, self).editorToTree(parent)
     if self.Error is not None:
         div = HTMLIntf.SubElement(parent,
                                   u"div",
                                   attrib={u"class": u"error"})
         if type(self.Error) == ElementTree.Element:
             div.append(self.Error)
         else:
             div.text = unicode(self.Error)
Beispiel #20
0
 def buildDoc(self, trans, elements):
     path = trans.get_virtual_path_info().split('/')[1:]
     if len(path) == 0:
         self.redirect()
     
     self.table = path[0]
     if not self.table:
         self.table = None
     #if self.table and not self.table in UITree.virtualTables:
     #    self.notFound()
     
     self.link(u"/css/admin.css")
     
     self.navbar = HTMLIntf.SubElement(self.body, u"navbar")
     self.editor = HTMLIntf.SubElement(self.body, u"section", attrib={
         u"class": u"editor"
     })
     
     self.renderNavbar(self.navbar, path[1:])
     self.renderEditor(self.editor, path[1:])
Beispiel #21
0
 def newSelect(self, parent, name):
     select = HTMLIntf.SubElement(parent, u"select", attrib={
         u"name": name
     })
     option = HTMLIntf.SubElement(select, u"option")
     option.set(u"value", u"0 AM")
     option.text = u"Select a known frequency or just add a custom one"
     knownFrequencies = self.store.using(
         libPriyom.BroadcastFrequency, 
         LeftJoin(libPriyom.Modulation, libPriyom.Modulation.ID == libPriyom.BroadcastFrequency.ModulationID), 
         LeftJoin(libPriyom.Broadcast, libPriyom.BroadcastFrequency.BroadcastID == libPriyom.Broadcast.ID)
     ).find(
         (libPriyom.BroadcastFrequency.Frequency, libPriyom.Modulation.Name), 
         libPriyom.Broadcast.StationID == self.Instance.Station.ID
     ).config(distinct=True) if self.Instance.Station is not None else None
     for frequency, modulation in knownFrequencies:
         option = HTMLIntf.SubElement(select, u"option")
         option.set(u"value", u"{0} {1}".format(frequency, modulation))
         option.text = u"{0}, {1}".format(libPriyom.BroadcastFrequency.formatFrequency(frequency), modulation)
     return select
Beispiel #22
0
 def inputToRow(self, row, item):
     td = HTMLIntf.SubElement(row, u"td")
     freqInput = HTMLIntf.SubElement(td, u"input", attrib={            
         u"name": self.itemPrefix+item[0]+self.freqSuffix,
         u"value": libPriyom.BroadcastFrequency.formatFrequency(item[1]),
     })
     
     td = HTMLIntf.SubElement(row, u"td")
     #modInput = HTMLIntf.SubElement(td, u"input", attrib={
     #    u"name": self.itemPrefix+item[0]+self.modSuffix,
     #    u"value": 
     #})
     modSelect = self.modSelect(td, self.itemPrefix+item[0]+self.modSuffix, item[2])
     
     td = HTMLIntf.SubElement(row, u"td")
     updateInput = HTMLIntf.SubElement(td, u"input", attrib={
         u"type": u"submit",
         u"name": self.itemPrefix+item[0]+self.updateSuffix,
         u"value": "Validate",
         u"class": "hidden"
     })
     deleteInput = HTMLIntf.SubElement(td, u"input", attrib={
         u"type": u"submit",
         u"name": self.itemPrefix+item[0]+self.deleteSuffix,
         u"value": u"✗"
     })
Beispiel #23
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)
Beispiel #24
0
 def renderReferencedTable(self, parent, virtualTable, obj, referencingTable, referencedVirtualTable, h1):
     h1.text = u"Rows of “{1}” referencing {0}".format(unicode(obj), referencingTable.name)
     referencedVirtualTable.Model = self.model
     
     orderColumn = self.getQueryValue(u"orderColumn", referencedVirtualTable.columnMap.get, default=referencedVirtualTable.columns[0])
     orderDirection = self.getQueryValue(u"orderDirection", unicode, default=u"ASC")
     if not orderDirection in (u"ASC", u"DESC"):
         orderDirection = u"ASC"
     offset = self.getQueryValue(u"offset", int, default=0)
     
     a = HTMLIntf.SubElement(parent, u"a", href=self.editItemHref(virtualTable.name, obj.ID))
     a.text = u"Return to {0}".format(unicode(obj))
     
     self.renderHTMLTable(parent, referencedVirtualTable, referencingTable.select(referencedVirtualTable, obj, orderColumn, orderDirection), orderColumn, orderDirection, offset)
     
     self.renderObjectNavbar(self.navbar, virtualTable, obj)
Beispiel #25
0
    def editorToTree(self, parent):
        table = HTMLIntf.SubElement(parent, u"table", attrib={
            u"class": "list fit"
        })
        colgroup = HTMLIntf.SubElement(table, u"colgroup")
        thead = HTMLIntf.SubElement(table, u"thead")
        
        HTMLIntf.SubElement(colgroup, u"col", span="1")
        HTMLIntf.SubElement(colgroup, u"col", span="1")
        HTMLIntf.SubElement(colgroup, u"col", span="1", attrib={
            u"class": u"buttons"
        })
        
        HTMLIntf.SubElement(thead, u"th").text = u"Frequency"
        HTMLIntf.SubElement(thead, u"th").text = u"Modulation"
        HTMLIntf.SubElement(thead, u"th", attrib={
            u"class": u"buttons"
        }).text = u"Act."
        
        tbody = HTMLIntf.SubElement(table, u"tbody")
        for item in self.Value:
            tr = HTMLIntf.SubElement(tbody, u"tr")
            self.inputToRow(tr, item)
        
        addDiv = HTMLIntf.SubElement(parent, u"div")
        newInput = self.newSelect(addDiv, self.newName)
        
        addInput = HTMLIntf.SubElement(addDiv, u"input", attrib={
            u"name": self.addName,
            u"type": u"submit",
            u"value": u"Add"
        })
        
        super(BroadcastFrequencies, self).editorToTree(parent)

            
Beispiel #26
0
 def renderHTMLTable(self, parent, virtualTable, resultSet, orderColumn, orderDirection, offset, limit=30, allowNew=False):
     limit = 30
     
     paginationElement = HTMLIntf.SubElement(parent, u"div", attrib={
         u"class": u"button-bar pagination"
     })
     HTMLIntf.SubElement(paginationElement, u"span").text = u"Pages:"
     pagesUl = HTMLIntf.SubElement(paginationElement, u"ul")
     
     if allowNew:
         tableActions = HTMLIntf.SubElement(parent, u"div", attrib={
             u"class": u"button-bar"
         })
         HTMLIntf.SubElement(tableActions, u"span").text = u"Actions:"
         actionsUl = HTMLIntf.SubElement(tableActions, u"ul")
         new = HTMLIntf.SubElement(HTMLIntf.SubElement(actionsUl, u"li"), u"a", href=self.editItemHref(virtualTable.name, "new"), title="Create a new object")
         new.text = u"New"
     
     table = HTMLIntf.SubElement(parent, u"table", attrib={
         u"class": u"list view"
     })
     colgroup = HTMLIntf.SubElement(table, u"colgroup")
     thead = HTMLIntf.SubElement(table, u"thead")
     
     HTMLIntf.SubElement(thead, u"th", attrib={
         u"class": u"buttons"
     }).text = u"Act."
     HTMLIntf.SubElement(colgroup, u"col", span="1").set("style", "width: 8em;")
     
     for column in virtualTable.columns:
         th = HTMLIntf.SubElement(thead, u"th")
         if Sortable in column:
             a = HTMLIntf.SubElement(th, u"a")
             order = HTMLIntf.SubElement(a, u"div", attrib={
                 u"class": u"order"
             })
             order.tail = column.title
         
             if orderColumn is not column:
                 a.set(u"href", self.buildQueryOnSameTable(orderColumn=column.name, orderDirection=column.defaultSort))
             else:
                 if orderDirection == u"ASC":
                     a.set(u"href", self.buildQueryOnSameTable(orderColumn=column.name, orderDirection=u"DESC"))
                     order.text = u"▲"
                 else:
                     a.set(u"href", self.buildQueryOnSameTable(orderColumn=column.name, orderDirection=u"ASC"))
                     order.text = u"▼"
         else:
             th.set(u"class", u"static")
             HTMLIntf.SubElement(th, u"div").text = column.title
         
         col = HTMLIntf.SubElement(colgroup, u"col", span="1")
         if column.width is not None:
             col.set(u"style", u"width: {0};".format(column.width))
         
     
     tbody = HTMLIntf.SubElement(table, u"tbody")
     
     amount = resultSet.count()
     if offset >= amount:
         offset = 0
     resultSet.config(offset=offset, limit=limit)
     
     for obj in resultSet:
         if not isinstance(obj, tuple):
             id = obj.ID
             obj = (obj,)
         else:
             id = obj[0].ID
         tr = HTMLIntf.SubElement(tbody, u"tr")
         actions = HTMLIntf.SubElement(tr, u"td", attrib={
             u"class": u"buttons"
         })
         HTMLIntf.SubElement(actions, u"a", href=self.editItemHref(virtualTable.name, id), title=u"Edit / View this row in detail").text = u"E"
         HTMLIntf.SubElement(actions, u"a", href=self.buildQueryOnSameTable(orderColumn=orderColumn.name, orderDirection=orderDirection, touch=id), title=u"Touch this object (set the Modified timestamp to the current time).").text = u"T"
         for column in virtualTable.columns:
             HTMLIntf.SubElement(tr, u"td").text = column.getFormattedValue(obj)
     
     pages = int(amount/limit)
     if pages*limit < amount:
         pages += 1
     
     for pageNumber in xrange(1,pages+1):
         a = HTMLIntf.SubElement(HTMLIntf.SubElement(pagesUl, u"li"), u"a", href=self.buildQueryOnSameTable(orderColumn=orderColumn.name, orderDirection=orderDirection, offset=(pageNumber-1)*limit))
         a.text = unicode(pageNumber)
         if pageNumber == (offset/limit)+1:
             a.set(u"class", u"current")
     
     parent.append(paginationElement)
Beispiel #27
0
    def buildDoc(self, trans, elements):
        self.link(u"css/home.css")
        self.setTitle(u"Priyom.org API")

        section = HTMLIntf.SubElement(self.body, u"section")
        HTMLIntf.SubElement(section, u"h1").text = u"Welcome!"
        HTMLIntf.SubElement(section,
                            u"h2").text = u"… to the priyom.org API server."
        p = HTMLIntf.SubElement(section, u"p")
        p.text = u"This is the API server which does the hard number station database work behind the curtains of "
        a = HTMLIntf.SubElement(p, u"a", href=u"http://priyom.org")
        a.text = u"priyom.org"
        a.tail = u"."

        p = HTMLIntf.SubElement(section, u"p")
        stats = self.priyomInterface.getStatistics()
        p.text = u"Currently, we have {0} stations with {1} broadcasts and {2} transmissions, containing {4} transmission items in our database. In average, about {3} transmissions occur per broadcast and each transmission contains (in average) {5} transmission items.".format(
            *stats)

        p = HTMLIntf.SubElement(section, u"p")
        p.text = u"Found a malfunction? Flic over a mail to "
        a = HTMLIntf.SubElement(p,
                                u"a",
                                href=u"mailto:{0}".format(
                                    admin.get(u"mail",
                                              u"*****@*****.**")))
        a.text = admin.get(u"name", u"Horrorcat")
        a.tail = u" or check out our IRC channel "
        a = HTMLIntf.SubElement(p, u"a", href=u"irc:irc.freenode.net/#priyom")
        a.text = u"#priyom on irc.freenode.net"
        a.tail = u"."

        p = HTMLIntf.SubElement(section, u"p")
        p.text = u"Looking for documentation? Try "
        a = HTMLIntf.SubElement(p, u"a", href=u"doc/")
        a.text = u"this link"
        a.tail = u"."

        HTMLIntf.SubElement(
            section, u"p"
        ).text = u"This database server is set on open-source techonolgies only:"
        self.technologyListToTree(section, self.technologies)

        newsSection = HTMLIntf.SubElement(section, u"section")
        HTMLIntf.SubElement(newsSection,
                            u"h3").text = u"News / current information"

        table = HTMLIntf.SubElement(newsSection,
                                    u"table",
                                    attrib={u"class": u"news-table"})
        thead = HTMLIntf.SubElement(table, u"thead")
        HTMLIntf.SubElement(thead, u"th", width=u"200pt").text = u"Timestamp"
        HTMLIntf.SubElement(thead, u"th", width=u"350pt").text = u"Title"
        HTMLIntf.SubElement(thead, u"th").text = u"Contents"

        tbody = HTMLIntf.SubElement(table, u"tbody")
        news = self.store.find(APINews)
        news.order_by(Desc(APINews.Timestamp))
        news.config(limit=5)

        for item in news:
            tr = HTMLIntf.SubElement(tbody, u"tr")
            item.toTableRow(tr)
Beispiel #28
0
 def toTableRow(self, tr):
     HTMLIntf.SubElement(tr, u"td").text = TimeUtils.fromTimestamp(
         self.Timestamp).strftime(priyomdate)
     HTMLIntf.SubElement(tr, u"th").text = self.Title
     HTMLIntf.SubElement(HTMLIntf.SubElement(tr, u"td"),
                         u"p").text = self.Contents
Beispiel #29
0
 def toTableRow(self, tr):
     self.component.descriptionToTree(HTMLIntf.SubElement(tr, u"th"))
     self.component.editorToTree(HTMLIntf.SubElement(tr, u"td"))
Beispiel #30
0
 def toTable(self, tbody):
     self.toTableRow(HTMLIntf.SubElement(tbody, u"tr"))