leichte Layout-Aufhuebschungen
This commit is contained in:
parent
115f9bdfbc
commit
1ba9bfed33
6 changed files with 85 additions and 61 deletions
32
helpers.py
Normal file
32
helpers.py
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
import creoleparser
|
||||||
|
import genshi
|
||||||
|
import datetime
|
||||||
|
from settings import DATE_FORMAT_SHORT, DATE_FORMAT_FULL
|
||||||
|
|
||||||
|
|
||||||
|
def formatter(text):
|
||||||
|
if not text:
|
||||||
|
return u""
|
||||||
|
text = text.replace("\\", "\\\\")
|
||||||
|
html = creoleparser.text2html(text, encoding=None).strip()
|
||||||
|
if html.startswith("<p>") and html.endswith("</p>"):
|
||||||
|
html = html[3:-4]
|
||||||
|
return genshi.Markup(html)
|
||||||
|
|
||||||
|
|
||||||
|
last_day = datetime.datetime.today() - datetime.timedelta(days=1)
|
||||||
|
def show_timestamp(date):
|
||||||
|
if date <= last_day:
|
||||||
|
template = DATE_FORMAT_SHORT
|
||||||
|
else:
|
||||||
|
template = DATE_FORMAT_FULL
|
||||||
|
return date.strftime(template)
|
||||||
|
|
||||||
|
def nav_links(prev_link, next_link):
|
||||||
|
result = []
|
||||||
|
if prev_link:
|
||||||
|
result.append('<a href="%s" title="zeige neuere Einträge">aktuellere</a>' % prev_link)
|
||||||
|
if next_link:
|
||||||
|
result.append('<a href="%s" title="zeige ältere Einträge">ältere</a>' % next_link)
|
||||||
|
return genshi.Markup(" | ".join(result))
|
||||||
|
|
11
settings.py
Normal file
11
settings.py
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
import os as __os
|
||||||
|
__BASE_DIR = __os.path.dirname(__os.path.abspath(__file__))
|
||||||
|
|
||||||
|
DATE_FORMAT_SHORT = __os.environ.get("DATE_FORMAT_SHORT", "%H:%M")
|
||||||
|
DATE_FORMAT_FULL = __os.environ.get("DATE_FORMAT_FULL", "%d.%m.%Y - %H:%M Uhr")
|
||||||
|
PAGE_SIZE = int(__os.environ.get("PAGE_SIZE", 20))
|
||||||
|
FILENAME_TEMPLATE = __os.environ.get("FILENAME_TEMPLATE", "ticker%d.html")
|
||||||
|
OUTPUT_DIR = __os.environ.get("OUTPUT_DIR", __os.path.join(__BASE_DIR, "output"))
|
||||||
|
DB_FILE = __os.environ.get("DB_FILE", __os.path.join(__BASE_DIR, "tycker.sqlite"))
|
||||||
|
BASE_URL = __os.environ.get("BASE_URL", "./")
|
||||||
|
|
|
@ -20,13 +20,13 @@
|
||||||
<table border="1">
|
<table border="1">
|
||||||
<tr><th>Timestamp</th><th>Title</th><th>Content</th></tr>
|
<tr><th>Timestamp</th><th>Title</th><th>Content</th></tr>
|
||||||
<tr><form action="submit" method="GET">
|
<tr><form action="submit" method="GET">
|
||||||
<td><input type="text" size="15" name="date" value="${now.strftime(date_format)}" /></td>
|
<td><input type="text" size="20" name="date" value="${now.strftime(date_format)}" /></td>
|
||||||
<td><input type="text" size="25" name="title" value="" autofocus="autofocus" /></td>
|
<td><input type="text" size="25" name="title" value="" autofocus="autofocus" /></td>
|
||||||
<td><textarea name="content" rows="8" cols="80" /></td>
|
<td><textarea name="content" rows="8" cols="80" /></td>
|
||||||
<td><input type="submit" value="Create" /></td>
|
<td><input type="submit" value="Create" /></td>
|
||||||
</form></tr>
|
</form></tr>
|
||||||
<tr py:for="entry in entries"><form action="submit" method="GET">
|
<tr py:for="entry in entries"><form action="submit" method="GET">
|
||||||
<td><input type="text" size="15" name="date" value="${entry['timestamp'].strftime(date_format)}" /></td>
|
<td><input type="text" size="20" name="date" value="${entry['timestamp'].strftime(date_format)}" /></td>
|
||||||
<td><input type="text" size="25" name="title" value="${entry['title']}" /></td>
|
<td><input type="text" size="25" name="title" value="${entry['title']}" /></td>
|
||||||
<td><textarea name="content" rows="8" cols="80">${entry['content']}</textarea></td>
|
<td><textarea name="content" rows="8" cols="80">${entry['content']}</textarea></td>
|
||||||
<td><input type="hidden" name="entry_id" value="${entry.id}" /><input type="submit" value="Update" /></td>
|
<td><input type="hidden" name="entry_id" value="${entry.id}" /><input type="submit" value="Update" /></td>
|
||||||
|
|
|
@ -1,23 +1,43 @@
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml"
|
<!DOCTYPE html>
|
||||||
xmlns:py="http://genshi.edgewall.org/"
|
<html xmlns="http://www.w3.org/1999/xhtml" lang="en"
|
||||||
xmlns:xi="http://www.w3.org/2001/XInclude">
|
xmlns:w="http://www.example.org/widgets"
|
||||||
<xi:include href="layout.html" />
|
xmlns:xi="http://www.w3.org/2001/XInclude"
|
||||||
|
xmlns:py="http://genshi.edgewall.org/">
|
||||||
<head>
|
<head>
|
||||||
<title>Ticker</title>
|
<title>Ticker</title>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<link type="text/css" rel="stylesheet" media="all" href="bootstrap/css/bootstrap.min.css" />
|
||||||
|
<link type="text/css" rel="stylesheet" media="all" href="bootstrap/css/bootstrap-theme.min.css" />
|
||||||
|
<link type="text/css" rel="stylesheet" media="all" href="style.css" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
|
<?python from helpers import formatter, show_timestamp, nav_links ?>
|
||||||
|
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
${nav_links()}
|
<div class="container theme-showcase" role="main">
|
||||||
<ul>
|
<div class="page-header">
|
||||||
<li py:for="entry in entries">
|
<h1 id="title" />
|
||||||
<span class="timestamp">${show_timestamp(entry['timestamp'])}</span><br/>
|
</div>
|
||||||
<span class="title">${entry['title']}:</span>
|
|
||||||
<span class="content">${formatter(entry['content'])}</span>
|
<div class="container">
|
||||||
</li>
|
${nav_links(prev_link, next_link)}
|
||||||
</ul>
|
|
||||||
${nav_links()}
|
<div class="well" py:for="entry in entries">
|
||||||
|
<h2>${entry['title']}</h2>
|
||||||
|
<blockquote class="blockquote">
|
||||||
|
${formatter(entry['content'])}
|
||||||
|
<footer>${show_timestamp(entry['timestamp'])}</footer>
|
||||||
|
</blockquote>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
${nav_links(prev_link, next_link)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="footer" class="page-footer" />
|
||||||
|
</div>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -4,45 +4,11 @@
|
||||||
|
|
||||||
<py:match path="head" once="true">
|
<py:match path="head" once="true">
|
||||||
<head py:attrs="select('@*')">
|
<head py:attrs="select('@*')">
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
||||||
${select('*|text()')}
|
${select('*|text()')}
|
||||||
</head>
|
</head>
|
||||||
</py:match>
|
</py:match>
|
||||||
|
|
||||||
<?python
|
|
||||||
import creoleparser
|
|
||||||
import genshi
|
|
||||||
import datetime
|
|
||||||
|
|
||||||
def formatter(text):
|
|
||||||
if not text:
|
|
||||||
return u""
|
|
||||||
text = text.replace("\\", "\\\\")
|
|
||||||
html = creoleparser.text2html(text, encoding=None).strip()
|
|
||||||
if html.startswith("<p>") and html.endswith("</p>"):
|
|
||||||
html = html[3:-4]
|
|
||||||
return genshi.Markup(html)
|
|
||||||
|
|
||||||
|
|
||||||
TODAY_FORMAT = "%H:%M"
|
|
||||||
FULL_FORMAT = "%d.%m.%y %H:%M"
|
|
||||||
last_day = datetime.datetime.today() - datetime.timedelta(days=1)
|
|
||||||
def show_timestamp(date):
|
|
||||||
if date <= last_day:
|
|
||||||
template = TODAY_FORMAT
|
|
||||||
else:
|
|
||||||
template = FULL_FORMAT
|
|
||||||
return date.strftime(template)
|
|
||||||
|
|
||||||
def nav_links():
|
|
||||||
result = []
|
|
||||||
if prev_link:
|
|
||||||
result.append('<a href="%s" title="zeige neuere Einträge">aktuellere</a>' % prev_link)
|
|
||||||
if next_link:
|
|
||||||
result.append('<a href="%s" title="zeige ältere Einträge">ältere</a>' % next_link)
|
|
||||||
return genshi.Markup(" | ".join(result))
|
|
||||||
?>
|
|
||||||
|
|
||||||
<py:match path="body" once="true">
|
<py:match path="body" once="true">
|
||||||
<body py:attrs="select('@*')">
|
<body py:attrs="select('@*')">
|
||||||
|
|
||||||
|
|
15
tycker.py
15
tycker.py
|
@ -34,19 +34,14 @@ for path in list(sys.path):
|
||||||
if os.path.isdir(option):
|
if os.path.isdir(option):
|
||||||
sys.path.append(option)
|
sys.path.append(option)
|
||||||
|
|
||||||
DATE_FORMAT = "%H:%M %d.%m.%Y"
|
|
||||||
PAGE_SIZE = 10
|
|
||||||
FILENAME_TEMPLATE = "ticker%d.html"
|
|
||||||
FULL_PATH_FILENAME_TEMPLATE = os.path.join(BASE_DIR, os.path.pardir, FILENAME_TEMPLATE)
|
|
||||||
BASE_URL = "./"
|
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
import bobo
|
import bobo
|
||||||
import sqlobject
|
import sqlobject
|
||||||
import genshi.template
|
import genshi.template
|
||||||
|
|
||||||
|
from settings import *
|
||||||
|
|
||||||
db_uri = "sqlite:///%s/tycker.sqlite" % BASE_DIR
|
db_uri = "sqlite://%s" % DB_FILE
|
||||||
sqlobject.sqlhub.processConnection = sqlobject.connectionForURI(db_uri)
|
sqlobject.sqlhub.processConnection = sqlobject.connectionForURI(db_uri)
|
||||||
|
|
||||||
loader = genshi.template.TemplateLoader(os.path.join(BASE_DIR, 'templates'), auto_reload=True)
|
loader = genshi.template.TemplateLoader(os.path.join(BASE_DIR, 'templates'), auto_reload=True)
|
||||||
|
@ -63,7 +58,7 @@ def render(filename, **values):
|
||||||
return stream.render("html", doctype="html")
|
return stream.render("html", doctype="html")
|
||||||
|
|
||||||
def get_filename(index):
|
def get_filename(index):
|
||||||
return FULL_PATH_FILENAME_TEMPLATE % index
|
return os.path.join(OUTPUT_DIR, FILENAME_TEMPLATE % index)
|
||||||
|
|
||||||
def get_link(index):
|
def get_link(index):
|
||||||
return FILENAME_TEMPLATE % index
|
return FILENAME_TEMPLATE % index
|
||||||
|
@ -98,7 +93,7 @@ def submit_entry(entry_id=None, title=None, content=None, date=None):
|
||||||
if not all((title, content, date)):
|
if not all((title, content, date)):
|
||||||
return bobo.redirect(BASE_URL)
|
return bobo.redirect(BASE_URL)
|
||||||
try:
|
try:
|
||||||
date = datetime.datetime.strptime(date, DATE_FORMAT)
|
date = datetime.datetime.strptime(date, DATE_FORMAT_FULL)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
bobo.redirect(BASE_URL)
|
bobo.redirect(BASE_URL)
|
||||||
if entry_id is None:
|
if entry_id is None:
|
||||||
|
@ -132,7 +127,7 @@ def generate_static():
|
||||||
def show_entries():
|
def show_entries():
|
||||||
values = {}
|
values = {}
|
||||||
values["entries"] = Entry.select().orderBy("-timestamp")
|
values["entries"] = Entry.select().orderBy("-timestamp")
|
||||||
values["date_format"] = DATE_FORMAT
|
values["date_format"] = DATE_FORMAT_FULL
|
||||||
values["static_url"] = get_link(1)
|
values["static_url"] = get_link(1)
|
||||||
return render("admin_show_entries.html", **values)
|
return render("admin_show_entries.html", **values)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue