From 1fa6e78a9df8cc045efbb9f0b034564a57038bb2 Mon Sep 17 00:00:00 2001 From: lthanhhieu Date: Thu, 21 Mar 2024 17:05:40 +0700 Subject: [PATCH 1/4] fix-9127: Add the unique ticket code into the downlad CSV file --- app/models/ticket_holder.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/ticket_holder.py b/app/models/ticket_holder.py index 3501b54e7a..1d8f1371a3 100644 --- a/app/models/ticket_holder.py +++ b/app/models/ticket_holder.py @@ -108,7 +108,7 @@ def qr_code(self): box_size=10, border=0, ) - qr.add_data(self.order.identifier + "-" + str(self.id)) + qr.add_data(self.order.identifier) qr.make(fit=True) img = qr.make_image() From 7a21f9de02e9f549a7f21c0db9dea678ca56a900 Mon Sep 17 00:00:00 2001 From: lthanhhieu Date: Sat, 23 Mar 2024 09:24:04 +0700 Subject: [PATCH 2/4] fix-9127: Add the unique ticket code into the downlad CSV file --- app/api/helpers/csv_jobs_util.py | 12 ++++++--- app/api/schema/attendees.py | 1 + app/models/ticket_holder.py | 16 ++++++++++- app/templates/pdf/attendees_pdf.html | 6 ++++- .../rev-2024-03-23-08:47:20-e7e952b58504_.py | 27 +++++++++++++++++++ 5 files changed, 57 insertions(+), 5 deletions(-) create mode 100644 migrations/versions/rev-2024-03-23-08:47:20-e7e952b58504_.py diff --git a/app/api/helpers/csv_jobs_util.py b/app/api/helpers/csv_jobs_util.py index 18b5b2f711..edf9b3f88e 100644 --- a/app/api/helpers/csv_jobs_util.py +++ b/app/api/helpers/csv_jobs_util.py @@ -82,7 +82,7 @@ def export_orders_csv(orders): return rows -def get_order_ticket_data(order, ticket): +def get_order_ticket_data(attendee, order, ticket): """Get order ticket data""" data = {} if not order: @@ -104,6 +104,12 @@ def get_order_ticket_data(order, ticket): 'City': '', 'Zipcode': '', } + ticketId = '' + if order.identifier: + if not attendee.identifier: + ticketId = order.identifier + '-' + attendee.get_new_identifier() + else: + ticketId = order.identifier + '-' + attendee.identifier data = { 'Order#': str(order.get_invoice_number()), @@ -113,7 +119,7 @@ def get_order_ticket_data(order, ticket): 'Status': str(order.status) if order.status else '-', 'Payment Type': str(order.paid_via) if order.paid_via else '', 'Payment Mode': str(order.payment_mode) if order.payment_mode else '', - 'Ticket ID': str(order.identifier) if order.identifier else '', + 'Ticket ID': ticketId, } if ticket: @@ -162,7 +168,7 @@ def get_ticket_data(ticket): def get_attendee_data(attendee, custom_forms, attendee_form_dict): """Get attendee data from attendee object""" - order_ticket_data = get_order_ticket_data(attendee.order, attendee.ticket) + order_ticket_data = get_order_ticket_data(attendee, attendee.order, attendee.ticket) data = { **order_ticket_data, 'Email': '', diff --git a/app/api/schema/attendees.py b/app/api/schema/attendees.py index 8637d4dba6..f48e1d8f44 100644 --- a/app/api/schema/attendees.py +++ b/app/api/schema/attendees.py @@ -85,6 +85,7 @@ def validate_json(self, data, original_data): is_discount_applied = fields.Boolean(allow_none=True) is_access_code_applied = fields.Boolean(allow_none=True) tag_id = fields.Int(allow_none=True) + identifier = fields.Str(dump_only=True) event = Relationship( self_view='v1.attendee_event', self_view_kwargs={'id': ''}, diff --git a/app/models/ticket_holder.py b/app/models/ticket_holder.py index 1d8f1371a3..fb20ffe1ab 100644 --- a/app/models/ticket_holder.py +++ b/app/models/ticket_holder.py @@ -1,4 +1,6 @@ import base64 +import binascii +import os from dataclasses import dataclass from datetime import datetime from io import BytesIO @@ -11,6 +13,10 @@ from app.models.base import SoftDeletionModel +def get_new_id(): + return str(binascii.b2a_hex(os.urandom(3)), 'utf-8') + + @dataclass(init=False, unsafe_hash=True) class TicketHolder(SoftDeletionModel): __tablename__ = "ticket_holders" @@ -90,6 +96,7 @@ class TicketHolder(SoftDeletionModel): is_access_code_applied: bool = db.Column(db.Boolean, default=False) tag_id: int = db.Column(db.Integer, db.ForeignKey('tags.id', ondelete='CASCADE')) tag = db.relationship('Tag', backref='ticket_holders') + identifier = db.Column(db.String, default=get_new_id) @property def name(self): @@ -108,7 +115,11 @@ def qr_code(self): box_size=10, border=0, ) - qr.add_data(self.order.identifier) + identifier = self.identifier + if not self.identifier: + identifier = get_new_id() + + qr.add_data(self.order.identifier + "-" + identifier) qr.make(fit=True) img = qr.make_image() @@ -143,3 +154,6 @@ def pdf_url_path(self) -> str: + self.order.identifier + '.pdf' ) + + def get_new_identifier(self): + return str(binascii.b2a_hex(os.urandom(3)), 'utf-8') diff --git a/app/templates/pdf/attendees_pdf.html b/app/templates/pdf/attendees_pdf.html index 71eb0160d2..cc3047eef9 100644 --- a/app/templates/pdf/attendees_pdf.html +++ b/app/templates/pdf/attendees_pdf.html @@ -128,7 +128,11 @@

{{ holders[0].event.name }} - {{ ("Attendees List {% else %} {{ "Free Ticket" }}
{% endif %} - {{ holder.order.identifier }}
+ {% if holder.identifier %} + {{ holder.order.identifier }} - {{ holder.identifier }}
+ {% else %} + {{ holder.order.identifier }} - {{ holder.get_new_identifier()}}
+ {% endif %} {{ holder.ticket.name }}
{% if holder.is_checked_in %} {{ ("Checked In") }}
diff --git a/migrations/versions/rev-2024-03-23-08:47:20-e7e952b58504_.py b/migrations/versions/rev-2024-03-23-08:47:20-e7e952b58504_.py new file mode 100644 index 0000000000..18504c1787 --- /dev/null +++ b/migrations/versions/rev-2024-03-23-08:47:20-e7e952b58504_.py @@ -0,0 +1,27 @@ +"""empty message + +Revision ID: e7e952b58504 +Revises: 414c776ae509 +Create Date: 2024-03-23 08:47:20.614874 + +""" + +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = 'e7e952b58504' +down_revision = '414c776ae509' + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.add_column('ticket_holders', sa.Column('identifier', sa.String(), nullable=True)) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column('ticket_holders', 'identifier') + # ### end Alembic commands ### From 8e248bc840dba4296c5cc7d1d784a53771cdf014 Mon Sep 17 00:00:00 2001 From: lthanhhieu Date: Sat, 23 Mar 2024 09:35:09 +0700 Subject: [PATCH 3/4] fix-9127: Add the unique ticket code into the downlad CSV file --- app/models/ticket_holder.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/models/ticket_holder.py b/app/models/ticket_holder.py index fb20ffe1ab..d9fa9251cb 100644 --- a/app/models/ticket_holder.py +++ b/app/models/ticket_holder.py @@ -14,6 +14,7 @@ def get_new_id(): + """Generate a new id for a ticket holder.""" return str(binascii.b2a_hex(os.urandom(3)), 'utf-8') @@ -155,5 +156,7 @@ def pdf_url_path(self) -> str: + '.pdf' ) - def get_new_identifier(self): + @staticmethod + def get_new_identifier(): + """Generate a new identifier for the ticket holder.""" return str(binascii.b2a_hex(os.urandom(3)), 'utf-8') From 884eecefd16ebe6c8910ccbe5b614ad16d2cbb7b Mon Sep 17 00:00:00 2001 From: lthanhhieu Date: Mon, 25 Mar 2024 16:50:07 +0700 Subject: [PATCH 4/4] fix-9127: Add the unique ticket code into the downlad CSV file --- app/api/helpers/csv_jobs_util.py | 2 +- app/models/ticket_holder.py | 7 +------ app/templates/pdf/attendees_pdf.html | 4 ++-- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/app/api/helpers/csv_jobs_util.py b/app/api/helpers/csv_jobs_util.py index edf9b3f88e..71ae66d7ae 100644 --- a/app/api/helpers/csv_jobs_util.py +++ b/app/api/helpers/csv_jobs_util.py @@ -107,7 +107,7 @@ def get_order_ticket_data(attendee, order, ticket): ticketId = '' if order.identifier: if not attendee.identifier: - ticketId = order.identifier + '-' + attendee.get_new_identifier() + ticketId = order.identifier + '-' + str(attendee.id) else: ticketId = order.identifier + '-' + attendee.identifier diff --git a/app/models/ticket_holder.py b/app/models/ticket_holder.py index d9fa9251cb..ddea51fa41 100644 --- a/app/models/ticket_holder.py +++ b/app/models/ticket_holder.py @@ -118,7 +118,7 @@ def qr_code(self): ) identifier = self.identifier if not self.identifier: - identifier = get_new_id() + identifier = str(self.id) qr.add_data(self.order.identifier + "-" + identifier) qr.make(fit=True) @@ -155,8 +155,3 @@ def pdf_url_path(self) -> str: + self.order.identifier + '.pdf' ) - - @staticmethod - def get_new_identifier(): - """Generate a new identifier for the ticket holder.""" - return str(binascii.b2a_hex(os.urandom(3)), 'utf-8') diff --git a/app/templates/pdf/attendees_pdf.html b/app/templates/pdf/attendees_pdf.html index cc3047eef9..d4fefd4729 100644 --- a/app/templates/pdf/attendees_pdf.html +++ b/app/templates/pdf/attendees_pdf.html @@ -129,9 +129,9 @@

{{ holders[0].event.name }} - {{ ("Attendees List {{ "Free Ticket" }}
{% endif %} {% if holder.identifier %} - {{ holder.order.identifier }} - {{ holder.identifier }}
+ {{ holder.order.identifier }}-{{ holder.identifier }}
{% else %} - {{ holder.order.identifier }} - {{ holder.get_new_identifier()}}
+ {{ holder.order.identifier }}-{{ holder.id }}
{% endif %} {{ holder.ticket.name }}
{% if holder.is_checked_in %}