from django.shortcuts import render,redirect,reverse from django.http import HttpResponse, HttpResponseNotFound, Http404,HttpResponseRedirect #zeitgeraffel from django.utils import timezone from django.core.exceptions import ObjectDoesNotExist import datetime import pytz from hpst.models import Termin from hpst.models import Kontakt from hpst.forms import KontaktForm #Email from django.core.mail import BadHeaderError,send_mail # Hauptseite def index(request): termine=Termin.objects.filter(date__gt=timezone.now()).order_by( 'date') context ={ "termine":termine, "form":KontaktForm(initial={'subject': 'Kontaktformular - Index - sinnestau.de',}) } return render(request, "index.html", context) def wildnispaedagogik(request): termine=Termin.objects.filter(date__gt=timezone.now()).order_by( 'date') context ={ "termine":termine, } # return response with template and context return render(request, "wildnispaedagogik.html", context) def kinderfreizeit(request): termine=Termin.objects.filter(date__gt=timezone.now()).filter(termintyp__in=['K','W']).order_by( 'date') context ={ "termine":termine, } # return response with template and context return render(request, "kinderfreizeit.html", context) def lamatour(request): termine=Termin.objects.filter(date__gt=timezone.now()).filter(termintyp='L').order_by( 'date') context ={ "termine":termine, "form":KontaktForm(initial={'subject': 'Kontaktformular - Lamatour - sinnestau.de',}) } # return response with template and context return render(request, "lamatour.html", context) def externereferentin(request): termine=Termin.objects.filter(date__gt=timezone.now()).order_by( 'date') context ={ "termine":termine, } # return response with template and context return render(request, "externereferentin.html", context) def honigmassage(request): termine=Termin.objects.filter(date__gt=timezone.now()).order_by( 'date') context ={ "termine":termine, } return render(request, "honigmassage.html", context) def psychologischeberatung(request): termine=Termin.objects.filter(date__gt=timezone.now()).order_by( 'date') context ={ "termine":termine, } return render(request, "psychologischeberatung.html", context) def pflanzenheilkunde(request): termine=Termin.objects.filter(date__gt=timezone.now()).order_by( 'date') context ={ "termine":termine, } return render(request, "pflanzenheilkunde.html", context) def ohrakupunktur(request): termine=Termin.objects.filter(date__gt=timezone.now()).order_by( 'date') context ={ "termine":termine, } return render(request, "ohrakupunktur.html", context) def termin(request,tid): #print (tid) error="" try: termin=Termin.objects.get(id=tid) except ObjectDoesNotExist: error="Dieser Termin existiert nicht" context ={ "termin":termin, "error":error, } # return response with template and context return render(request, "termin.html", context) def impressum(request): cookies=request.COOKIES #print(cookies) error="Kein Impressum" context ={ "cookies":cookies, } # return response with template and context return render(request, "impressum.html", context) def contactView(request): r_message = { "titel": "Kontaktformular", "color": "w3-yellow", "text": 'Hier das Kontaktformular', } if request.method == 'GET': r_message['titel']="Kontakt Form" form = KontaktForm(initial={'subject': 'Kontaktformular - Kontakt - sinnestau.de',}) else: #print("havepost") form = KontaktForm(request.POST) if form.is_valid(): #print("form valid") subject = form.cleaned_data['subject'] from_email = form.cleaned_data['from_email'] message = form.cleaned_data['message'] name = form.cleaned_data['name'] text=from_email+'\n.........................\n'+message newkon=Kontakt.objects.create( name=name, subject=subject, email=from_email, text=text ) r_message['titel']="Vielen Dank" r_message['color']="w3-green" r_message['text']="Wir haben Ihre Mitteilung erhalten!" form=None try: send_mail(subject, text, 'formular@sinnes-tau.de', ['tanja@kuntner.de']) except BadHeaderError: return HttpResponse('Invalid header found.') #return redirect('success') else: print(form.errors) r_message['titel']="Fehler" r_message['color']="w3-orange" r_message['text']="Ungültiges Formular!" form=None return render(request, "email.html", {'form': form,'message':r_message}) def successView(request): return HttpResponse('Success! Thank you for your message.')