We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Users with many allergies or long text overflows their cell in the pdf
Example from prod can be seen on Immball 2015.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `apps/events/pdf_generator.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 from django.contrib.auth.decorators import login_required, user_passes_test
3 
4 from pdfdocument.utils import pdf_response
5 from reportlab.platypus import TableStyle, Paragraph
6 from reportlab.lib import colors
7 from reportlab.lib.styles import getSampleStyleSheet
8 
9 class EventPDF(object):
10 
11     event = None
12     attendees = None
13     waiters = None
14     reservees = None
15     attendee_table_data = None
16     waiters_table_data = None
17     reservee_table_data = None
18     allergies_table_data = None
19 
20     def __init__(self, event):
21         self.event = event
22         attendee_qs = event.attendance_event.attendees_qs
23         self.attendees = sorted(attendee_qs, key=lambda attendee: attendee.user.last_name)
24         self.waiters = event.attendance_event.waitlist_qs
25         self.reservees = event.attendance_event.reservees_qs 
26         self.attendee_table_data = [(u'Navn', u'Klasse', u'Studie', u'Telefon'), ]
27         self.waiters_table_data = [(u'Navn', u'Klasse', u'Studie', u'Telefon'), ]
28         self.reservee_table_data = [(u'Navn', u'Notat'), ]
29         self.allergies_table_data = [(u'Allergisk mot', u'Navn'), ]
30 
31         self.full_span_attendee_lines = []
32         self.full_span_waiters_lines = []
33         self.create_attendees_table_data()
34         self.create_waiters_table_data()
35         self.create_reservees_table_data()
36         
37 
38     # Create table data for attendees with a spot
39     def create_attendees_table_data(self):
40         i = 1
41 
42         for attendee in self.attendees:
43             user = attendee.user
44             self.attendee_table_data.append((
45                                             create_body_text("%s, %s" % (user.last_name, user.first_name)),
46                                             user.year, 
47                                             create_body_text(user.get_field_of_study_display()),
48                                             user.phone_number
49                                             ))
50 
51             if attendee.note:
52                 self.attendee_table_data.append((create_body_text(u'Notat for %s: ' % attendee.user.first_name + attendee.note),))
53                 i += 1
54                 self.full_span_attendee_lines.append(i) 
55             if user.allergies:
56                 self.allergies_table_data.append((user.allergies, user.get_full_name(),))
57 
58             i += 1
59 
60     # Create table data for attendees waiting for a spot
61     def create_waiters_table_data(self):
62         i = 1
63 
64         for attendee in self.waiters:
65             user = attendee.user
66             self.waiters_table_data.append((
67                                             create_body_text("%s, %s" % (user.last_name, user.first_name)),
68                                             user.year, 
69                                             create_body_text(user.get_field_of_study_display()),
70                                             user.phone_number
71                                             ))
72                 
73             if attendee.note:
74                 self.waiters_table_data.append((create_body_text(u'Notat for %s: ' % attendee.user.first_name + attendee.note),))
75                 i += 1
76                 self.full_span_waiters_lines.append(i) 
77             if user.allergies:
78                 self.allergies_table_data.append((user.allergies, user.get_full_name(),))
79 
80             i += 1
81 
82     def create_reservees_table_data(self):
83         for reservee in self.reservees:
84             self.reservee_table_data.append((
85                                              create_body_text(reservee.name), 
86                                              create_body_text(reservee.note)
87                                              ))
88             if reservee.allergies:
89                 self.allergies_table_data.append((
90                                                   create_body_text(reservee.allergies),
91                                                   create_body_text(reservee.name), 
92                                                   ))
93                 if reservee.allergies:
94                     #self.allergies_table_data = self.allergies_table_data + [reservee.name + ' ' + reservee.allergies] 
95                     pass
96 
97     def attendee_column_widths(self):
98         return (185, 40, 170, 75)
99 
100     def reservee_column_widths(self):
101         return (185, 285)
102 
103     def allergies_column_widths(self):
104         return (285, 185)
105 
106     def render_pdf(self):
107         pdf, response = pdf_response(self.event.title + u" attendees")
108         pdf.init_report()
109 
110         pdf.p(self.event.title, style=create_paragraph_style(font_size=18))
111         pdf.spacer(10)
112         pdf.p(self.event.event_start.strftime('%d. %B %Y'), create_paragraph_style(font_size=9))
113         pdf.spacer(height=25)
114 
115         pdf.p(u"Påmeldte", style=create_paragraph_style(font_size=14))
116         pdf.spacer(height=20)
117         pdf.table(self.attendee_table_data, self.attendee_column_widths(), style=get_table_style(self.full_span_attendee_lines))
118         pdf.spacer(height=25)
119         
120         if self.waiters.count() > 0:
121             pdf.p(u"Venteliste", style=create_paragraph_style(font_size=14))
122             pdf.spacer(height=20)
123             pdf.table(self.waiters_table_data, self.attendee_column_widths(), style=get_table_style(self.full_span_waiters_lines))
124             pdf.spacer(height=25)
125     
126         if self.reservees and self.reservees.count() > 0: 
127             pdf.p(u"Reservasjoner", style=create_paragraph_style(font_size=14))
128             pdf.spacer(height=20)
129             pdf.table(self.reservee_table_data, self.reservee_column_widths(), style=get_table_style())
130             pdf.spacer(height=25)
131 
132         if self.allergies_table_data:
133             pdf.p(u"Allergier", style=create_paragraph_style(font_size=14))
134             pdf.spacer(height=20)
135             pdf.table(self.allergies_table_data, self.allergies_column_widths(), style=get_table_style())
136             pdf.spacer(height=25)
137 
138         pdf.generate()
139         return response
140 
141 
142 # Table style for framed table with grids
143 def get_table_style(full_spans=None):
144     style = [
145                 ('GRID',(0,0),(-1,-1),0.5,colors.grey),
146                 ('BOX',(0,0),(-1,-1),1,colors.black),
147             ]
148     if full_spans:
149         for line in full_spans:
150             style.append(('SPAN',(0,line),(-1,line)))
151 
152     return TableStyle(style)
153 
154 # Normal paragraph
155 def create_paragraph_style(font_name='Helvetica', font_size=10, color=colors.black):
156     style = getSampleStyleSheet()['Normal']
157     style.fontSize = font_size
158     style.fontName = font_name
159     style.textColor = color
160 
161     return style
162 
163 # Paragraph with word-wrapping, useful for tables
164 def create_body_text(text, font_name='Helvetica', font_size=10, color=colors.black):
165     style = getSampleStyleSheet()['BodyText']
166     style.fontSize = font_size
167     style.fontName = font_name
168     style.textColor = color
169 
170     return Paragraph(text, style=style)
171
```
--- 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/apps/events/pdf_generator.py b/apps/events/pdf_generator.py
--- a/apps/events/pdf_generator.py
+++ b/apps/events/pdf_generator.py
@@ -6,6 +6,8 @@
 from reportlab.lib import colors
 from reportlab.lib.styles import getSampleStyleSheet
 
+from textwrap import wrap
+
 class EventPDF(object):
 
     event = None
@@ -53,7 +55,9 @@
                 i += 1
                 self.full_span_attendee_lines.append(i) 
             if user.allergies:
-                self.allergies_table_data.append((user.allergies, user.get_full_name(),))
+                # Breaks the line every 60th character
+                allergies = "\n".join(wrap(user.allergies, width=60))
+                self.allergies_table_data.append((allergies, user.get_full_name(),))
 
             i += 1
 
@@ -75,7 +79,9 @@
                 i += 1
                 self.full_span_waiters_lines.append(i) 
             if user.allergies:
-                self.allergies_table_data.append((user.allergies, user.get_full_name(),))
+                # Breaks the line every 60th character
+                allergies = "\n".join(wrap(user.allergies, width=60))
+                self.allergies_table_data.append((allergies, user.get_full_name(),))
 
             i += 1

{"golden_diff": "diff --git a/apps/events/pdf_generator.py b/apps/events/pdf_generator.py\n--- a/apps/events/pdf_generator.py\n+++ b/apps/events/pdf_generator.py\n@@ -6,6 +6,8 @@\n from reportlab.lib import colors\n from reportlab.lib.styles import getSampleStyleSheet\n \n+from textwrap import wrap\n+\n class EventPDF(object):\n \n     event = None\n@@ -53,7 +55,9 @@\n                 i += 1\n                 self.full_span_attendee_lines.append(i) \n             if user.allergies:\n-                self.allergies_table_data.append((user.allergies, user.get_full_name(),))\n+                # Breaks the line every 60th character\n+                allergies = \"\\n\".join(wrap(user.allergies, width=60))\n+                self.allergies_table_data.append((allergies, user.get_full_name(),))\n \n             i += 1\n \n@@ -75,7 +79,9 @@\n                 i += 1\n                 self.full_span_waiters_lines.append(i) \n             if user.allergies:\n-                self.allergies_table_data.append((user.allergies, user.get_full_name(),))\n+                # Breaks the line every 60th character\n+                allergies = \"\\n\".join(wrap(user.allergies, width=60))\n+                self.allergies_table_data.append((allergies, user.get_full_name(),))\n \n             i += 1\n", "issue": "Users with many allergies or long text overflows their cell in the pdf\nExample from prod can be seen on Immball 2015.\n\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\nfrom django.contrib.auth.decorators import login_required, user_passes_test\n\nfrom pdfdocument.utils import pdf_response\nfrom reportlab.platypus import TableStyle, Paragraph\nfrom reportlab.lib import colors\nfrom reportlab.lib.styles import getSampleStyleSheet\n\nclass EventPDF(object):\n\n    event = None\n    attendees = None\n    waiters = None\n    reservees = None\n    attendee_table_data = None\n    waiters_table_data = None\n    reservee_table_data = None\n    allergies_table_data = None\n\n    def __init__(self, event):\n        self.event = event\n        attendee_qs = event.attendance_event.attendees_qs\n        self.attendees = sorted(attendee_qs, key=lambda attendee: attendee.user.last_name)\n        self.waiters = event.attendance_event.waitlist_qs\n        self.reservees = event.attendance_event.reservees_qs \n        self.attendee_table_data = [(u'Navn', u'Klasse', u'Studie', u'Telefon'), ]\n        self.waiters_table_data = [(u'Navn', u'Klasse', u'Studie', u'Telefon'), ]\n        self.reservee_table_data = [(u'Navn', u'Notat'), ]\n        self.allergies_table_data = [(u'Allergisk mot', u'Navn'), ]\n\n        self.full_span_attendee_lines = []\n        self.full_span_waiters_lines = []\n        self.create_attendees_table_data()\n        self.create_waiters_table_data()\n        self.create_reservees_table_data()\n        \n\n    # Create table data for attendees with a spot\n    def create_attendees_table_data(self):\n        i = 1\n\n        for attendee in self.attendees:\n            user = attendee.user\n            self.attendee_table_data.append((\n                                            create_body_text(\"%s, %s\" % (user.last_name, user.first_name)),\n                                            user.year, \n                                            create_body_text(user.get_field_of_study_display()),\n                                            user.phone_number\n                                            ))\n\n            if attendee.note:\n                self.attendee_table_data.append((create_body_text(u'Notat for %s: ' % attendee.user.first_name + attendee.note),))\n                i += 1\n                self.full_span_attendee_lines.append(i) \n            if user.allergies:\n                self.allergies_table_data.append((user.allergies, user.get_full_name(),))\n\n            i += 1\n\n    # Create table data for attendees waiting for a spot\n    def create_waiters_table_data(self):\n        i = 1\n\n        for attendee in self.waiters:\n            user = attendee.user\n            self.waiters_table_data.append((\n                                            create_body_text(\"%s, %s\" % (user.last_name, user.first_name)),\n                                            user.year, \n                                            create_body_text(user.get_field_of_study_display()),\n                                            user.phone_number\n                                            ))\n                \n            if attendee.note:\n                self.waiters_table_data.append((create_body_text(u'Notat for %s: ' % attendee.user.first_name + attendee.note),))\n                i += 1\n                self.full_span_waiters_lines.append(i) \n            if user.allergies:\n                self.allergies_table_data.append((user.allergies, user.get_full_name(),))\n\n            i += 1\n\n    def create_reservees_table_data(self):\n        for reservee in self.reservees:\n            self.reservee_table_data.append((\n                                             create_body_text(reservee.name), \n                                             create_body_text(reservee.note)\n                                             ))\n            if reservee.allergies:\n                self.allergies_table_data.append((\n                                                  create_body_text(reservee.allergies),\n                                                  create_body_text(reservee.name), \n                                                  ))\n                if reservee.allergies:\n                    #self.allergies_table_data = self.allergies_table_data + [reservee.name + ' ' + reservee.allergies] \n                    pass\n\n    def attendee_column_widths(self):\n        return (185, 40, 170, 75)\n\n    def reservee_column_widths(self):\n        return (185, 285)\n\n    def allergies_column_widths(self):\n        return (285, 185)\n\n    def render_pdf(self):\n        pdf, response = pdf_response(self.event.title + u\" attendees\")\n        pdf.init_report()\n\n        pdf.p(self.event.title, style=create_paragraph_style(font_size=18))\n        pdf.spacer(10)\n        pdf.p(self.event.event_start.strftime('%d. %B %Y'), create_paragraph_style(font_size=9))\n        pdf.spacer(height=25)\n\n        pdf.p(u\"P\u00e5meldte\", style=create_paragraph_style(font_size=14))\n        pdf.spacer(height=20)\n        pdf.table(self.attendee_table_data, self.attendee_column_widths(), style=get_table_style(self.full_span_attendee_lines))\n        pdf.spacer(height=25)\n        \n        if self.waiters.count() > 0:\n            pdf.p(u\"Venteliste\", style=create_paragraph_style(font_size=14))\n            pdf.spacer(height=20)\n            pdf.table(self.waiters_table_data, self.attendee_column_widths(), style=get_table_style(self.full_span_waiters_lines))\n            pdf.spacer(height=25)\n    \n        if self.reservees and self.reservees.count() > 0: \n            pdf.p(u\"Reservasjoner\", style=create_paragraph_style(font_size=14))\n            pdf.spacer(height=20)\n            pdf.table(self.reservee_table_data, self.reservee_column_widths(), style=get_table_style())\n            pdf.spacer(height=25)\n\n        if self.allergies_table_data:\n            pdf.p(u\"Allergier\", style=create_paragraph_style(font_size=14))\n            pdf.spacer(height=20)\n            pdf.table(self.allergies_table_data, self.allergies_column_widths(), style=get_table_style())\n            pdf.spacer(height=25)\n\n        pdf.generate()\n        return response\n\n\n# Table style for framed table with grids\ndef get_table_style(full_spans=None):\n    style = [\n                ('GRID',(0,0),(-1,-1),0.5,colors.grey),\n                ('BOX',(0,0),(-1,-1),1,colors.black),\n            ]\n    if full_spans:\n        for line in full_spans:\n            style.append(('SPAN',(0,line),(-1,line)))\n\n    return TableStyle(style)\n\n# Normal paragraph\ndef create_paragraph_style(font_name='Helvetica', font_size=10, color=colors.black):\n    style = getSampleStyleSheet()['Normal']\n    style.fontSize = font_size\n    style.fontName = font_name\n    style.textColor = color\n\n    return style\n\n# Paragraph with word-wrapping, useful for tables\ndef create_body_text(text, font_name='Helvetica', font_size=10, color=colors.black):\n    style = getSampleStyleSheet()['BodyText']\n    style.fontSize = font_size\n    style.fontName = font_name\n    style.textColor = color\n\n    return Paragraph(text, style=style)\n", "path": "apps/events/pdf_generator.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\nfrom django.contrib.auth.decorators import login_required, user_passes_test\n\nfrom pdfdocument.utils import pdf_response\nfrom reportlab.platypus import TableStyle, Paragraph\nfrom reportlab.lib import colors\nfrom reportlab.lib.styles import getSampleStyleSheet\n\nfrom textwrap import wrap\n\nclass EventPDF(object):\n\n    event = None\n    attendees = None\n    waiters = None\n    reservees = None\n    attendee_table_data = None\n    waiters_table_data = None\n    reservee_table_data = None\n    allergies_table_data = None\n\n    def __init__(self, event):\n        self.event = event\n        attendee_qs = event.attendance_event.attendees_qs\n        self.attendees = sorted(attendee_qs, key=lambda attendee: attendee.user.last_name)\n        self.waiters = event.attendance_event.waitlist_qs\n        self.reservees = event.attendance_event.reservees_qs \n        self.attendee_table_data = [(u'Navn', u'Klasse', u'Studie', u'Telefon'), ]\n        self.waiters_table_data = [(u'Navn', u'Klasse', u'Studie', u'Telefon'), ]\n        self.reservee_table_data = [(u'Navn', u'Notat'), ]\n        self.allergies_table_data = [(u'Allergisk mot', u'Navn'), ]\n\n        self.full_span_attendee_lines = []\n        self.full_span_waiters_lines = []\n        self.create_attendees_table_data()\n        self.create_waiters_table_data()\n        self.create_reservees_table_data()\n        \n\n    # Create table data for attendees with a spot\n    def create_attendees_table_data(self):\n        i = 1\n\n        for attendee in self.attendees:\n            user = attendee.user\n            self.attendee_table_data.append((\n                                            create_body_text(\"%s, %s\" % (user.last_name, user.first_name)),\n                                            user.year, \n                                            create_body_text(user.get_field_of_study_display()),\n                                            user.phone_number\n                                            ))\n\n            if attendee.note:\n                self.attendee_table_data.append((create_body_text(u'Notat for %s: ' % attendee.user.first_name + attendee.note),))\n                i += 1\n                self.full_span_attendee_lines.append(i) \n            if user.allergies:\n                # Breaks the line every 60th character\n                allergies = \"\\n\".join(wrap(user.allergies, width=60))\n                self.allergies_table_data.append((allergies, user.get_full_name(),))\n\n            i += 1\n\n    # Create table data for attendees waiting for a spot\n    def create_waiters_table_data(self):\n        i = 1\n\n        for attendee in self.waiters:\n            user = attendee.user\n            self.waiters_table_data.append((\n                                            create_body_text(\"%s, %s\" % (user.last_name, user.first_name)),\n                                            user.year, \n                                            create_body_text(user.get_field_of_study_display()),\n                                            user.phone_number\n                                            ))\n                \n            if attendee.note:\n                self.waiters_table_data.append((create_body_text(u'Notat for %s: ' % attendee.user.first_name + attendee.note),))\n                i += 1\n                self.full_span_waiters_lines.append(i) \n            if user.allergies:\n                # Breaks the line every 60th character\n                allergies = \"\\n\".join(wrap(user.allergies, width=60))\n                self.allergies_table_data.append((allergies, user.get_full_name(),))\n\n            i += 1\n\n    def create_reservees_table_data(self):\n        for reservee in self.reservees:\n            self.reservee_table_data.append((\n                                             create_body_text(reservee.name), \n                                             create_body_text(reservee.note)\n                                             ))\n            if reservee.allergies:\n                self.allergies_table_data.append((\n                                                  create_body_text(reservee.allergies),\n                                                  create_body_text(reservee.name), \n                                                  ))\n                if reservee.allergies:\n                    #self.allergies_table_data = self.allergies_table_data + [reservee.name + ' ' + reservee.allergies] \n                    pass\n\n    def attendee_column_widths(self):\n        return (185, 40, 170, 75)\n\n    def reservee_column_widths(self):\n        return (185, 285)\n\n    def allergies_column_widths(self):\n        return (285, 185)\n\n    def render_pdf(self):\n        pdf, response = pdf_response(self.event.title + u\" attendees\")\n        pdf.init_report()\n\n        pdf.p(self.event.title, style=create_paragraph_style(font_size=18))\n        pdf.spacer(10)\n        pdf.p(self.event.event_start.strftime('%d. %B %Y'), create_paragraph_style(font_size=9))\n        pdf.spacer(height=25)\n\n        pdf.p(u\"P\u00e5meldte\", style=create_paragraph_style(font_size=14))\n        pdf.spacer(height=20)\n        pdf.table(self.attendee_table_data, self.attendee_column_widths(), style=get_table_style(self.full_span_attendee_lines))\n        pdf.spacer(height=25)\n        \n        if self.waiters.count() > 0:\n            pdf.p(u\"Venteliste\", style=create_paragraph_style(font_size=14))\n            pdf.spacer(height=20)\n            pdf.table(self.waiters_table_data, self.attendee_column_widths(), style=get_table_style(self.full_span_waiters_lines))\n            pdf.spacer(height=25)\n    \n        if self.reservees and self.reservees.count() > 0: \n            pdf.p(u\"Reservasjoner\", style=create_paragraph_style(font_size=14))\n            pdf.spacer(height=20)\n            pdf.table(self.reservee_table_data, self.reservee_column_widths(), style=get_table_style())\n            pdf.spacer(height=25)\n\n        if self.allergies_table_data:\n            pdf.p(u\"Allergier\", style=create_paragraph_style(font_size=14))\n            pdf.spacer(height=20)\n            pdf.table(self.allergies_table_data, self.allergies_column_widths(), style=get_table_style())\n            pdf.spacer(height=25)\n\n        pdf.generate()\n        return response\n\n\n# Table style for framed table with grids\ndef get_table_style(full_spans=None):\n    style = [\n                ('GRID',(0,0),(-1,-1),0.5,colors.grey),\n                ('BOX',(0,0),(-1,-1),1,colors.black),\n            ]\n    if full_spans:\n        for line in full_spans:\n            style.append(('SPAN',(0,line),(-1,line)))\n\n    return TableStyle(style)\n\n# Normal paragraph\ndef create_paragraph_style(font_name='Helvetica', font_size=10, color=colors.black):\n    style = getSampleStyleSheet()['Normal']\n    style.fontSize = font_size\n    style.fontName = font_name\n    style.textColor = color\n\n    return style\n\n# Paragraph with word-wrapping, useful for tables\ndef create_body_text(text, font_name='Helvetica', font_size=10, color=colors.black):\n    style = getSampleStyleSheet()['BodyText']\n    style.fontSize = font_size\n    style.fontName = font_name\n    style.textColor = color\n\n    return Paragraph(text, style=style)\n", "path": "apps/events/pdf_generator.py"}]}