leichte Layout-Aufhuebschungen
This commit is contained in:
parent
e84e413dd7
commit
297b268395
6 changed files with 85 additions and 61 deletions
32
tycker/helpers.py
Normal file
32
tycker/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
tycker/settings.py
Normal file
11
tycker/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">
|
||||
<tr><th>Timestamp</th><th>Title</th><th>Content</th></tr>
|
||||
<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><textarea name="content" rows="8" cols="80" /></td>
|
||||
<td><input type="submit" value="Create" /></td>
|
||||
</form></tr>
|
||||
<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><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>
|
||||
|
|
|
@ -1,23 +1,43 @@
|
|||
<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" />
|
||||
<!DOCTYPE html>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en"
|
||||
xmlns:w="http://www.example.org/widgets"
|
||||
xmlns:xi="http://www.w3.org/2001/XInclude"
|
||||
xmlns:py="http://genshi.edgewall.org/">
|
||||
<head>
|
||||
<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>
|
||||
|
||||
<?python from helpers import formatter, show_timestamp, nav_links ?>
|
||||
|
||||
|
||||
<body>
|
||||
|
||||
${nav_links()}
|
||||
<ul>
|
||||
<li py:for="entry in entries">
|
||||
<span class="timestamp">${show_timestamp(entry['timestamp'])}</span><br/>
|
||||
<span class="title">${entry['title']}:</span>
|
||||
<span class="content">${formatter(entry['content'])}</span>
|
||||
</li>
|
||||
</ul>
|
||||
${nav_links()}
|
||||
<div class="container theme-showcase" role="main">
|
||||
<div class="page-header">
|
||||
<h1 id="title" />
|
||||
</div>
|
||||
|
||||
<div class="container">
|
||||
${nav_links(prev_link, next_link)}
|
||||
|
||||
<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>
|
||||
</html>
|
||||
|
|
|
@ -4,45 +4,11 @@
|
|||
|
||||
<py:match path="head" once="true">
|
||||
<head py:attrs="select('@*')">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
||||
${select('*|text()')}
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
||||
${select('*|text()')}
|
||||
</head>
|
||||
</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">
|
||||
<body py:attrs="select('@*')">
|
||||
|
||||
|
|
|
@ -34,19 +34,14 @@ for path in list(sys.path):
|
|||
if os.path.isdir(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 bobo
|
||||
import sqlobject
|
||||
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)
|
||||
|
||||
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")
|
||||
|
||||
def get_filename(index):
|
||||
return FULL_PATH_FILENAME_TEMPLATE % index
|
||||
return os.path.join(OUTPUT_DIR, FILENAME_TEMPLATE % index)
|
||||
|
||||
def get_link(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)):
|
||||
return bobo.redirect(BASE_URL)
|
||||
try:
|
||||
date = datetime.datetime.strptime(date, DATE_FORMAT)
|
||||
date = datetime.datetime.strptime(date, DATE_FORMAT_FULL)
|
||||
except ValueError:
|
||||
bobo.redirect(BASE_URL)
|
||||
if entry_id is None:
|
||||
|
@ -132,7 +127,7 @@ def generate_static():
|
|||
def show_entries():
|
||||
values = {}
|
||||
values["entries"] = Entry.select().orderBy("-timestamp")
|
||||
values["date_format"] = DATE_FORMAT
|
||||
values["date_format"] = DATE_FORMAT_FULL
|
||||
values["static_url"] = get_link(1)
|
||||
return render("admin_show_entries.html", **values)
|
||||
|
||||
|
|
Loading…
Reference in a new issue