a little code clean up
This commit is contained in:
parent
df87fb5337
commit
5922bfcef0
@ -9,6 +9,7 @@ from sqlalchemy.exc import (
|
|||||||
from usermodel import User # noqa: F401
|
from usermodel import User # noqa: F401
|
||||||
from distribusimodel import Distribusis # noqa: F401
|
from distribusimodel import Distribusis # noqa: F401
|
||||||
|
|
||||||
|
|
||||||
def admintool():
|
def admintool():
|
||||||
"""Admin CLI tool. To elevate a user to admin"""
|
"""Admin CLI tool. To elevate a user to admin"""
|
||||||
app = create_app()
|
app = create_app()
|
||||||
|
@ -5,9 +5,9 @@ from flask import (
|
|||||||
render_template,
|
render_template,
|
||||||
redirect,
|
redirect,
|
||||||
url_for,
|
url_for,
|
||||||
|
flash,
|
||||||
)
|
)
|
||||||
from sqlalchemy.exc import (
|
from sqlalchemy.exc import (
|
||||||
IntegrityError,
|
|
||||||
InvalidRequestError,
|
InvalidRequestError,
|
||||||
DataError,
|
DataError,
|
||||||
InterfaceError,
|
InterfaceError,
|
||||||
@ -77,9 +77,7 @@ def UnzipDistribusiFiles(distribusi, userfolder):
|
|||||||
|
|
||||||
def GetCssFile(distribusi):
|
def GetCssFile(distribusi):
|
||||||
cssfile = ""
|
cssfile = ""
|
||||||
cssfolder = os.path.join(
|
cssfolder = os.path.join("themes/userthemes", distribusi.distribusiname)
|
||||||
"themes/userthemes", distribusi.distribusiname
|
|
||||||
)
|
|
||||||
for filename in os.listdir(cssfolder):
|
for filename in os.listdir(cssfolder):
|
||||||
if filename.endswith(".css"):
|
if filename.endswith(".css"):
|
||||||
cssfile = os.path.join(cssfolder, filename)
|
cssfile = os.path.join(cssfolder, filename)
|
||||||
@ -99,7 +97,7 @@ def SetDistribusiToVisible(distribusi, user):
|
|||||||
db.session.commit()
|
db.session.commit()
|
||||||
except (InvalidRequestError, DataError, InterfaceError, DatabaseError):
|
except (InvalidRequestError, DataError, InterfaceError, DatabaseError):
|
||||||
db.session.rollback()
|
db.session.rollback()
|
||||||
distribusiform.submit.errors.append("Unknown error occured!")
|
flash("Unknown error occured!")
|
||||||
|
|
||||||
|
|
||||||
def DeleteCssFile(cssfile):
|
def DeleteCssFile(cssfile):
|
||||||
|
@ -63,10 +63,10 @@ def SaveUploadCssFile(editorform, newcssfolder):
|
|||||||
cssfile = editorform.cssfile.data
|
cssfile = editorform.cssfile.data
|
||||||
cssfilename = f"{secure_filename(editorform.cssname.data)}.css"
|
cssfilename = f"{secure_filename(editorform.cssname.data)}.css"
|
||||||
cssfile.save(os.path.join(newcssfolder, cssfilename))
|
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())
|
cleancss = bleach.clean(openfile.read())
|
||||||
openfile.close()
|
openfile.close()
|
||||||
cleanfile = open(os.path.join(newcssfolder, cssfilename), 'w')
|
cleanfile = open(os.path.join(newcssfolder, cssfilename), "w")
|
||||||
cleanfile.write(cleancss)
|
cleanfile.write(cleancss)
|
||||||
cleanfile.close()
|
cleanfile.close()
|
||||||
|
|
||||||
|
@ -15,6 +15,5 @@ class User(UserMixin, db.Model):
|
|||||||
tutor = db.Column(db.Boolean, default=False)
|
tutor = db.Column(db.Boolean, default=False)
|
||||||
admin = db.Column(db.Boolean, default=False)
|
admin = db.Column(db.Boolean, default=False)
|
||||||
|
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<User %r>" % self.email
|
return "<User %r>" % self.email
|
||||||
|
Loading…
Reference in New Issue
Block a user