Editierbare Sidebar
This commit is contained in:
parent
f33a78467d
commit
21e941bf3a
5 changed files with 100 additions and 14 deletions
|
@ -3,7 +3,7 @@
|
||||||
xmlns:xi="http://www.w3.org/2001/XInclude">
|
xmlns:xi="http://www.w3.org/2001/XInclude">
|
||||||
<xi:include href="layout.html" />
|
<xi:include href="layout.html" />
|
||||||
<head>
|
<head>
|
||||||
<title>Admin Ticker</title>
|
<title>Administration::Ticker</title>
|
||||||
<link href="../admin.css" type="text/css" rel="stylesheet" />
|
<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.min.css" type="text/css" rel="stylesheet" media="all" />
|
||||||
<link href="../bootstrap/css/bootstrap-theme.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">
|
<ul class="nav nav-tabs">
|
||||||
<li role="presentation" class="active"><a href="#">New entry</a></li>
|
<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="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>
|
<li role="presentation"><a href="../../${static_url}" title="static website" target="_blank">Ticker</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
@ -57,3 +58,4 @@
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -44,7 +44,8 @@
|
||||||
<div class="panel panel-default">
|
<div class="panel panel-default">
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
<div id="clockbox"></div>
|
<div id="clockbox"></div>
|
||||||
<!--#include file="sidebar.html" -->
|
<hr/>
|
||||||
|
<p>${formatter(sidebar_text)}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
xmlns:xi="http://www.w3.org/2001/XInclude">
|
xmlns:xi="http://www.w3.org/2001/XInclude">
|
||||||
<xi:include href="layout.html" />
|
<xi:include href="layout.html" />
|
||||||
<head>
|
<head>
|
||||||
<title>Admin Ticker</title>
|
<title>Administration::Ticker</title>
|
||||||
<link href="../admin.css" type="text/css" rel="stylesheet" />
|
<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.min.css" type="text/css" rel="stylesheet" media="all" />
|
||||||
<link href="../bootstrap/css/bootstrap-theme.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">
|
<ul class="nav nav-tabs">
|
||||||
<li role="presentation"><a href="../admin">New entry</a></li>
|
<li role="presentation"><a href="../admin">New entry</a></li>
|
||||||
<li role="presentation" class="active"><a href="#">All entries</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>
|
<li role="presentation"><a href="../../${static_url}" title="static website" target="_blank">Ticker</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
41
tycker/templates/sidebar.html
Normal file
41
tycker/templates/sidebar.html
Normal 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> </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>
|
||||||
|
|
|
@ -52,7 +52,9 @@ class Entry(sqlobject.SQLObject):
|
||||||
title = sqlobject.UnicodeCol()
|
title = sqlobject.UnicodeCol()
|
||||||
content = sqlobject.UnicodeCol()
|
content = sqlobject.UnicodeCol()
|
||||||
|
|
||||||
|
class Sidebar(sqlobject.SQLObject):
|
||||||
|
sidebar = sqlobject.UnicodeCol()
|
||||||
|
|
||||||
def render(filename, **values):
|
def render(filename, **values):
|
||||||
stream = loader.load(filename).generate(**values)
|
stream = loader.load(filename).generate(**values)
|
||||||
return stream.render("html", doctype="html")
|
return stream.render("html", doctype="html")
|
||||||
|
@ -65,27 +67,36 @@ def get_link(index):
|
||||||
|
|
||||||
def update_static_html():
|
def update_static_html():
|
||||||
entries = list(Entry.select().orderBy("-timestamp"))
|
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
|
file_index = 1
|
||||||
while entries:
|
remaining_entries = entries
|
||||||
current = entries[:PAGE_SIZE]
|
while remaining_entries:
|
||||||
entries = entries[PAGE_SIZE:]
|
current = remaining_entries[:PAGE_SIZE]
|
||||||
|
remaining_entries = remaining_entries[PAGE_SIZE:]
|
||||||
current_filename = get_filename(file_index)
|
current_filename = get_filename(file_index)
|
||||||
if file_index > 1:
|
if file_index > 1:
|
||||||
previous_link = get_link(file_index - 1)
|
previous_link = get_link(file_index - 1)
|
||||||
else:
|
else:
|
||||||
previous_link = None
|
previous_link = None
|
||||||
if entries:
|
if remaining_entries:
|
||||||
next_link = get_link(file_index + 1)
|
next_link = get_link(file_index + 1)
|
||||||
else:
|
else:
|
||||||
next_link = None
|
next_link = None
|
||||||
values = { "entries": current,
|
values = {"entries": current,
|
||||||
"prev_link": previous_link,
|
"prev_link": previous_link,
|
||||||
"next_link": next_link,
|
"next_link": next_link,
|
||||||
|
"sidebar_text": sidebar_text,
|
||||||
}
|
}
|
||||||
|
# WAP unterstuetzt wohl nur Latin-1
|
||||||
rendered = render("display.html", **values).encode("latin-1")
|
rendered = render("display.html", **values).encode("latin-1")
|
||||||
open(current_filename, "w").write(rendered)
|
open(current_filename, "w").write(rendered)
|
||||||
|
subprocess.call(["html2wml", "-n", current_filename, "-o", "ticker%d.wml" % file_index], cwd=OUTPUT_DIR)
|
||||||
file_index += 1
|
file_index += 1
|
||||||
subprocess.call(["html2wml", "-n", "ticker1.html", "-o", "ticker1.wml"], cwd=OUTPUT_DIR)
|
|
||||||
|
|
||||||
@bobo.query('/submit')
|
@bobo.query('/submit')
|
||||||
def submit_entry(entry_id=None, title=None, content=None, date=None):
|
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
|
entry.date = date
|
||||||
update_static_html()
|
update_static_html()
|
||||||
return bobo.redirect(BASE_URL)
|
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')
|
@bobo.query('/delete')
|
||||||
def delete_entry(entry_id):
|
def delete_entry(entry_id):
|
||||||
|
@ -129,7 +151,7 @@ def create_entry():
|
||||||
values = {}
|
values = {}
|
||||||
values["date_format"] = DATE_FORMAT_FULL
|
values["date_format"] = DATE_FORMAT_FULL
|
||||||
values["static_url"] = get_link(1)
|
values["static_url"] = get_link(1)
|
||||||
return render("admin_create.html", **values)
|
return render("create.html", **values)
|
||||||
|
|
||||||
@bobo.query('/edit')
|
@bobo.query('/edit')
|
||||||
def edit_entries():
|
def edit_entries():
|
||||||
|
@ -137,7 +159,19 @@ def edit_entries():
|
||||||
values["entries"] = Entry.select().orderBy("-timestamp")
|
values["entries"] = Entry.select().orderBy("-timestamp")
|
||||||
values["date_format"] = DATE_FORMAT_FULL
|
values["date_format"] = DATE_FORMAT_FULL
|
||||||
values["static_url"] = get_link(1)
|
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('')
|
@bobo.query('')
|
||||||
def redirect_base():
|
def redirect_base():
|
||||||
|
@ -149,5 +183,12 @@ for table in (Entry, ):
|
||||||
if not table.tableExists():
|
if not table.tableExists():
|
||||||
table.createTable()
|
table.createTable()
|
||||||
|
|
||||||
|
for table in (Sidebar, ):
|
||||||
|
#table.dropTable()
|
||||||
|
if not table.tableExists():
|
||||||
|
table.createTable()
|
||||||
|
#Sidebar(sidebar='Test')
|
||||||
|
|
||||||
application = bobo.Application(bobo_resources=__name__)
|
application = bobo.Application(bobo_resources=__name__)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue