update sites.py for a folder per user
This commit is contained in:
@@ -7,49 +7,51 @@ from os import remove, path
|
||||
|
||||
|
||||
class DataSite:
|
||||
filej = ""
|
||||
datas = ""
|
||||
static_path =""
|
||||
trash = list()
|
||||
|
||||
def __init__(self, filej, static_path):
|
||||
self.filej = filej
|
||||
self.static_path = static_path
|
||||
datas = ""
|
||||
static_path = ""
|
||||
trash = list()
|
||||
filej= ""
|
||||
|
||||
def __init__(self, username, users_folder ):
|
||||
self.filej = os.path.join(users_folder, username,'ident.json')
|
||||
|
||||
with open(self.filej, 'r') as f:
|
||||
self.datas = json.load(f)
|
||||
self.static_path = os.path.join(users_folder, username, 'public')
|
||||
|
||||
def loadFile(self):
|
||||
with open(self.filej, 'r') as f:
|
||||
self.datas = json.load(f)
|
||||
|
||||
def loadFile_tmp(self):
|
||||
with open(self.filej_tmp, 'r') as f:
|
||||
self.datas = json.load(f)
|
||||
|
||||
def updateDatas(self, bloc, form):
|
||||
match bloc['type']:
|
||||
case "presentation":
|
||||
self.datas['blocs'][bloc['name']]['title'] = form.title.data
|
||||
self.datas['blocs'][bloc['name']]['text'] = form.text.data
|
||||
self.datas['blocs'][bloc['name']]['text_button']=form.text_button.data
|
||||
self.datas['blocs'][bloc['name']]['link'] = form.link.data
|
||||
if form.image.data :
|
||||
f=form.image.data
|
||||
filename = secure_filename(f.filename)
|
||||
extension = filename.rsplit('.', 1)[1].lower()
|
||||
f.save(os.path.join(
|
||||
self.static_path, 'img','bg_custom.'+ extension))
|
||||
self.datas['blocs'][bloc['name']]['bg_img']='bg_custom.'+extension
|
||||
case "text" :
|
||||
self.datas['blocs'][bloc['name']]['title']=form.title.data
|
||||
self.datas['blocs'][bloc['name']]['text']=form.text.data
|
||||
case "external_link" :
|
||||
self.datas['blocs'][bloc['name']]['title'] = form.title.data
|
||||
self.datas['blocs'][bloc['name']]['text'] = form.text.data
|
||||
self.datas['blocs'][bloc['name']]['link'] = form.link.data
|
||||
self.datas['blocs'][bloc['name']]['text_button']=form.text_button.data
|
||||
case 'contact':
|
||||
self.datas['blocs'][bloc['name']]['title'] = form.title.data
|
||||
self.datas['blocs'][bloc['name']]['text'] = form.text.data
|
||||
self.datas['blocs'][bloc['name']]['email'] = form.email.data
|
||||
self.datas['blocs'][bloc['name']]['phone'] = form.phone.data
|
||||
self.datas['blocs'][bloc['name']]['postal_code'] = form.postal_code.data
|
||||
self.datas['blocs'][bloc['name']]['city'] = form.city.data
|
||||
|
||||
def updateBloc(bloc, form):
|
||||
bloc['name'] = form.name.data
|
||||
bloc['bg_color'] = form.bg_color.data
|
||||
bloc['fg_color']=form.fg_color.data
|
||||
bloc['title'] = form.title.data
|
||||
bloc['text'] = form.text.data
|
||||
bloc['text_button']=form.text_button.data
|
||||
bloc['link'] = form.link.data
|
||||
if form.image.data :
|
||||
f=form.image.data
|
||||
filename = secure_filename(f.filename)
|
||||
extension = filename.rsplit('.', 1)[1].lower()
|
||||
f.save(os.path.join(
|
||||
self.static_path, 'img','bg_custom.'+ extension))
|
||||
|
||||
bloc['bg_img']='bg_custom.'+extension
|
||||
bloc['email'] = form.email.data
|
||||
bloc['address']=form.address.data
|
||||
bloc['phone'] = form.phone.data
|
||||
bloc['postal_code'] = form.postal_code.data
|
||||
bloc['city'] = form.city.data
|
||||
|
||||
return bloc
|
||||
|
||||
def updateImg(self, bloc, img, form):
|
||||
filename = img['file']
|
||||
@@ -59,6 +61,15 @@ class DataSite:
|
||||
img['category'] = form.category.data
|
||||
self.datas['blocs'][bloc][filename]=img
|
||||
|
||||
def updateImg_tmp(self, bloc, img, form):
|
||||
filename = img['file']
|
||||
img['title'] = form.title.data
|
||||
img['subtitle'] = form.subtitle.data
|
||||
img['description'] = form.description.data
|
||||
img['category'] = form.category.data
|
||||
self.datas['blocs'][bloc][filename]=img
|
||||
|
||||
|
||||
def addImg(self, bloc, image_uploaded):
|
||||
img = dict()
|
||||
img['title'] = ""
|
||||
@@ -68,10 +79,20 @@ class DataSite:
|
||||
img['file']=image_uploaded
|
||||
self.datas['blocs'][bloc][image_uploaded]=img
|
||||
|
||||
def saveJson(self, datas):
|
||||
|
||||
def addImg_tmp(self, bloc, image_uploaded):
|
||||
img = dict()
|
||||
img['title'] = ""
|
||||
img['subtitle']=""
|
||||
img['text'] = ""
|
||||
img['category'] = ""
|
||||
img['file']=image_uploaded
|
||||
self.datas_tmp['blocs'][bloc][image_uploaded]=img
|
||||
|
||||
def saveJson(self):
|
||||
remove(self.filej)
|
||||
with open (self.filej, 'w') as f:
|
||||
f.write(json.dumps(datas, indent=4))
|
||||
f.write(json.dumps(self.datas, indent=5))
|
||||
|
||||
def delImg(self, img):
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user