Start repo
This commit is contained in:
0
app/models/__init__.py
Normal file
0
app/models/__init__.py
Normal file
BIN
app/models/__pycache__/__init__.cpython-312.pyc
Normal file
BIN
app/models/__pycache__/__init__.cpython-312.pyc
Normal file
Binary file not shown.
BIN
app/models/__pycache__/__init__.cpython-313.pyc
Normal file
BIN
app/models/__pycache__/__init__.cpython-313.pyc
Normal file
Binary file not shown.
BIN
app/models/__pycache__/blocs.cpython-312.pyc
Normal file
BIN
app/models/__pycache__/blocs.cpython-312.pyc
Normal file
Binary file not shown.
BIN
app/models/__pycache__/blocs.cpython-313.pyc
Normal file
BIN
app/models/__pycache__/blocs.cpython-313.pyc
Normal file
Binary file not shown.
BIN
app/models/__pycache__/site.cpython-312.pyc
Normal file
BIN
app/models/__pycache__/site.cpython-312.pyc
Normal file
Binary file not shown.
BIN
app/models/__pycache__/sites.cpython-312.pyc
Normal file
BIN
app/models/__pycache__/sites.cpython-312.pyc
Normal file
Binary file not shown.
BIN
app/models/__pycache__/sites.cpython-313.pyc
Normal file
BIN
app/models/__pycache__/sites.cpython-313.pyc
Normal file
Binary file not shown.
31
app/models/blocs.py
Normal file
31
app/models/blocs.py
Normal file
@@ -0,0 +1,31 @@
|
||||
import json
|
||||
import os
|
||||
from werkzeug.utils import secure_filename
|
||||
from app.forms import *
|
||||
from PIL import Image
|
||||
from os import remove, path
|
||||
|
||||
|
||||
class MyBlocs:
|
||||
|
||||
def makeForm(bloc):
|
||||
match bloc['type']:
|
||||
case 'presentation' :
|
||||
form = Accueil()
|
||||
case 'text' :
|
||||
form = Description()
|
||||
case 'external_link':
|
||||
form = Lien()
|
||||
case 'gallery':
|
||||
form = ImageForm()
|
||||
case 'contact':
|
||||
form = Contact()
|
||||
case _:
|
||||
form = None
|
||||
return form
|
||||
|
||||
def imgForm():
|
||||
return ImageForm()
|
||||
|
||||
def newImgForm():
|
||||
return ImageUpload()
|
||||
93
app/models/sites.py
Normal file
93
app/models/sites.py
Normal file
@@ -0,0 +1,93 @@
|
||||
import json
|
||||
import os
|
||||
from werkzeug.utils import secure_filename
|
||||
from app.forms import *
|
||||
from PIL import Image
|
||||
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
|
||||
|
||||
def loadFile(self):
|
||||
with open(self.filej, '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 updateImg(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'] = ""
|
||||
img['subtitle']=""
|
||||
img['text'] = ""
|
||||
img['category'] = ""
|
||||
img['file']=image_uploaded
|
||||
self.datas['blocs'][bloc][image_uploaded]=img
|
||||
|
||||
def saveJson(self, datas):
|
||||
remove(self.filej)
|
||||
with open (self.filej, 'w') as f:
|
||||
f.write(json.dumps(datas, indent=4))
|
||||
|
||||
def delImg(self, img):
|
||||
try:
|
||||
images = self.datas['images']
|
||||
images.pop(img)
|
||||
except KeyError:
|
||||
print("Le fichier n'est pas dans la liste")
|
||||
else:
|
||||
self.trash.append(img)
|
||||
|
||||
def emptyTrash(self):
|
||||
for file in self.trash:
|
||||
try:
|
||||
remove(self.static_path+'img/portfolio/fullsize/'+file)
|
||||
except FileNotFoundError:
|
||||
print (f'Le fichier {file} n\'existe pas')
|
||||
if path.exists((self.static_path+'img/portfolio/thumbnails/'+file)):
|
||||
remove(self.static_path+'img/portfolio/thumbnails/'+file)
|
||||
self.trash.clear()
|
||||
32
app/models/users.py
Normal file
32
app/models/users.py
Normal file
@@ -0,0 +1,32 @@
|
||||
|
||||
|
||||
class Users:
|
||||
__pub_folder = None
|
||||
__username = None
|
||||
__auth_file = None
|
||||
__auth_method = None
|
||||
|
||||
def __init__(self, username, public_path, auth_file):
|
||||
self.__username = username
|
||||
self.__pub_folder = public_path + '/' +username
|
||||
if auth_file != None:
|
||||
self.__auth_file = auth_file
|
||||
self.__auth_method = "file"
|
||||
|
||||
def getPasswd(self, username):
|
||||
with open(self.auth_file, 'r') as f:
|
||||
users_info = f.readlines()
|
||||
|
||||
for userinfo in users_info:
|
||||
user = userinfo.split(':', maxsplit=1)[0]
|
||||
passwd = userinfo.split(':', maxsplit=1)[1]
|
||||
if user == username:
|
||||
return passwd
|
||||
|
||||
return None
|
||||
|
||||
def getPubfolder:
|
||||
return __pub_folder
|
||||
|
||||
def getUsername:
|
||||
return __username
|
||||
Reference in New Issue
Block a user