color style

This commit is contained in:
CHIEFSOFT\ameye
2025-10-19 13:07:07 -04:00
parent 2baf7c9a55
commit 9d2e0df144
5 changed files with 90 additions and 11 deletions
+8
View File
@@ -208,6 +208,14 @@ def get_myproduct_templates_activate():
response = MyProductsService.process_set_template(data)
return response
@api.route("/panel/account/colorstyle/activate", methods=["POST"])
# @token_required
def get_myproduct_colorstyle_activate():
data = request.get_json()
# logger.info(f"Route Product Template Data ==>>>> {data}")
response = MyProductsService.process_set_colorstyle(data)
return response
@api.route("/panel/contacts", methods=["POST"])
def merms_contacts():
@@ -0,0 +1,8 @@
from marshmallow import Schema, fields
class MyProductSetColorStyleSchema(Schema):
token = fields.Str(required=True)
uid = fields.Str(required=True)
product_id = fields.Str(required=True)
color_style_uid = fields.Str(required=True)
+49 -1
View File
@@ -4,6 +4,7 @@ from flask import session, jsonify
from app.api.enums import SettingsItemsData, KafkaMessage
from app.api.schemas.myproduct_external_url import MyProductExternalUrlSchema
from app.api.schemas.myproduct_set_colorstyle import MyProductSetColorStyleSchema
from app.api.schemas.myproduct_set_template import MyProductSetTemplateSchema
from app.utils.logger import logger
from app.api.services.base_service import BaseService
@@ -30,6 +31,52 @@ class MyProductsService(BaseService):
def process_provision_actions(data):
pass
@staticmethod
def process_set_colorstyle(data):
try:
with db.session.begin():
# logger.info(f"Incoming MyProduct data ==>>>> {data}")
validated_data = MyProductsService.validate_data(data, MyProductSetColorStyleSchema())
token = validated_data.get('token')
uid = validated_data.get('uid')
color_style_uid = validated_data.get('color_style_uid')
product_id = validated_data.get('product_id')
member_data = Members.get_member_by_uid(uid)
member_id = member_data.id
# is this a valid olor scheme
colorStyle= ProductsColorStyle.get_colorstyle_by_product_id_and_uid(product_id, color_style_uid)
if colorStyle and colorStyle.color_style != '':
MembersProducts.set_member_product_colorstyle(member_id, product_id, color_style_uid)
response_data = {}
response_data = {
"product_id": product_id,
"color_style_uid": color_style_uid,
"last_update": datetime.datetime.utcnow(),
}
return ResponseHelper.success(data=response_data)
except ValidationError as err:
logger.error(f"Validation Error: {getattr(err, 'messages', str(err))}")
db.session.rollback()
return ResponseHelper.unprocessable_entity(result_description="Validation exception")
except ValueError as err:
logger.error(f"{getattr(err, 'messages', str(err))}")
db.session.rollback()
return ResponseHelper.error(result_description=str(err))
except Exception as e:
logger.error(f"An error occurred: {str(e)}", exc_info=True)
db.session.rollback()
return ResponseHelper.internal_server_error()
@staticmethod
def process_set_template(data):
try:
@@ -154,9 +201,10 @@ class MyProductsService(BaseService):
response_data = {
"product_id": product_id,
"current_colorstyle_uid": memberSubscription.colorstyle if memberSubscription else None,
"current_template_uid": memberSubscription.product_template if memberSubscription else None,
"custom_template_name": memberSubscription.custom_template if memberSubscription else '',
"templates": color_style_data,
"color_styles": color_style_data,
"last_update": datetime.datetime.utcnow(),
}
+11
View File
@@ -34,6 +34,7 @@ class MembersProducts(db.Model):
custom_template = db.Column(db.String(100), nullable=True)
primary_server = db.Column(db.String(100), nullable=True)
provision_port = db.Column(db.Integer, nullable=True, default=0)
colorstyle = db.Column(db.String(55), nullable=True)
# name = db.Column(db.String(100), nullable=False)
@@ -90,6 +91,15 @@ class MembersProducts(db.Model):
return None
return member_product
@classmethod
def set_member_product_colorstyle(cls, member_id, product_id, colorstyle):
member_product = cls.query.filter_by(member_id=str(member_id), product_id=str(product_id)).first()
if not member_product:
return None
member_product.colorstyle = colorstyle
return colorstyle
@classmethod
def set_member_product_template(cls, member_id, product_id, product_template):
member_product = cls.query.filter_by(member_id=str(member_id), product_id=str(product_id)).first()
@@ -190,6 +200,7 @@ class MembersProducts(db.Model):
'provision_port': self.provision_port,
'product_template': self.product_template,
'custom_template': self.custom_template,
'colorstyle': self.colorstyle,
'updated': self.updated
}
+14 -10
View File
@@ -21,20 +21,24 @@ class ProductsColorStyle(db.Model):
@classmethod
def get_colorstyle_by_product_id(cls, product_id):
templates = cls.query.filter_by(product_id=str(product_id)).all()
if not templates:
# raise ValueError(f"Templates with Product ID {product_id} not found")
colorStyle = cls.query.filter_by(product_id=str(product_id)).all()
if not colorStyle:
return None
return templates
return colorStyle
@classmethod
def get_colorstyle_by_product_id_and_uid(cls, product_id, style_uid):
colorStyle = cls.query.filter_by(product_id=str(product_id), uid=str(style_uid)).first()
if not colorStyle:
return None
return colorStyle
@classmethod
def get_colorstyle_for_office(cls, filters):
templates = cls.query.all()
if not templates:
raise ValueError(f"Templates not found")
return templates
colorStyle = cls.query.all()
if not colorStyle:
raise ValueError(f"Color Style not found")
return colorStyle
# @classmethod
# def get_template_by_uid(cls, template_uid):