bckend fix
This commit is contained in:
@@ -4,7 +4,7 @@ from app.api.services.base_service import BaseService
|
|||||||
from sqlalchemy import func, desc
|
from sqlalchemy import func, desc
|
||||||
from datetime import datetime, timedelta, timezone
|
from datetime import datetime, timedelta, timezone
|
||||||
from app.extensions import db
|
from app.extensions import db
|
||||||
from app.models import OfficeUsers
|
from app.models import OfficeUsers, CustomTemplates
|
||||||
|
|
||||||
|
|
||||||
class OfficeTemplatesService(BaseService):
|
class OfficeTemplatesService(BaseService):
|
||||||
@@ -78,23 +78,20 @@ class OfficeTemplatesService(BaseService):
|
|||||||
def create_custom_template(data):
|
def create_custom_template(data):
|
||||||
logger.info('create_custom_template')
|
logger.info('create_custom_template')
|
||||||
try:
|
try:
|
||||||
# office_users = OfficeUsers.get_office_users_list()
|
custom_id = data.get('custom_id', '')
|
||||||
# office_users_data = []
|
provision_name = data.get('provision_name', '')
|
||||||
# if office_users:
|
|
||||||
# for t in office_users:
|
similarName = CustomTemplates.get_template_by_custom_id(custom_id)
|
||||||
# office_users_data.append({
|
if not similarName and provision_name !='':
|
||||||
# 'id': t.id,
|
# with db.session.begin():
|
||||||
# 'uid': t.uid,
|
custom_data = CustomTemplates.create_template(custom_id, provision_name)
|
||||||
# 'username': t.username,
|
else:
|
||||||
# 'firstname': t.firstname,
|
custom_data ={
|
||||||
# 'lastname': t.lastname,
|
"error": "Possible duplicate"
|
||||||
# 'acc_level': t.acc_level,
|
}
|
||||||
# 'status': t.status,
|
|
||||||
# 'added': t.added.isoformat() if t.added else None
|
|
||||||
# })
|
|
||||||
|
|
||||||
office_users_result = {
|
office_users_result = {
|
||||||
"set_office_user_template": [],
|
"custom_data": custom_data,
|
||||||
}
|
}
|
||||||
return office_users_result
|
return office_users_result
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,14 @@ from app.extensions import db
|
|||||||
from app.models.charge import Charge
|
from app.models.charge import Charge
|
||||||
from sqlalchemy.orm import relationship
|
from sqlalchemy.orm import relationship
|
||||||
from sqlalchemy.sql import func
|
from sqlalchemy.sql import func
|
||||||
|
from sqlalchemy.exc import IntegrityError
|
||||||
|
from dateutil.relativedelta import relativedelta
|
||||||
|
import logging
|
||||||
|
from sqlalchemy import and_, or_, not_
|
||||||
|
from sqlalchemy.sql import func
|
||||||
|
import uuid
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
class CustomTemplates(db.Model):
|
class CustomTemplates(db.Model):
|
||||||
__tablename__ = 'custom_templates'
|
__tablename__ = 'custom_templates'
|
||||||
@@ -16,12 +23,31 @@ class CustomTemplates(db.Model):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_template_by_custom_id(cls, custom_id):
|
def get_template_by_custom_id(cls, custom_id):
|
||||||
templates = cls.query.filter_by(custom_id=str(custom_id)).all()
|
templates = cls.query.filter_by(custom_id=str(custom_id)).first()
|
||||||
|
|
||||||
if not templates:
|
if not templates:
|
||||||
raise ValueError(f"Templates with Custom ID {custom_id} not found")
|
return None
|
||||||
return templates
|
return templates
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def create_template(cls, custom_id,provision_name):
|
||||||
|
custom_data = cls(
|
||||||
|
uid=str(uuid.uuid4()),
|
||||||
|
custom_id=custom_id,
|
||||||
|
provision_name=provision_name,
|
||||||
|
added=datetime.now(timezone.utc)
|
||||||
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
|
logger.info(f" About to Insert Subscription Data {custom_data.custom_id} ")
|
||||||
|
db.session.add(custom_data)
|
||||||
|
db.session.flush()
|
||||||
|
except IntegrityError as err:
|
||||||
|
logger.error(f" Error inserting custom data {err} -- ")
|
||||||
|
raise ValueError(f"Database integrity error: {err}")
|
||||||
|
return custom_data
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_custom_template_for_office(cls, filters):
|
def get_custom_template_for_office(cls, filters):
|
||||||
templates = cls.query.all()
|
templates = cls.query.all()
|
||||||
|
|||||||
Reference in New Issue
Block a user