diff --git a/src/bornhack/settings.py b/src/bornhack/settings.py index 67359fed..eb3c47d5 100644 --- a/src/bornhack/settings.py +++ b/src/bornhack/settings.py @@ -48,6 +48,7 @@ INSTALLED_APPS = [ 'events', 'rideshare', 'tokens', + 'feedback', 'allauth', 'allauth.account', diff --git a/src/bornhack/urls.py b/src/bornhack/urls.py index cd2907c6..79b34a00 100644 --- a/src/bornhack/urls.py +++ b/src/bornhack/urls.py @@ -2,15 +2,14 @@ from allauth.account.views import ( LoginView, LogoutView, ) -from django.conf import settings from django.urls import include, path from django.contrib import admin from camps.views import * +from feedback.views import FeedbackCreate from info.views import * from villages.views import * from program.views import * from sponsors.views import * -from teams.views import * from people.views import * from bar.views import MenuView @@ -197,6 +196,12 @@ urlpatterns = [ include('backoffice.urls', namespace='backoffice') ), + path( + 'feedback/', + FeedbackCreate.as_view(), + name='feedback' + ), + ]) ) ] diff --git a/src/feedback/__init__.py b/src/feedback/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/feedback/admin.py b/src/feedback/admin.py new file mode 100644 index 00000000..d3da8238 --- /dev/null +++ b/src/feedback/admin.py @@ -0,0 +1,8 @@ +from django.contrib import admin + +from .models import Feedback + + +@admin.register(Feedback) +class FeedbackAdmin(admin.ModelAdmin): + pass diff --git a/src/feedback/apps.py b/src/feedback/apps.py new file mode 100644 index 00000000..63cb2219 --- /dev/null +++ b/src/feedback/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class FeedbackConfig(AppConfig): + name = 'feedback' diff --git a/src/feedback/migrations/0001_initial.py b/src/feedback/migrations/0001_initial.py new file mode 100644 index 00000000..4e401ab1 --- /dev/null +++ b/src/feedback/migrations/0001_initial.py @@ -0,0 +1,31 @@ +# Generated by Django 2.1 on 2018-08-20 13:13 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion +import uuid + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.CreateModel( + name='Feedback', + fields=[ + ('uuid', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), + ('created', models.DateTimeField(auto_now_add=True)), + ('updated', models.DateTimeField(auto_now=True)), + ('feedback', models.TextField()), + ('user', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL)), + ], + options={ + 'abstract': False, + }, + ), + ] diff --git a/src/feedback/migrations/__init__.py b/src/feedback/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/feedback/models.py b/src/feedback/models.py new file mode 100644 index 00000000..c1e71e95 --- /dev/null +++ b/src/feedback/models.py @@ -0,0 +1,8 @@ +from django.db import models + +from utils.models import UUIDModel, CreatedUpdatedModel + + +class Feedback(UUIDModel, CreatedUpdatedModel): + user = models.ForeignKey('auth.User', on_delete=models.PROTECT) + feedback = models.TextField() diff --git a/src/feedback/templates/feedback/feedback_form.html b/src/feedback/templates/feedback/feedback_form.html new file mode 100644 index 00000000..6ee63271 --- /dev/null +++ b/src/feedback/templates/feedback/feedback_form.html @@ -0,0 +1,28 @@ +{% extends "base.html" %} +{% load commonmark %} +{% load bootstrap3 %} + +{% block content %} + + + +
+

+ BornHack can always improve, but we need your feedback to know how. So write you thoughts on what was good and what wasn't, it's highly appreciated! +

+
+ +
+
+ {% csrf_token %} + {% bootstrap_form form %} + + +
+
+ +{% endblock %} \ No newline at end of file diff --git a/src/feedback/tests.py b/src/feedback/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/src/feedback/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/src/feedback/views.py b/src/feedback/views.py new file mode 100644 index 00000000..3fdb4c84 --- /dev/null +++ b/src/feedback/views.py @@ -0,0 +1,31 @@ +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 + 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})) diff --git a/src/templates/includes/menuitems.html b/src/templates/includes/menuitems.html index 308c3f1d..0434b7d3 100644 --- a/src/templates/includes/menuitems.html +++ b/src/templates/includes/menuitems.html @@ -7,6 +7,7 @@ Teams {% if request.user.is_authenticated %} Rideshare + Feedback {% endif %} {% if request.user.is_staff or perms.camps.infodesk_permission %} Backoffice