a little code clean up

This commit is contained in:
crunk 2022-03-21 20:08:56 +01:00
parent df87fb5337
commit 5922bfcef0
4 changed files with 6 additions and 8 deletions

View File

@ -9,6 +9,7 @@ from sqlalchemy.exc import (
from usermodel import User # noqa: F401
from distribusimodel import Distribusis # noqa: F401
def admintool():
"""Admin CLI tool. To elevate a user to admin"""
app = create_app()

View File

@ -5,9 +5,9 @@ from flask import (
render_template,
redirect,
url_for,
flash,
)
from sqlalchemy.exc import (
IntegrityError,
InvalidRequestError,
DataError,
InterfaceError,
@ -77,9 +77,7 @@ def UnzipDistribusiFiles(distribusi, userfolder):
def GetCssFile(distribusi):
cssfile = ""
cssfolder = os.path.join(
"themes/userthemes", distribusi.distribusiname
)
cssfolder = os.path.join("themes/userthemes", distribusi.distribusiname)
for filename in os.listdir(cssfolder):
if filename.endswith(".css"):
cssfile = os.path.join(cssfolder, filename)
@ -99,7 +97,7 @@ def SetDistribusiToVisible(distribusi, user):
db.session.commit()
except (InvalidRequestError, DataError, InterfaceError, DatabaseError):
db.session.rollback()
distribusiform.submit.errors.append("Unknown error occured!")
flash("Unknown error occured!")
def DeleteCssFile(cssfile):

View File

@ -63,10 +63,10 @@ def SaveUploadCssFile(editorform, newcssfolder):
cssfile = editorform.cssfile.data
cssfilename = f"{secure_filename(editorform.cssname.data)}.css"
cssfile.save(os.path.join(newcssfolder, cssfilename))
openfile = open(os.path.join(newcssfolder, cssfilename), 'r')
openfile = open(os.path.join(newcssfolder, cssfilename), "r")
cleancss = bleach.clean(openfile.read())
openfile.close()
cleanfile = open(os.path.join(newcssfolder, cssfilename), 'w')
cleanfile = open(os.path.join(newcssfolder, cssfilename), "w")
cleanfile.write(cleancss)
cleanfile.close()

View File

@ -15,6 +15,5 @@ class User(UserMixin, db.Model):
tutor = db.Column(db.Boolean, default=False)
admin = db.Column(db.Boolean, default=False)
def __repr__(self):
return "<User %r>" % self.email