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.
61 lines
1.8 KiB
61 lines
1.8 KiB
import os
|
|
import secrets
|
|
from PIL import Image
|
|
from flask import url_for, current_app
|
|
from flask_mail import Message
|
|
from minibase.app import mail
|
|
from minibase.blueprints.main.models import Industries
|
|
import minibase.blueprints.database.utils as dbUtils
|
|
|
|
|
|
def formFill(item, table, to_ignore=[]):
|
|
if item.type not in ["SubmitField", "CSRFTokenField"]:
|
|
if item.name not in to_ignore:
|
|
attribute = getattr(table, item.name)
|
|
if hasattr(attribute, 'name'):
|
|
return getattr(attribute, 'name')
|
|
else:
|
|
return attribute
|
|
|
|
|
|
def modelFill(table, item, to_ignore=[]):
|
|
if item.type not in ["SubmitField", "CSRFTokenField"]:
|
|
print(item.type)
|
|
if item.name not in to_ignore:
|
|
setattr(table, item.name, item.data)
|
|
|
|
|
|
def save_picture(form_picture):
|
|
random_hex = secrets.token_hex(8)
|
|
_, f_ext = os.path.splitext(form_picture.filename)
|
|
picture_fn = random_hex + f_ext
|
|
picture_path = os.path.join(current_app.root_path, 'static/pics', picture_fn)
|
|
output_size = (125, 125)
|
|
i = Image.open(form_picture)
|
|
i.thumbnail(output_size)
|
|
i.save(picture_path)
|
|
return picture_fn
|
|
|
|
|
|
def send_reset_email(user):
|
|
token = user.get_reset_token()
|
|
msg = Message('Password Reset Request',
|
|
sender='noreply@demo.com',
|
|
recipients=[user.email_account])
|
|
msg.body = f'''To reset your password, visit the following link:
|
|
{url_for('user.reset_token', token=token, _external=True)}
|
|
If you didn't make this request, then simply ingnore this email and no chancges will be made.
|
|
'''
|
|
mail.send(msg)
|
|
|
|
|
|
def queryIndustryNames():
|
|
choices = Industries.query.order_by(Industries.name.asc())
|
|
return choices
|
|
|
|
|
|
def queryIndustryNamesWithDefault(defId):
|
|
choices = dbUtils.queryNameWithDefaultId(Industries,defId)
|
|
return choices
|
|
|