Editierbare Sidebar

This commit is contained in:
phil 2016-04-26 20:01:41 +00:00
parent f33a78467d
commit 21e941bf3a
5 changed files with 100 additions and 14 deletions

View file

@ -3,7 +3,7 @@
xmlns:xi="http://www.w3.org/2001/XInclude">
<xi:include href="layout.html" />
<head>
<title>Admin Ticker</title>
<title>Administration::Ticker</title>
<link href="../admin.css" type="text/css" rel="stylesheet" />
<link href="../bootstrap/css/bootstrap.min.css" type="text/css" rel="stylesheet" media="all" />
<link href="../bootstrap/css/bootstrap-theme.min.css" type="text/css" rel="stylesheet" media="all" />
@ -21,6 +21,7 @@
<ul class="nav nav-tabs">
<li role="presentation" class="active"><a href="#">New entry</a></li>
<li role="presentation"><a href="edit">All entries</a></li>
<li role="presentation"><a href="sidebar">Sidebar</a></li>
<li role="presentation"><a href="../../${static_url}" title="static website" target="_blank">Ticker</a></li>
</ul>
@ -57,3 +58,4 @@
</div>
</body>
</html>

View file

@ -44,7 +44,8 @@
<div class="panel panel-default">
<div class="panel-body">
<div id="clockbox"></div>
<!--#include file="sidebar.html" -->
<hr/>
<p>${formatter(sidebar_text)}</p>
</div>
</div>

View file

@ -3,7 +3,7 @@
xmlns:xi="http://www.w3.org/2001/XInclude">
<xi:include href="layout.html" />
<head>
<title>Admin Ticker</title>
<title>Administration::Ticker</title>
<link href="../admin.css" type="text/css" rel="stylesheet" />
<link href="../bootstrap/css/bootstrap.min.css" type="text/css" rel="stylesheet" media="all" />
<link href="../bootstrap/css/bootstrap-theme.min.css" type="text/css" rel="stylesheet" media="all" />
@ -21,6 +21,7 @@
<ul class="nav nav-tabs">
<li role="presentation"><a href="../admin">New entry</a></li>
<li role="presentation" class="active"><a href="#">All entries</a></li>
<li role="presentation"><a href="sidebar">Sidebar</a></li>
<li role="presentation"><a href="../../${static_url}" title="static website" target="_blank">Ticker</a></li>
</ul>

View file

@ -0,0 +1,41 @@
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:py="http://genshi.edgewall.org/"
xmlns:xi="http://www.w3.org/2001/XInclude">
<xi:include href="layout.html" />
<head>
<title>Administration::Ticker</title>
<link href="../admin.css" type="text/css" rel="stylesheet" />
<link href="../bootstrap/css/bootstrap.min.css" type="text/css" rel="stylesheet" media="all" />
<link href="../bootstrap/css/bootstrap-theme.min.css" type="text/css" rel="stylesheet" media="all" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
<body>
<div class="container theme-showcase" role="main">
<div class="page-header"><h1>Tycker Administration</h1></div>
<ul class="nav nav-tabs">
<li role="presentation"><a href="../admin">New entry</a></li>
<li role="presentation"><a href="edit">All entries</a></li>
<li role="presentation" class="active"><a href="#">Sidebar</a></li>
<li role="presentation"><a href="../../${static_url}" title="static website" target="_blank">Ticker</a></li>
</ul>
<div class="row">
<div class="col-xs-12 col-sm-8">
<p>&nbsp;</p>
<form action="submit_sidebar" method="GET">
<div class="form-group">
<label for="sidebar">Sidebar Content</label>
<textarea class="form-control" name="sidebar" rows="8" placeholder="required">${sidebar['sidebar']}</textarea>
</div>
<button type="submit" class="btn btn-default">Save</button>
</form>
</div>
<div class="col-xs-12 col-sm-4">
<xi:include href="help.html" />
</div>
</div>
</div>
</body>
</html>

View file

@ -52,7 +52,9 @@ class Entry(sqlobject.SQLObject):
title = sqlobject.UnicodeCol()
content = sqlobject.UnicodeCol()
class Sidebar(sqlobject.SQLObject):
sidebar = sqlobject.UnicodeCol()
def render(filename, **values):
stream = loader.load(filename).generate(**values)
return stream.render("html", doctype="html")
@ -65,27 +67,36 @@ def get_link(index):
def update_static_html():
entries = list(Entry.select().orderBy("-timestamp"))
sidebar = Sidebar.select()[0]
try:
sidebar_text = Sidebar.select()[0].sidebar
except (AttriubuteError, IndexError) as exc:
sidebar_text = ""
file_index = 1
while entries:
current = entries[:PAGE_SIZE]
entries = entries[PAGE_SIZE:]
remaining_entries = entries
while remaining_entries:
current = remaining_entries[:PAGE_SIZE]
remaining_entries = remaining_entries[PAGE_SIZE:]
current_filename = get_filename(file_index)
if file_index > 1:
previous_link = get_link(file_index - 1)
else:
previous_link = None
if entries:
if remaining_entries:
next_link = get_link(file_index + 1)
else:
next_link = None
values = { "entries": current,
"prev_link": previous_link,
"next_link": next_link,
values = {"entries": current,
"prev_link": previous_link,
"next_link": next_link,
"sidebar_text": sidebar_text,
}
# WAP unterstuetzt wohl nur Latin-1
rendered = render("display.html", **values).encode("latin-1")
open(current_filename, "w").write(rendered)
subprocess.call(["html2wml", "-n", current_filename, "-o", "ticker%d.wml" % file_index], cwd=OUTPUT_DIR)
file_index += 1
subprocess.call(["html2wml", "-n", "ticker1.html", "-o", "ticker1.wml"], cwd=OUTPUT_DIR)
@bobo.query('/submit')
def submit_entry(entry_id=None, title=None, content=None, date=None):
@ -109,6 +120,17 @@ def submit_entry(entry_id=None, title=None, content=None, date=None):
entry.date = date
update_static_html()
return bobo.redirect(BASE_URL)
@bobo.query('/submit_sidebar')
def submit_sb(sidebar=None):
sidebar = sidebar.strip()
try:
entry = Sidebar.select()[0]
entry.sidebar = sidebar
except IndexError:
Sidebar(sidebar=sidebar)
update_static_html()
return bobo.redirect(BASE_URL)
@bobo.query('/delete')
def delete_entry(entry_id):
@ -129,7 +151,7 @@ def create_entry():
values = {}
values["date_format"] = DATE_FORMAT_FULL
values["static_url"] = get_link(1)
return render("admin_create.html", **values)
return render("create.html", **values)
@bobo.query('/edit')
def edit_entries():
@ -137,7 +159,19 @@ def edit_entries():
values["entries"] = Entry.select().orderBy("-timestamp")
values["date_format"] = DATE_FORMAT_FULL
values["static_url"] = get_link(1)
return render("admin_edit.html", **values)
return render("edit.html", **values)
@bobo.query('/sidebar')
def edit_sidebar():
entries_sb = list(Sidebar.select())
if len(entries_sb) == 0:
sidebar = Sidebar(sidebar="")
else:
sidebar = entries_sb[0]
values = {}
values["sidebar"] = sidebar
values["static_url"] = get_link(1)
return render("sidebar.html", **values)
@bobo.query('')
def redirect_base():
@ -149,5 +183,12 @@ for table in (Entry, ):
if not table.tableExists():
table.createTable()
for table in (Sidebar, ):
#table.dropTable()
if not table.tableExists():
table.createTable()
#Sidebar(sidebar='Test')
application = bobo.Application(bobo_resources=__name__)