bornhack-website/src/feedback/views.py

36 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
2018-08-20 13:13:51 +00:00
from .models import Feedback
class FeedbackCreate(LoginRequiredMixin, CampViewMixin, CreateView):
model = Feedback
2019-06-16 12:32:24 +00:00
fields = ["feedback"]
2018-08-20 13:13:51 +00:00
def form_valid(self, form):
feedback = form.save(commit=False)
feedback.user = self.request.user
2018-08-20 13:57:00 +00:00
feedback.camp = self.camp
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:
2019-06-16 12:32:24 +00:00
token = Token.objects.get(camp=self.camp, description="Feedback thanks")
thanks_message += " And for your efforts, here is a token: {}".format(
token.token
2018-08-20 13:13:51 +00:00
)
except Token.DoesNotExist:
pass
messages.success(self.request, thanks_message)
2019-06-16 12:32:24 +00:00
return HttpResponseRedirect(
reverse("feedback", kwargs={"camp_slug": self.camp.slug})
)