prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Internal server error in promotion link
  https://open-event-dev.herokuapp.com/events/110/tickets/promotion/
  
  
  --- 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/views/admin/models_views/ticket_sales.py`
  Content:
  ```
  1 import flask_login
  2 import pycountry
  3 from flask import redirect
  4 from flask import request
  5 from flask import url_for
  6 from flask_admin import BaseView, expose
  7 
  8 from app import get_settings
  9 from app.helpers.cache import cache
  10 from app.helpers.data_getter import DataGetter
  11 from app.helpers.ticketing import TicketingManager
  12 from app.models.ticket import Ticket
  13 
  14 class TicketSalesView(BaseView):
  15     @cache.memoize(50)
  16     def get_ticket(self, ticket_id):
  17         return Ticket.query.get(ticket_id)
  18 
  19     @expose('/')
  20     @flask_login.login_required
  21     def display_ticket_stats(self, event_id):
  22         event = DataGetter.get_event(event_id)
  23         orders = TicketingManager.get_orders(event_id)
  24 
  25         completed_count = 0
  26         completed_amount = 0
  27         tickets_count = 0
  28 
  29         orders_summary = {
  30             'completed': {
  31                 'class': 'success',
  32                 'tickets_count': 0,
  33                 'orders_count': 0,
  34                 'total_sales': 0
  35             },
  36             'pending': {
  37                 'class': 'warning',
  38                 'tickets_count': 0,
  39                 'orders_count': 0,
  40                 'total_sales': 0
  41             },
  42             'expired': {
  43                 'class': 'danger',
  44                 'tickets_count': 0,
  45                 'orders_count': 0,
  46                 'total_sales': 0
  47             }
  48         }
  49 
  50         tickets_summary = {}
  51 
  52         for ticket in event.tickets:
  53             tickets_summary[str(ticket.id)] = {
  54                 'name': ticket.name,
  55                 'quantity': ticket.quantity,
  56                 'completed': {
  57                     'tickets_count': 0,
  58                     'sales': 0
  59                 },
  60                 'pending': {
  61                     'tickets_count': 0,
  62                     'sales': 0
  63                 },
  64                 'expired': {
  65                     'class': 'danger',
  66                     'tickets_count': 0,
  67                     'sales': 0
  68                 }
  69             }
  70 
  71         for order in orders:
  72             if order.status == 'initialized':
  73                 order.status = 'pending'
  74             orders_summary[str(order.status)]['orders_count'] += 1
  75             orders_summary[str(order.status)]['total_sales'] += order.amount
  76             for order_ticket in order.tickets:
  77                 orders_summary[str(order.status)]['tickets_count'] += order_ticket.quantity
  78                 ticket = self.get_ticket(order_ticket.ticket_id)
  79                 tickets_summary[str(ticket.id)][str(order.status)]['tickets_count'] += order_ticket.quantity
  80                 tickets_summary[str(ticket.id)][str(order.status)]['sales'] += order_ticket.quantity * ticket.price
  81 
  82         return self.render('/gentelella/admin/event/tickets/tickets.html', event=event, event_id=event_id,
  83                            orders_summary=orders_summary, tickets_summary=tickets_summary)
  84 
  85     @expose('/orders/')
  86     @flask_login.login_required
  87     def display_orders(self, event_id):
  88         event = DataGetter.get_event(event_id)
  89         orders = TicketingManager.get_orders(event_id)
  90         return self.render('/gentelella/admin/event/tickets/orders.html', event=event, event_id=event_id, orders=orders)
  91 
  92     @expose('/attendees/')
  93     @flask_login.login_required
  94     def display_attendees(self, event_id):
  95         event = DataGetter.get_event(event_id)
  96         orders = TicketingManager.get_orders(event_id)
  97         return self.render('/gentelella/admin/event/tickets/attendees.html', event=event,
  98                            event_id=event_id, orders=orders)
  99 
  100     @expose('/add-order/', methods=('GET', 'POST'))
  101     @flask_login.login_required
  102     def add_order(self, event_id):
  103 
  104         if request.method == 'POST':
  105             order = TicketingManager.create_order(request.form, True)
  106             return redirect(url_for('.proceed_order', event_id=event_id, order_identifier=order.identifier))
  107 
  108         event = DataGetter.get_event(event_id)
  109         return self.render('/gentelella/admin/event/tickets/add_order.html', event=event, event_id=event_id)
  110 
  111     @expose('/<order_identifier>/', methods=('GET',))
  112     def proceed_order(self, event_id, order_identifier):
  113         order = TicketingManager.get_order_by_identifier(order_identifier)
  114         if order.status == 'completed':
  115             return redirect(url_for('ticketing.view_order_after_payment', order_identifier=order_identifier))
  116         return self.render('/gentelella/guest/ticketing/order_pre_payment.html', order=order, event=order.event,
  117                            countries=list(pycountry.countries),
  118                            from_organizer=True,
  119                            pay_via=order.paid_via,
  120                            stripe_publishable_key=get_settings()['stripe_publishable_key'])
  121
  ```
  --- 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()
  
  ```
  
golden_diff: diff --git a/app/views/admin/models_views/ticket_sales.py b/app/views/admin/models_views/ticket_sales.py
  --- a/app/views/admin/models_views/ticket_sales.py
  +++ b/app/views/admin/models_views/ticket_sales.py
  @@ -1,6 +1,6 @@
   import flask_login
   import pycountry
  -from flask import redirect
  +from flask import redirect, flash
   from flask import request
   from flask import url_for
   from flask_admin import BaseView, expose
  @@ -111,10 +111,17 @@
       @expose('/<order_identifier>/', methods=('GET',))
       def proceed_order(self, event_id, order_identifier):
           order = TicketingManager.get_order_by_identifier(order_identifier)
  -        if order.status == 'completed':
  -            return redirect(url_for('ticketing.view_order_after_payment', order_identifier=order_identifier))
  -        return self.render('/gentelella/guest/ticketing/order_pre_payment.html', order=order, event=order.event,
  -                           countries=list(pycountry.countries),
  -                           from_organizer=True,
  -                           pay_via=order.paid_via,
  -                           stripe_publishable_key=get_settings()['stripe_publishable_key'])
  +        if order:
  +            if self.is_order_completed(order):
  +                return redirect(url_for('ticketing.view_order_after_payment', order_identifier=order_identifier))
  +            return self.render('/gentelella/guest/ticketing/order_pre_payment.html', order=order, event=order.event,
  +                               countries=list(pycountry.countries),
  +                               from_organizer=True,
  +                               pay_via=order.paid_via,
  +                               stripe_publishable_key=get_settings()['stripe_publishable_key'])
  +        flash("Can't find order", 'warning')
  +        return redirect(url_for('.display_ticket_stats', event_id=event_id))
  +
  +    @staticmethod
  +    def is_order_completed(order):
  +        return order.status == 'completed'
  
verification_info: {"golden_diff": "diff --git a/app/views/admin/models_views/ticket_sales.py b/app/views/admin/models_views/ticket_sales.py\n--- a/app/views/admin/models_views/ticket_sales.py\n+++ b/app/views/admin/models_views/ticket_sales.py\n@@ -1,6 +1,6 @@\n import flask_login\n import pycountry\n-from flask import redirect\n+from flask import redirect, flash\n from flask import request\n from flask import url_for\n from flask_admin import BaseView, expose\n@@ -111,10 +111,17 @@\n     @expose('/<order_identifier>/', methods=('GET',))\n     def proceed_order(self, event_id, order_identifier):\n         order = TicketingManager.get_order_by_identifier(order_identifier)\n-        if order.status == 'completed':\n-            return redirect(url_for('ticketing.view_order_after_payment', order_identifier=order_identifier))\n-        return self.render('/gentelella/guest/ticketing/order_pre_payment.html', order=order, event=order.event,\n-                           countries=list(pycountry.countries),\n-                           from_organizer=True,\n-                           pay_via=order.paid_via,\n-                           stripe_publishable_key=get_settings()['stripe_publishable_key'])\n+        if order:\n+            if self.is_order_completed(order):\n+                return redirect(url_for('ticketing.view_order_after_payment', order_identifier=order_identifier))\n+            return self.render('/gentelella/guest/ticketing/order_pre_payment.html', order=order, event=order.event,\n+                               countries=list(pycountry.countries),\n+                               from_organizer=True,\n+                               pay_via=order.paid_via,\n+                               stripe_publishable_key=get_settings()['stripe_publishable_key'])\n+        flash(\"Can't find order\", 'warning')\n+        return redirect(url_for('.display_ticket_stats', event_id=event_id))\n+\n+    @staticmethod\n+    def is_order_completed(order):\n+        return order.status == 'completed'\n", "issue": "Internal server error in promotion link\nhttps://open-event-dev.herokuapp.com/events/110/tickets/promotion/\n\n", "before_files": [{"content": "import flask_login\nimport pycountry\nfrom flask import redirect\nfrom flask import request\nfrom flask import url_for\nfrom flask_admin import BaseView, expose\n\nfrom app import get_settings\nfrom app.helpers.cache import cache\nfrom app.helpers.data_getter import DataGetter\nfrom app.helpers.ticketing import TicketingManager\nfrom app.models.ticket import Ticket\n\nclass TicketSalesView(BaseView):\n    @cache.memoize(50)\n    def get_ticket(self, ticket_id):\n        return Ticket.query.get(ticket_id)\n\n    @expose('/')\n    @flask_login.login_required\n    def display_ticket_stats(self, event_id):\n        event = DataGetter.get_event(event_id)\n        orders = TicketingManager.get_orders(event_id)\n\n        completed_count = 0\n        completed_amount = 0\n        tickets_count = 0\n\n        orders_summary = {\n            'completed': {\n                'class': 'success',\n                'tickets_count': 0,\n                'orders_count': 0,\n                'total_sales': 0\n            },\n            'pending': {\n                'class': 'warning',\n                'tickets_count': 0,\n                'orders_count': 0,\n                'total_sales': 0\n            },\n            'expired': {\n                'class': 'danger',\n                'tickets_count': 0,\n                'orders_count': 0,\n                'total_sales': 0\n            }\n        }\n\n        tickets_summary = {}\n\n        for ticket in event.tickets:\n            tickets_summary[str(ticket.id)] = {\n                'name': ticket.name,\n                'quantity': ticket.quantity,\n                'completed': {\n                    'tickets_count': 0,\n                    'sales': 0\n                },\n                'pending': {\n                    'tickets_count': 0,\n                    'sales': 0\n                },\n                'expired': {\n                    'class': 'danger',\n                    'tickets_count': 0,\n                    'sales': 0\n                }\n            }\n\n        for order in orders:\n            if order.status == 'initialized':\n                order.status = 'pending'\n            orders_summary[str(order.status)]['orders_count'] += 1\n            orders_summary[str(order.status)]['total_sales'] += order.amount\n            for order_ticket in order.tickets:\n                orders_summary[str(order.status)]['tickets_count'] += order_ticket.quantity\n                ticket = self.get_ticket(order_ticket.ticket_id)\n                tickets_summary[str(ticket.id)][str(order.status)]['tickets_count'] += order_ticket.quantity\n                tickets_summary[str(ticket.id)][str(order.status)]['sales'] += order_ticket.quantity * ticket.price\n\n        return self.render('/gentelella/admin/event/tickets/tickets.html', event=event, event_id=event_id,\n                           orders_summary=orders_summary, tickets_summary=tickets_summary)\n\n    @expose('/orders/')\n    @flask_login.login_required\n    def display_orders(self, event_id):\n        event = DataGetter.get_event(event_id)\n        orders = TicketingManager.get_orders(event_id)\n        return self.render('/gentelella/admin/event/tickets/orders.html', event=event, event_id=event_id, orders=orders)\n\n    @expose('/attendees/')\n    @flask_login.login_required\n    def display_attendees(self, event_id):\n        event = DataGetter.get_event(event_id)\n        orders = TicketingManager.get_orders(event_id)\n        return self.render('/gentelella/admin/event/tickets/attendees.html', event=event,\n                           event_id=event_id, orders=orders)\n\n    @expose('/add-order/', methods=('GET', 'POST'))\n    @flask_login.login_required\n    def add_order(self, event_id):\n\n        if request.method == 'POST':\n            order = TicketingManager.create_order(request.form, True)\n            return redirect(url_for('.proceed_order', event_id=event_id, order_identifier=order.identifier))\n\n        event = DataGetter.get_event(event_id)\n        return self.render('/gentelella/admin/event/tickets/add_order.html', event=event, event_id=event_id)\n\n    @expose('/<order_identifier>/', methods=('GET',))\n    def proceed_order(self, event_id, order_identifier):\n        order = TicketingManager.get_order_by_identifier(order_identifier)\n        if order.status == 'completed':\n            return redirect(url_for('ticketing.view_order_after_payment', order_identifier=order_identifier))\n        return self.render('/gentelella/guest/ticketing/order_pre_payment.html', order=order, event=order.event,\n                           countries=list(pycountry.countries),\n                           from_organizer=True,\n                           pay_via=order.paid_via,\n                           stripe_publishable_key=get_settings()['stripe_publishable_key'])\n", "path": "app/views/admin/models_views/ticket_sales.py"}], "after_files": [{"content": "import flask_login\nimport pycountry\nfrom flask import redirect, flash\nfrom flask import request\nfrom flask import url_for\nfrom flask_admin import BaseView, expose\n\nfrom app import get_settings\nfrom app.helpers.cache import cache\nfrom app.helpers.data_getter import DataGetter\nfrom app.helpers.ticketing import TicketingManager\nfrom app.models.ticket import Ticket\n\nclass TicketSalesView(BaseView):\n    @cache.memoize(50)\n    def get_ticket(self, ticket_id):\n        return Ticket.query.get(ticket_id)\n\n    @expose('/')\n    @flask_login.login_required\n    def display_ticket_stats(self, event_id):\n        event = DataGetter.get_event(event_id)\n        orders = TicketingManager.get_orders(event_id)\n\n        completed_count = 0\n        completed_amount = 0\n        tickets_count = 0\n\n        orders_summary = {\n            'completed': {\n                'class': 'success',\n                'tickets_count': 0,\n                'orders_count': 0,\n                'total_sales': 0\n            },\n            'pending': {\n                'class': 'warning',\n                'tickets_count': 0,\n                'orders_count': 0,\n                'total_sales': 0\n            },\n            'expired': {\n                'class': 'danger',\n                'tickets_count': 0,\n                'orders_count': 0,\n                'total_sales': 0\n            }\n        }\n\n        tickets_summary = {}\n\n        for ticket in event.tickets:\n            tickets_summary[str(ticket.id)] = {\n                'name': ticket.name,\n                'quantity': ticket.quantity,\n                'completed': {\n                    'tickets_count': 0,\n                    'sales': 0\n                },\n                'pending': {\n                    'tickets_count': 0,\n                    'sales': 0\n                },\n                'expired': {\n                    'class': 'danger',\n                    'tickets_count': 0,\n                    'sales': 0\n                }\n            }\n\n        for order in orders:\n            if order.status == 'initialized':\n                order.status = 'pending'\n            orders_summary[str(order.status)]['orders_count'] += 1\n            orders_summary[str(order.status)]['total_sales'] += order.amount\n            for order_ticket in order.tickets:\n                orders_summary[str(order.status)]['tickets_count'] += order_ticket.quantity\n                ticket = self.get_ticket(order_ticket.ticket_id)\n                tickets_summary[str(ticket.id)][str(order.status)]['tickets_count'] += order_ticket.quantity\n                tickets_summary[str(ticket.id)][str(order.status)]['sales'] += order_ticket.quantity * ticket.price\n\n        return self.render('/gentelella/admin/event/tickets/tickets.html', event=event, event_id=event_id,\n                           orders_summary=orders_summary, tickets_summary=tickets_summary)\n\n    @expose('/orders/')\n    @flask_login.login_required\n    def display_orders(self, event_id):\n        event = DataGetter.get_event(event_id)\n        orders = TicketingManager.get_orders(event_id)\n        return self.render('/gentelella/admin/event/tickets/orders.html', event=event, event_id=event_id, orders=orders)\n\n    @expose('/attendees/')\n    @flask_login.login_required\n    def display_attendees(self, event_id):\n        event = DataGetter.get_event(event_id)\n        orders = TicketingManager.get_orders(event_id)\n        return self.render('/gentelella/admin/event/tickets/attendees.html', event=event,\n                           event_id=event_id, orders=orders)\n\n    @expose('/add-order/', methods=('GET', 'POST'))\n    @flask_login.login_required\n    def add_order(self, event_id):\n\n        if request.method == 'POST':\n            order = TicketingManager.create_order(request.form, True)\n            return redirect(url_for('.proceed_order', event_id=event_id, order_identifier=order.identifier))\n\n        event = DataGetter.get_event(event_id)\n        return self.render('/gentelella/admin/event/tickets/add_order.html', event=event, event_id=event_id)\n\n    @expose('/<order_identifier>/', methods=('GET',))\n    def proceed_order(self, event_id, order_identifier):\n        order = TicketingManager.get_order_by_identifier(order_identifier)\n        if order:\n            if self.is_order_completed(order):\n                return redirect(url_for('ticketing.view_order_after_payment', order_identifier=order_identifier))\n            return self.render('/gentelella/guest/ticketing/order_pre_payment.html', order=order, event=order.event,\n                               countries=list(pycountry.countries),\n                               from_organizer=True,\n                               pay_via=order.paid_via,\n                               stripe_publishable_key=get_settings()['stripe_publishable_key'])\n        flash(\"Can't find order\", 'warning')\n        return redirect(url_for('.display_ticket_stats', event_id=event_id))\n\n    @staticmethod\n    def is_order_completed(order):\n        return order.status == 'completed'\n", "path": "app/views/admin/models_views/ticket_sales.py"}]}