- commit
- 91ff5fbc0ba2385b41d188a7acc8f5aa15db0f32
- parent
- 928557c0031daf33221d2d6a841951f3c01dea59
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2019-08-23 09:00
add ical feed
Diffstat
| M | Makefile | 2 | +- |
| A | rebelstuff/feeds.py | 43 | +++++++++++++++++++++++++++++++++++++++++++ |
| M | rebelstuff/urls.py | 2 | ++ |
3 files changed, 46 insertions, 1 deletions
diff --git a/Makefile b/Makefile
@@ -1,7 +1,7 @@ 1 1 .PHONY: all 2 2 all: 3 3 if [ ! -d .venv ]; then python3 -m venv .venv; fi4 -1 .venv/bin/pip install django-1 4 .venv/bin/pip install django django-ical 5 5 .venv/bin/python manage.py migrate 6 6 .venv/bin/python manage.py compilemessages -l de 7 7 .venv/bin/python manage.py loaddata sample_groups sample_data
diff --git a/rebelstuff/feeds.py b/rebelstuff/feeds.py
@@ -0,0 +1,43 @@
-1 1 from django.urls import reverse
-1 2
-1 3 from django_ical.views import ICalFeed
-1 4
-1 5 from .models import Booking
-1 6
-1 7 # not perfect, but still helpful
-1 8 STATUS_MAP = {
-1 9 'waiting': 'TENTATIVE',
-1 10 'delivered': 'CONFIRMED',
-1 11 'returned': 'CANCELLED',
-1 12 }
-1 13
-1 14 class BookingFeed(ICalFeed):
-1 15 def items(self):
-1 16 return Booking.objects.all()
-1 17
-1 18 def item_title(self, booking):
-1 19 return booking.name
-1 20
-1 21 def item_link(self, booking):
-1 22 return reverse('admin:rebelstuff_booking_change', args=[booking.id])
-1 23
-1 24 def item_start_datetime(self, booking):
-1 25 return booking.start
-1 26
-1 27 def item_end_datetime(self, booking):
-1 28 return booking.end
-1 29
-1 30 def item_status(self, booking):
-1 31 return STATUS_MAP[booking.status]
-1 32
-1 33 def item_description(self, booking):
-1 34 description = booking.get_status_display() + '\n'
-1 35
-1 36 if booking.contact:
-1 37 description += '\n' + booking.contact + '\n'
-1 38
-1 39 for item in booking.bookingitem_set.all():
-1 40 item_str = '%s: %i' % (item.stuff.name, item.amount)
-1 41 description += '\n' + item_str
-1 42
-1 43 return description
diff --git a/rebelstuff/urls.py b/rebelstuff/urls.py
@@ -1,7 +1,9 @@ 1 1 from django.urls import path 2 2 3 3 from .admin import site -1 4 from .feeds import BookingFeed 4 5 5 6 urlpatterns = [ 6 7 path('', site.urls), -1 8 path('ical/', BookingFeed()) 7 9 ]