prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Improve calendar design
  As a user, I expect the event calendar view to display the shifts in small boxes with times inside of each calendar day (similiar to Google Calendar etc.)
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `ephios/core/calendar.py`
  Content:
  ```
  1 from calendar import HTMLCalendar, day_abbr
  2 from datetime import date, datetime
  3 from itertools import groupby
  4 
  5 from django.utils.formats import date_format
  6 from django.utils.translation import gettext as _
  7 
  8 
  9 class ShiftCalendar(HTMLCalendar):
  10     cssclass_month = "table table-fixed"
  11 
  12     def __init__(self, shifts, *args, **kwargs):
  13         super().__init__(*args, **kwargs)
  14         self.shifts = {
  15             k: list(v) for (k, v) in groupby(shifts, lambda shift: shift.start_time.date().day)
  16         }
  17 
  18     def formatmonth(self, theyear, themonth, withyear=True):
  19         self.year, self.month = theyear, themonth
  20         return super().formatmonth(theyear, themonth)
  21 
  22     def formatmonthname(self, theyear, themonth, withyear=True):
  23         dt = datetime(theyear, themonth, 1)
  24         return f'<tr><th colspan="7" class="month">{date_format(dt, format="b Y")}</th></tr>'
  25 
  26     def formatweekday(self, day):
  27         return f'<th class="{self.cssclasses[day]}">{_(day_abbr[day])}</th>'
  28 
  29     def formatday(self, day, weekday):
  30         if day != 0:
  31             cssclass = self.cssclasses[weekday]
  32             if date.today() == date(self.year, self.month, day):
  33                 cssclass += " calendar-today"
  34             if day in self.shifts:
  35                 cssclass += " filled"
  36                 body = ["<br />"]
  37                 for shift in self.shifts[day]:
  38                     body.append(f'<a href="{shift.event.get_absolute_url()}">')
  39                     body.append(shift.event.title)
  40                     body.append("</a><br />")
  41                 return self.day_cell(cssclass, f"{day} {''.join(body)}")
  42             return self.day_cell(cssclass, day)
  43         return self.day_cell("noday", "&nbsp;")
  44 
  45     def day_cell(self, cssclass, body):
  46         return f'<td class="calendar-row-height p-1 break-word {cssclass}">{body}</td>'
  47
  ```
  
  Path: `ephios/extra/colors.py`
  Content:
  ```
  1 # inspired by https://jfelix.info/blog/how-to-make-a-text-color-fit-any-background-color
  2 from math import sqrt
  3 
  4 from ephios.core.models import EventType
  5 
  6 
  7 def calculate_luminance(rgb: tuple):
  8     r, g, b = map(
  9         lambda channel: channel / 255 / 12.92
  10         if channel / 255 <= 0.03928
  11         else ((channel / 255 + 0.055) / 1.055) ** 2.4,
  12         rgb,
  13     )
  14     return 0.2126 * r + 0.7152 * g + 0.0722 * b
  15 
  16 
  17 def get_text_color_for_background(background_luminance: int):
  18     return "#000000" if background_luminance > sqrt(1.05 * 0.05) - 0.05 else "#ffffff"
  19 
  20 
  21 def get_eventtype_color_style(eventtype: EventType):
  22     luminance = calculate_luminance(
  23         (
  24             int(eventtype.color[1:3], 16),
  25             int(eventtype.color[3:5], 16),
  26             int(eventtype.color[5:7], 16),
  27         )
  28     )
  29     text_color = get_text_color_for_background(luminance)
  30     return f".badge-{eventtype.pk}-color{{background-color:{eventtype.color};color:{text_color}}}"
  31
  ```
  --- 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/ephios/core/calendar.py b/ephios/core/calendar.py
  --- a/ephios/core/calendar.py
  +++ b/ephios/core/calendar.py
  @@ -2,6 +2,7 @@
   from datetime import date, datetime
   from itertools import groupby
   
  +from django.template.loader import render_to_string
   from django.utils.formats import date_format
   from django.utils.translation import gettext as _
   
  @@ -24,23 +25,20 @@
           return f'<tr><th colspan="7" class="month">{date_format(dt, format="b Y")}</th></tr>'
   
       def formatweekday(self, day):
  -        return f'<th class="{self.cssclasses[day]}">{_(day_abbr[day])}</th>'
  +        return f'<th class="text-center {self.cssclasses[day]}">{_(day_abbr[day])}</th>'
   
       def formatday(self, day, weekday):
           if day != 0:
               cssclass = self.cssclasses[weekday]
  -            if date.today() == date(self.year, self.month, day):
  -                cssclass += " calendar-today"
  +            today = date.today() == date(self.year, self.month, day)
               if day in self.shifts:
                   cssclass += " filled"
  -                body = ["<br />"]
  -                for shift in self.shifts[day]:
  -                    body.append(f'<a href="{shift.event.get_absolute_url()}">')
  -                    body.append(shift.event.title)
  -                    body.append("</a><br />")
  -                return self.day_cell(cssclass, f"{day} {''.join(body)}")
  -            return self.day_cell(cssclass, day)
  +            content = render_to_string(
  +                "core/fragments/calendar_day.html",
  +                {"day": day, "shifts": self.shifts.get(day, None), "today": today},
  +            )
  +            return self.day_cell(cssclass, content)
           return self.day_cell("noday", "&nbsp;")
   
       def day_cell(self, cssclass, body):
  -        return f'<td class="calendar-row-height p-1 break-word {cssclass}">{body}</td>'
  +        return f'<td class="calendar-row-height p-0 pe-1 p-lg-1 {cssclass}">{body}</td>'
  diff --git a/ephios/extra/colors.py b/ephios/extra/colors.py
  --- a/ephios/extra/colors.py
  +++ b/ephios/extra/colors.py
  @@ -27,4 +27,6 @@
           )
       )
       text_color = get_text_color_for_background(luminance)
  -    return f".badge-{eventtype.pk}-color{{background-color:{eventtype.color};color:{text_color}}}"
  +    return (
  +        f".eventtype-{eventtype.pk}-color{{background-color:{eventtype.color};color:{text_color}}}"
  +    )
  
verification_info: {"golden_diff": "diff --git a/ephios/core/calendar.py b/ephios/core/calendar.py\n--- a/ephios/core/calendar.py\n+++ b/ephios/core/calendar.py\n@@ -2,6 +2,7 @@\n from datetime import date, datetime\n from itertools import groupby\n \n+from django.template.loader import render_to_string\n from django.utils.formats import date_format\n from django.utils.translation import gettext as _\n \n@@ -24,23 +25,20 @@\n         return f'<tr><th colspan=\"7\" class=\"month\">{date_format(dt, format=\"b Y\")}</th></tr>'\n \n     def formatweekday(self, day):\n-        return f'<th class=\"{self.cssclasses[day]}\">{_(day_abbr[day])}</th>'\n+        return f'<th class=\"text-center {self.cssclasses[day]}\">{_(day_abbr[day])}</th>'\n \n     def formatday(self, day, weekday):\n         if day != 0:\n             cssclass = self.cssclasses[weekday]\n-            if date.today() == date(self.year, self.month, day):\n-                cssclass += \" calendar-today\"\n+            today = date.today() == date(self.year, self.month, day)\n             if day in self.shifts:\n                 cssclass += \" filled\"\n-                body = [\"<br />\"]\n-                for shift in self.shifts[day]:\n-                    body.append(f'<a href=\"{shift.event.get_absolute_url()}\">')\n-                    body.append(shift.event.title)\n-                    body.append(\"</a><br />\")\n-                return self.day_cell(cssclass, f\"{day} {''.join(body)}\")\n-            return self.day_cell(cssclass, day)\n+            content = render_to_string(\n+                \"core/fragments/calendar_day.html\",\n+                {\"day\": day, \"shifts\": self.shifts.get(day, None), \"today\": today},\n+            )\n+            return self.day_cell(cssclass, content)\n         return self.day_cell(\"noday\", \"&nbsp;\")\n \n     def day_cell(self, cssclass, body):\n-        return f'<td class=\"calendar-row-height p-1 break-word {cssclass}\">{body}</td>'\n+        return f'<td class=\"calendar-row-height p-0 pe-1 p-lg-1 {cssclass}\">{body}</td>'\ndiff --git a/ephios/extra/colors.py b/ephios/extra/colors.py\n--- a/ephios/extra/colors.py\n+++ b/ephios/extra/colors.py\n@@ -27,4 +27,6 @@\n         )\n     )\n     text_color = get_text_color_for_background(luminance)\n-    return f\".badge-{eventtype.pk}-color{{background-color:{eventtype.color};color:{text_color}}}\"\n+    return (\n+        f\".eventtype-{eventtype.pk}-color{{background-color:{eventtype.color};color:{text_color}}}\"\n+    )\n", "issue": "Improve calendar design\nAs a user, I expect the event calendar view to display the shifts in small boxes with times inside of each calendar day (similiar to Google Calendar etc.)\n", "before_files": [{"content": "from calendar import HTMLCalendar, day_abbr\nfrom datetime import date, datetime\nfrom itertools import groupby\n\nfrom django.utils.formats import date_format\nfrom django.utils.translation import gettext as _\n\n\nclass ShiftCalendar(HTMLCalendar):\n    cssclass_month = \"table table-fixed\"\n\n    def __init__(self, shifts, *args, **kwargs):\n        super().__init__(*args, **kwargs)\n        self.shifts = {\n            k: list(v) for (k, v) in groupby(shifts, lambda shift: shift.start_time.date().day)\n        }\n\n    def formatmonth(self, theyear, themonth, withyear=True):\n        self.year, self.month = theyear, themonth\n        return super().formatmonth(theyear, themonth)\n\n    def formatmonthname(self, theyear, themonth, withyear=True):\n        dt = datetime(theyear, themonth, 1)\n        return f'<tr><th colspan=\"7\" class=\"month\">{date_format(dt, format=\"b Y\")}</th></tr>'\n\n    def formatweekday(self, day):\n        return f'<th class=\"{self.cssclasses[day]}\">{_(day_abbr[day])}</th>'\n\n    def formatday(self, day, weekday):\n        if day != 0:\n            cssclass = self.cssclasses[weekday]\n            if date.today() == date(self.year, self.month, day):\n                cssclass += \" calendar-today\"\n            if day in self.shifts:\n                cssclass += \" filled\"\n                body = [\"<br />\"]\n                for shift in self.shifts[day]:\n                    body.append(f'<a href=\"{shift.event.get_absolute_url()}\">')\n                    body.append(shift.event.title)\n                    body.append(\"</a><br />\")\n                return self.day_cell(cssclass, f\"{day} {''.join(body)}\")\n            return self.day_cell(cssclass, day)\n        return self.day_cell(\"noday\", \"&nbsp;\")\n\n    def day_cell(self, cssclass, body):\n        return f'<td class=\"calendar-row-height p-1 break-word {cssclass}\">{body}</td>'\n", "path": "ephios/core/calendar.py"}, {"content": "# inspired by https://jfelix.info/blog/how-to-make-a-text-color-fit-any-background-color\nfrom math import sqrt\n\nfrom ephios.core.models import EventType\n\n\ndef calculate_luminance(rgb: tuple):\n    r, g, b = map(\n        lambda channel: channel / 255 / 12.92\n        if channel / 255 <= 0.03928\n        else ((channel / 255 + 0.055) / 1.055) ** 2.4,\n        rgb,\n    )\n    return 0.2126 * r + 0.7152 * g + 0.0722 * b\n\n\ndef get_text_color_for_background(background_luminance: int):\n    return \"#000000\" if background_luminance > sqrt(1.05 * 0.05) - 0.05 else \"#ffffff\"\n\n\ndef get_eventtype_color_style(eventtype: EventType):\n    luminance = calculate_luminance(\n        (\n            int(eventtype.color[1:3], 16),\n            int(eventtype.color[3:5], 16),\n            int(eventtype.color[5:7], 16),\n        )\n    )\n    text_color = get_text_color_for_background(luminance)\n    return f\".badge-{eventtype.pk}-color{{background-color:{eventtype.color};color:{text_color}}}\"\n", "path": "ephios/extra/colors.py"}], "after_files": [{"content": "from calendar import HTMLCalendar, day_abbr\nfrom datetime import date, datetime\nfrom itertools import groupby\n\nfrom django.template.loader import render_to_string\nfrom django.utils.formats import date_format\nfrom django.utils.translation import gettext as _\n\n\nclass ShiftCalendar(HTMLCalendar):\n    cssclass_month = \"table table-fixed\"\n\n    def __init__(self, shifts, *args, **kwargs):\n        super().__init__(*args, **kwargs)\n        self.shifts = {\n            k: list(v) for (k, v) in groupby(shifts, lambda shift: shift.start_time.date().day)\n        }\n\n    def formatmonth(self, theyear, themonth, withyear=True):\n        self.year, self.month = theyear, themonth\n        return super().formatmonth(theyear, themonth)\n\n    def formatmonthname(self, theyear, themonth, withyear=True):\n        dt = datetime(theyear, themonth, 1)\n        return f'<tr><th colspan=\"7\" class=\"month\">{date_format(dt, format=\"b Y\")}</th></tr>'\n\n    def formatweekday(self, day):\n        return f'<th class=\"text-center {self.cssclasses[day]}\">{_(day_abbr[day])}</th>'\n\n    def formatday(self, day, weekday):\n        if day != 0:\n            cssclass = self.cssclasses[weekday]\n            today = date.today() == date(self.year, self.month, day)\n            if day in self.shifts:\n                cssclass += \" filled\"\n            content = render_to_string(\n                \"core/fragments/calendar_day.html\",\n                {\"day\": day, \"shifts\": self.shifts.get(day, None), \"today\": today},\n            )\n            return self.day_cell(cssclass, content)\n        return self.day_cell(\"noday\", \"&nbsp;\")\n\n    def day_cell(self, cssclass, body):\n        return f'<td class=\"calendar-row-height p-0 pe-1 p-lg-1 {cssclass}\">{body}</td>'\n", "path": "ephios/core/calendar.py"}, {"content": "# inspired by https://jfelix.info/blog/how-to-make-a-text-color-fit-any-background-color\nfrom math import sqrt\n\nfrom ephios.core.models import EventType\n\n\ndef calculate_luminance(rgb: tuple):\n    r, g, b = map(\n        lambda channel: channel / 255 / 12.92\n        if channel / 255 <= 0.03928\n        else ((channel / 255 + 0.055) / 1.055) ** 2.4,\n        rgb,\n    )\n    return 0.2126 * r + 0.7152 * g + 0.0722 * b\n\n\ndef get_text_color_for_background(background_luminance: int):\n    return \"#000000\" if background_luminance > sqrt(1.05 * 0.05) - 0.05 else \"#ffffff\"\n\n\ndef get_eventtype_color_style(eventtype: EventType):\n    luminance = calculate_luminance(\n        (\n            int(eventtype.color[1:3], 16),\n            int(eventtype.color[3:5], 16),\n            int(eventtype.color[5:7], 16),\n        )\n    )\n    text_color = get_text_color_for_background(luminance)\n    return (\n        f\".eventtype-{eventtype.pk}-color{{background-color:{eventtype.color};color:{text_color}}}\"\n    )\n", "path": "ephios/extra/colors.py"}]}