From 4eef509a74498380e487aa9b8c3e3f0423775ec8 Mon Sep 17 00:00:00 2001 From: crunk Date: Tue, 8 Mar 2022 22:58:05 +0100 Subject: [PATCH] start of public custom css sharing --- verse/forms/editorform.py | 14 ++++++++++++++ verse/start.py | 8 +++----- verse/templates/editor.html | 14 ++++++++++++++ verse/templates/index.html | 4 ++-- 4 files changed, 33 insertions(+), 7 deletions(-) diff --git a/verse/forms/editorform.py b/verse/forms/editorform.py index baf5d64..7c3dc8b 100644 --- a/verse/forms/editorform.py +++ b/verse/forms/editorform.py @@ -2,11 +2,13 @@ from wtforms import ( StringField, TextAreaField, + BooleanField, SubmitField, ) from wtforms import validators from wtforms.validators import Length +from flask_wtf.file import FileField, FileAllowed, FileSize from flask_wtf import FlaskForm @@ -17,5 +19,17 @@ class EditorForm(FlaskForm): "fill in a name for your css style:", validators=[validators.InputRequired(), Length(5, 200)], ) + cssfile = FileField( + "(Optional) upload your own css file:", + validators=[ + FileAllowed(["css"], "css files only!"), + FileSize( + max_size=10485760, + message="Zipfile size must be smaller than 100MB", + ), + ], + ) css = TextAreaField() + public = BooleanField("Make your CSS public so others can use it") + submit = SubmitField("Save") diff --git a/verse/start.py b/verse/start.py index 18ed71c..c7133ee 100644 --- a/verse/start.py +++ b/verse/start.py @@ -72,20 +72,18 @@ def index(): distribusies = {} for distribusi in distribusis: user = User.query.filter_by(id=distribusi.userid).first() - #distribusies[distribusi.distribusiname] = user.email - distribusies[user.email] = distribusi singledistribusi = { - "name": distribusi.distribusiname, + "useremail": user.email, "term": distribusi.term, "course": distribusi.course, "year": distribusi.year, "tags": distribusi.tags.split(','), } - distribusies[user.email] = singledistribusi + distribusies[distribusi.distribusiname] = singledistribusi years = uploadform.academicyear.choices terms = uploadform.term.choices courses = uploadform.course.choices - print(type(courses[0])) + template = render_template( "index.html", distribusies=distribusies, diff --git a/verse/templates/editor.html b/verse/templates/editor.html index c41da2d..0f31170 100644 --- a/verse/templates/editor.html +++ b/verse/templates/editor.html @@ -27,6 +27,20 @@
{{ message }}
{% endfor %} +
+ {{ editorform.cssfile.label }} + {{ editorform.cssfile }} + {% for message in editorform.cssfile.errors %} +
{{ message }}
+ {% endfor %} +
+
+ {{ editorform.public.label }} + {{ editorform.public }} + {% for message in editorform.public.errors %} +
{{ message }}
+ {% endfor %} +
{{ editorform.submit }}
diff --git a/verse/templates/index.html b/verse/templates/index.html index 04dac68..d7dd0ed 100644 --- a/verse/templates/index.html +++ b/verse/templates/index.html @@ -44,9 +44,9 @@

List of distribusis

{% include 'filtermenu.html' %}