Commit 2d4c02d3 authored by Julian Rother's avatar Julian Rother

Add publish and expire date to announcements also redo the editing interface for them

Closes #21
parent 4be38f71
......@@ -186,10 +186,11 @@ CREATE TABLE IF NOT EXISTS `videos_data` (
CREATE TABLE IF NOT EXISTS `announcements` (
`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
`text` text NOT NULL DEFAULT '',
`internal` text NOT NULL DEFAULT "",
`level` INTEGER NOT NULL DEFAULT 0,
`visible` INTEGER NOT NULL DEFAULT 0,
`deleted` INTEGER NOT NULL DEFAULT 0,
`time_publish` datetime DEFAULT "",
`time_expire` datetime DEFAULT "",
`time_created` datetime NOT NULL,
`time_updated` datetime NOT NULL,
`created_by` INTEGER NOT NULL
......
......@@ -13,6 +13,8 @@ app = Flask(__name__)
app.jinja_env.trim_blocks = True
app.jinja_env.lstrip_blocks = True
app.add_template_global(random.randint, name='randint')
app.add_template_global(datetime, name='datetime')
app.add_template_global(timedelta, name='timedelta')
def timer_func():
with app.test_request_context():
......@@ -121,7 +123,10 @@ def rfc3339(d):
@app.template_global()
def get_announcements(minlevel=0):
return query('SELECT * FROM announcements WHERE NOT deleted AND (? OR visible) AND level >= ? ORDER BY level DESC', ismod(), minlevel)
offset = timedelta()
if ismod():
offset = timedelta(minutes=10)
return query('SELECT * FROM announcements WHERE NOT deleted AND (time_expire ISNULL OR time_expire > ?) AND (? OR (visible AND time_publish < ?)) AND level >= ? ORDER BY level DESC', datetime.now()-offset, ismod(), datetime.now(), minlevel)
@app.template_filter()
def fixnl(s):
......@@ -257,7 +262,7 @@ tabs = {
'internal', 'speaker', 'place', 'time', 'duration', 'jumplist','deleted']),
'videos': ('videos_data', 'id', ['visible','deleted']),
'chapters': ('chapters', 'id', ['time', 'text', 'visible', 'deleted']),
'announcements': ('announcements', 'id', ['text', 'internal', 'level', 'visible', 'deleted']),
'announcements': ('announcements', 'id', ['text', 'level', 'visible', 'deleted', 'time_publish', 'time_expire']),
'featured': ('featured', 'id', ['title', 'text', 'internal', 'visible', 'deleted'])
}
......
{% set page_border = page_border|default(1) %}
{% set min_announcement_level = min_announcement_level|default(1) %}
{% set announcement_levels = {0: 'info', 1: 'info', 2: 'warning', 3: 'danger'} %}
{% set levels = {0: ('info', 'Nur auf Hauptseite sichtbar'), 1: ('info', 'Überall sichtbar (Hinweis)'), 2: ('warning', 'Überall sichtbar (Warnung)'), 3: ('danger', 'Überall sichtbar (Wichtig)')} %}
{% from 'macros.html' import valueeditor, valuecheckbox, valuedeletebtn %}
<!DOCTYPE html>
......@@ -101,18 +101,28 @@
<div class="alert alert-danger" role="alert">{{ msg }}</div>
{% endfor %}
{% for msg in get_announcements(min_announcement_level) if (not request.cookies['alert-info-'+msg.id|string]) or ismod() %}
<div class="alert alert-{{announcement_levels.get(msg.level, 'info')}}" role="alert">
<div class="alert alert-{{levels.get(msg.level, ('info', ''))[0]}}" role="alert">
{% if not ismod() %}
<a href="#" class="close" data-dismiss="alert" aria-label="close" onclick="Cookies.set('alert-info-{{msg.id}}', '1');">&times;</a>
{% endif %}
<ul class="list-unstyled">
<li>{{ valueeditor(('announcements',msg.id,'text'), msg.text|safe) }}</li>
{% if ismod() %}
<li class="pull-right">{{ valuedeletebtn(('announcements',msg.id,'deleted')) }}</li>
{% if ismod() %}
<li>{{ valueeditor(('announcements',msg.id,'internal'), msg.internal) }}</li>
<li class="pull-right">Sichtbar: {{ valuecheckbox(('announcements',msg.id,'visible'),msg.visible) }}</li>
<li>Level: {{ valueeditor(('announcements',msg.id,'level'), msg.level) }}</li>
{% endif %}
<li class="pull-right" style="padding-right: 5px;"><a href="{{ url_for('edit', ref=request.url) }}&announcements.{{ msg.id }}.visible=1" class="btn btn-primary {% if msg.visible %}disabled{% endif %}">Veröffentlichen</a></li>
<li class="dropdown pull-right" style="padding-right: 5px;">
<span class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown">{{levels.get(msg.level, ('', 'Unbekannt'))[1]}} <span class="caret"></span></span>
<ul class="dropdown-menu">
{% for level, descr in levels.items() %}
<li><a href="{{ url_for('edit', ref=request.url) }}&announcements.{{ msg.id }}.level={{ level }}">{{ descr[1] }}</a></li>
{% endfor %}
</ul>
</li>
<li>
Aktiv von {{ valueeditor(('announcements',msg.id,'time_publish'), msg.time_publish) }}
bis {{ valueeditor(('announcements',msg.id,'time_expire'), msg.time_expire) }}
</li>
{% endif %}
</ul>
</div>
{% endfor %}
......
......@@ -8,7 +8,7 @@
<ul class="list-inline pull-right">
{% if ismod() %}
<li style="padding-right: 0px;">
<a class="btn btn-default" href="{{ url_for('create', table='announcements', text='Neue Ankündigung', ref=request.url) }}">Neue Ankündigung</a>
<a class="btn btn-default" href="{{ url_for('create', table='announcements', text='Neue Ankündigung', time_publish=datetime.now().replace(hour=0, minute=0, second=0, microsecond=0), time_expire=datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)+timedelta(days=7), ref=request.url) }}">Neue Ankündigung</a>
</li>
{% endif %}
</ul>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment