|
|
@ -14,85 +14,72 @@ from distribusisinfo import DistribusisInfo |
|
|
|
from app import db |
|
|
|
|
|
|
|
|
|
|
|
def IsZipUploaded(distribusiname): |
|
|
|
userfolder = os.path.join("stash", distribusiname) |
|
|
|
if os.path.exists(userfolder): |
|
|
|
zipfilename = "{}.zip".format(distribusiname) |
|
|
|
if os.path.exists(os.path.join(userfolder, zipfilename)): |
|
|
|
print("folder with zipfile found, file uploaded") |
|
|
|
return True |
|
|
|
print("distribusi folder has no zipfile") |
|
|
|
return False |
|
|
|
|
|
|
|
|
|
|
|
def IsDistribusiLive(distribusiname): |
|
|
|
userfolder = os.path.join("stash", distribusiname) |
|
|
|
if os.path.exists(userfolder): |
|
|
|
zipfilename = "{}.zip".format(distribusiname) |
|
|
|
if os.path.exists(os.path.join(userfolder, zipfilename)): |
|
|
|
print("folder with zipfile found, file uploaded") |
|
|
|
return False |
|
|
|
if len(os.listdir(userfolder)) > 0: |
|
|
|
return True |
|
|
|
print("distribusi folder is empty") |
|
|
|
return False |
|
|
|
|
|
|
|
|
|
|
|
def IsCssSelected(distribusiname): |
|
|
|
userfolder = os.path.join("themes/userthemes", distribusiname) |
|
|
|
if os.path.exists(userfolder): |
|
|
|
for file in os.listdir(userfolder): |
|
|
|
if file.endswith(".css"): |
|
|
|
class UserHelper: |
|
|
|
def is_zip_uploaded(distribusiname): |
|
|
|
userfolder = os.path.join("stash", distribusiname) |
|
|
|
if os.path.exists(userfolder): |
|
|
|
zipfilename = "{}.zip".format(distribusiname) |
|
|
|
if os.path.exists(os.path.join(userfolder, zipfilename)): |
|
|
|
print("folder with zipfile found, file uploaded") |
|
|
|
return True |
|
|
|
print("distribusi folder has no css file") |
|
|
|
return False |
|
|
|
|
|
|
|
|
|
|
|
def HasDistribusi(): |
|
|
|
user = User.query.filter_by(email=current_user.email).first() |
|
|
|
distribusi = Distribusis.query.filter_by(userid=user.id).first() |
|
|
|
if distribusi is None: |
|
|
|
print("no distribusi found") |
|
|
|
print("distribusi folder has no zipfile") |
|
|
|
return False |
|
|
|
return True |
|
|
|
|
|
|
|
def is_distribusi_live(distribusiname): |
|
|
|
userfolder = os.path.join("stash", distribusiname) |
|
|
|
if os.path.exists(userfolder): |
|
|
|
zipfilename = "{}.zip".format(distribusiname) |
|
|
|
if os.path.exists(os.path.join(userfolder, zipfilename)): |
|
|
|
print("folder with zipfile found, file uploaded") |
|
|
|
return False |
|
|
|
if len(os.listdir(userfolder)) > 0: |
|
|
|
return True |
|
|
|
print("distribusi folder is empty") |
|
|
|
return False |
|
|
|
|
|
|
|
def CurrentDistribusi(): |
|
|
|
user = User.query.filter_by(email=current_user.email).first() |
|
|
|
if user.currentdistribusi is None: |
|
|
|
return "None" |
|
|
|
return user.currentdistribusi |
|
|
|
|
|
|
|
def is_css_selected(distribusiname): |
|
|
|
userfolder = os.path.join("themes/userthemes", distribusiname) |
|
|
|
if os.path.exists(userfolder): |
|
|
|
for file in os.listdir(userfolder): |
|
|
|
if file.endswith(".css"): |
|
|
|
return True |
|
|
|
print("distribusi folder has no css file") |
|
|
|
return False |
|
|
|
|
|
|
|
def ResetUserState(): |
|
|
|
"""reset user state upon visiting index, so that distribusi workflow can |
|
|
|
be done correctly""" |
|
|
|
if not current_user.is_authenticated: |
|
|
|
return |
|
|
|
try: |
|
|
|
def has_distribusi(): |
|
|
|
user = User.query.filter_by(email=current_user.email).first() |
|
|
|
user.currentdistribusi = None |
|
|
|
db.session.commit() |
|
|
|
except (InvalidRequestError, DataError, InterfaceError, DatabaseError): |
|
|
|
db.session.rollback() |
|
|
|
flash("An error occured !", "danger") |
|
|
|
|
|
|
|
|
|
|
|
def DistribusiLimitReached(): |
|
|
|
user = User.query.filter_by(email=current_user.email).first() |
|
|
|
distribusiamount = len( |
|
|
|
DistribusisInfo.getuserdistribusis(user.email) |
|
|
|
) |
|
|
|
if user.tutor and distribusiamount > 14: |
|
|
|
print("tutor already has 15 distribusis") |
|
|
|
return True |
|
|
|
if not user.tutor and distribusiamount > 4: |
|
|
|
print("user already has 5 distribusis") |
|
|
|
distribusi = Distribusis.query.filter_by(userid=user.id).first() |
|
|
|
if distribusi is None: |
|
|
|
print("no distribusi found") |
|
|
|
return False |
|
|
|
return True |
|
|
|
return False |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# def IsThemeSelected |
|
|
|
# def IsCustomThemePresent |
|
|
|
# def IsDistribusiLive |
|
|
|
def current_distribusi(): |
|
|
|
user = User.query.filter_by(email=current_user.email).first() |
|
|
|
if user.currentdistribusi is None: |
|
|
|
return "None" |
|
|
|
return user.currentdistribusi |
|
|
|
|
|
|
|
def reset_user_state(): |
|
|
|
"""reset user state upon visiting index, so that distribusi workflow can |
|
|
|
be done correctly""" |
|
|
|
if not current_user.is_authenticated: |
|
|
|
return |
|
|
|
try: |
|
|
|
user = User.query.filter_by(email=current_user.email).first() |
|
|
|
user.currentdistribusi = None |
|
|
|
db.session.commit() |
|
|
|
except (InvalidRequestError, DataError, InterfaceError, DatabaseError): |
|
|
|
db.session.rollback() |
|
|
|
flash("An error occured !", "danger") |
|
|
|
|
|
|
|
def distribusi_limit_reached(): |
|
|
|
user = User.query.filter_by(email=current_user.email).first() |
|
|
|
distribusiamount = len(DistribusisInfo.getuserdistribusis(user.email)) |
|
|
|
if user.tutor and distribusiamount > 14: |
|
|
|
print("tutor already has 15 distribusis") |
|
|
|
return True |
|
|
|
if not user.tutor and distribusiamount > 4: |
|
|
|
print("user already has 5 distribusis") |
|
|
|
return True |
|
|
|
return False |
|
|
|