prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Newsletters show unpublished events
  ### Describe the bug
  Newsletters show unpublished events
  
  ### How to reproduce
  Steps to reproduce the behaviour:
  1. Check one of the newsletters of the last weeks
  
  ### Expected behaviour
  Only published events should show.
  
  ### Additional context
  This is probably because of the low number of events during these days.
  
  
  </issue>
  <code>
  [start of website/newsletters/services.py]
  1 import os
  2 
  3 from django.conf import settings
  4 from django.template.loader import get_template
  5 from django.utils import translation, timezone
  6 
  7 from events.models import Event
  8 from members.models import Member
  9 from newsletters import emails
  10 from partners.models import Partner
  11 from pushnotifications.models import Message, Category
  12 
  13 
  14 def write_to_file(pk, lang, html_message):
  15     """
  16     Write newsletter to a file
  17     """
  18     cache_dir = os.path.join(settings.MEDIA_ROOT, "newsletters")
  19     if not os.path.isdir(cache_dir):
  20         os.makedirs(cache_dir)
  21 
  22     with open(os.path.join(cache_dir, f"{pk}_{lang}.html"), "w+") as cache_file:
  23         cache_file.write(html_message)
  24 
  25 
  26 def save_to_disk(newsletter, request):
  27     """
  28     Writes the newsletter as HTML to file (in all languages)
  29     """
  30     main_partner = Partner.objects.filter(is_main_partner=True).first()
  31     local_partner = Partner.objects.filter(is_local_partner=True).first()
  32 
  33     html_template = get_template("newsletters/email.html")
  34 
  35     for language in settings.LANGUAGES:
  36         translation.activate(language[0])
  37 
  38         context = {
  39             "newsletter": newsletter,
  40             "agenda_events": (
  41                 newsletter.newslettercontent_set.filter(newsletteritem=None).order_by(
  42                     "newsletterevent__start_datetime"
  43                 )
  44             ),
  45             "main_partner": main_partner,
  46             "local_partner": local_partner,
  47             "lang_code": language[0],
  48             "request": request,
  49         }
  50 
  51         html_message = html_template.render(context)
  52 
  53         write_to_file(newsletter.pk, language[0], html_message)
  54 
  55 
  56 def get_agenda(start_date):
  57     end_date = start_date + timezone.timedelta(weeks=2)
  58     base_events = Event.objects.filter(
  59         start__gte=start_date, end__lt=end_date, published=True
  60     ).order_by("start")
  61     if base_events.count() < 10:
  62         more_events = Event.objects.filter(end__gte=end_date).order_by("start")
  63         return [*base_events, *more_events][:10]
  64     return base_events
  65 
  66 
  67 def send_newsletter(newsletter):
  68     emails.send_newsletter(newsletter)
  69     newsletter.sent = True
  70     newsletter.save()
  71     message = Message.objects.create(
  72         title_nl=newsletter.title_nl,
  73         title_en=newsletter.title_en,
  74         body_nl="Tik om te bekijken",
  75         body_en="Tap to view",
  76         url=settings.BASE_URL + newsletter.get_absolute_url(),
  77         category=Category.objects.get(key=Category.NEWSLETTER),
  78     )
  79     message.users.set(Member.current_members.all())
  80     message.send()
  81
  [end of website/newsletters/services.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/website/newsletters/services.py b/website/newsletters/services.py
  --- a/website/newsletters/services.py
  +++ b/website/newsletters/services.py
  @@ -55,11 +55,12 @@
   
   def get_agenda(start_date):
       end_date = start_date + timezone.timedelta(weeks=2)
  -    base_events = Event.objects.filter(
  -        start__gte=start_date, end__lt=end_date, published=True
  +    published_events = Event.objects.filter(published=True)
  +    base_events = published_events.filter(
  +        start__gte=start_date, end__lt=end_date
       ).order_by("start")
       if base_events.count() < 10:
  -        more_events = Event.objects.filter(end__gte=end_date).order_by("start")
  +        more_events = published_events.filter(end__gte=end_date).order_by("start")
           return [*base_events, *more_events][:10]
       return base_events
  
verification_info: {"golden_diff": "diff --git a/website/newsletters/services.py b/website/newsletters/services.py\n--- a/website/newsletters/services.py\n+++ b/website/newsletters/services.py\n@@ -55,11 +55,12 @@\n \n def get_agenda(start_date):\n     end_date = start_date + timezone.timedelta(weeks=2)\n-    base_events = Event.objects.filter(\n-        start__gte=start_date, end__lt=end_date, published=True\n+    published_events = Event.objects.filter(published=True)\n+    base_events = published_events.filter(\n+        start__gte=start_date, end__lt=end_date\n     ).order_by(\"start\")\n     if base_events.count() < 10:\n-        more_events = Event.objects.filter(end__gte=end_date).order_by(\"start\")\n+        more_events = published_events.filter(end__gte=end_date).order_by(\"start\")\n         return [*base_events, *more_events][:10]\n     return base_events\n", "issue": "Newsletters show unpublished events\n### Describe the bug\r\nNewsletters show unpublished events\r\n\r\n### How to reproduce\r\nSteps to reproduce the behaviour:\r\n1. Check one of the newsletters of the last weeks\r\n\r\n### Expected behaviour\r\nOnly published events should show.\r\n\r\n### Additional context\r\nThis is probably because of the low number of events during these days.\r\n\n", "before_files": [{"content": "import os\n\nfrom django.conf import settings\nfrom django.template.loader import get_template\nfrom django.utils import translation, timezone\n\nfrom events.models import Event\nfrom members.models import Member\nfrom newsletters import emails\nfrom partners.models import Partner\nfrom pushnotifications.models import Message, Category\n\n\ndef write_to_file(pk, lang, html_message):\n    \"\"\"\n    Write newsletter to a file\n    \"\"\"\n    cache_dir = os.path.join(settings.MEDIA_ROOT, \"newsletters\")\n    if not os.path.isdir(cache_dir):\n        os.makedirs(cache_dir)\n\n    with open(os.path.join(cache_dir, f\"{pk}_{lang}.html\"), \"w+\") as cache_file:\n        cache_file.write(html_message)\n\n\ndef save_to_disk(newsletter, request):\n    \"\"\"\n    Writes the newsletter as HTML to file (in all languages)\n    \"\"\"\n    main_partner = Partner.objects.filter(is_main_partner=True).first()\n    local_partner = Partner.objects.filter(is_local_partner=True).first()\n\n    html_template = get_template(\"newsletters/email.html\")\n\n    for language in settings.LANGUAGES:\n        translation.activate(language[0])\n\n        context = {\n            \"newsletter\": newsletter,\n            \"agenda_events\": (\n                newsletter.newslettercontent_set.filter(newsletteritem=None).order_by(\n                    \"newsletterevent__start_datetime\"\n                )\n            ),\n            \"main_partner\": main_partner,\n            \"local_partner\": local_partner,\n            \"lang_code\": language[0],\n            \"request\": request,\n        }\n\n        html_message = html_template.render(context)\n\n        write_to_file(newsletter.pk, language[0], html_message)\n\n\ndef get_agenda(start_date):\n    end_date = start_date + timezone.timedelta(weeks=2)\n    base_events = Event.objects.filter(\n        start__gte=start_date, end__lt=end_date, published=True\n    ).order_by(\"start\")\n    if base_events.count() < 10:\n        more_events = Event.objects.filter(end__gte=end_date).order_by(\"start\")\n        return [*base_events, *more_events][:10]\n    return base_events\n\n\ndef send_newsletter(newsletter):\n    emails.send_newsletter(newsletter)\n    newsletter.sent = True\n    newsletter.save()\n    message = Message.objects.create(\n        title_nl=newsletter.title_nl,\n        title_en=newsletter.title_en,\n        body_nl=\"Tik om te bekijken\",\n        body_en=\"Tap to view\",\n        url=settings.BASE_URL + newsletter.get_absolute_url(),\n        category=Category.objects.get(key=Category.NEWSLETTER),\n    )\n    message.users.set(Member.current_members.all())\n    message.send()\n", "path": "website/newsletters/services.py"}]}