added ical export support
This commit is contained in:
1
.idea/dictionaries/vabene1111_PC.xml
generated
1
.idea/dictionaries/vabene1111_PC.xml
generated
@ -3,6 +3,7 @@
|
||||
<words>
|
||||
<w>csrftoken</w>
|
||||
<w>gunicorn</w>
|
||||
<w>ical</w>
|
||||
<w>traefik</w>
|
||||
</words>
|
||||
</dictionary>
|
||||
|
@ -175,7 +175,8 @@
|
||||
<a href="#" data-toggle="modal"
|
||||
data-target="#id_plan_types_modal">{% trans 'Edit plan types' %}</a> <br/>
|
||||
<a href="#" data-toggle="modal"
|
||||
data-target="#id_plan_help_modal">{% trans 'Show help' %}</a>
|
||||
data-target="#id_plan_help_modal">{% trans 'Show help' %}</a><br/>
|
||||
<a v-bind:href="getIcalUrl()" >{% trans 'Week iCal export' %}</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -621,6 +622,10 @@
|
||||
}
|
||||
return url
|
||||
},
|
||||
getIcalUrl: function () {
|
||||
return "{% url 'api_get_plan_ical' 12345 %}".replace(/12345/, this.week);
|
||||
},
|
||||
|
||||
addDayToShopping: function (day) {
|
||||
let date = moment(this.week).weekday(this.days.indexOf(day)).format('YYYY-MM-DD')
|
||||
|
||||
|
@ -53,6 +53,7 @@ urlpatterns = [
|
||||
path('api/get_recipe_file/<int:recipe_id>/', api.get_recipe_file, name='api_get_recipe_file'),
|
||||
path('api/sync_all/', api.sync_all, name='api_sync'),
|
||||
path('api/log_cooking/<int:recipe_id>/', api.log_cooking, name='api_log_cooking'),
|
||||
path('api/plan-ical/<slug:html_week>/', api.get_plan_ical, name='api_get_plan_ical'),
|
||||
|
||||
path('dal/keyword/', dal.KeywordAutocomplete.as_view(), name='dal_keyword'),
|
||||
path('dal/ingredient/', dal.IngredientsAutocomplete.as_view(), name='dal_ingredient'),
|
||||
|
@ -1,3 +1,4 @@
|
||||
import io
|
||||
import json
|
||||
import re
|
||||
|
||||
@ -9,6 +10,7 @@ from django.db.models import Q
|
||||
from django.http import HttpResponse, FileResponse
|
||||
from django.shortcuts import redirect
|
||||
from django.utils.translation import gettext as _
|
||||
from icalendar import Calendar, Event
|
||||
from rest_framework import viewsets, permissions
|
||||
from rest_framework.exceptions import APIException
|
||||
|
||||
@ -164,3 +166,27 @@ def log_cooking(request, recipe_id):
|
||||
return {'msg': 'updated successfully'}
|
||||
|
||||
return {'error': 'recipe does not exist'}
|
||||
|
||||
|
||||
@group_required('user')
|
||||
def get_plan_ical(request, html_week):
|
||||
queryset = MealPlan.objects.filter(Q(created_by=request.user) | Q(shared=request.user)).distinct().all()
|
||||
|
||||
y, w = html_week.replace('-W', ' ').split()
|
||||
queryset = queryset.filter(date__week=w, date__year=y)
|
||||
|
||||
cal = Calendar()
|
||||
|
||||
for p in queryset:
|
||||
event = Event()
|
||||
event['uid'] = p.id
|
||||
event.add('dtstart', p.date)
|
||||
event.add('dtend', p.date)
|
||||
event['summary'] = f'{p.meal_type.name}: {p.get_label()}'
|
||||
event['description'] = p.note
|
||||
cal.add_component(event)
|
||||
|
||||
response = FileResponse(io.BytesIO(cal.to_ical()))
|
||||
response["Content-Disposition"] = f'attachment; filename=meal_plan_{html_week}.ics'
|
||||
|
||||
return response
|
||||
|
@ -20,3 +20,4 @@ simplejson==3.17.0
|
||||
six==1.15.0
|
||||
webdavclient3==3.14.4
|
||||
whitenoise==5.1.0
|
||||
icalendar==4.0.6
|
Reference in New Issue
Block a user