bornhack-website/src/feedback/views.py

33 lines
1.1 KiB
Python
Raw Normal View History

2018-08-20 13:13:51 +00:00
from django.contrib import messages
from django.contrib.auth.mixins import LoginRequiredMixin
from django.http import HttpResponseRedirect
from django.urls import reverse
from django.views.generic import CreateView
from camps.mixins import CampViewMixin
from tokens.models import Token
from .models import Feedback
class FeedbackCreate(LoginRequiredMixin, CampViewMixin, CreateView):
model = Feedback
fields = ['feedback']
def form_valid(self, form):
feedback = form.save(commit=False)
feedback.user = self.request.user
2018-08-20 13:39:08 +00:00
feedback.save()
2018-08-20 13:13:51 +00:00
thanks_message = "Thank you! Your feedback is highly appreciated!"
try:
token = Token.objects.get(
camp=self.camp,
description="Feedback thanks"
)
thanks_message += " And for your efforts, here is a token: {}".format(token.token)
except Token.DoesNotExist:
pass
messages.success(self.request, thanks_message)
return HttpResponseRedirect(reverse("feedback", kwargs={"camp_slug": self.camp.slug}))