2021-06-14 04:06:32 +00:00
|
|
|
from django.views.generic import TemplateView, View
|
|
|
|
from django.conf import settings
|
2021-06-14 12:11:45 +00:00
|
|
|
from django.http.response import HttpResponse, JsonResponse
|
2021-06-14 04:06:32 +00:00
|
|
|
from django.contrib import messages
|
2021-10-28 07:26:17 +00:00
|
|
|
from django.utils.formats import get_format
|
2021-03-01 09:56:10 +00:00
|
|
|
|
2021-06-14 12:11:45 +00:00
|
|
|
from .models import InspirationRegion, Inspiration
|
|
|
|
|
|
|
|
import django_countries
|
|
|
|
|
2021-03-21 15:50:50 +00:00
|
|
|
class HomeView(TemplateView):
|
2021-04-13 12:44:22 +00:00
|
|
|
template_name = "frontend/index.html"
|
|
|
|
|
|
|
|
class Error404View(TemplateView):
|
2021-05-30 05:41:29 +00:00
|
|
|
template_name = "frontend/404.html"
|
|
|
|
|
|
|
|
class DemoTemplateView(TemplateView):
|
2021-10-28 07:26:17 +00:00
|
|
|
template_name = "partners/calendar.html"
|
2021-05-30 05:48:56 +00:00
|
|
|
|
|
|
|
class ImpressumView(TemplateView):
|
|
|
|
template_name = "frontend/impressum.html"
|
|
|
|
|
|
|
|
class PrivacyNoticeView(TemplateView):
|
|
|
|
template_name = "frontend/privacy.html"
|
|
|
|
|
|
|
|
class TOSView(TemplateView):
|
2021-06-06 08:59:10 +00:00
|
|
|
template_name = "frontend/terms.html"
|
|
|
|
|
|
|
|
class InspirationsView(TemplateView):
|
2021-06-14 04:06:32 +00:00
|
|
|
template_name = "frontend/inspirations.html"
|
|
|
|
|
2021-06-14 12:11:45 +00:00
|
|
|
class InspirationsCountryAPIView(View):
|
|
|
|
def get(self, request, *args, **kwargs):
|
|
|
|
countries = [{"code": country[0], "name": django_countries.countries.name(country[0])} for country in InspirationRegion.country_set.all()]
|
|
|
|
return JsonResponse(countries, safe=False)
|
|
|
|
|
|
|
|
class InspirationsRegionAPIView(View):
|
|
|
|
def get(self, request, *args, **kwargs):
|
|
|
|
regions = [{"id": region.id, "name": region.name, "state": region.is_state} for region in InspirationRegion.objects.filter(country=kwargs["country"])]
|
|
|
|
return JsonResponse(regions, safe=False)
|
|
|
|
|
|
|
|
class InspirationsAPIView(View):
|
|
|
|
def get(self, request, *args, **kwargs):
|
|
|
|
inspirations = [
|
|
|
|
{
|
|
|
|
"id": inspiration.id,
|
|
|
|
"title": inspiration.title,
|
|
|
|
"subtitle": inspiration.subtitle,
|
|
|
|
"image": inspiration.image.url,
|
|
|
|
"sponsor": {
|
|
|
|
"id": inspiration.sponsor.id,
|
|
|
|
"name": inspiration.sponsor.name,
|
|
|
|
"image": inspiration.sponsor.image.url
|
|
|
|
},
|
|
|
|
"destination": {
|
|
|
|
"name": inspiration.destination_name,
|
|
|
|
"coords": {
|
|
|
|
"lat": inspiration.destination_coords.y,
|
|
|
|
"lon": inspiration.destination_coords.x
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} for inspiration in Inspiration.objects.filter(region__id=kwargs["region"])]
|
|
|
|
|
|
|
|
return JsonResponse(inspirations, safe=False)
|
|
|
|
|
2021-06-14 04:06:32 +00:00
|
|
|
class LanguageChoiceView(View):
|
|
|
|
def get(self, request, *args, **kwargs):
|
|
|
|
response = HttpResponse()
|
|
|
|
for language, _ in settings.LANGUAGES:
|
|
|
|
if language.startswith(kwargs["code"]):
|
|
|
|
response.set_cookie(settings.LANGUAGE_COOKIE_NAME, language)
|
|
|
|
if request.user.is_authenticated:
|
|
|
|
request.user.language = language
|
|
|
|
request.user.save()
|
2021-10-28 07:26:17 +00:00
|
|
|
return response
|
|
|
|
|
|
|
|
class LocaleVariableView(View):
|
|
|
|
def get(self, request, *args, **kwargs):
|
|
|
|
variables = {
|
|
|
|
"date_format": get_format('SHORT_DATE_FORMAT', use_l10n=True)
|
|
|
|
}
|
|
|
|
return JsonResponse(variables)
|