contact actions
This commit is contained in:
@@ -6,6 +6,9 @@ import logging
|
|||||||
from sqlalchemy import and_, or_, not_
|
from sqlalchemy import and_, or_, not_
|
||||||
from sqlalchemy.sql import func
|
from sqlalchemy.sql import func
|
||||||
|
|
||||||
|
from datetime import datetime, timezone
|
||||||
|
import uuid
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
class ProductsContacts(db.Model):
|
class ProductsContacts(db.Model):
|
||||||
@@ -29,6 +32,37 @@ class ProductsContacts(db.Model):
|
|||||||
added = db.Column(db.DateTime(timezone=True), server_default=func.now())
|
added = db.Column(db.DateTime(timezone=True), server_default=func.now())
|
||||||
updated = db.Column(db.DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
|
updated = db.Column(db.DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
|
||||||
|
|
||||||
|
# message = data.get('message', '')
|
||||||
|
# subscription_uid = data.get('subscription_uid', '')
|
||||||
|
# title = data.get('title', '')
|
||||||
|
# email = data.get('email', '')
|
||||||
|
# sender = data.get('sender', '')
|
||||||
|
#
|
||||||
|
@classmethod
|
||||||
|
def add_product_contact(cls, member_id ,product_id,subscription_uid,title,email,sender,message):
|
||||||
|
logger.info(f"Data for Product Contact: {member_id} ,{product_id} ,{subscription_uid} ")
|
||||||
|
product_contact_data = cls(
|
||||||
|
uid=str(uuid.uuid4()),
|
||||||
|
member_id=member_id,
|
||||||
|
product_id=product_id,
|
||||||
|
title=title,
|
||||||
|
email=email,
|
||||||
|
sender=sender,
|
||||||
|
message=message,
|
||||||
|
subscription_uid=subscription_uid,
|
||||||
|
added=datetime.now(timezone.utc),
|
||||||
|
updated=datetime.now(timezone.utc)
|
||||||
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
|
logger.info(f" About to Insert Product Contact Data {product_contact_data.member_id} ")
|
||||||
|
db.session.add(product_contact_data)
|
||||||
|
db.session.flush()
|
||||||
|
except IntegrityError as err:
|
||||||
|
logger.error(f" Error inserting Contact Data {err} -- ")
|
||||||
|
raise ValueError(f"Database integrity error: {err}")
|
||||||
|
return product_contact_data
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def to_dict(self):
|
def to_dict(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user