We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
SplashYear matching query does not exist
https://github.com/dotKom/onlineweb4/blob/develop/apps/splash/models.py#L11 tries to get a SplashYear, but there are no objects matching the query, so it triggers an exception. 

> DoesNotExist: SplashYear matching query does not exist.

How to quick-fix: Create a SplashYear which satisfies the matching query.


--- 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/utils.py`
Content:
```
1 #-*- coding: utf-8 -*-
2 from datetime import timedelta
3 
4 from django.conf import settings
5 from django.core.mail import send_mail
6 from django.utils import timezone
7 
8 from django.core.signing import Signer, BadSignature
9 from django.http import HttpResponse
10 from django.utils import timezone
11 from filebrowser.base import FileObject
12 from filebrowser.settings import VERSIONS
13 
14 from apps.authentication.models import OnlineUser as User
15 from apps.events.models import Event
16 from apps.splash.models import SplashYear
17 
18 import icalendar
19 
20 
21 def get_group_restricted_events(user):
22     """ Returns a queryset of events with attendance_event that a user has access to """
23     types_allowed = []
24 
25     groups = user.groups.all()
26 
27     if reduce(lambda r, g: g.name in ['Hovedstyret', 'dotKom'] or r, groups, False):
28         return Event.objects.filter(attendance_event__isnull=False)
29 
30     for group in groups:
31         if group.name == 'arrKom':
32             types_allowed.append(1) # sosialt
33             types_allowed.append(4) # utflukt
34 
35         if group.name == 'bedKom':
36             types_allowed.append(2) # bedriftspresentasjon
37 
38         if group.name == 'fagKom':
39             types_allowed.append(3) # kurs
40 
41     return Event.objects.filter(attendance_event__isnull=False, event_type__in=types_allowed)
42 
43 
44 def handle_waitlist_bump(event, host, attendees, payment=None):
45 
46     title = u'Du har fått plass på %s' % (event.title)
47 
48     extended_deadline = timezone.now() + timedelta(days=2)
49     message = u'Du har stått på venteliste for arrangementet "%s" og har nå fått plass.\n' % (unicode(event.title))
50 
51     if payment:
52         if payment.payment_type == 1: #Instant
53             for attendee in attendees:
54                 payment.create_payment_delay(attendee.user, extended_deadline)
55             message += u"Dette arrangementet krever betaling og du må betale innen 48 timer."
56 
57         elif payment.payment_type == 2: #Deadline
58             if payment.deadline > extended_deadline: #More than 2 days left of payment deadline
59                 message += u"Dette arrangementet krever betaling og fristen for og betale er %s" % (payment.deadline.strftime('%-d %B %Y kl: %H:%M'))
60             else: #The deadline is in less than 2 days
61                 for attendee in attendees:
62                     payment.create_payment_delay(attendee.user, extended_deadline)
63                 message += u"Dette arrangementet krever betaling og du har 48 timer på å betale"
64 
65         elif payment.payment_type == 3: #Delay
66             deadline = timezone.now() + timedelta(days=payment.delay)
67             for attendee in attendees:
68                 payment.create_payment_delay(attendee.user, deadline)
69             message += u"Dette arrangementet krever betaling og du må betale innen %d dager." % (payment.delay)
70         if len(payment.prices()) == 1:
71             message += u"\nPrisen for dette arrangementet er %skr." % (payment.prices()[0].price)
72         # elif len(payment.prices()) >= 2:
73         #     message += u"\nDette arrangementet har flere prisklasser:"
74         #     for payment_price in payment.prices():
75         #         message += "\n%s: %skr" % (payment_price.description, payment_price.price)
76     else:
77         message += u"Det kreves ingen ekstra handling fra deg med mindre du vil melde deg av."
78 
79     message += u"\n\nFor mer info:"
80     message += u"\nhttp://%s%s" % (host, event.get_absolute_url())
81 
82     for attendee in attendees:
83         send_mail(title, message, settings.DEFAULT_FROM_EMAIL, [attendee.user.email])
84 
85 
86 class Calendar(object):
87     def __init__(self):
88         self.cal = icalendar.Calendar()
89         # Filename served by webserver
90         self.filename = 'online'
91         # Required ical info
92         self.cal.add('prodid', '-//Online//Onlineweb//EN')
93         self.cal.add('version', '2.0')
94 
95     def add_event(self, event):
96         raise NotImplementedError
97 
98     def add_events(self, events):
99         for event in events:
100             self.add_event(event)
101 
102     def output(self):
103         """Return icalendar as text"""
104         return self.cal.to_ical()
105 
106     def response(self):
107         """Returns a response object"""
108         response = HttpResponse(self.cal.to_ical(), content_type='text/calendar')
109         response['Content-Type'] = 'text/calendar; charset=utf-8'
110         response['Content-Disposition'] = 'attachment; filename=' + self.filename + '.ics'
111         return response
112 
113 
114 class EventCalendar(Calendar):
115     def user(self, user):
116         """
117             Personalized calendar
118             This calendar is publicly available, but the url is not guessable so data should not be leaked to everyone
119         """
120         signer = Signer()
121         try:
122             username = signer.unsign(user)
123             user = User.objects.get(username=username)
124         except (BadSignature, User.DoesNotExist):
125             user = None
126         if user:
127             # Getting all events that the user has/is participating in
128             self.add_events(Event.objects.filter(
129                 attendance_event__attendees__user=user
130             ).order_by('event_start').prefetch_related(
131                 'attendance_event', 'attendance_event__attendees'
132             ))
133             self.filename = username
134 
135     def event(self, event_id):
136         """Single event"""
137         try:
138             self.add_event(Event.objects.get(id=event_id))
139         except Event.DoesNotExist:
140             pass
141         self.filename = str(event_id)
142 
143     def events(self):
144         """All events that haven't ended yet"""
145         self.add_events(Event.objects.filter(event_end__gt=timezone.now()).order_by('event_start'))
146         self.filename = 'events'
147 
148     def add_event(self, event):
149         cal_event = icalendar.Event()
150 
151         cal_event.add('dtstart', event.event_start)
152         cal_event.add('dtend', event.event_end)
153         cal_event.add('location', event.location)
154         cal_event.add('summary', event.title)
155         cal_event.add('description', event.ingress_short)
156         cal_event.add('uid', 'event-' + str(event.id) + '@online.ntnu.no')
157 
158         self.cal.add_component(cal_event)
159 
160 
161 class SplashCalendar(Calendar):
162     def add_event(self, event):
163         cal_event = icalendar.Event()
164         cal_event.add('dtstart', event.start_time)
165         cal_event.add('dtend', event.end_time)
166         cal_event.add('summary', event.title)
167         cal_event.add('description', event.content)
168         cal_event.add('uid', 'splash-' + str(event.id) + '@online.ntnu.no')
169 
170         self.cal.add_component(cal_event)
171 
172     def events(self):
173         self.add_events(SplashYear.objects.current().splash_events.all())
174         self.filename = 'events'
175 
176 
177 def find_image_versions(event):
178     img = event.image
179     img_strings = []
180 
181     for ver in VERSIONS.keys():
182         if ver.startswith('events_'):
183             img_strings.append(img.version_generate(ver).url)
184 
185     return img_strings
186
```

Path: `apps/splash/views.py`
Content:
```
1 from django.shortcuts import render
2 from apps.splash.models import SplashYear
3 
4 from apps.events.utils import SplashCalendar
5 
6 
7 def index(request):
8     splash_year = SplashYear.objects.current()
9 
10     splash_year.events = _merge_events(splash_year.splash_events.all())
11 
12     return render(request, 'splash/base.html', {'splash_year': splash_year})
13 
14 
15 def calendar_export(request):
16     calendar = SplashCalendar()
17     calendar.events()
18     return calendar.response()
19 
20 
21 # And I'm really sorry for this ...
22 def _merge_events(splash_events):
23     events = []
24 
25     for event in splash_events:
26         if len(events) > 0 and event.start_time.strftime('%d-%m') == events[-1][0].start_time.strftime('%d-%m'):
27             events[-1].append(event)
28         else:
29             events.append([event])
30 
31     return events
32
```

Path: `apps/splash/models.py`
Content:
```
1 from django.db import models
2 
3 from django_extensions.db.models import TimeStampedModel
4 import datetime
5 import reversion
6 
7 
8 class SplashYearManager(models.Manager):
9     def current(self):
10         # I'm really sorry ...
11         return self.get(start_date__gt=str(datetime.date.today() - datetime.timedelta(180)))
12 
13 
14 class SplashYear(models.Model):
15     title = models.CharField(u'title', max_length=100)
16     start_date = models.DateField(u'start_date')
17 
18     objects = SplashYearManager()
19 
20     def __unicode__(self):
21         return self.title
22 
23     class Meta(object):
24         ordering = ('-start_date',)
25 
26 
27 class SplashEvent(TimeStampedModel, models.Model):
28     title = models.CharField(u'title', max_length=100)
29     content = models.TextField(u'content')
30     start_time = models.DateTimeField()
31     end_time = models.DateTimeField()
32     splash_year = models.ForeignKey('SplashYear', related_name='splash_events')
33 
34     def __unicode__(self):
35         return self.title
36 
37     class Meta(object):
38         ordering = ('start_time',)
39 
40 reversion.register(SplashYear)
41 reversion.register(SplashEvent)
42
```
--- 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/utils.py b/apps/events/utils.py
--- a/apps/events/utils.py
+++ b/apps/events/utils.py
@@ -170,7 +170,7 @@
         self.cal.add_component(cal_event)
 
     def events(self):
-        self.add_events(SplashYear.objects.current().splash_events.all())
+        self.add_events(SplashYear.objects.current_events())
         self.filename = 'events'
 
 
diff --git a/apps/splash/models.py b/apps/splash/models.py
--- a/apps/splash/models.py
+++ b/apps/splash/models.py
@@ -8,7 +8,14 @@
 class SplashYearManager(models.Manager):
     def current(self):
         # I'm really sorry ...
-        return self.get(start_date__gt=str(datetime.date.today() - datetime.timedelta(180)))
+        half_a_year_ago = str(datetime.date.today() - datetime.timedelta(180))
+        return self.filter(start_date__gt=half_a_year_ago).first()
+
+    def current_events(self):
+        current_splash = self.current()
+        if current_splash:
+            return current_splash.events()
+        return self.none()
 
 
 class SplashYear(models.Model):
@@ -17,6 +24,9 @@
 
     objects = SplashYearManager()
 
+    def events(self):
+        return self.splash_events.all()
+
     def __unicode__(self):
         return self.title
 
diff --git a/apps/splash/views.py b/apps/splash/views.py
--- a/apps/splash/views.py
+++ b/apps/splash/views.py
@@ -1,3 +1,4 @@
+from django.http import Http404
 from django.shortcuts import render
 from apps.splash.models import SplashYear
 
@@ -6,8 +7,10 @@
 
 def index(request):
     splash_year = SplashYear.objects.current()
+    if not splash_year:
+        raise Http404
 
-    splash_year.events = _merge_events(splash_year.splash_events.all())
+    splash_year.events = _merge_events(splash_year.events())
 
     return render(request, 'splash/base.html', {'splash_year': splash_year})

{"golden_diff": "diff --git a/apps/events/utils.py b/apps/events/utils.py\n--- a/apps/events/utils.py\n+++ b/apps/events/utils.py\n@@ -170,7 +170,7 @@\n         self.cal.add_component(cal_event)\n \n     def events(self):\n-        self.add_events(SplashYear.objects.current().splash_events.all())\n+        self.add_events(SplashYear.objects.current_events())\n         self.filename = 'events'\n \n \ndiff --git a/apps/splash/models.py b/apps/splash/models.py\n--- a/apps/splash/models.py\n+++ b/apps/splash/models.py\n@@ -8,7 +8,14 @@\n class SplashYearManager(models.Manager):\n     def current(self):\n         # I'm really sorry ...\n-        return self.get(start_date__gt=str(datetime.date.today() - datetime.timedelta(180)))\n+        half_a_year_ago = str(datetime.date.today() - datetime.timedelta(180))\n+        return self.filter(start_date__gt=half_a_year_ago).first()\n+\n+    def current_events(self):\n+        current_splash = self.current()\n+        if current_splash:\n+            return current_splash.events()\n+        return self.none()\n \n \n class SplashYear(models.Model):\n@@ -17,6 +24,9 @@\n \n     objects = SplashYearManager()\n \n+    def events(self):\n+        return self.splash_events.all()\n+\n     def __unicode__(self):\n         return self.title\n \ndiff --git a/apps/splash/views.py b/apps/splash/views.py\n--- a/apps/splash/views.py\n+++ b/apps/splash/views.py\n@@ -1,3 +1,4 @@\n+from django.http import Http404\n from django.shortcuts import render\n from apps.splash.models import SplashYear\n \n@@ -6,8 +7,10 @@\n \n def index(request):\n     splash_year = SplashYear.objects.current()\n+    if not splash_year:\n+        raise Http404\n \n-    splash_year.events = _merge_events(splash_year.splash_events.all())\n+    splash_year.events = _merge_events(splash_year.events())\n \n     return render(request, 'splash/base.html', {'splash_year': splash_year})\n", "issue": "SplashYear matching query does not exist\nhttps://github.com/dotKom/onlineweb4/blob/develop/apps/splash/models.py#L11 tries to get a SplashYear, but there are no objects matching the query, so it triggers an exception. \n\n> DoesNotExist: SplashYear matching query does not exist.\n\nHow to quick-fix: Create a SplashYear which satisfies the matching query.\n\n", "before_files": [{"content": "#-*- coding: utf-8 -*-\nfrom datetime import timedelta\n\nfrom django.conf import settings\nfrom django.core.mail import send_mail\nfrom django.utils import timezone\n\nfrom django.core.signing import Signer, BadSignature\nfrom django.http import HttpResponse\nfrom django.utils import timezone\nfrom filebrowser.base import FileObject\nfrom filebrowser.settings import VERSIONS\n\nfrom apps.authentication.models import OnlineUser as User\nfrom apps.events.models import Event\nfrom apps.splash.models import SplashYear\n\nimport icalendar\n\n\ndef get_group_restricted_events(user):\n    \"\"\" Returns a queryset of events with attendance_event that a user has access to \"\"\"\n    types_allowed = []\n\n    groups = user.groups.all()\n\n    if reduce(lambda r, g: g.name in ['Hovedstyret', 'dotKom'] or r, groups, False):\n        return Event.objects.filter(attendance_event__isnull=False)\n\n    for group in groups:\n        if group.name == 'arrKom':\n            types_allowed.append(1) # sosialt\n            types_allowed.append(4) # utflukt\n\n        if group.name == 'bedKom':\n            types_allowed.append(2) # bedriftspresentasjon\n\n        if group.name == 'fagKom':\n            types_allowed.append(3) # kurs\n\n    return Event.objects.filter(attendance_event__isnull=False, event_type__in=types_allowed)\n\n\ndef handle_waitlist_bump(event, host, attendees, payment=None):\n\n    title = u'Du har f\u00e5tt plass p\u00e5 %s' % (event.title)\n\n    extended_deadline = timezone.now() + timedelta(days=2)\n    message = u'Du har st\u00e5tt p\u00e5 venteliste for arrangementet \"%s\" og har n\u00e5 f\u00e5tt plass.\\n' % (unicode(event.title))\n\n    if payment:\n        if payment.payment_type == 1: #Instant\n            for attendee in attendees:\n                payment.create_payment_delay(attendee.user, extended_deadline)\n            message += u\"Dette arrangementet krever betaling og du m\u00e5 betale innen 48 timer.\"\n\n        elif payment.payment_type == 2: #Deadline\n            if payment.deadline > extended_deadline: #More than 2 days left of payment deadline\n                message += u\"Dette arrangementet krever betaling og fristen for og betale er %s\" % (payment.deadline.strftime('%-d %B %Y kl: %H:%M'))\n            else: #The deadline is in less than 2 days\n                for attendee in attendees:\n                    payment.create_payment_delay(attendee.user, extended_deadline)\n                message += u\"Dette arrangementet krever betaling og du har 48 timer p\u00e5 \u00e5 betale\"\n\n        elif payment.payment_type == 3: #Delay\n            deadline = timezone.now() + timedelta(days=payment.delay)\n            for attendee in attendees:\n                payment.create_payment_delay(attendee.user, deadline)\n            message += u\"Dette arrangementet krever betaling og du m\u00e5 betale innen %d dager.\" % (payment.delay)\n        if len(payment.prices()) == 1:\n            message += u\"\\nPrisen for dette arrangementet er %skr.\" % (payment.prices()[0].price)\n        # elif len(payment.prices()) >= 2:\n        #     message += u\"\\nDette arrangementet har flere prisklasser:\"\n        #     for payment_price in payment.prices():\n        #         message += \"\\n%s: %skr\" % (payment_price.description, payment_price.price)\n    else:\n        message += u\"Det kreves ingen ekstra handling fra deg med mindre du vil melde deg av.\"\n\n    message += u\"\\n\\nFor mer info:\"\n    message += u\"\\nhttp://%s%s\" % (host, event.get_absolute_url())\n\n    for attendee in attendees:\n        send_mail(title, message, settings.DEFAULT_FROM_EMAIL, [attendee.user.email])\n\n\nclass Calendar(object):\n    def __init__(self):\n        self.cal = icalendar.Calendar()\n        # Filename served by webserver\n        self.filename = 'online'\n        # Required ical info\n        self.cal.add('prodid', '-//Online//Onlineweb//EN')\n        self.cal.add('version', '2.0')\n\n    def add_event(self, event):\n        raise NotImplementedError\n\n    def add_events(self, events):\n        for event in events:\n            self.add_event(event)\n\n    def output(self):\n        \"\"\"Return icalendar as text\"\"\"\n        return self.cal.to_ical()\n\n    def response(self):\n        \"\"\"Returns a response object\"\"\"\n        response = HttpResponse(self.cal.to_ical(), content_type='text/calendar')\n        response['Content-Type'] = 'text/calendar; charset=utf-8'\n        response['Content-Disposition'] = 'attachment; filename=' + self.filename + '.ics'\n        return response\n\n\nclass EventCalendar(Calendar):\n    def user(self, user):\n        \"\"\"\n            Personalized calendar\n            This calendar is publicly available, but the url is not guessable so data should not be leaked to everyone\n        \"\"\"\n        signer = Signer()\n        try:\n            username = signer.unsign(user)\n            user = User.objects.get(username=username)\n        except (BadSignature, User.DoesNotExist):\n            user = None\n        if user:\n            # Getting all events that the user has/is participating in\n            self.add_events(Event.objects.filter(\n                attendance_event__attendees__user=user\n            ).order_by('event_start').prefetch_related(\n                'attendance_event', 'attendance_event__attendees'\n            ))\n            self.filename = username\n\n    def event(self, event_id):\n        \"\"\"Single event\"\"\"\n        try:\n            self.add_event(Event.objects.get(id=event_id))\n        except Event.DoesNotExist:\n            pass\n        self.filename = str(event_id)\n\n    def events(self):\n        \"\"\"All events that haven't ended yet\"\"\"\n        self.add_events(Event.objects.filter(event_end__gt=timezone.now()).order_by('event_start'))\n        self.filename = 'events'\n\n    def add_event(self, event):\n        cal_event = icalendar.Event()\n\n        cal_event.add('dtstart', event.event_start)\n        cal_event.add('dtend', event.event_end)\n        cal_event.add('location', event.location)\n        cal_event.add('summary', event.title)\n        cal_event.add('description', event.ingress_short)\n        cal_event.add('uid', 'event-' + str(event.id) + '@online.ntnu.no')\n\n        self.cal.add_component(cal_event)\n\n\nclass SplashCalendar(Calendar):\n    def add_event(self, event):\n        cal_event = icalendar.Event()\n        cal_event.add('dtstart', event.start_time)\n        cal_event.add('dtend', event.end_time)\n        cal_event.add('summary', event.title)\n        cal_event.add('description', event.content)\n        cal_event.add('uid', 'splash-' + str(event.id) + '@online.ntnu.no')\n\n        self.cal.add_component(cal_event)\n\n    def events(self):\n        self.add_events(SplashYear.objects.current().splash_events.all())\n        self.filename = 'events'\n\n\ndef find_image_versions(event):\n    img = event.image\n    img_strings = []\n\n    for ver in VERSIONS.keys():\n        if ver.startswith('events_'):\n            img_strings.append(img.version_generate(ver).url)\n\n    return img_strings\n", "path": "apps/events/utils.py"}, {"content": "from django.shortcuts import render\nfrom apps.splash.models import SplashYear\n\nfrom apps.events.utils import SplashCalendar\n\n\ndef index(request):\n    splash_year = SplashYear.objects.current()\n\n    splash_year.events = _merge_events(splash_year.splash_events.all())\n\n    return render(request, 'splash/base.html', {'splash_year': splash_year})\n\n\ndef calendar_export(request):\n    calendar = SplashCalendar()\n    calendar.events()\n    return calendar.response()\n\n\n# And I'm really sorry for this ...\ndef _merge_events(splash_events):\n    events = []\n\n    for event in splash_events:\n        if len(events) > 0 and event.start_time.strftime('%d-%m') == events[-1][0].start_time.strftime('%d-%m'):\n            events[-1].append(event)\n        else:\n            events.append([event])\n\n    return events\n", "path": "apps/splash/views.py"}, {"content": "from django.db import models\n\nfrom django_extensions.db.models import TimeStampedModel\nimport datetime\nimport reversion\n\n\nclass SplashYearManager(models.Manager):\n    def current(self):\n        # I'm really sorry ...\n        return self.get(start_date__gt=str(datetime.date.today() - datetime.timedelta(180)))\n\n\nclass SplashYear(models.Model):\n    title = models.CharField(u'title', max_length=100)\n    start_date = models.DateField(u'start_date')\n\n    objects = SplashYearManager()\n\n    def __unicode__(self):\n        return self.title\n\n    class Meta(object):\n        ordering = ('-start_date',)\n\n\nclass SplashEvent(TimeStampedModel, models.Model):\n    title = models.CharField(u'title', max_length=100)\n    content = models.TextField(u'content')\n    start_time = models.DateTimeField()\n    end_time = models.DateTimeField()\n    splash_year = models.ForeignKey('SplashYear', related_name='splash_events')\n\n    def __unicode__(self):\n        return self.title\n\n    class Meta(object):\n        ordering = ('start_time',)\n\nreversion.register(SplashYear)\nreversion.register(SplashEvent)\n", "path": "apps/splash/models.py"}], "after_files": [{"content": "#-*- coding: utf-8 -*-\nfrom datetime import timedelta\n\nfrom django.conf import settings\nfrom django.core.mail import send_mail\nfrom django.utils import timezone\n\nfrom django.core.signing import Signer, BadSignature\nfrom django.http import HttpResponse\nfrom django.utils import timezone\nfrom filebrowser.base import FileObject\nfrom filebrowser.settings import VERSIONS\n\nfrom apps.authentication.models import OnlineUser as User\nfrom apps.events.models import Event\nfrom apps.splash.models import SplashYear\n\nimport icalendar\n\n\ndef get_group_restricted_events(user):\n    \"\"\" Returns a queryset of events with attendance_event that a user has access to \"\"\"\n    types_allowed = []\n\n    groups = user.groups.all()\n\n    if reduce(lambda r, g: g.name in ['Hovedstyret', 'dotKom'] or r, groups, False):\n        return Event.objects.filter(attendance_event__isnull=False)\n\n    for group in groups:\n        if group.name == 'arrKom':\n            types_allowed.append(1) # sosialt\n            types_allowed.append(4) # utflukt\n\n        if group.name == 'bedKom':\n            types_allowed.append(2) # bedriftspresentasjon\n\n        if group.name == 'fagKom':\n            types_allowed.append(3) # kurs\n\n    return Event.objects.filter(attendance_event__isnull=False, event_type__in=types_allowed)\n\n\ndef handle_waitlist_bump(event, host, attendees, payment=None):\n\n    title = u'Du har f\u00e5tt plass p\u00e5 %s' % (event.title)\n\n    extended_deadline = timezone.now() + timedelta(days=2)\n    message = u'Du har st\u00e5tt p\u00e5 venteliste for arrangementet \"%s\" og har n\u00e5 f\u00e5tt plass.\\n' % (unicode(event.title))\n\n    if payment:\n        if payment.payment_type == 1: #Instant\n            for attendee in attendees:\n                payment.create_payment_delay(attendee.user, extended_deadline)\n            message += u\"Dette arrangementet krever betaling og du m\u00e5 betale innen 48 timer.\"\n\n        elif payment.payment_type == 2: #Deadline\n            if payment.deadline > extended_deadline: #More than 2 days left of payment deadline\n                message += u\"Dette arrangementet krever betaling og fristen for og betale er %s\" % (payment.deadline.strftime('%-d %B %Y kl: %H:%M'))\n            else: #The deadline is in less than 2 days\n                for attendee in attendees:\n                    payment.create_payment_delay(attendee.user, extended_deadline)\n                message += u\"Dette arrangementet krever betaling og du har 48 timer p\u00e5 \u00e5 betale\"\n\n        elif payment.payment_type == 3: #Delay\n            deadline = timezone.now() + timedelta(days=payment.delay)\n            for attendee in attendees:\n                payment.create_payment_delay(attendee.user, deadline)\n            message += u\"Dette arrangementet krever betaling og du m\u00e5 betale innen %d dager.\" % (payment.delay)\n        if len(payment.prices()) == 1:\n            message += u\"\\nPrisen for dette arrangementet er %skr.\" % (payment.prices()[0].price)\n        # elif len(payment.prices()) >= 2:\n        #     message += u\"\\nDette arrangementet har flere prisklasser:\"\n        #     for payment_price in payment.prices():\n        #         message += \"\\n%s: %skr\" % (payment_price.description, payment_price.price)\n    else:\n        message += u\"Det kreves ingen ekstra handling fra deg med mindre du vil melde deg av.\"\n\n    message += u\"\\n\\nFor mer info:\"\n    message += u\"\\nhttp://%s%s\" % (host, event.get_absolute_url())\n\n    for attendee in attendees:\n        send_mail(title, message, settings.DEFAULT_FROM_EMAIL, [attendee.user.email])\n\n\nclass Calendar(object):\n    def __init__(self):\n        self.cal = icalendar.Calendar()\n        # Filename served by webserver\n        self.filename = 'online'\n        # Required ical info\n        self.cal.add('prodid', '-//Online//Onlineweb//EN')\n        self.cal.add('version', '2.0')\n\n    def add_event(self, event):\n        raise NotImplementedError\n\n    def add_events(self, events):\n        for event in events:\n            self.add_event(event)\n\n    def output(self):\n        \"\"\"Return icalendar as text\"\"\"\n        return self.cal.to_ical()\n\n    def response(self):\n        \"\"\"Returns a response object\"\"\"\n        response = HttpResponse(self.cal.to_ical(), content_type='text/calendar')\n        response['Content-Type'] = 'text/calendar; charset=utf-8'\n        response['Content-Disposition'] = 'attachment; filename=' + self.filename + '.ics'\n        return response\n\n\nclass EventCalendar(Calendar):\n    def user(self, user):\n        \"\"\"\n            Personalized calendar\n            This calendar is publicly available, but the url is not guessable so data should not be leaked to everyone\n        \"\"\"\n        signer = Signer()\n        try:\n            username = signer.unsign(user)\n            user = User.objects.get(username=username)\n        except (BadSignature, User.DoesNotExist):\n            user = None\n        if user:\n            # Getting all events that the user has/is participating in\n            self.add_events(Event.objects.filter(\n                attendance_event__attendees__user=user\n            ).order_by('event_start').prefetch_related(\n                'attendance_event', 'attendance_event__attendees'\n            ))\n            self.filename = username\n\n    def event(self, event_id):\n        \"\"\"Single event\"\"\"\n        try:\n            self.add_event(Event.objects.get(id=event_id))\n        except Event.DoesNotExist:\n            pass\n        self.filename = str(event_id)\n\n    def events(self):\n        \"\"\"All events that haven't ended yet\"\"\"\n        self.add_events(Event.objects.filter(event_end__gt=timezone.now()).order_by('event_start'))\n        self.filename = 'events'\n\n    def add_event(self, event):\n        cal_event = icalendar.Event()\n\n        cal_event.add('dtstart', event.event_start)\n        cal_event.add('dtend', event.event_end)\n        cal_event.add('location', event.location)\n        cal_event.add('summary', event.title)\n        cal_event.add('description', event.ingress_short)\n        cal_event.add('uid', 'event-' + str(event.id) + '@online.ntnu.no')\n\n        self.cal.add_component(cal_event)\n\n\nclass SplashCalendar(Calendar):\n    def add_event(self, event):\n        cal_event = icalendar.Event()\n        cal_event.add('dtstart', event.start_time)\n        cal_event.add('dtend', event.end_time)\n        cal_event.add('summary', event.title)\n        cal_event.add('description', event.content)\n        cal_event.add('uid', 'splash-' + str(event.id) + '@online.ntnu.no')\n\n        self.cal.add_component(cal_event)\n\n    def events(self):\n        self.add_events(SplashYear.objects.current_events())\n        self.filename = 'events'\n\n\ndef find_image_versions(event):\n    img = event.image\n    img_strings = []\n\n    for ver in VERSIONS.keys():\n        if ver.startswith('events_'):\n            img_strings.append(img.version_generate(ver).url)\n\n    return img_strings\n", "path": "apps/events/utils.py"}, {"content": "from django.http import Http404\nfrom django.shortcuts import render\nfrom apps.splash.models import SplashYear\n\nfrom apps.events.utils import SplashCalendar\n\n\ndef index(request):\n    splash_year = SplashYear.objects.current()\n    if not splash_year:\n        raise Http404\n\n    splash_year.events = _merge_events(splash_year.events())\n\n    return render(request, 'splash/base.html', {'splash_year': splash_year})\n\n\ndef calendar_export(request):\n    calendar = SplashCalendar()\n    calendar.events()\n    return calendar.response()\n\n\n# And I'm really sorry for this ...\ndef _merge_events(splash_events):\n    events = []\n\n    for event in splash_events:\n        if len(events) > 0 and event.start_time.strftime('%d-%m') == events[-1][0].start_time.strftime('%d-%m'):\n            events[-1].append(event)\n        else:\n            events.append([event])\n\n    return events\n", "path": "apps/splash/views.py"}, {"content": "from django.db import models\n\nfrom django_extensions.db.models import TimeStampedModel\nimport datetime\nimport reversion\n\n\nclass SplashYearManager(models.Manager):\n    def current(self):\n        # I'm really sorry ...\n        half_a_year_ago = str(datetime.date.today() - datetime.timedelta(180))\n        return self.filter(start_date__gt=half_a_year_ago).first()\n\n    def current_events(self):\n        current_splash = self.current()\n        if current_splash:\n            return current_splash.events()\n        return self.none()\n\n\nclass SplashYear(models.Model):\n    title = models.CharField(u'title', max_length=100)\n    start_date = models.DateField(u'start_date')\n\n    objects = SplashYearManager()\n\n    def events(self):\n        return self.splash_events.all()\n\n    def __unicode__(self):\n        return self.title\n\n    class Meta(object):\n        ordering = ('-start_date',)\n\n\nclass SplashEvent(TimeStampedModel, models.Model):\n    title = models.CharField(u'title', max_length=100)\n    content = models.TextField(u'content')\n    start_time = models.DateTimeField()\n    end_time = models.DateTimeField()\n    splash_year = models.ForeignKey('SplashYear', related_name='splash_events')\n\n    def __unicode__(self):\n        return self.title\n\n    class Meta(object):\n        ordering = ('start_time',)\n\nreversion.register(SplashYear)\nreversion.register(SplashEvent)\n", "path": "apps/splash/models.py"}]}