Add initial implementation of feedback form

This commit is contained in:
Ramon Wenger 2022-11-21 12:07:27 +01:00
parent 59f717fa39
commit e1d9df7d31
13 changed files with 174 additions and 0 deletions

View File

@ -109,6 +109,7 @@ LOCAL_APPS = [
"vbv_lernwelt.learnpath",
"vbv_lernwelt.competence",
"vbv_lernwelt.media_library",
"vbv_lernwelt.feedback",
]
# https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps
INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS

View File

@ -32,6 +32,8 @@ from wagtail import urls as wagtail_urls
from wagtail.admin import urls as wagtailadmin_urls
from wagtail.documents import urls as wagtaildocs_urls
from vbv_lernwelt.feedback.views import get_name
def raise_example_error(request):
"""
@ -82,6 +84,7 @@ urlpatterns = [
raise_example_error), ),
path("server/checkratelimit/", check_rate_limit),
path("server/", include(grapple_urls)),
path(r"your-name/", get_name)
]
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

View File

View File

@ -0,0 +1,7 @@
from vbv_lernwelt.feedback.models import Motivation
from django.contrib.admin import ModelAdmin, register
@register(Motivation)
class MotivationAdmin(ModelAdmin):
pass

View File

@ -0,0 +1,13 @@
from django import forms
from vbv_lernwelt.feedback.models import Feedback
class FeedbackForm(forms.ModelForm):
class Meta:
model = Feedback
fields = "__all__"
class NameForm(forms.Form):
your_name = forms.CharField(label="Your name", max_length=100)

View File

@ -0,0 +1,16 @@
import graphene
from graphene_django.forms.mutation import DjangoModelFormMutation
from vbv_lernwelt.feedback.forms import FeedbackForm
from vbv_lernwelt.feedback.graphql.types import FeedbackType
class SendFeedback(DjangoModelFormMutation):
feedback = graphene.Field(FeedbackType)
class Meta:
form_class = FeedbackForm
class Mutation(object):
send_feedback = SendFeedback.Field()

View File

@ -0,0 +1,8 @@
from graphene_django import DjangoObjectType
from vbv_lernwelt.feedback.models import Feedback
class FeedbackType(DjangoObjectType):
class Meta:
model = Feedback

View File

@ -0,0 +1,42 @@
# Generated by Django 3.2.13 on 2022-11-17 16:13
import django.core.validators
from django.db import migrations, models
import vbv_lernwelt.feedback.models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Motivation',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=50)),
],
),
migrations.CreateModel(
name='Feedback',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('satisfaction', vbv_lernwelt.feedback.models.FeedbackIntegerField(validators=[django.core.validators.MinValueValidator(1), django.core.validators.MaxValueValidator(4), django.core.validators.MinValueValidator(1), django.core.validators.MaxValueValidator(4)])),
('goal_attainment', vbv_lernwelt.feedback.models.FeedbackIntegerField(validators=[django.core.validators.MinValueValidator(1), django.core.validators.MaxValueValidator(4), django.core.validators.MinValueValidator(1), django.core.validators.MaxValueValidator(4)])),
('proficiency', models.IntegerField(validators=[django.core.validators.MinValueValidator(1), django.core.validators.MaxValueValidator(5)])),
('received_materials', models.BooleanField()),
('materials_rating', vbv_lernwelt.feedback.models.FeedbackIntegerField(blank=True, validators=[django.core.validators.MinValueValidator(1), django.core.validators.MaxValueValidator(4), django.core.validators.MinValueValidator(1), django.core.validators.MaxValueValidator(4)])),
('instructor_competence', vbv_lernwelt.feedback.models.FeedbackIntegerField(validators=[django.core.validators.MinValueValidator(1), django.core.validators.MaxValueValidator(4), django.core.validators.MinValueValidator(1), django.core.validators.MaxValueValidator(4)])),
('instructor_respect', vbv_lernwelt.feedback.models.FeedbackIntegerField(validators=[django.core.validators.MinValueValidator(1), django.core.validators.MaxValueValidator(4), django.core.validators.MinValueValidator(1), django.core.validators.MaxValueValidator(4)])),
('instructor_open_feedback', models.TextField()),
('would_recommend', models.BooleanField()),
('course_positive_feedback', models.TextField()),
('course_negative_feedback', models.TextField()),
('how_discovered', models.CharField(choices=[('I', 'Internet'), ('L', 'Leaflet'), ('N', 'Newspaper'), ('R', 'Personal recommendation'), ('E', 'Public event'), ('O', 'Other')], max_length=1)),
('motivation', models.ManyToManyField(to='feedback.Motivation')),
],
),
]

View File

@ -0,0 +1,57 @@
from django.core.validators import MaxValueValidator, MinValueValidator
from django.db import models
from django.utils.translation import gettext_lazy as _
class FeedbackIntegerField(models.IntegerField):
def __init__(self, **kwargs):
validators = kwargs.pop("validators", [])
super().__init__(
validators=validators + [MinValueValidator(1), MaxValueValidator(4)],
**kwargs
)
class Motivation(models.Model):
title = models.CharField(max_length=50)
def __str__(self):
return self.title
class Feedback(models.Model):
class DiscoveredChoices(models.TextChoices):
INTERNET = "I", _("Internet")
LEAFLET = "L", _("Leaflet")
NEWSPAPER = "N", _("Newspaper")
RECOMMENDATION = "R", _("Personal recommendation")
EVENT = "E", _("Public event")
OTHER = "O", _("Other")
class RatingChoices(models.IntegerChoices):
ONE = 1, "1"
TWO = 2, "2"
THREE = 3, "3"
FOUR = 4, "4"
class PercentageChoices(models.IntegerChoices):
TWENTY = 20, "20%"
FOURTY = 40, "40%"
SIXTY = 60, "60%"
EIGHTY = 80, "80%"
HUNDRED = 100, "100%"
satisfaction = FeedbackIntegerField(choices=RatingChoices.choices)
goal_attainment = FeedbackIntegerField(choices=RatingChoices.choices)
proficiency = models.IntegerField(choices=PercentageChoices.choices)
received_materials = models.BooleanField()
materials_rating = FeedbackIntegerField(blank=True)
instructor_competence = FeedbackIntegerField(choices=RatingChoices.choices)
instructor_respect = FeedbackIntegerField(choices=RatingChoices.choices)
instructor_open_feedback = models.TextField()
would_recommend = models.BooleanField()
course_positive_feedback = models.TextField()
course_negative_feedback = models.TextField()
how_discovered = models.CharField(max_length=1, choices=DiscoveredChoices.choices)
motivation = models.ManyToManyField(Motivation)

View File

@ -0,0 +1,15 @@
from django.http import HttpResponseRedirect
from django.shortcuts import render
from .forms import FeedbackForm
def get_name(request):
if request.method == "POST":
form = FeedbackForm(request.POST)
if form.is_valid():
return HttpResponseRedirect("/thanks/")
else:
form = FeedbackForm()
return render(request, "feedback/name.html", {"form": form})

View File

@ -0,0 +1,7 @@
from wagtail.core import hooks
from .graphql.mutations import Mutation
@hooks.register("register_schema_mutation")
def register_feedback_mutations(mutation_mixins):
mutation_mixins.append(Mutation)

View File

@ -0,0 +1,5 @@
<form action="/your-name/" method="post">
{% csrf_token %}
{{ form }}
<input type="submit" value="submit" />
</form>