From 51ddd5172b27b02d8de753ff09fee344a8d0f67c Mon Sep 17 00:00:00 2001
From: Julian Rother <julianr@fsmpi.rwth-aachen.de>
Date: Sat, 10 Sep 2016 12:44:56 +0200
Subject: [PATCH] Replace new_course with create

---
 db_schema.sql          | 24 ++++++++++++------------
 server.py              | 16 +---------------
 templates/courses.html |  2 +-
 3 files changed, 14 insertions(+), 28 deletions(-)

diff --git a/db_schema.sql b/db_schema.sql
index 5496ae1..f38b5a5 100644
--- a/db_schema.sql
+++ b/db_schema.sql
@@ -42,26 +42,26 @@ CREATE TABLE IF NOT EXISTS `chapters` (
 );
 CREATE TABLE IF NOT EXISTS `courses_data` (
 `id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
-  `visible` INTEGER NOT NULL,
+  `visible` INTEGER NOT NULL DEFAULT '0',
   `listed` INTEGER NOT NULL DEFAULT '1',
   `deleted` INTEGER NOT NULL DEFAULT '0',
-  `title` text NOT NULL,
-  `short` varchar(32) NOT NULL,
-  `handle` varchar(32) NOT NULL,
-  `organizer` text NOT NULL,
-  `subject` varchar(32) NOT NULL,
+  `title` text NOT NULL DEFAULT 'Neue Veranstaltung',
+  `short` varchar(32) NOT NULL DEFAULT '',
+  `handle` varchar(32) NOT NULL DEFAULT '',
+  `organizer` text NOT NULL DEFAULT '',
+  `subject` varchar(32) NOT NULL DEFAULT '',
   `credits` INTEGER NOT NULL DEFAULT '0',
   `created_by` INTEGER DEFAULT NULL,
   `time_created` datetime NOT NULL,
   `time_updated` datetime NOT NULL,
-  `semester` char(6) NOT NULL,
-  `settings` text NOT NULL,
+  `semester` char(6) NOT NULL DEFAULT '',
+  `settings` text NOT NULL DEFAULT '',
   `downloadable` INTEGER NOT NULL DEFAULT '1',
   `embedinvisible` INTEGER NOT NULL DEFAULT '0',
-  `description` text NOT NULL,
-  `internal` text NOT NULL,
-  `responsible` text NOT NULL,
-  `feed_url` text NOT NULL
+  `description` text NOT NULL DEFAULT '',
+  `internal` text NOT NULL DEFAULT '',
+  `responsible` text NOT NULL DEFAULT '',
+  `feed_url` text NOT NULL DEFAULT ''
 );
 CREATE TABLE IF NOT EXISTS `filesizes` (
   `path` varchar(255) NOT NULL PRIMARY KEY,
diff --git a/server.py b/server.py
index 769228a..ff8dfc8 100755
--- a/server.py
+++ b/server.py
@@ -12,6 +12,7 @@ app = Flask(__name__)
 
 app.jinja_env.trim_blocks = True
 app.jinja_env.lstrip_blocks = True
+app.add_template_global(random.randint, name='randint')
 
 def timer_func():
 	with app.test_request_context():
@@ -295,21 +296,6 @@ def create(table):
 		return redirect(request.values['ref'])
 	return str(id), 200
 
-@app.route('/newcourse', methods=['GET', 'POST'])
-@mod_required
-def new_course():
-	id = modify('''
-		INSERT INTO courses_data
-			(visible, title, short, handle, organizer, subject, created_by, time_created,
-			 time_updated, semester, settings, description, internal, responsible, feed_url)
-			VALUES (0, "Neue Veranstaltung", "Neu", ?, "", "", ?, ?, ?, "", "", "", "", ?, "")
-		''', 'new'+str(random.randint(0,1000)), session['user']['dbid'], datetime.now(), datetime.now(),
-		session['user']['givenName'])
-	edit(prefix='courses.'+str(id)+'.', ignore=['ref'])
-	if 'ref' in request.values:
-		return redirect(request.values['ref'])
-	return str(id), 200
-
 @app.route('/newlecture/<courseid>', methods=['GET', 'POST'])
 @mod_required
 def new_lecture(courseid):
diff --git a/templates/courses.html b/templates/courses.html
index f8f07bf..6f34a57 100644
--- a/templates/courses.html
+++ b/templates/courses.html
@@ -9,7 +9,7 @@
 			</li>
 			{% if ismod() %} 
 			<li>
-				<a class="btn btn-default" href="{{ url_for('new_course', ref=request.url) }}">Neue Veranstaltung</a>
+				<a class="btn btn-default" href="{{ url_for('create', table='courses', handle='new'+(randint(0,1000)|string), responsible=session.user.givenName, ref=request.url) }}">Neue Veranstaltung</a>
 			</li>
 			{% endif %}
 			<li class="dropdown" style="padding-right: 0px">
-- 
GitLab