profile_picture
This commit is contained in:
@@ -148,7 +148,7 @@ def upload_profile_picture_file():
|
|||||||
|
|
||||||
if file and allowed_file(file.filename):
|
if file and allowed_file(file.filename):
|
||||||
logger.info(f'POST CALLED 5 {file.filename}')
|
logger.info(f'POST CALLED 5 {file.filename}')
|
||||||
response = FileUploadService.process_file_upload("WEB_MEDIA", file, member_uid)
|
response = FileUploadService.process_profile_file_upload("PROFILE_MEDIA", file, member_uid)
|
||||||
|
|
||||||
|
|
||||||
if request.method == 'GET':
|
if request.method == 'GET':
|
||||||
|
|||||||
@@ -67,6 +67,75 @@ class FileUploadService(BaseService):
|
|||||||
|
|
||||||
# return file_list
|
# return file_list
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def process_profile_file_upload(upload_type: str, file, member_uid):
|
||||||
|
timestamp_integer = int(time.time())
|
||||||
|
|
||||||
|
## MAKE SURE WE HAVE BASE FOLDERS
|
||||||
|
if not os.path.isdir(FileUploadService.UPLOAD_FOLDER):
|
||||||
|
os.makedirs(FileUploadService.UPLOAD_FOLDER)
|
||||||
|
|
||||||
|
profile_path = FileUploadService.UPLOAD_FOLDER + "/PROFILE"
|
||||||
|
if not os.path.isdir(profile_path):
|
||||||
|
os.makedirs(profile_path)
|
||||||
|
|
||||||
|
file_uid = ""
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Who is this
|
||||||
|
member_data = Members.get_member_by_uid(member_uid)
|
||||||
|
if not member_data:
|
||||||
|
return jsonify({"message": "User not found"}), 500
|
||||||
|
|
||||||
|
member_id = member_data.id
|
||||||
|
final_folder = f"W{member_id:010d}"
|
||||||
|
|
||||||
|
logger.info(f'POST CALLED 5 {file.filename}')
|
||||||
|
save_path = profile_path + "/" + final_folder
|
||||||
|
|
||||||
|
if not os.path.isdir(save_path):
|
||||||
|
os.makedirs(save_path)
|
||||||
|
|
||||||
|
filename = secure_filename(file.filename)
|
||||||
|
# This is to avert duplicate file name issues
|
||||||
|
save_filename = str(timestamp_integer) + "-" + filename
|
||||||
|
final_save_path = os.path.join(save_path, save_filename)
|
||||||
|
|
||||||
|
logger.info(f'POST CALLED 6 {final_save_path}')
|
||||||
|
|
||||||
|
file.save(final_save_path)
|
||||||
|
save_result = []
|
||||||
|
# Confirm file was created before stamping
|
||||||
|
if os.path.isfile(final_save_path):
|
||||||
|
logger.info(f"'{final_save_path}' was found in the folder '{final_save_path}'")
|
||||||
|
|
||||||
|
save_file_props = MemberFileData()
|
||||||
|
save_file_props.member_uid = member_uid
|
||||||
|
save_file_props.filename = filename
|
||||||
|
save_file_props.save_filename = save_filename
|
||||||
|
save_file_props.file_group = "WEBSITE"
|
||||||
|
save_file_props.member_id = member_id
|
||||||
|
save_file_props.file_size = 0
|
||||||
|
save_file_props.file_type = filename.rsplit('.', 1)[1].lower()
|
||||||
|
|
||||||
|
save_result = MembersWebfiles.create_file_profile(save_file_props)
|
||||||
|
logger.info(f"After Insert Members File Data {save_result} ")
|
||||||
|
|
||||||
|
else:
|
||||||
|
logger.info(f"'{final_save_path}' was not found as a file in '{final_save_path}'")
|
||||||
|
|
||||||
|
response_data = {
|
||||||
|
"save_result": save_result,
|
||||||
|
"file_uid": file_uid,
|
||||||
|
}
|
||||||
|
|
||||||
|
return response_data
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"An error occurred while uploading file: {str(e)}", exc_info=True)
|
||||||
|
return jsonify({"message": "Internal Server Error"}), 500
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def process_file_upload(upload_type: str, file, member_uid):
|
def process_file_upload(upload_type: str, file, member_uid):
|
||||||
timestamp_integer = int(time.time())
|
timestamp_integer = int(time.time())
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ class Members(db.Model):
|
|||||||
last_login = db.Column(db.DateTime(timezone=False), server_default=func.now(), onupdate=func.now())
|
last_login = db.Column(db.DateTime(timezone=False), server_default=func.now(), onupdate=func.now())
|
||||||
phone = db.Column(db.String(25), nullable=True)
|
phone = db.Column(db.String(25), nullable=True)
|
||||||
full_address = db.Column(db.String(150), nullable=True)
|
full_address = db.Column(db.String(150), nullable=True)
|
||||||
|
profile_picture = db.Column(db.String(100), nullable=True)
|
||||||
|
|
||||||
# "account_id": self.account_id,
|
# "account_id": self.account_id,
|
||||||
def to_dict(self):
|
def to_dict(self):
|
||||||
@@ -54,7 +55,8 @@ class Members(db.Model):
|
|||||||
'option_name': self.option_name,
|
'option_name': self.option_name,
|
||||||
"next_billing": self.next_billing,
|
"next_billing": self.next_billing,
|
||||||
"trial_end": self.trial_end,
|
"trial_end": self.trial_end,
|
||||||
"stripe_customer_id": self.stripe_customer_id
|
"stripe_customer_id": self.stripe_customer_id,
|
||||||
|
"profile_picture": self.profile_picture,
|
||||||
}
|
}
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user