Browse Source

added course dropdown and fixed multiple distribusi dropdown

current_wdka_release
crunk 3 years ago
parent
commit
ef219832f1
  1. 3
      verse/distribusimodel.py
  2. 18
      verse/forms/uploadform.py
  3. 42
      verse/start.py
  4. 29
      verse/static/css/selector.css
  5. 2
      verse/static/css/style.css
  6. 14
      verse/templates/distribusiworkflow/selector.html
  7. 11
      verse/templates/distribusiworkflow/upload.html
  8. 1
      verse/usermodel.py

3
verse/distribusimodel.py

@ -10,7 +10,8 @@ class Distribusis(db.Model):
distribusiname = db.Column(db.String(300), nullable=True, unique=True)
userid = db.Column(db.Integer, db.ForeignKey("users.id"))
term = db.Column(db.Integer, nullable=False, unique=False)
course = db.Column(db.String(500), nullable=True, unique=False)
# Academic year eg:2020-2021, so no need for a Datetime object
year = db.Column(db.String(9), nullable=True, unique=False)
tags = db.Column(db.String(500), nullable=True, unique=False)

18
verse/forms/uploadform.py

@ -1,11 +1,12 @@
from flask_wtf import FlaskForm
from flask_wtf.file import FileField, FileAllowed, FileRequired, FileSize
from wtforms import validators
from wtforms.validators import Length, NumberRange
from wtforms.validators import Length, NumberRange, DataRequired
from wtforms import (
SubmitField,
StringField,
IntegerField,
SelectField,
)
@ -27,6 +28,21 @@ class UploadForm(FlaskForm):
"Add search tags, comma-separated:",
validators=[validators.InputRequired(), Length(2, 500)],
)
course = SelectField(
u'Course:',
validate_choice=True,
coerce=str,
choices=[
('hacking', u'Autonomous - Hacking'),
('digitalcraft', u'Autonomous - Digital Craft'),
('criticalstudies', u'Autonomous - Critical Studies'),
('publicprivate', u'Autonomous - Public&Private'),
],
option_widget=None,
validators=[DataRequired()]
)
zipfile = FileField(
"Upload your zip file with content here:",
validators=[

42
verse/start.py

@ -119,7 +119,12 @@ def upload():
uploadform = UploadForm()
distribusiform = DistribusiForm()
themeform = ThemeForm()
files_uploaded = False
selectorform = SelectorForm()
selectorform.distribusis.choices = distribusisfields()
files_uploaded = AreFilesUploaded()
has_distribusi = HasDistribusi()
if uploadform.validate_on_submit():
user = User.query.filter_by(email=current_user.email).first()
@ -127,8 +132,9 @@ def upload():
newdistribusi = Distribusis(
distribusiname=uploadform.sitename.data,
userid=user.id,
year=uploadform.academicyear.data,
term=uploadform.term.data,
course=uploadform.course.data,
year=uploadform.academicyear.data,
tags=uploadform.tags.data,
)
db.session.add(newdistribusi)
@ -156,12 +162,17 @@ def upload():
shutil.copy(copyzipfile, newuserfolder)
os.remove(os.path.join(APP.config["UPLOAD_FOLDER"], zipfilename))
files_uploaded = AreFilesUploaded()
else:
print("there is a problem with form validation")
print(uploadform.course.data)
template = render_template(
"distribusi.html",
uploadform=uploadform,
distribusiform=distribusiform,
themeform=themeform,
selectorform=selectorform,
files_uploaded=files_uploaded,
has_distribusi=has_distribusi,
)
return template
@ -172,7 +183,12 @@ def theme():
uploadform = UploadForm()
distribusiform = DistribusiForm()
themeform = ThemeForm()
selectorform = SelectorForm()
selectorform.distribusis.choices = distribusisfields()
files_uploaded = AreFilesUploaded()
has_distribusi = HasDistribusi()
if themeform.validate_on_submit():
user = User.query.filter_by(email=current_user.email).first()
distribusi = Distribusis.query.filter_by(userid=user.id).first()
@ -188,7 +204,9 @@ def theme():
uploadform=uploadform,
distribusiform=distribusiform,
themeform=themeform,
selectorform=selectorform,
files_uploaded=files_uploaded,
has_distribusi=has_distribusi,
)
return template
@ -214,6 +232,26 @@ def editor():
return template
@APP.route("/selector", methods=["GET", "POST"])
@login_required
def selector():
selectorform = SelectorForm()
selectorform.distribusis.choices = distribusisfields()
user = User.query.filter_by(email=current_user.email).first()
if selectorform.validate_on_submit():
print(selectorform.distribusis.data)
print()
template = render_template(
"distribusi.html",
uploadform=uploadform,
distribusiform=distribusiform,
themeform=themeform,
selectorform=selectorform,
files_uploaded=files_uploaded,
has_distribusi=has_distribusi,
)
return template
@APP.route("/stash/<path:path>")
def distribusistash(path):
return send_from_directory("stash", path)

29
verse/static/css/selector.css

@ -2,20 +2,25 @@
padding: 0;
margin: 0;
border: 1px solid #ccc;
width: 120px;
border-radius: 3px;
overflow: hidden;
background-color: #fff;
background: #fff;
width: 20em;
max-width: 20em;
position: relative;
border: none;
background: #E0B0FF;
text-decoration: none;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
margin: 1px;
}
.selector-style select {
padding: 5px 8px;
width: 130%;
padding: 0.2em 0.2em;
width: 20em;
max-width: 20em;
border: none;
box-shadow: none;
background-color: transparent;
background-color: #E0B0FF;
background-image: none;
-webkit-appearance: none;
-moz-appearance: none;
@ -25,7 +30,7 @@
.selector-style:after {
top: 50%;
left: 85%;
border: solid transparent;
border: solid;
content: " ";
height: 0;
width: 0;
@ -33,10 +38,14 @@
pointer-events: none;
border-color: rgba(0, 0, 0, 0);
border-top-color: #000000;
border-width: 5px;
margin-top: -2px;
z-index: 100;
}
select.selector option{
color: white;
background-color: #60337F;
padding: 0 10px;
}
.selector-style select:focus {
outline: none;

2
verse/static/css/style.css

@ -125,6 +125,7 @@ a:hover {
a:active {
color: white;
}
/* STOLEN GOODS */
#fancyboi::before {
content: "$ ";
@ -151,6 +152,7 @@ a:active {
animation: flash 0.5s step-end infinite;
}
}
div.maincontent{
width: 55%;
border: 3px solid #E0B0FF;

14
verse/templates/distribusiworkflow/selector.html

@ -3,11 +3,15 @@
<p>You have already uploaded a distribusi website, do you want to make a new one, update or delete?</p>
<form method="POST" enctype="multipart/form-data" action="{{ url_for('distribusi') }}">
{{ selectorform.csrf_token }}
<select class="selector-style">
{% for subfield in selectorform.distribusis %}
{{ subfield }}
{% endfor %}
</select>
<fieldset class="required">
{{ selectorform.distribusis.label }}
<div class="selector-style">
{{ selectorform.distribusis }}
{% for message in selectorform.distribusis.errors %}
<div class="error">{{ message }}</div>
{% endfor %}
</div>
</fieldset>
<fieldset class="button required multiselect">
{{ selectorform.new }}
</fieldset>

11
verse/templates/distribusiworkflow/upload.html

@ -1,6 +1,6 @@
<div id="upload" class="workflow">
<h3>Step 1: Upload</h3>
<p>Upload your files here, the only accepted file type is a zip file</p>
<p>Upload your files here:</p>
<form method="POST" enctype="multipart/form-data" action="{{ url_for('upload') }}">
{{ uploadform.csrf_token }}
<fieldset class="required">
@ -24,6 +24,15 @@
<div class="error">{{ message }}</div>
{% endfor %}
</fieldset>
<fieldset class="required">
{{ uploadform.course.label }}
<div class="selector-style">
{{ uploadform.course }}
{% for message in uploadform.course.errors %}
<div class="error">{{ message }}</div>
{% endfor %}
</div>
</fieldset>
<fieldset class="required tags">
{{ uploadform.tags.label }}
{{ uploadform.tags }}

1
verse/usermodel.py

@ -10,6 +10,7 @@ class User(UserMixin, db.Model):
id = db.Column(db.Integer, primary_key=True)
email = db.Column(db.String(150), unique=True, nullable=False)
password = db.Column(db.String(300), nullable=False, unique=False)
currentdistribusi = db.Column(db.String(300), nullable=True, unique=False)
def __repr__(self):
return "<User %r>" % self.email

Loading…
Cancel
Save