We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Unable to receive pdf from [/v1/badge-forms/print-badge-pdf]
**Describe the bug**
Internal server error 500 returned with no response of the type of error on the server side.

**To Reproduce**
Steps to reproduce the behavior:
1. Send POST to [/v1/badge-forms/print-badge-pdf] with payload
2. Error 500 with no response received




--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `app/api/helpers/badge_forms.py`
Content:
```
1 import base64
2 import io
3 from datetime import datetime
4 
5 import qrcode
6 from flask import render_template
7 from sqlalchemy import asc
8 
9 from app.api.helpers.db import save_to_db
10 from app.api.helpers.files import create_save_pdf
11 from app.api.helpers.storage import UPLOAD_PATHS, generate_hash
12 from app.api.helpers.utilities import to_snake_case
13 from app.models.badge_field_form import BadgeFieldForms
14 from app.models.custom_form import CustomForms
15 from app.models.ticket_holder import TicketHolder
16 
17 
18 def file_pdf_path(self) -> str:
19     """Contructor path of File PDF"""
20     key = UPLOAD_PATHS['pdf']['badge_forms_pdf'].format(identifier=self.badge_id)
21     return f'static/media/{key}/{generate_hash(key)}/{self.badge_id}.pdf'
22 
23 
24 def create_preivew_badge_pdf(badgeForms):
25     """
26     Create tickets and invoices for the holders of an order.
27     :param badgeForms: The order for which to create tickets for.
28     """
29     badgeForms = badgeForms[0]
30     badgeFieldForms = badgeForms['badgeFields']
31     badgeId = badgeForms['badgeID']
32     for badge_field in badgeFieldForms:
33         font_weight = []
34         font_style = []
35         text_decoration = []
36         if badge_field.get('font_weight'):
37             for item in badge_field.get('font_weight'):
38                 if item.get('font_weight'):
39                     font_weight.append(item.get('font_weight'))
40                 if item.get('font_style'):
41                     font_style.append(item.get('font_style'))
42                 if item.get('text_decoration'):
43                     text_decoration.append(item.get('text_decoration'))
44         if not font_weight:
45             badge_field['font_weight'] = 'none'
46         else:
47             badge_field['font_weight'] = ','.join(font_weight)
48         if not font_style:
49             badge_field['font_style'] = 'none'
50         else:
51             badge_field['font_style'] = ','.join(font_style)
52         if not text_decoration:
53             badge_field['text_decoration'] = 'none'
54         else:
55             badge_field['text_decoration'] = ','.join(text_decoration)
56     create_save_pdf(
57         render_template(
58             'pdf/badge_forms.html', badgeForms=badgeForms, badgeFieldForms=badgeFieldForms
59         ),
60         UPLOAD_PATHS['pdf']['badge_forms_pdf'].format(identifier=badgeId),
61         identifier=badgeId,
62     )
63     key = UPLOAD_PATHS['pdf']['badge_forms_pdf'].format(identifier=badgeId)
64     return f'static/media/{key}/{generate_hash(key)}/{badgeId}.pdf'
65 
66 
67 def get_value_from_field_indentifier(field: BadgeFieldForms, ticket_holder: TicketHolder):
68     """Get the value of a field."""
69     snake_case_field_identifier = to_snake_case(field.field_identifier)
70     try:
71         field.sample_text = getattr(ticket_holder, snake_case_field_identifier)
72     except AttributeError:
73         try:
74             field.sample_text = ticket_holder.complex_field_values[field.field_identifier]
75         except AttributeError:
76             print(snake_case_field_identifier)
77 
78 
79 def get_value_from_qr_filed(field: BadgeFieldForms, ticket_holder: TicketHolder) -> dict:
80     """Get the value of a QR code field."""
81     qr_value = {}
82     custom_fields = []
83     for field_identifier in field.qr_custom_field:
84         value_ = ""
85         try:
86             snake_case_field_identifier = to_snake_case(field_identifier)
87             value_ = getattr(ticket_holder, snake_case_field_identifier)
88         except AttributeError:
89             try:
90                 value_ = ticket_holder.complex_field_values[field_identifier]
91                 # Get the field description then Capitalize first letter and remove space.
92                 custom_form = CustomForms.query.filter_by(
93                     field_identifier=field_identifier,
94                     form_id=ticket_holder.ticket.form_id,
95                 ).first()
96                 field_description = custom_form.description.title().replace(' ', '')
97                 custom_fields.append({field_description: value_})
98             except AttributeError:
99                 print(field_identifier)
100 
101         qr_value.update({field_identifier: str(value_)})
102     qr_value.update({'custom_fields': custom_fields, 'ticket_id': ticket_holder.id})
103     return qr_value
104 
105 
106 def create_base64_img_qr(qr_code_data: str) -> str:
107     """Create a base64 image of a QR code."""
108     qr = qrcode.QRCode(
109         version=1,
110         error_correction=qrcode.constants.ERROR_CORRECT_L,
111         box_size=10,
112         border=2,
113     )
114     qr.add_data(qr_code_data)
115     qr.make(fit=True)
116     img = qr.make_image(fill_color="black", back_color="white")
117     io_buffer = io.BytesIO()
118     img.save(io_buffer)
119     qr_img_str = base64.b64encode(io_buffer.getvalue()).decode()
120     return qr_img_str
121 
122 
123 def create_print_badge_pdf(badge_form, ticket_holder, list_field_show):
124     """
125     Create tickets and invoices for the holders of an order.
126     :param badgeForms: The order for which to create tickets for.
127     """
128     badgeFieldForms = (
129         BadgeFieldForms.query.filter_by(badge_form_id=badge_form.id)
130         .filter_by(badge_id=badge_form.badge_id)
131         .order_by(asc("id"))
132         .all()
133     )
134     for field in badgeFieldForms:
135         if field.custom_field.lower() == 'qr':
136             qr_code_data = get_value_from_qr_filed(field, ticket_holder)
137             qr_rendered = render_template('cvf/badge_qr_template.cvf', **qr_code_data)
138 
139             field.sample_text = create_base64_img_qr(qr_rendered)
140             continue
141         if list_field_show is None or field.field_identifier not in list_field_show:
142             field.sample_text = ' '
143             continue
144 
145         get_value_from_field_indentifier(field, ticket_holder)
146 
147     for badge_field in badgeFieldForms:
148         font_weight = []
149         font_style = []
150         text_decoration = []
151         if badge_field.get('font_weight'):
152             for item in badge_field.get('font_weight'):
153                 if item.get('font_weight'):
154                     font_weight.append(item.get('font_weight'))
155                 if item.get('font_style'):
156                     font_style.append(item.get('font_style'))
157                 if item.get('text_decoration'):
158                     text_decoration.append(item.get('text_decoration'))
159         if not font_weight:
160             badge_field['font_weight'] = 'none'
161         else:
162             badge_field['font_weight'] = ','.join(font_weight)
163         if not font_style:
164             badge_field['font_style'] = 'none'
165         else:
166             badge_field['font_style'] = ','.join(font_style)
167         if not text_decoration:
168             badge_field['text_decoration'] = 'none'
169         else:
170             badge_field['text_decoration'] = ','.join(text_decoration)
171 
172     create_save_pdf(
173         render_template(
174             'pdf/badge_forms.html', badgeForms=badge_form, badgeFieldForms=badgeFieldForms
175         ),
176         UPLOAD_PATHS['pdf']['badge_forms_pdf'].format(identifier=badge_form.badge_id),
177         identifier=badge_form.badge_id,
178     )
179     ticket_holder.is_badge_printed = True
180     ticket_holder.badge_printed_at = datetime.now()
181     save_to_db(ticket_holder, 'Ticket Holder saved')
182     return file_pdf_path(badge_form)
183
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/app/api/helpers/badge_forms.py b/app/api/helpers/badge_forms.py
--- a/app/api/helpers/badge_forms.py
+++ b/app/api/helpers/badge_forms.py
@@ -33,8 +33,8 @@
         font_weight = []
         font_style = []
         text_decoration = []
-        if badge_field.get('font_weight'):
-            for item in badge_field.get('font_weight'):
+        if badge_field['font_weight']:
+            for item in badge_field['font_weight']:
                 if item.get('font_weight'):
                     font_weight.append(item.get('font_weight'))
                 if item.get('font_style'):
@@ -148,8 +148,9 @@
         font_weight = []
         font_style = []
         text_decoration = []
-        if badge_field.get('font_weight'):
-            for item in badge_field.get('font_weight'):
+        badge_field.font_weight_tmp = badge_field.font_weight
+        if badge_field.font_weight:
+            for item in badge_field.font_weight:
                 if item.get('font_weight'):
                     font_weight.append(item.get('font_weight'))
                 if item.get('font_style'):
@@ -157,18 +158,17 @@
                 if item.get('text_decoration'):
                     text_decoration.append(item.get('text_decoration'))
         if not font_weight:
-            badge_field['font_weight'] = 'none'
+            badge_field.font_weight = 'none'
         else:
-            badge_field['font_weight'] = ','.join(font_weight)
+            badge_field.font_weight = ','.join(font_weight)
         if not font_style:
-            badge_field['font_style'] = 'none'
+            badge_field.font_style = 'none'
         else:
-            badge_field['font_style'] = ','.join(font_style)
+            badge_field.font_style = ','.join(font_style)
         if not text_decoration:
-            badge_field['text_decoration'] = 'none'
+            badge_field.text_decoration = 'none'
         else:
-            badge_field['text_decoration'] = ','.join(text_decoration)
-
+            badge_field.text_decoration = ','.join(text_decoration)
     create_save_pdf(
         render_template(
             'pdf/badge_forms.html', badgeForms=badge_form, badgeFieldForms=badgeFieldForms
@@ -178,5 +178,7 @@
     )
     ticket_holder.is_badge_printed = True
     ticket_holder.badge_printed_at = datetime.now()
+    for badge_field in badgeFieldForms:
+        badge_field.font_weight = badge_field.font_weight_tmp
     save_to_db(ticket_holder, 'Ticket Holder saved')
     return file_pdf_path(badge_form)

{"golden_diff": "diff --git a/app/api/helpers/badge_forms.py b/app/api/helpers/badge_forms.py\n--- a/app/api/helpers/badge_forms.py\n+++ b/app/api/helpers/badge_forms.py\n@@ -33,8 +33,8 @@\n         font_weight = []\n         font_style = []\n         text_decoration = []\n-        if badge_field.get('font_weight'):\n-            for item in badge_field.get('font_weight'):\n+        if badge_field['font_weight']:\n+            for item in badge_field['font_weight']:\n                 if item.get('font_weight'):\n                     font_weight.append(item.get('font_weight'))\n                 if item.get('font_style'):\n@@ -148,8 +148,9 @@\n         font_weight = []\n         font_style = []\n         text_decoration = []\n-        if badge_field.get('font_weight'):\n-            for item in badge_field.get('font_weight'):\n+        badge_field.font_weight_tmp = badge_field.font_weight\n+        if badge_field.font_weight:\n+            for item in badge_field.font_weight:\n                 if item.get('font_weight'):\n                     font_weight.append(item.get('font_weight'))\n                 if item.get('font_style'):\n@@ -157,18 +158,17 @@\n                 if item.get('text_decoration'):\n                     text_decoration.append(item.get('text_decoration'))\n         if not font_weight:\n-            badge_field['font_weight'] = 'none'\n+            badge_field.font_weight = 'none'\n         else:\n-            badge_field['font_weight'] = ','.join(font_weight)\n+            badge_field.font_weight = ','.join(font_weight)\n         if not font_style:\n-            badge_field['font_style'] = 'none'\n+            badge_field.font_style = 'none'\n         else:\n-            badge_field['font_style'] = ','.join(font_style)\n+            badge_field.font_style = ','.join(font_style)\n         if not text_decoration:\n-            badge_field['text_decoration'] = 'none'\n+            badge_field.text_decoration = 'none'\n         else:\n-            badge_field['text_decoration'] = ','.join(text_decoration)\n-\n+            badge_field.text_decoration = ','.join(text_decoration)\n     create_save_pdf(\n         render_template(\n             'pdf/badge_forms.html', badgeForms=badge_form, badgeFieldForms=badgeFieldForms\n@@ -178,5 +178,7 @@\n     )\n     ticket_holder.is_badge_printed = True\n     ticket_holder.badge_printed_at = datetime.now()\n+    for badge_field in badgeFieldForms:\n+        badge_field.font_weight = badge_field.font_weight_tmp\n     save_to_db(ticket_holder, 'Ticket Holder saved')\n     return file_pdf_path(badge_form)\n", "issue": "Unable to receive pdf from [/v1/badge-forms/print-badge-pdf]\n**Describe the bug**\r\nInternal server error 500 returned with no response of the type of error on the server side.\r\n\r\n**To Reproduce**\r\nSteps to reproduce the behavior:\r\n1. Send POST to [/v1/badge-forms/print-badge-pdf] with payload\r\n2. Error 500 with no response received\r\n\r\n\r\n\n", "before_files": [{"content": "import base64\nimport io\nfrom datetime import datetime\n\nimport qrcode\nfrom flask import render_template\nfrom sqlalchemy import asc\n\nfrom app.api.helpers.db import save_to_db\nfrom app.api.helpers.files import create_save_pdf\nfrom app.api.helpers.storage import UPLOAD_PATHS, generate_hash\nfrom app.api.helpers.utilities import to_snake_case\nfrom app.models.badge_field_form import BadgeFieldForms\nfrom app.models.custom_form import CustomForms\nfrom app.models.ticket_holder import TicketHolder\n\n\ndef file_pdf_path(self) -> str:\n    \"\"\"Contructor path of File PDF\"\"\"\n    key = UPLOAD_PATHS['pdf']['badge_forms_pdf'].format(identifier=self.badge_id)\n    return f'static/media/{key}/{generate_hash(key)}/{self.badge_id}.pdf'\n\n\ndef create_preivew_badge_pdf(badgeForms):\n    \"\"\"\n    Create tickets and invoices for the holders of an order.\n    :param badgeForms: The order for which to create tickets for.\n    \"\"\"\n    badgeForms = badgeForms[0]\n    badgeFieldForms = badgeForms['badgeFields']\n    badgeId = badgeForms['badgeID']\n    for badge_field in badgeFieldForms:\n        font_weight = []\n        font_style = []\n        text_decoration = []\n        if badge_field.get('font_weight'):\n            for item in badge_field.get('font_weight'):\n                if item.get('font_weight'):\n                    font_weight.append(item.get('font_weight'))\n                if item.get('font_style'):\n                    font_style.append(item.get('font_style'))\n                if item.get('text_decoration'):\n                    text_decoration.append(item.get('text_decoration'))\n        if not font_weight:\n            badge_field['font_weight'] = 'none'\n        else:\n            badge_field['font_weight'] = ','.join(font_weight)\n        if not font_style:\n            badge_field['font_style'] = 'none'\n        else:\n            badge_field['font_style'] = ','.join(font_style)\n        if not text_decoration:\n            badge_field['text_decoration'] = 'none'\n        else:\n            badge_field['text_decoration'] = ','.join(text_decoration)\n    create_save_pdf(\n        render_template(\n            'pdf/badge_forms.html', badgeForms=badgeForms, badgeFieldForms=badgeFieldForms\n        ),\n        UPLOAD_PATHS['pdf']['badge_forms_pdf'].format(identifier=badgeId),\n        identifier=badgeId,\n    )\n    key = UPLOAD_PATHS['pdf']['badge_forms_pdf'].format(identifier=badgeId)\n    return f'static/media/{key}/{generate_hash(key)}/{badgeId}.pdf'\n\n\ndef get_value_from_field_indentifier(field: BadgeFieldForms, ticket_holder: TicketHolder):\n    \"\"\"Get the value of a field.\"\"\"\n    snake_case_field_identifier = to_snake_case(field.field_identifier)\n    try:\n        field.sample_text = getattr(ticket_holder, snake_case_field_identifier)\n    except AttributeError:\n        try:\n            field.sample_text = ticket_holder.complex_field_values[field.field_identifier]\n        except AttributeError:\n            print(snake_case_field_identifier)\n\n\ndef get_value_from_qr_filed(field: BadgeFieldForms, ticket_holder: TicketHolder) -> dict:\n    \"\"\"Get the value of a QR code field.\"\"\"\n    qr_value = {}\n    custom_fields = []\n    for field_identifier in field.qr_custom_field:\n        value_ = \"\"\n        try:\n            snake_case_field_identifier = to_snake_case(field_identifier)\n            value_ = getattr(ticket_holder, snake_case_field_identifier)\n        except AttributeError:\n            try:\n                value_ = ticket_holder.complex_field_values[field_identifier]\n                # Get the field description then Capitalize first letter and remove space.\n                custom_form = CustomForms.query.filter_by(\n                    field_identifier=field_identifier,\n                    form_id=ticket_holder.ticket.form_id,\n                ).first()\n                field_description = custom_form.description.title().replace(' ', '')\n                custom_fields.append({field_description: value_})\n            except AttributeError:\n                print(field_identifier)\n\n        qr_value.update({field_identifier: str(value_)})\n    qr_value.update({'custom_fields': custom_fields, 'ticket_id': ticket_holder.id})\n    return qr_value\n\n\ndef create_base64_img_qr(qr_code_data: str) -> str:\n    \"\"\"Create a base64 image of a QR code.\"\"\"\n    qr = qrcode.QRCode(\n        version=1,\n        error_correction=qrcode.constants.ERROR_CORRECT_L,\n        box_size=10,\n        border=2,\n    )\n    qr.add_data(qr_code_data)\n    qr.make(fit=True)\n    img = qr.make_image(fill_color=\"black\", back_color=\"white\")\n    io_buffer = io.BytesIO()\n    img.save(io_buffer)\n    qr_img_str = base64.b64encode(io_buffer.getvalue()).decode()\n    return qr_img_str\n\n\ndef create_print_badge_pdf(badge_form, ticket_holder, list_field_show):\n    \"\"\"\n    Create tickets and invoices for the holders of an order.\n    :param badgeForms: The order for which to create tickets for.\n    \"\"\"\n    badgeFieldForms = (\n        BadgeFieldForms.query.filter_by(badge_form_id=badge_form.id)\n        .filter_by(badge_id=badge_form.badge_id)\n        .order_by(asc(\"id\"))\n        .all()\n    )\n    for field in badgeFieldForms:\n        if field.custom_field.lower() == 'qr':\n            qr_code_data = get_value_from_qr_filed(field, ticket_holder)\n            qr_rendered = render_template('cvf/badge_qr_template.cvf', **qr_code_data)\n\n            field.sample_text = create_base64_img_qr(qr_rendered)\n            continue\n        if list_field_show is None or field.field_identifier not in list_field_show:\n            field.sample_text = ' '\n            continue\n\n        get_value_from_field_indentifier(field, ticket_holder)\n\n    for badge_field in badgeFieldForms:\n        font_weight = []\n        font_style = []\n        text_decoration = []\n        if badge_field.get('font_weight'):\n            for item in badge_field.get('font_weight'):\n                if item.get('font_weight'):\n                    font_weight.append(item.get('font_weight'))\n                if item.get('font_style'):\n                    font_style.append(item.get('font_style'))\n                if item.get('text_decoration'):\n                    text_decoration.append(item.get('text_decoration'))\n        if not font_weight:\n            badge_field['font_weight'] = 'none'\n        else:\n            badge_field['font_weight'] = ','.join(font_weight)\n        if not font_style:\n            badge_field['font_style'] = 'none'\n        else:\n            badge_field['font_style'] = ','.join(font_style)\n        if not text_decoration:\n            badge_field['text_decoration'] = 'none'\n        else:\n            badge_field['text_decoration'] = ','.join(text_decoration)\n\n    create_save_pdf(\n        render_template(\n            'pdf/badge_forms.html', badgeForms=badge_form, badgeFieldForms=badgeFieldForms\n        ),\n        UPLOAD_PATHS['pdf']['badge_forms_pdf'].format(identifier=badge_form.badge_id),\n        identifier=badge_form.badge_id,\n    )\n    ticket_holder.is_badge_printed = True\n    ticket_holder.badge_printed_at = datetime.now()\n    save_to_db(ticket_holder, 'Ticket Holder saved')\n    return file_pdf_path(badge_form)\n", "path": "app/api/helpers/badge_forms.py"}], "after_files": [{"content": "import base64\nimport io\nfrom datetime import datetime\n\nimport qrcode\nfrom flask import render_template\nfrom sqlalchemy import asc\n\nfrom app.api.helpers.db import save_to_db\nfrom app.api.helpers.files import create_save_pdf\nfrom app.api.helpers.storage import UPLOAD_PATHS, generate_hash\nfrom app.api.helpers.utilities import to_snake_case\nfrom app.models.badge_field_form import BadgeFieldForms\nfrom app.models.custom_form import CustomForms\nfrom app.models.ticket_holder import TicketHolder\n\n\ndef file_pdf_path(self) -> str:\n    \"\"\"Contructor path of File PDF\"\"\"\n    key = UPLOAD_PATHS['pdf']['badge_forms_pdf'].format(identifier=self.badge_id)\n    return f'static/media/{key}/{generate_hash(key)}/{self.badge_id}.pdf'\n\n\ndef create_preivew_badge_pdf(badgeForms):\n    \"\"\"\n    Create tickets and invoices for the holders of an order.\n    :param badgeForms: The order for which to create tickets for.\n    \"\"\"\n    badgeForms = badgeForms[0]\n    badgeFieldForms = badgeForms['badgeFields']\n    badgeId = badgeForms['badgeID']\n    for badge_field in badgeFieldForms:\n        font_weight = []\n        font_style = []\n        text_decoration = []\n        if badge_field['font_weight']:\n            for item in badge_field['font_weight']:\n                if item.get('font_weight'):\n                    font_weight.append(item.get('font_weight'))\n                if item.get('font_style'):\n                    font_style.append(item.get('font_style'))\n                if item.get('text_decoration'):\n                    text_decoration.append(item.get('text_decoration'))\n        if not font_weight:\n            badge_field['font_weight'] = 'none'\n        else:\n            badge_field['font_weight'] = ','.join(font_weight)\n        if not font_style:\n            badge_field['font_style'] = 'none'\n        else:\n            badge_field['font_style'] = ','.join(font_style)\n        if not text_decoration:\n            badge_field['text_decoration'] = 'none'\n        else:\n            badge_field['text_decoration'] = ','.join(text_decoration)\n    create_save_pdf(\n        render_template(\n            'pdf/badge_forms.html', badgeForms=badgeForms, badgeFieldForms=badgeFieldForms\n        ),\n        UPLOAD_PATHS['pdf']['badge_forms_pdf'].format(identifier=badgeId),\n        identifier=badgeId,\n    )\n    key = UPLOAD_PATHS['pdf']['badge_forms_pdf'].format(identifier=badgeId)\n    return f'static/media/{key}/{generate_hash(key)}/{badgeId}.pdf'\n\n\ndef get_value_from_field_indentifier(field: BadgeFieldForms, ticket_holder: TicketHolder):\n    \"\"\"Get the value of a field.\"\"\"\n    snake_case_field_identifier = to_snake_case(field.field_identifier)\n    try:\n        field.sample_text = getattr(ticket_holder, snake_case_field_identifier)\n    except AttributeError:\n        try:\n            field.sample_text = ticket_holder.complex_field_values[field.field_identifier]\n        except AttributeError:\n            print(snake_case_field_identifier)\n\n\ndef get_value_from_qr_filed(field: BadgeFieldForms, ticket_holder: TicketHolder) -> dict:\n    \"\"\"Get the value of a QR code field.\"\"\"\n    qr_value = {}\n    custom_fields = []\n    for field_identifier in field.qr_custom_field:\n        value_ = \"\"\n        try:\n            snake_case_field_identifier = to_snake_case(field_identifier)\n            value_ = getattr(ticket_holder, snake_case_field_identifier)\n        except AttributeError:\n            try:\n                value_ = ticket_holder.complex_field_values[field_identifier]\n                # Get the field description then Capitalize first letter and remove space.\n                custom_form = CustomForms.query.filter_by(\n                    field_identifier=field_identifier,\n                    form_id=ticket_holder.ticket.form_id,\n                ).first()\n                field_description = custom_form.description.title().replace(' ', '')\n                custom_fields.append({field_description: value_})\n            except AttributeError:\n                print(field_identifier)\n\n        qr_value.update({field_identifier: str(value_)})\n    qr_value.update({'custom_fields': custom_fields, 'ticket_id': ticket_holder.id})\n    return qr_value\n\n\ndef create_base64_img_qr(qr_code_data: str) -> str:\n    \"\"\"Create a base64 image of a QR code.\"\"\"\n    qr = qrcode.QRCode(\n        version=1,\n        error_correction=qrcode.constants.ERROR_CORRECT_L,\n        box_size=10,\n        border=2,\n    )\n    qr.add_data(qr_code_data)\n    qr.make(fit=True)\n    img = qr.make_image(fill_color=\"black\", back_color=\"white\")\n    io_buffer = io.BytesIO()\n    img.save(io_buffer)\n    qr_img_str = base64.b64encode(io_buffer.getvalue()).decode()\n    return qr_img_str\n\n\ndef create_print_badge_pdf(badge_form, ticket_holder, list_field_show):\n    \"\"\"\n    Create tickets and invoices for the holders of an order.\n    :param badgeForms: The order for which to create tickets for.\n    \"\"\"\n    badgeFieldForms = (\n        BadgeFieldForms.query.filter_by(badge_form_id=badge_form.id)\n        .filter_by(badge_id=badge_form.badge_id)\n        .order_by(asc(\"id\"))\n        .all()\n    )\n    for field in badgeFieldForms:\n        if field.custom_field.lower() == 'qr':\n            qr_code_data = get_value_from_qr_filed(field, ticket_holder)\n            qr_rendered = render_template('cvf/badge_qr_template.cvf', **qr_code_data)\n\n            field.sample_text = create_base64_img_qr(qr_rendered)\n            continue\n        if list_field_show is None or field.field_identifier not in list_field_show:\n            field.sample_text = ' '\n            continue\n\n        get_value_from_field_indentifier(field, ticket_holder)\n\n    for badge_field in badgeFieldForms:\n        font_weight = []\n        font_style = []\n        text_decoration = []\n        badge_field.font_weight_tmp = badge_field.font_weight\n        if badge_field.font_weight:\n            for item in badge_field.font_weight:\n                if item.get('font_weight'):\n                    font_weight.append(item.get('font_weight'))\n                if item.get('font_style'):\n                    font_style.append(item.get('font_style'))\n                if item.get('text_decoration'):\n                    text_decoration.append(item.get('text_decoration'))\n        if not font_weight:\n            badge_field.font_weight = 'none'\n        else:\n            badge_field.font_weight = ','.join(font_weight)\n        if not font_style:\n            badge_field.font_style = 'none'\n        else:\n            badge_field.font_style = ','.join(font_style)\n        if not text_decoration:\n            badge_field.text_decoration = 'none'\n        else:\n            badge_field.text_decoration = ','.join(text_decoration)\n    create_save_pdf(\n        render_template(\n            'pdf/badge_forms.html', badgeForms=badge_form, badgeFieldForms=badgeFieldForms\n        ),\n        UPLOAD_PATHS['pdf']['badge_forms_pdf'].format(identifier=badge_form.badge_id),\n        identifier=badge_form.badge_id,\n    )\n    ticket_holder.is_badge_printed = True\n    ticket_holder.badge_printed_at = datetime.now()\n    for badge_field in badgeFieldForms:\n        badge_field.font_weight = badge_field.font_weight_tmp\n    save_to_db(ticket_holder, 'Ticket Holder saved')\n    return file_pdf_path(badge_form)\n", "path": "app/api/helpers/badge_forms.py"}]}