forked from crunk/distribusi-verse
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
90 lines
2.6 KiB
90 lines
2.6 KiB
import os
|
|
from flask_login import current_user
|
|
from flask import flash
|
|
from usermodel import User
|
|
from distribusimodel import Distribusis
|
|
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/userstyles", 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 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")
|
|
return False
|
|
return True
|
|
|
|
|
|
def CurrentDistribusi():
|
|
user = User.query.filter_by(email=current_user.email).first()
|
|
if user.currentdistribusi is None:
|
|
return "None"
|
|
return user.currentdistribusi
|
|
|
|
|
|
def DistribusiSelected():
|
|
user = User.query.filter_by(email=current_user.email).first()
|
|
if user.currentdistribusi is None:
|
|
return False
|
|
return True
|
|
|
|
|
|
def ResetUserState():
|
|
"""reset user state upon visiting index, so that distribusi workflow can
|
|
be done correctly"""
|
|
try:
|
|
user = User.query.filter_by(email=current_user.email).first()
|
|
user.currentdistribusi = None
|
|
db.session.commit()
|
|
except:
|
|
db.session.rollback()
|
|
flash("An error occured !", "danger")
|
|
|
|
|
|
def SelectCurrentDistribusi(distribusiname):
|
|
user = User.query.filter_by(email=current_user.email).first()
|
|
try:
|
|
user.currentdistribusi = distribusiname
|
|
db.session.commit()
|
|
except:
|
|
db.session.rollback()
|
|
flash("An error occured !", "danger")
|
|
|
|
|
|
# def IsThemeSelected
|
|
# def IsCustomThemePresent
|
|
# def IsDistribusiLive
|
|
|