HMS

Home Media Server for Roku Players
git clone https://www.brianlane.com/git/HMS
Log | Files | Refs | README | LICENSE

commit a056dd80347fbd002c9c68c246d35f0037509232
parent f3ee0bc4e439ad43b9109c4f471a2cbbf50328a8
Author: Brian C. Lane <bcl@brianlane.com>
Date:   Thu,  4 Mar 2010 20:38:07 -0800

Added editing of Media Sources

Diffstat:
Mserver/hms/hms.py | 48++++++++++++++++++++++++++++++++++++++++++++++++
Aserver/hms/templates/sourceedit.html | 37+++++++++++++++++++++++++++++++++++++
2 files changed, 85 insertions(+), 0 deletions(-)

diff --git a/server/hms/hms.py b/server/hms/hms.py @@ -665,7 +665,54 @@ class LogoutHandler(BaseHandler): def get(self): self.set_secure_cookie("user", "") self.redirect("/login") + +class SourceEditHandler(BaseHandler): + """ + Handle Editing the Media sources + """ + @tornado.web.authenticated + def get(self, id): + if self.current_user != 'admin': + self.redirect("/") + + conn = sqlite3.connect(options.database) + conn.row_factory = sqlite3.Row + cur = conn.cursor() + cur.execute("select * from source where id=?", (id,)) + row = cur.fetchone() + cur.close() + conn.close() + + name = tornado.escape.xhtml_escape(self.current_user) + self.render(os.path.join("templates","sourceedit.html"), + source=row, + name=name) + + @tornado.web.authenticated + def post(self, id): + if self.current_user != 'admin': + self.redirect("/") + return + + sql_set = [] + sql_args = [] + for field in self.request.arguments: + if field[0] == "_": + continue + sql_set.append("%s=?" % (field)) + sql_args.append(self.get_argument(field)) + + sql_args.append(int(id)) + sql = "update source set %s where id=?" % ",".join(sql_set) + conn = sqlite3.connect(options.database) + conn.row_factory = sqlite3.Row + cur = conn.cursor() + cur.execute(sql, sql_args) + conn.commit() + + self.redirect("/source/") + class SourceHandler(BaseHandler): """ @@ -1320,6 +1367,7 @@ def main(): (r"/", MainHandler), (r"/login", LoginHandler), (r"/logout", LogoutHandler), + (r"/source/edit/(.*)", SourceEditHandler), (r"/source/(.*)", SourceHandler), (r"/media/list/(.*)/(.*)", MediaListHandler), (r"/media/edit/(.*)", MediaEditHandler), diff --git a/server/hms/templates/sourceedit.html b/server/hms/templates/sourceedit.html @@ -0,0 +1,37 @@ +{% extends "base.html" %} + +{% block title %}Edit Media Source{% end %} + +{% block body %} +<div id="Source"> +<fieldset> +<legend>Edit Media Source</legend> +<form action="{{ request.path }}" method="post" id="sourceForm"> + <div class="form-input"> + <label for="name">{{ _("Source Name") }}</label> + <input type="text" name="name" id="name" size="40" value="{{ source["name"] }}"/> + </div> + + <div class="form-input"> + <label for="type">{{ _("Type") }}</label> + <select name="type" id="type"> + <option value="local" {% if source["type"] == "local" %}selected{% end %}>Local Directory</option> + <option value="remote" {% if source["type"] == "remote" %}selected{% end %}>Remote URL</option> + </select> + </div> + + <div class="form-input"> + <label for="path">{{ _("Path") }}</label> + <input type="text" name="path" id="path" size="40" value="{{ source["path"] }}"/> + </div> + + <div class="submit"> + <input type="submit" value="{{ _("Update") }}"/> + </div> + {{ xsrf_form_html() }} +</form> +</fieldset> + +</div> + +{% end %}