Skip to content
Snippets Groups Projects
Commit 423eaed0 authored by Andreas Valder's avatar Andreas Valder
Browse files

Merge branch 'master' of git.fsmpi.rwth-aachen.de:videoagwebsite/videoagwebsite

parents 769f4cb5 a6f89b6a
Branches
No related tags found
No related merge requests found
...@@ -19,3 +19,4 @@ SQLITE_INIT_SCHEMA = True ...@@ -19,3 +19,4 @@ SQLITE_INIT_SCHEMA = True
SQLITE_INIT_DATA = False SQLITE_INIT_DATA = False
#LDAP_HOST = 'ldaps://rumo.fsmpi.rwth-aachen.de' #LDAP_HOST = 'ldaps://rumo.fsmpi.rwth-aachen.de'
#ICAL_URL = 'https://user:password@mail.fsmpi.rwth-aachen.de/SOGo/....ics'
...@@ -84,19 +84,19 @@ CREATE TABLE IF NOT EXISTS `lectures_data` ( ...@@ -84,19 +84,19 @@ CREATE TABLE IF NOT EXISTS `lectures_data` (
`visible` INTEGER NOT NULL DEFAULT '1', `visible` INTEGER NOT NULL DEFAULT '1',
`timed_release` datetime DEFAULT NULL, `timed_release` datetime DEFAULT NULL,
`use_timed_release` INTEGER NOT NULL DEFAULT '0', `use_timed_release` INTEGER NOT NULL DEFAULT '0',
`drehplan` varchar(10) NOT NULL, `drehplan` varchar(10) NOT NULL DEFAULT '',
`deleted` INTEGER NOT NULL DEFAULT '0', `deleted` INTEGER NOT NULL DEFAULT '0',
`title` text NOT NULL, `title` text NOT NULL DEFAULT '',
`comment` text NOT NULL, `comment` text NOT NULL DEFAULT '',
`internal` text NOT NULL, `internal` text NOT NULL DEFAULT '',
`speaker` text NOT NULL, `speaker` text NOT NULL DEFAULT '',
`place` text NOT NULL, `place` text NOT NULL DEFAULT '',
`time` datetime NOT NULL, `time` datetime NOT NULL,
`duration` INTEGER NOT NULL DEFAULT '90', `duration` INTEGER NOT NULL DEFAULT '90',
`time_created` datetime NOT NULL, `time_created` datetime NOT NULL,
`time_updated` datetime NOT NULL, `time_updated` datetime NOT NULL,
`jumplist` text NOT NULL, `jumplist` text NOT NULL DEFAULT '',
`titlefile` varchar(255) NOT NULL `titlefile` varchar(255) NOT NULL DEFAULT ''
); );
CREATE TABLE IF NOT EXISTS `places` ( CREATE TABLE IF NOT EXISTS `places` (
`place` varchar(20) NOT NULL PRIMARY KEY, `place` varchar(20) NOT NULL PRIMARY KEY,
......
...@@ -21,6 +21,7 @@ def get_next_meeting(): ...@@ -21,6 +21,7 @@ def get_next_meeting():
event = sorted(meetings, key=lambda e: e['DTSTART'].dt)[0] event = sorted(meetings, key=lambda e: e['DTSTART'].dt)[0]
return str(event['UID']), event['DTSTART'].dt.replace(tzinfo=None) return str(event['UID']), event['DTSTART'].dt.replace(tzinfo=None)
@sched_func(60*60)
def update_meeting(): def update_meeting():
try: try:
uid, start = get_next_meeting() uid, start = get_next_meeting()
......
...@@ -7,6 +7,8 @@ import os ...@@ -7,6 +7,8 @@ import os
import sys import sys
import hashlib import hashlib
import random import random
import sched
import time
app = Flask(__name__) app = Flask(__name__)
...@@ -16,15 +18,25 @@ app.add_template_global(random.randint, name='randint') ...@@ -16,15 +18,25 @@ app.add_template_global(random.randint, name='randint')
app.add_template_global(datetime, name='datetime') app.add_template_global(datetime, name='datetime')
app.add_template_global(timedelta, name='timedelta') app.add_template_global(timedelta, name='timedelta')
def timer_func(): scheduler = sched.scheduler()
def run_scheduler():
time.sleep(1) # UWSGI does weird things on startup
while True:
scheduler.run()
def sched_func(delay, priority=0, firstdelay=None, args=[], kargs={}):
if firstdelay == None:
firstdelay = random.randint(1, 120)
def wrapper(func):
def sched_wrapper():
with app.test_request_context(): with app.test_request_context():
pass # do something func(*args, *kargs)
timer = threading.Timer(60*60, timer_func) scheduler.enter(delay, priority, sched_wrapper)
timer.start() scheduler.enter(firstdelay, priority, sched_wrapper)
return func
return wrapper
timer = threading.Timer(0, timer_func) threading.Thread(target=run_scheduler, daemon=True).start()
timer.daemon = True
timer.start()
config = app.config config = app.config
config.from_pyfile('config.py.example', silent=True) config.from_pyfile('config.py.example', silent=True)
...@@ -257,13 +269,22 @@ def logout(): ...@@ -257,13 +269,22 @@ def logout():
tabs = { tabs = {
'courses': ('courses_data', 'id', ['visible', 'listed', 'title', 'short', 'courses': ('courses_data', 'id', ['visible', 'listed', 'title', 'short',
'handle', 'organizer', 'subject', 'semester', 'downloadable', 'handle', 'organizer', 'subject', 'semester', 'downloadable',
'internal', 'responsible','deleted']), 'internal', 'responsible','deleted'],
['created_by', 'time_created', 'time_updated']),
'lectures': ('lectures_data', 'id', ['visible', 'title', 'comment', 'lectures': ('lectures_data', 'id', ['visible', 'title', 'comment',
'internal', 'speaker', 'place', 'time', 'duration', 'jumplist','deleted']), 'internal', 'speaker', 'place', 'time', 'duration', 'jumplist','deleted'],
'videos': ('videos_data', 'id', ['visible','deleted']), ['course_id', 'time_created', 'time_updated']),
'chapters': ('chapters', 'id', ['time', 'text', 'visible', 'deleted']), 'videos': ('videos_data', 'id', ['visible','deleted'],
'announcements': ('announcements', 'id', ['text', 'level', 'visible', 'deleted', 'time_publish', 'time_expire']), ['created_by', 'time_created', 'time_updated']),
'featured': ('featured', 'id', ['title', 'text', 'internal', 'visible', 'deleted']) 'chapters': ('chapters', 'id', ['time', 'text', 'visible', 'deleted'],
['created_by', 'time_created', 'time_updated']),
'announcements': ('announcements', 'id', ['text', 'level', 'visible',
'deleted', 'time_publish', 'time_expire'],
['created_by', 'time_created', 'time_updated']),
'featured': ('featured', 'id', ['title', 'text', 'internal', 'visible', 'deleted'],
['created_by', 'time_created', 'time_updated']),
'auth': ('auth', 'auth_id', ['auth_type', 'auth_user', 'auth_passwd'],
['course_id', 'lecture_id', 'video_id'])
} }
@app.route('/edit', methods=['GET', 'POST']) @app.route('/edit', methods=['GET', 'POST'])
...@@ -275,11 +296,9 @@ def edit(prefix='', ignore=[]): ...@@ -275,11 +296,9 @@ def edit(prefix='', ignore=[]):
if not prefix and 'prefix' in request.args: if not prefix and 'prefix' in request.args:
prefix = request.args['prefix'] prefix = request.args['prefix']
modify('BEGIN') modify('BEGIN')
changes = request.values.items()
if request.is_json: if request.is_json:
changes = request.get_json().items() changes = request.get_json().items()
else:
changes = request.args.items()
created = {}
for key, val in changes: for key, val in changes:
if key in ignore: if key in ignore:
continue continue
...@@ -299,23 +318,25 @@ def edit(prefix='', ignore=[]): ...@@ -299,23 +318,25 @@ def edit(prefix='', ignore=[]):
@mod_required @mod_required
def create(table): def create(table):
assert table in tabs assert table in tabs
id = modify('INSERT INTO %s (created_by, time_created, time_updated) VALUES (?, ?, ?)'%tabs[table][0], defaults = {'created_by': session['user']['dbid'], 'time_created': datetime.now(), 'time_updated': datetime.now()}
session['user']['dbid'], datetime.now(), datetime.now()) columns = []
edit(prefix=table+'.'+str(id)+'.') values = []
if 'ref' in request.values: for column, val in defaults.items():
return redirect(request.values['ref']) if column in tabs[table][3]:
return str(id), 200 columns.append(column)
values.append(val)
@app.route('/newlecture/<courseid>', methods=['GET', 'POST']) args = request.values
@mod_required if request.is_json:
def new_lecture(courseid): args = request.get_json()
id = modify(''' for column, val in args.items():
INSERT INTO lectures_data if column == 'ref':
(course_id, visible, drehplan, title, comment, internal, speaker, place, continue
time, time_created, time_updated, jumplist, titlefile) assert column in tabs[table][2]+tabs[table][3]
VALUES (?, 0, "", "Noch kein Titel", "", "", "", "", ?, ?, ?, "", "") assert column not in defaults
''', courseid, datetime.now(), datetime.now(), datetime.now()) columns.append(column)
edit(prefix='lectures.'+str(id)+'.', ignore=['ref']) values.append(val)
id = modify('INSERT INTO %s (%s) VALUES (%s)'%(tabs[table][0],
','.join(columns), ','.join(['?']*len(values))), *values)
if 'ref' in request.values: if 'ref' in request.values:
return redirect(request.values['ref']) return redirect(request.values['ref'])
return str(id), 200 return str(id), 200
...@@ -432,3 +453,5 @@ import feeds ...@@ -432,3 +453,5 @@ import feeds
import importer import importer
import schedule import schedule
import sorter import sorter
if 'ICAL_URL' in config:
import meetings
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
</div> </div>
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading"> <div class="panel-heading">
<h1 class="panel-title">Videos{% if ismod() %} <a class="btn btn-default" style="margin-right: 5px;" href="{{ url_for('new_lecture', courseid=course.id, ref=request.url) }}">Neuer Termin</a><a class="btn btn-default" style="margin-right: 5px;" href="{{url_for('import_from', id=course['id'])}}">Campus Import</a>{% endif %} <a class="fa fa-rss-square pull-right" aria-hidden="true" href="{{url_for('feed', handle=course.handle)}}"></a> </h1> <h1 class="panel-title">Videos{% if ismod() %} <a class="btn btn-default" style="margin-right: 5px;" href="{{ url_for('create', table='lectures', time=datetime.now(), title='Noch kein Titel', course_id=course.id, ref=request.url) }}">Neuer Termin</a><a class="btn btn-default" style="margin-right: 5px;" href="{{url_for('import_from', id=course['id'])}}">Campus Import</a>{% endif %} <a class="fa fa-rss-square pull-right" aria-hidden="true" href="{{url_for('feed', handle=course.handle)}}"></a> </h1>
</div> </div>
<ul class="list-group lectureslist"> <ul class="list-group lectureslist">
{% for l in lectures %} {% for l in lectures %}
......
...@@ -90,7 +90,7 @@ ...@@ -90,7 +90,7 @@
{{ valuedeletebtn(['lectures',i.id,'deleted']) }} {{ valuedeletebtn(['lectures',i.id,'deleted']) }}
{% endif%} {% endif%}
{% if (i.type == 'import') %} {% if (i.type == 'import') %}
<button class="btn btn-default newlecture" onclick="moderatorinterface.gethttp('{{ url_for('new_lecture', courseid=course.id, time=i.time, title=i.title, place=i.place) }}')">anlegen</a> <button class="btn btn-default newlecture" onclick="moderatorinterface.gethttp('{{ url_for('create', table='lecture', course_id=course.id, time=i.time, title=i.title, place=i.place) }}')">anlegen</a>
{% endif%} {% endif%}
</span> </span>
</span> </span>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment