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