2022-01-23 14:36:23 +01:00
|
|
|
import os
|
|
|
|
from flask_login import current_user
|
2022-03-04 19:08:55 +01:00
|
|
|
from flask import flash
|
2022-01-23 14:36:23 +01:00
|
|
|
from usermodel import User
|
2022-02-13 21:49:07 +01:00
|
|
|
from distribusimodel import Distribusis
|
2022-03-04 19:08:55 +01:00
|
|
|
from app import db
|
2022-01-23 17:33:50 +01:00
|
|
|
|
2022-02-13 22:24:56 +01:00
|
|
|
|
2022-03-04 19:08:55 +01:00
|
|
|
def IsZipUploaded(distribusiname):
|
|
|
|
userfolder = os.path.join("stash", distribusiname)
|
2022-01-23 14:36:23 +01:00
|
|
|
if os.path.exists(userfolder):
|
2022-03-04 19:08:55 +01:00
|
|
|
zipfilename = "{}.zip".format(distribusiname)
|
|
|
|
if os.path.exists(os.path.join(userfolder, zipfilename)):
|
|
|
|
print("folder with zipfile found, file uploaded")
|
|
|
|
return True
|
2022-03-18 17:32:49 +01:00
|
|
|
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
|
2022-03-04 19:08:55 +01:00
|
|
|
print("distribusi folder is empty")
|
|
|
|
return False
|
2022-01-23 17:33:50 +01:00
|
|
|
|
2022-01-23 14:36:23 +01:00
|
|
|
|
2022-03-04 21:10:06 +01:00
|
|
|
def IsCssSelected(distribusiname):
|
2022-03-18 17:32:49 +01:00
|
|
|
userfolder = os.path.join("themes/userstyles", distribusiname)
|
2022-03-04 21:10:06 +01:00
|
|
|
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
|
|
|
|
|
|
|
|
|
2022-02-18 09:58:24 +01:00
|
|
|
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:
|
2022-02-18 14:47:37 +01:00
|
|
|
print("no distribusi found")
|
|
|
|
return False
|
2022-02-18 09:58:24 +01:00
|
|
|
return True
|
|
|
|
|
|
|
|
|
2022-03-04 16:41:14 +01:00
|
|
|
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
|
|
|
|
|
2022-03-04 19:08:55 +01:00
|
|
|
|
|
|
|
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")
|
|
|
|
|
|
|
|
|
2022-03-18 17:32:49 +01:00
|
|
|
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")
|
|
|
|
|
|
|
|
|
2022-01-23 17:33:50 +01:00
|
|
|
# def IsThemeSelected
|
|
|
|
# def IsCustomThemePresent
|
|
|
|
# def IsDistribusiLive
|