Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature-8683: Add Options for Badges in Wizard #8968

Merged
merged 48 commits into from Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
2a41ae6
feature-8683: Add Options for Badges in Wizard
Jul 10, 2023
304bb1b
feature-8683: Add Options for Badges in Wizard
Jul 10, 2023
3adb4c8
feature-8683: Add Options for Badges in Wizard
Jul 10, 2023
040fb44
feature-8683: Add Options for Badges in Wizard
Jul 11, 2023
44e0950
feature-8683: Add Options for Badges in Wizard
Jul 11, 2023
3d73add
feature-8683: Add Options for Badges in Wizard
Jul 11, 2023
c2ac4fc
feature-8683: Add Options for Badges in Wizard
Jul 11, 2023
33a7fa1
feature-8683: Add Options for Badges in Wizard
Jul 11, 2023
c1e4564
Merge branch 'development' into lthanhhieu-tma/feature-8683
Jul 11, 2023
49b3d68
Merge pull request #27 from lthanhhieu/lthanhhieu-tma/feature-8683
khangon Jul 11, 2023
f4db85a
feature-8683: Add Options for Badges in Wizard
odkhang Jul 12, 2023
c592df4
Merge pull request #4 from khangon/khangon_tma/feature-8683
Jul 12, 2023
41ec4fa
feature-8683: Add Options for Badges in Wizard
Jul 13, 2023
e10a3fa
Merge pull request #28 from lthanhhieu/lthanhhieu-tma/feature-8683
khangon Jul 13, 2023
92bd59f
feature-8683: Add Options for Badges in Wizard
odkhang Jul 13, 2023
16b93f3
feature-8683: Add Options for Badges in Wizard
Jul 13, 2023
690babf
feature-8683: Add Options for Badges in Wizard
odkhang Jul 13, 2023
90fb335
Merge pull request #29 from lthanhhieu/lthanhhieu-tma/feature-8683
khangon Jul 14, 2023
5991bf2
feature-8683: Add Options for Badges in Wizard
Jul 14, 2023
b60548f
Merge pull request #5 from khangon/khangon_tma/feature-8683
Jul 14, 2023
d32a06c
feature-8683: Add Options for Badges in Wizard
Jul 14, 2023
d5145f7
feature-8683: Add Options for Badges in Wizard
Jul 14, 2023
9031abf
Merge pull request #30 from lthanhhieu/lthanhhieu-tma/feature-8683
khangon Jul 16, 2023
9935873
feature-8683: Add Options for Badges in Wizard
odkhang Jul 16, 2023
1c72dc2
Merge pull request #6 from khangon/khangon_tma/feature-8683
khangon Jul 16, 2023
a037aa6
feature-8683: Add Options for Badges in Wizard
Jul 17, 2023
9df562f
feature-8683: Add Options for Badges in Wizard
Jul 17, 2023
6e3b299
feature-8683: Add Options for Badges in Wizard
Jul 17, 2023
854b9a0
feature-8683: Add Options for Badges in Wizard
Jul 17, 2023
725685e
thanhhieu-tma/feature-8683: Add print QR code
Jul 18, 2023
ef58dcf
feature-8683: Add Options for Badges in Wizard
Jul 18, 2023
98daed9
feature-8683: Add Options for Badges in Wizard
Jul 18, 2023
9a1044b
feature-8683: Add Options for Badges in Wizard
Jul 18, 2023
ed7f14f
feature-8683: Add Options for Badges in Wizard
Jul 18, 2023
674dd9f
feature-8683: Add Options for Badges in Wizard
Jul 18, 2023
d67c6be
Merge branch 'development' into lthanhhieu-tma/feature-8683
Jul 18, 2023
e3943da
feature-8683: Add Options for Badges in Wizard
Jul 18, 2023
44c88f6
feature-8683: Add Options for Badges in Wizard
Jul 19, 2023
31a3ef1
feature-8683: Merge code development
Jul 19, 2023
04ea004
feature-8683: Merge code development
Jul 19, 2023
7f21dd8
feature-8683: Merge code development
Jul 19, 2023
a93712d
feature-8683: Merge code development
Jul 19, 2023
180a77c
feature-8683: Merge code development
Jul 19, 2023
938382b
feature-8683: Merge code development
Jul 19, 2023
c3864fa
feature-8683: Merge code development
Jul 20, 2023
addc6d1
feature-8683: Add Options for Badges in Wizard
Jul 20, 2023
3f03fe3
feature-8683: EVENTYAY ID in CVF should be the id of ticket holder.
Jul 20, 2023
14c0bb0
Merge branch 'development' into lthanhhieu-tma/feature-8683
Jul 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions app/api/badge_field_forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
from flask_rest_jsonapi import ResourceDetail, ResourceList, ResourceRelationship
from flask_rest_jsonapi.exceptions import ObjectNotFound

from app.api.helpers.permission_manager import has_access
from app.api.helpers.permissions import jwt_required
from app.api.helpers.utilities import require_relationship
from app.api.schema.badge_field_forms import BadgeFieldFormSchema
from app.models import db
from app.models.badge_field_form import BadgeFieldForms


class BadgeFieldFormList(ResourceList):
"""Create and List Custom Form Translates"""

def query(self, view_kwargs):
"""
query method for different view_kwargs
:param view_kwargs:
:return:
"""
query_ = self.session.query(BadgeFieldForms)
if view_kwargs.get('badge_form_id'):
query_ = query_.filter_by(badge_forms_id=view_kwargs['badge_form_id'])
return query_

schema = BadgeFieldFormSchema
data_layer = {
'session': db.session,
'model': BadgeFieldForms,
'methods': {'query': query},
}


class BadgeFieldFormDetail(ResourceDetail):
"""BadgeFieldForm Resource Detail"""

schema = BadgeFieldFormSchema
data_layer = {'session': db.session, 'model': BadgeFieldForms}


class BadgeFieldFormRelationship(ResourceRelationship):
"""BadgeFieldForm Relationship (Required)"""

decorators = (jwt_required,)
methods = ['GET', 'PATCH']
schema = BadgeFieldFormSchema
data_layer = {'session': db.session, 'model': BadgeFieldForms}


class BadgeFieldFormListPost(ResourceList):
"""Create and List Custom Form Translates"""

@staticmethod
def before_post(data):
"""
method to check for required relationship with event
:param data:
:return:
"""
require_relationship(['badge_form'], data)
if not has_access('is_coorganizer', badge_form=data['badge_form']):
raise ObjectNotFound(
{'parameter': 'badge_form'},
f"Custom Form: {data['badge_form']} not found",
)

schema = BadgeFieldFormSchema
methods = [
'POST',
]
data_layer = {'session': db.session, 'model': BadgeFieldForms}
226 changes: 226 additions & 0 deletions app/api/badge_forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
from flask_rest_jsonapi import ResourceDetail, ResourceList, ResourceRelationship
from flask_rest_jsonapi.exceptions import ObjectNotFound

from app.api.bootstrap import api
from app.api.data_layers.BadgeFormLayer import BadgeFormLayer
from app.api.helpers.db import safe_query, safe_query_kwargs
from app.api.helpers.permission_manager import has_access
from app.api.helpers.permissions import jwt_required
from app.api.helpers.query import event_query
from app.api.helpers.utilities import require_relationship
from app.api.schema.badge_forms import BadgeFormSchema
from app.models import db
from app.models.badge_field_form import BadgeFieldForms
from app.models.badge_form import BadgeForms
from app.models.event import Event


class BadgeFormList(ResourceList):
"""Create and List Custom Form Translates"""

def query(self, view_kwargs):
"""
query method for different view_kwargs
:param view_kwargs:
:return:
"""
query_ = self.session.query(BadgeForms)
if view_kwargs.get('badge_id'):
events = safe_query_kwargs(Event, view_kwargs, 'event_id')
query_ = self.session.query(BadgeForms).filter_by(event_id=events.id)
query_ = query_.filter_by(badge_id=view_kwargs.get('badge_id'))
else:
query_ = event_query(query_, view_kwargs)
return query_

@staticmethod
def after_get(badge_forms):
"""
query method for different view_kwargs
:param view_kwargs:
:return:
"""
for item in badge_forms['data']:
badgeFields = []
badgeFieldForms = (
BadgeFieldForms.query.filter_by(badge_form_id=item['id'])
.filter_by(badge_id=item['attributes']['badge-id'])
.all()
)
for badgeFieldForm in badgeFieldForms:
badgeFields.append(badgeFieldForm.convert_to_dict())
item['attributes']['badge-fields'] = badgeFields
return badge_forms

view_kwargs = True
decorators = (jwt_required,)
methods = [
'GET',
]
schema = BadgeFormSchema
data_layer = {
'session': db.session,
'model': BadgeForms,
'methods': {'query': query, 'after_get': after_get},
}


class BadgeFormDetail(ResourceDetail):
"""BadgeForm Resource Detail"""

@staticmethod
def before_get_object(view_kwargs):
"""
before get method
:param view_kwargs:
:return:
"""
event = None
if view_kwargs.get('event_id'):
event = safe_query_kwargs(Event, view_kwargs, 'event_id')
elif view_kwargs.get('event_identifier'):
event = safe_query_kwargs(
Event,
view_kwargs,
'event_identifier',
'identifier',
)

if event:
badge_form = safe_query(BadgeForms, 'event_id', event.id, 'event_id')
view_kwargs['id'] = badge_form.id

@staticmethod
def before_patch(_args, kwargs, data):
"""
before patch method
:param _args:
:param kwargs:
:param data:
:return:
"""
badgeFields = data.get('badge_fields')
if badgeFields:
for badgeField in badgeFields:
badgeFieldForm = None
if 'badge_field_id' in badgeField:
badgeFieldForm = BadgeFieldForms.get_badge_field_form_if_exist(
badgeField['badge_field_id'], badgeField['badge_id']
)
if (
badgeFieldForm is not None
and 'is_deleted' in badgeField
and badgeField['is_deleted']
):
db.session.delete(badgeFieldForm)
else:
if badgeFieldForm:
badgeFieldForm.badge_id = data['badge_id']
else:
badgeFieldForm = BadgeFieldForms()
badgeFieldForm.badge_id = data['badge_id']

badgeFieldForm.badge_form_id = kwargs['id']
badgeFieldForm.field_identifier = badgeField['field_identifier']
badgeFieldForm.custom_field = badgeField['custom_field']
badgeFieldForm.sample_text = badgeField['sample_text']
badgeFieldForm.font_name = badgeField['font_name']
badgeFieldForm.font_size = badgeField['font_size']
badgeFieldForm.font_color = badgeField['font_color']
badgeFieldForm.font_weight = badgeField['font_weight']
badgeFieldForm.text_rotation = badgeField['text_rotation']
badgeFieldForm.text_alignment = badgeField['text_alignment']
badgeFieldForm.text_type = badgeField['text_type']
badgeFieldForm.margin_top = badgeField['margin_top']
badgeFieldForm.margin_bottom = badgeField['margin_bottom']
badgeFieldForm.margin_left = badgeField['margin_left']
badgeFieldForm.margin_right = badgeField['margin_right']
badgeFieldForm.qr_custom_field = badgeField.get('qr_custom_field')
badgeFieldForm.is_deleted = badgeField['is_deleted']
db.session.add(badgeFieldForm)

@staticmethod
def before_delete(_obj, kwargs):
"""
before delete method
:param _obj:
:param kwargs:
:return:
"""
badgeFieldForm = BadgeFieldForms.query.filter_by(badge_form_id=kwargs['id']).all()
for item in badgeFieldForm:
db.session.delete(item)

@staticmethod
def after_patch(badge_form):
"""
after patch method
:param badge_form:
:return:
"""
badgeFields = []
data = badge_form['data']
attributes = data['attributes']
badgeFieldForms = (
BadgeFieldForms.query.filter_by(badge_form_id=data['id'])
.filter_by(badge_id=attributes['badge-id'])
.all()
)
for badgeFieldForm in badgeFieldForms:
badgeFields.append(badgeFieldForm.convert_to_dict())
attributes['badge-fields'] = badgeFields
return badge_form

decorators = (
api.has_permission(
'is_coorganizer',
fetch='event_id',
model=BadgeForms,
methods="PATCH,DELETE",
),
)
schema = BadgeFormSchema
data_layer = {
'session': db.session,
'model': BadgeForms,
'methods': {
'before_patch': before_patch,
'before_delete': before_delete,
'after_patch': after_patch,
},
}


class BadgeFormRelationship(ResourceRelationship):
"""BadgeForm Relationship (Required)"""

decorators = (jwt_required,)
methods = ['GET', 'PATCH']
schema = BadgeFormSchema
data_layer = {'session': db.session, 'model': BadgeForms}


class BadgeFormListPost(ResourceList):
"""Create and List Custom Form Translates"""

@staticmethod
def before_post(_args, _kwargs, data):
"""
method to check for required relationship with event
:param args:
:param kwargs:
:param data:
:return:
"""
require_relationship(['event'], data)
if not has_access('is_coorganizer', event_id=data['event']):
raise ObjectNotFound(
{'parameter': 'event_id'},
f"Event: {data['event_id']} not found",
)

schema = BadgeFormSchema
methods = [
'POST',
]
data_layer = {'class': BadgeFormLayer, 'session': db.session, 'model': BadgeForms}
52 changes: 52 additions & 0 deletions app/api/custom/badge_forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from flask import Blueprint, request
from flask.helpers import send_from_directory
from flask_jwt_extended import jwt_required

from app.api.helpers.badge_forms import create_preivew_badge_pdf, create_print_badge_pdf
from app.api.helpers.errors import ForbiddenError, NotFoundError
from app.api.helpers.permission_manager import has_access
from app.models.badge_form import BadgeForms
from app.models.ticket_holder import TicketHolder

badge_forms_routes = Blueprint(
'badge_forms_routes', __name__, url_prefix='/v1/badge-forms'
)


@badge_forms_routes.route('/preview-badge-pdf', methods=['POST'])
@jwt_required
def preivew_badge_pdf():
"""Preview Badge Template PDF"""
badgeForms = request.json.get('badgeForms')
if badgeForms is None:
raise NotFoundError(
{'source': ''}, 'This badge form is not associated with any ticket'
)

file_path = create_preivew_badge_pdf(badgeForms)
return send_from_directory('../', file_path, as_attachment=True)


@badge_forms_routes.route('/print-badge-pdf', methods=['POST'])
@jwt_required
def print_badge_pdf():
"""Print Badge Template PDF"""
attendee_id = request.json.get('attendee_id')
list_field_show = request.json.get('list_field_show')
ticketHolders = TicketHolder.query.filter_by(id=attendee_id).first()
if ticketHolders is None:
raise NotFoundError(
{'source': ''}, 'This ticket holder is not associated with any ticket'
)
badgeForms = BadgeForms.query.filter_by(
badge_id=ticketHolders.ticket.badge_id
).first()
if badgeForms is None:
raise NotFoundError(
{'source': ''}, 'This badge form is not associated with any ticket'
)
if not has_access('is_coorganizer', event_id=badgeForms.event_id):
raise ForbiddenError({'source': ''}, 'Unauthorized Access')

file_path = create_print_badge_pdf(badgeForms, ticketHolders, list_field_show)
return send_from_directory('../', file_path, as_attachment=True)
25 changes: 25 additions & 0 deletions app/api/custom/schema/badge_form_field.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from marshmallow import Schema, fields


class BadgeFieldFormSchema(Schema):
"""Badge Field Form Schema"""

badge_field_id = fields.Integer(allow_none=False)
badge_id = fields.String(allow_none=False)
field_identifier = fields.String(allow_none=True)
custom_field = fields.String(allow_none=True)
sample_text = fields.String(allow_none=True)
font_size = fields.Integer(allow_none=True)
font_name = fields.String(allow_none=True)
font_weight = fields.Integer(allow_none=True)
font_color = fields.String(allow_none=True)
text_rotation = fields.Integer(allow_none=True)
text_alignment = fields.String(allow_none=True)
text_type = fields.String(allow_none=True)
badge_field_id = fields.Integer(allow_none=True)
is_deleted = fields.Boolean(allow_none=True, default=False)
margin_top = fields.Integer(allow_none=True)
margin_bottom = fields.Integer(allow_none=True)
margin_left = fields.Integer(allow_none=True)
margin_right = fields.Integer(allow_none=True)
qr_custom_field = fields.List(fields.String(), allow_none=True, default=None)
Loading