from owrx.controllers.template import WebpageController from owrx.controllers.admin import AuthorizationMixin from owrx.bookmarks import Bookmark, Bookmarks from owrx.modes import Modes class BookmarksController(AuthorizationMixin, WebpageController): def header_variables(self): variables = super().header_variables() variables["assets_prefix"] = "../" return variables def template_variables(self): variables = super().template_variables() variables["bookmarks"] = self.render_table() return variables def render_table(self): bookmarks = Bookmarks.getSharedInstance() def render_mode(m): return """ """.format( mode=m.modulation, name=m.name, ) return """ {bookmarks}
Name Frequency Modulation Actions
""".format( bookmarks="".join(self.render_bookmark(idx, b) for idx, b in enumerate(bookmarks.getBookmarks())), options="".join(render_mode(m) for m in Modes.getAvailableModes()), ) def render_bookmark(self, idx: int, bookmark: Bookmark): mode = Modes.findByModulation(bookmark.getModulation()) return """ {name} {frequency} {modulation_name}
delete
""".format( index=idx, id=id(bookmark), name=bookmark.getName(), frequency=bookmark.getFrequency(), modulation=bookmark.getModulation() if mode is None else mode.modulation, modulation_name=bookmark.getModulation() if mode is None else mode.name, ) def indexAction(self): self.serve_template("settings/bookmarks.html", **self.template_variables())