fixes to academic information, dropdown menus

This commit is contained in:
crunk 2022-02-18 14:47:37 +01:00
parent ef219832f1
commit 6e4ae4b419
8 changed files with 48 additions and 19 deletions

View File

@ -9,13 +9,13 @@ class Distribusis(db.Model):
id = db.Column(db.Integer, primary_key=True) id = db.Column(db.Integer, primary_key=True)
distribusiname = db.Column(db.String(300), nullable=True, unique=True) distribusiname = db.Column(db.String(300), nullable=True, unique=True)
userid = db.Column(db.Integer, db.ForeignKey("users.id")) userid = db.Column(db.Integer, db.ForeignKey("users.id"))
term = db.Column(db.Integer, nullable=False, unique=False) term = db.Column(db.String(5), nullable=False, unique=False)
course = db.Column(db.String(500), nullable=True, unique=False) course = db.Column(db.String(500), nullable=True, unique=False)
# Academic year eg:2020-2021, so no need for a Datetime object # Academic year eg:2020-2021, so no need for a Datetime object
year = db.Column(db.String(9), nullable=True, unique=False) year = db.Column(db.String(9), nullable=True, unique=False)
tags = db.Column(db.String(500), nullable=True, unique=False) tags = db.Column(db.String(500), nullable=True, unique=False)
visible = db.Column(db.Boolean, server_default="false") visible = db.Column(db.Boolean, default=False)
def __repr__(self): def __repr__(self):
return "<Distribusi %r>" % self.distribusiname return "<Distribusi %r>" % self.distribusiname

View File

@ -21,8 +21,19 @@ class UploadForm(FlaskForm):
"Academic year:", "Academic year:",
validators=[validators.InputRequired(), Length(9, 10)], validators=[validators.InputRequired(), Length(9, 10)],
) )
term = IntegerField( term = SelectField(
"Term:", [validators.InputRequired(), NumberRange(min=1, max=4)] "Term:",
validate_choice=True,
coerce=str,
choices=[
(u'1.2', u'1.2'),
(u'2.3', u'2.3'),
(u'3.1', u'3.1'),
(u'4.1', u'4.1'),
(u'4.2', u'4.2'),
],
option_widget=None,
validators=[DataRequired()]
) )
tags = StringField( tags = StringField(
"Add search tags, comma-separated:", "Add search tags, comma-separated:",

View File

@ -84,7 +84,7 @@ def distribusi():
zipfilename = "{}.zip".format(distribusi.distribusiname) zipfilename = "{}.zip".format(distribusi.distribusiname)
userfolder = os.path.join("stash", distribusi.distribusiname) userfolder = os.path.join("stash", distribusi.distribusiname)
unzipfile = os.path.join(userfolder, zipfilename) unzipfile = os.path.join(userfolder, zipfilename)
print(unzipfile)
if os.path.exists(unzipfile): if os.path.exists(unzipfile):
with zipfile.ZipFile(unzipfile, "r") as zip_ref: with zipfile.ZipFile(unzipfile, "r") as zip_ref:
# To do, replace extractall with inspection and extract # To do, replace extractall with inspection and extract
@ -100,6 +100,8 @@ def distribusi():
parser = build_argparser() parser = build_argparser()
args = parser.parse_args(["-s", cssfile]) args = parser.parse_args(["-s", cssfile])
distribusify(args, userfolder) distribusify(args, userfolder)
distribusi.visible = True
db.session.commit()
return redirect(url_for("index")) return redirect(url_for("index"))
template = render_template( template = render_template(
"distribusi.html", "distribusi.html",
@ -162,9 +164,6 @@ def upload():
shutil.copy(copyzipfile, newuserfolder) shutil.copy(copyzipfile, newuserfolder)
os.remove(os.path.join(APP.config["UPLOAD_FOLDER"], zipfilename)) os.remove(os.path.join(APP.config["UPLOAD_FOLDER"], zipfilename))
files_uploaded = AreFilesUploaded() files_uploaded = AreFilesUploaded()
else:
print("there is a problem with form validation")
print(uploadform.course.data)
template = render_template( template = render_template(
"distribusi.html", "distribusi.html",
uploadform=uploadform, uploadform=uploadform,

View File

@ -29,7 +29,7 @@
.selector-style:after { .selector-style:after {
top: 50%; top: 50%;
left: 85%; left: 95%;
border: solid; border: solid;
content: " "; content: " ";
height: 0; height: 0;
@ -50,3 +50,6 @@ select.selector option{
.selector-style select:focus { .selector-style select:focus {
outline: none; outline: none;
} }
.selector-style select option:hover {
background: #60337F;
}

View File

@ -22,8 +22,10 @@ div#login form {
} }
input[type=text], input[type=password], input[type=file] { input[type=text], input[type=password], input[type=file] {
background-color: #2D3039;
color: white; color: white;
width: 18em;
max-width: 18em;
background-color: #2D3039;
border: 1px solid #E0B0FF; border: 1px solid #E0B0FF;
} }
@ -104,6 +106,9 @@ input[type="submit"]:disabled:focus {
.error { .error {
color: #ff5a5a; color: #ff5a5a;
} }
.delete !important {
color: #ff5a5a;
}
/* unvisited link */ /* unvisited link */
@ -169,8 +174,13 @@ medium
dark dark
#60337F #60337F
yellow background dark
#2D3039
yellow important
#fff600 #fff600
red: danger
ff5a5a
backgrounds backgrounds
*/ */

View File

@ -8,7 +8,7 @@ def AreFilesUploaded():
user = User.query.filter_by(email=current_user.email).first() user = User.query.filter_by(email=current_user.email).first()
distribusi = Distribusis.query.filter_by(userid=user.id).first() distribusi = Distribusis.query.filter_by(userid=user.id).first()
if distribusi is None: if distribusi is None:
print("distribusi is empty") print("distribusi folder is empty")
return False return False
userfolder = os.path.join("stash", distribusi.distribusiname) userfolder = os.path.join("stash", distribusi.distribusiname)
if os.path.exists(userfolder): if os.path.exists(userfolder):
@ -20,7 +20,10 @@ def HasDistribusi():
user = User.query.filter_by(email=current_user.email).first() user = User.query.filter_by(email=current_user.email).first()
distribusi = Distribusis.query.filter_by(userid=user.id).first() distribusi = Distribusis.query.filter_by(userid=user.id).first()
if distribusi is None: if distribusi is None:
print("distribusi is empty") print("no distribusi found")
return False
if distribusi.visible is False:
print("distribusi not visible")
return False return False
return True return True

View File

@ -19,10 +19,12 @@
</fieldset> </fieldset>
<fieldset class="required"> <fieldset class="required">
{{ uploadform.term.label }} {{ uploadform.term.label }}
<div class="selector-style">
{{ uploadform.term }} {{ uploadform.term }}
{% for message in uploadform.term.errors %} {% for message in uploadform.term.errors %}
<div class="error">{{ message }}</div> <div class="error">{{ message }}</div>
{% endfor %} {% endfor %}
</div>
</fieldset> </fieldset>
<fieldset class="required"> <fieldset class="required">
{{ uploadform.course.label }} {{ uploadform.course.label }}

View File

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