prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Visiting /roll raises an error if no rolls exist
  ```
  Environment:
  
  
  Request Method: GET
  Request URL: http://localhost:8000/roll/
  
  Django Version: 2.2
  Python Version: 3.7.3
  Installed Applications:
  ['raven.contrib.django.raven_compat',
   'django.contrib.admin',
   'django.contrib.auth',
   'django.contrib.contenttypes',
   'django.contrib.sessions',
   'django.contrib.messages',
   'django.contrib.staticfiles',
   'sass_processor',
   'widget_tweaks',
   'tz_detect',
   'debug_toolbar',
   's3direct',
   'bootstrap',
   'will_of_the_prophets']
  Installed Middleware:
  ('raven.contrib.django.middleware.DjangoRestFrameworkCompatMiddleware',
   'raven.contrib.django.middleware.SentryMiddleware',
   'whitenoise.middleware.WhiteNoiseMiddleware',
   'raven.contrib.django.raven_compat.middleware.Sentry404CatchMiddleware',
   'debug_toolbar.middleware.DebugToolbarMiddleware',
   'django.middleware.security.SecurityMiddleware',
   'django.contrib.sessions.middleware.SessionMiddleware',
   'django.middleware.common.CommonMiddleware',
   'django.middleware.csrf.CsrfViewMiddleware',
   'django.contrib.auth.middleware.AuthenticationMiddleware',
   'django.contrib.messages.middleware.MessageMiddleware',
   'django.middleware.clickjacking.XFrameOptionsMiddleware',
   'tz_detect.middleware.TimezoneMiddleware')
  
  
  
  Traceback:
  
  File "/Users/craiga/.ve/will_of_the_prophets-4-oJArpS/lib/python3.7/site-packages/django/core/handlers/exception.py" in inner
    34.             response = get_response(request)
  
  File "/Users/craiga/.ve/will_of_the_prophets-4-oJArpS/lib/python3.7/site-packages/django/core/handlers/base.py" in _get_response
    115.                 response = self.process_exception_by_middleware(e, request)
  
  File "/Users/craiga/.ve/will_of_the_prophets-4-oJArpS/lib/python3.7/site-packages/django/core/handlers/base.py" in _get_response
    113.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)
  
  File "/Users/craiga/.ve/will_of_the_prophets-4-oJArpS/lib/python3.7/site-packages/django/views/generic/base.py" in view
    71.             return self.dispatch(request, *args, **kwargs)
  
  File "/Users/craiga/.ve/will_of_the_prophets-4-oJArpS/lib/python3.7/site-packages/django/contrib/auth/mixins.py" in dispatch
    52.         return super().dispatch(request, *args, **kwargs)
  
  File "/Users/craiga/.ve/will_of_the_prophets-4-oJArpS/lib/python3.7/site-packages/django/views/generic/base.py" in dispatch
    97.         return handler(request, *args, **kwargs)
  
  File "/Users/craiga/.ve/will_of_the_prophets-4-oJArpS/lib/python3.7/site-packages/django/views/generic/edit.py" in get
    168.         return super().get(request, *args, **kwargs)
  
  File "/Users/craiga/.ve/will_of_the_prophets-4-oJArpS/lib/python3.7/site-packages/django/views/generic/edit.py" in get
    133.         return self.render_to_response(self.get_context_data())
  
  File "/Users/craiga/will_of_the_prophets/will_of_the_prophets/views.py" in get_context_data
    82.             board=board.Board(now=last_roll.embargo),
  
  Exception Type: AttributeError at /roll/
  Exception Value: 'NoneType' object has no attribute 'embargo'
  ```
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `will_of_the_prophets/views.py`
  Content:
  ```
  1 """Views."""
  2 
  3 from django.conf import settings
  4 from django.contrib.auth.mixins import LoginRequiredMixin
  5 from django.shortcuts import render
  6 from django.urls import reverse
  7 from django.utils import timezone
  8 from django.views.decorators.cache import cache_control
  9 from django.views.decorators.clickjacking import xframe_options_exempt
  10 from django.views.decorators.http import condition
  11 from django.views.generic.edit import CreateView
  12 
  13 from will_of_the_prophets import board, forms, models
  14 
  15 
  16 def get_last_modified(request):
  17     """Get board's last modified datetime."""
  18     try:
  19         return (
  20             models.Roll.objects.filter(embargo__lte=timezone.now())
  21             .latest("embargo")
  22             .embargo
  23         )
  24     except models.Roll.DoesNotExist:
  25         return None
  26 
  27 
  28 @xframe_options_exempt
  29 @condition(last_modified_func=get_last_modified)
  30 @cache_control(max_age=3600)
  31 def public_board(request):
  32     """
  33     Board for the public.
  34 
  35     Does not take embargoed rolls into account.
  36     """
  37     response = render(
  38         request,
  39         "will_of_the_prophets/public_board.html",
  40         {
  41             "board": board.Board(),
  42             "special_square_types": models.SpecialSquareType.objects.all(),
  43         },
  44     )
  45 
  46     canonical_url = settings.PUBLIC_BOARD_CANONICAL_URL
  47     if canonical_url:
  48         response["Link"] = f'<{canonical_url}>; rel="canonical"'
  49 
  50     return response
  51 
  52 
  53 @xframe_options_exempt
  54 @condition(last_modified_func=get_last_modified)
  55 @cache_control(max_age=3600)
  56 def roll_frequency(request):
  57     """
  58     Show roll frequency.
  59     """
  60     roll_count = {1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0}
  61     for roll in board.Board().rolls:
  62         roll_count[roll] += 1
  63 
  64     return render(
  65         request,
  66         "will_of_the_prophets/roll_frequency.html",
  67         {"roll_frequency": roll_count},
  68     )
  69 
  70 
  71 class RollView(LoginRequiredMixin, CreateView):
  72     """View for rolling the die."""
  73 
  74     form_class = forms.RollForm
  75     template_name = "will_of_the_prophets/roll.html"
  76 
  77     def get_context_data(self, **kwargs):
  78         last_roll = models.Roll.objects.order_by("-embargo").first()
  79         return super().get_context_data(
  80             **kwargs,
  81             last_roll=last_roll,
  82             board=board.Board(now=last_roll.embargo),
  83             special_square_types=models.SpecialSquareType.objects.all(),
  84         )
  85 
  86     def get_success_url(self):
  87         return reverse("roll") + "#chula"
  88
  ```
  --- 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/will_of_the_prophets/views.py b/will_of_the_prophets/views.py
  --- a/will_of_the_prophets/views.py
  +++ b/will_of_the_prophets/views.py
  @@ -76,10 +76,14 @@
   
       def get_context_data(self, **kwargs):
           last_roll = models.Roll.objects.order_by("-embargo").first()
  +        last_roll_embargo = None
  +        if last_roll:
  +            last_roll_embargo = last_roll.embargo
  +
           return super().get_context_data(
               **kwargs,
               last_roll=last_roll,
  -            board=board.Board(now=last_roll.embargo),
  +            board=board.Board(now=last_roll_embargo),
               special_square_types=models.SpecialSquareType.objects.all(),
           )
  
verification_info: {"golden_diff": "diff --git a/will_of_the_prophets/views.py b/will_of_the_prophets/views.py\n--- a/will_of_the_prophets/views.py\n+++ b/will_of_the_prophets/views.py\n@@ -76,10 +76,14 @@\n \n     def get_context_data(self, **kwargs):\n         last_roll = models.Roll.objects.order_by(\"-embargo\").first()\n+        last_roll_embargo = None\n+        if last_roll:\n+            last_roll_embargo = last_roll.embargo\n+\n         return super().get_context_data(\n             **kwargs,\n             last_roll=last_roll,\n-            board=board.Board(now=last_roll.embargo),\n+            board=board.Board(now=last_roll_embargo),\n             special_square_types=models.SpecialSquareType.objects.all(),\n         )\n", "issue": "Visiting /roll raises an error if no rolls exist\n```\r\nEnvironment:\r\n\r\n\r\nRequest Method: GET\r\nRequest URL: http://localhost:8000/roll/\r\n\r\nDjango Version: 2.2\r\nPython Version: 3.7.3\r\nInstalled Applications:\r\n['raven.contrib.django.raven_compat',\r\n 'django.contrib.admin',\r\n 'django.contrib.auth',\r\n 'django.contrib.contenttypes',\r\n 'django.contrib.sessions',\r\n 'django.contrib.messages',\r\n 'django.contrib.staticfiles',\r\n 'sass_processor',\r\n 'widget_tweaks',\r\n 'tz_detect',\r\n 'debug_toolbar',\r\n 's3direct',\r\n 'bootstrap',\r\n 'will_of_the_prophets']\r\nInstalled Middleware:\r\n('raven.contrib.django.middleware.DjangoRestFrameworkCompatMiddleware',\r\n 'raven.contrib.django.middleware.SentryMiddleware',\r\n 'whitenoise.middleware.WhiteNoiseMiddleware',\r\n 'raven.contrib.django.raven_compat.middleware.Sentry404CatchMiddleware',\r\n 'debug_toolbar.middleware.DebugToolbarMiddleware',\r\n 'django.middleware.security.SecurityMiddleware',\r\n 'django.contrib.sessions.middleware.SessionMiddleware',\r\n 'django.middleware.common.CommonMiddleware',\r\n 'django.middleware.csrf.CsrfViewMiddleware',\r\n 'django.contrib.auth.middleware.AuthenticationMiddleware',\r\n 'django.contrib.messages.middleware.MessageMiddleware',\r\n 'django.middleware.clickjacking.XFrameOptionsMiddleware',\r\n 'tz_detect.middleware.TimezoneMiddleware')\r\n\r\n\r\n\r\nTraceback:\r\n\r\nFile \"/Users/craiga/.ve/will_of_the_prophets-4-oJArpS/lib/python3.7/site-packages/django/core/handlers/exception.py\" in inner\r\n  34.             response = get_response(request)\r\n\r\nFile \"/Users/craiga/.ve/will_of_the_prophets-4-oJArpS/lib/python3.7/site-packages/django/core/handlers/base.py\" in _get_response\r\n  115.                 response = self.process_exception_by_middleware(e, request)\r\n\r\nFile \"/Users/craiga/.ve/will_of_the_prophets-4-oJArpS/lib/python3.7/site-packages/django/core/handlers/base.py\" in _get_response\r\n  113.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)\r\n\r\nFile \"/Users/craiga/.ve/will_of_the_prophets-4-oJArpS/lib/python3.7/site-packages/django/views/generic/base.py\" in view\r\n  71.             return self.dispatch(request, *args, **kwargs)\r\n\r\nFile \"/Users/craiga/.ve/will_of_the_prophets-4-oJArpS/lib/python3.7/site-packages/django/contrib/auth/mixins.py\" in dispatch\r\n  52.         return super().dispatch(request, *args, **kwargs)\r\n\r\nFile \"/Users/craiga/.ve/will_of_the_prophets-4-oJArpS/lib/python3.7/site-packages/django/views/generic/base.py\" in dispatch\r\n  97.         return handler(request, *args, **kwargs)\r\n\r\nFile \"/Users/craiga/.ve/will_of_the_prophets-4-oJArpS/lib/python3.7/site-packages/django/views/generic/edit.py\" in get\r\n  168.         return super().get(request, *args, **kwargs)\r\n\r\nFile \"/Users/craiga/.ve/will_of_the_prophets-4-oJArpS/lib/python3.7/site-packages/django/views/generic/edit.py\" in get\r\n  133.         return self.render_to_response(self.get_context_data())\r\n\r\nFile \"/Users/craiga/will_of_the_prophets/will_of_the_prophets/views.py\" in get_context_data\r\n  82.             board=board.Board(now=last_roll.embargo),\r\n\r\nException Type: AttributeError at /roll/\r\nException Value: 'NoneType' object has no attribute 'embargo'\r\n```\n", "before_files": [{"content": "\"\"\"Views.\"\"\"\n\nfrom django.conf import settings\nfrom django.contrib.auth.mixins import LoginRequiredMixin\nfrom django.shortcuts import render\nfrom django.urls import reverse\nfrom django.utils import timezone\nfrom django.views.decorators.cache import cache_control\nfrom django.views.decorators.clickjacking import xframe_options_exempt\nfrom django.views.decorators.http import condition\nfrom django.views.generic.edit import CreateView\n\nfrom will_of_the_prophets import board, forms, models\n\n\ndef get_last_modified(request):\n    \"\"\"Get board's last modified datetime.\"\"\"\n    try:\n        return (\n            models.Roll.objects.filter(embargo__lte=timezone.now())\n            .latest(\"embargo\")\n            .embargo\n        )\n    except models.Roll.DoesNotExist:\n        return None\n\n\n@xframe_options_exempt\n@condition(last_modified_func=get_last_modified)\n@cache_control(max_age=3600)\ndef public_board(request):\n    \"\"\"\n    Board for the public.\n\n    Does not take embargoed rolls into account.\n    \"\"\"\n    response = render(\n        request,\n        \"will_of_the_prophets/public_board.html\",\n        {\n            \"board\": board.Board(),\n            \"special_square_types\": models.SpecialSquareType.objects.all(),\n        },\n    )\n\n    canonical_url = settings.PUBLIC_BOARD_CANONICAL_URL\n    if canonical_url:\n        response[\"Link\"] = f'<{canonical_url}>; rel=\"canonical\"'\n\n    return response\n\n\n@xframe_options_exempt\n@condition(last_modified_func=get_last_modified)\n@cache_control(max_age=3600)\ndef roll_frequency(request):\n    \"\"\"\n    Show roll frequency.\n    \"\"\"\n    roll_count = {1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0}\n    for roll in board.Board().rolls:\n        roll_count[roll] += 1\n\n    return render(\n        request,\n        \"will_of_the_prophets/roll_frequency.html\",\n        {\"roll_frequency\": roll_count},\n    )\n\n\nclass RollView(LoginRequiredMixin, CreateView):\n    \"\"\"View for rolling the die.\"\"\"\n\n    form_class = forms.RollForm\n    template_name = \"will_of_the_prophets/roll.html\"\n\n    def get_context_data(self, **kwargs):\n        last_roll = models.Roll.objects.order_by(\"-embargo\").first()\n        return super().get_context_data(\n            **kwargs,\n            last_roll=last_roll,\n            board=board.Board(now=last_roll.embargo),\n            special_square_types=models.SpecialSquareType.objects.all(),\n        )\n\n    def get_success_url(self):\n        return reverse(\"roll\") + \"#chula\"\n", "path": "will_of_the_prophets/views.py"}], "after_files": [{"content": "\"\"\"Views.\"\"\"\n\nfrom django.conf import settings\nfrom django.contrib.auth.mixins import LoginRequiredMixin\nfrom django.shortcuts import render\nfrom django.urls import reverse\nfrom django.utils import timezone\nfrom django.views.decorators.cache import cache_control\nfrom django.views.decorators.clickjacking import xframe_options_exempt\nfrom django.views.decorators.http import condition\nfrom django.views.generic.edit import CreateView\n\nfrom will_of_the_prophets import board, forms, models\n\n\ndef get_last_modified(request):\n    \"\"\"Get board's last modified datetime.\"\"\"\n    try:\n        return (\n            models.Roll.objects.filter(embargo__lte=timezone.now())\n            .latest(\"embargo\")\n            .embargo\n        )\n    except models.Roll.DoesNotExist:\n        return None\n\n\n@xframe_options_exempt\n@condition(last_modified_func=get_last_modified)\n@cache_control(max_age=3600)\ndef public_board(request):\n    \"\"\"\n    Board for the public.\n\n    Does not take embargoed rolls into account.\n    \"\"\"\n    response = render(\n        request,\n        \"will_of_the_prophets/public_board.html\",\n        {\n            \"board\": board.Board(),\n            \"special_square_types\": models.SpecialSquareType.objects.all(),\n        },\n    )\n\n    canonical_url = settings.PUBLIC_BOARD_CANONICAL_URL\n    if canonical_url:\n        response[\"Link\"] = f'<{canonical_url}>; rel=\"canonical\"'\n\n    return response\n\n\n@xframe_options_exempt\n@condition(last_modified_func=get_last_modified)\n@cache_control(max_age=3600)\ndef roll_frequency(request):\n    \"\"\"\n    Show roll frequency.\n    \"\"\"\n    roll_count = {1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0}\n    for roll in board.Board().rolls:\n        roll_count[roll] += 1\n\n    return render(\n        request,\n        \"will_of_the_prophets/roll_frequency.html\",\n        {\"roll_frequency\": roll_count},\n    )\n\n\nclass RollView(LoginRequiredMixin, CreateView):\n    \"\"\"View for rolling the die.\"\"\"\n\n    form_class = forms.RollForm\n    template_name = \"will_of_the_prophets/roll.html\"\n\n    def get_context_data(self, **kwargs):\n        last_roll = models.Roll.objects.order_by(\"-embargo\").first()\n        last_roll_embargo = None\n        if last_roll:\n            last_roll_embargo = last_roll.embargo\n\n        return super().get_context_data(\n            **kwargs,\n            last_roll=last_roll,\n            board=board.Board(now=last_roll_embargo),\n            special_square_types=models.SpecialSquareType.objects.all(),\n        )\n\n    def get_success_url(self):\n        return reverse(\"roll\") + \"#chula\"\n", "path": "will_of_the_prophets/views.py"}]}