Skip to content

Commit

Permalink
Feature/user feedback (#436)
Browse files Browse the repository at this point in the history
* Add feedback functionality

* Add feedback rating
  • Loading branch information
karol-bujacek authored Dec 12, 2023
1 parent 4e54c34 commit 42a2890
Show file tree
Hide file tree
Showing 20 changed files with 472 additions and 2 deletions.
40 changes: 39 additions & 1 deletion chcemvediet/apps/inforequests/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
ReadOnlyAdminInlineMixin, BulkDeleteAdminMixin)
from chcemvediet.apps.inforequests.constants import ADMIN_EXTEND_SNOOZE_BY_DAYS

from .models import Inforequest, InforequestDraft, InforequestEmail, Branch, Action
from .models import Inforequest, InforequestDraft, InforequestEmail, Branch, Action, Feedback


class DeleteNestedInforequestEmailAdminMixin(BulkDeleteAdminMixin, admin.ModelAdmin):
Expand Down Expand Up @@ -463,3 +463,41 @@ def delete_model(self, request, obj):
super(ActionAdmin, self).delete_model(request, obj)
if request.POST.get(u'snooze') and self.can_snooze_previous_action(obj):
self.snooze_action(obj.previous_action)


@admin.register(Feedback, site=admin.site)
class FeedbackAdmin(admin.ModelAdmin):
date_hierarchy = u'created'
list_display = [
u'id',
decorate(
lambda o: admin_obj_format(o.inforequest),
short_description=u'Inforequest',
admin_order_field=u'inforequest'
),
u'created',
u'content',
u'rating'
]
list_filter = [
u'created',
u'rating'
]
ordering = [
u'-created',
u'-id',
u'inforequest__id'
]
exclude = [
]
readonly_fields = [
u'inforequest',
u'content',
u'created',
u'rating'
]
raw_id_fields = [
u'inforequest'
]


1 change: 1 addition & 0 deletions chcemvediet/apps/inforequests/forms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
from .clarification_response import ClarificationResponseWizard
from .appeal import AppealWizard
from .action import SnoozeForm
from .feedback_action import FeedbackActionWizard
83 changes: 83 additions & 0 deletions chcemvediet/apps/inforequests/forms/feedback_action.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# vim: expandtab
# -*- coding: utf-8 -*-

from django import forms
from django.utils.translation import ugettext_lazy as _

from chcemvediet.apps.inforequests.models import Feedback
from poleno.utils.urls import reverse
from chcemvediet.apps.wizards.wizard import Bottom, Step, Wizard


class FeedbackActionStep(Step):
template = u'inforequests/feedback_action/wizard.html'
form_template = u'main/forms/form_horizontal.html'


class FeedbackContent(FeedbackActionStep):
label = u'label free text feedback'
text_template = u'inforequests/feedback_action/texts/content.html'
global_fields = [u'content']
post_step_class = Bottom

def add_fields(self):
super(FeedbackContent, self).add_fields()

self.fields[u'content'] = forms.CharField(
label=_(u'inforequests:feedback_action:FeedbackContent:content:label'),
required=False,
widget=forms.Textarea(attrs={
u'placeholder':
_(u'inforequests:feedback_action:FeedbackContent:content:placeholder'),
u'class': u'pln-autosize',
u'cols': u'', u'rows': u''
})
)


class FeedbackRating(FeedbackActionStep):
label = u''
text_template = u'inforequests/feedback_action/texts/rating.html'
global_fields = [u'rating']
post_step_class = FeedbackContent

def add_fields(self):
super(FeedbackRating, self).add_fields()
self.fields[u'rating'] = forms.TypedChoiceField(
label=u' ',
coerce=int,
choices=Feedback.RATING_LEVELS._choices,
widget=forms.RadioSelect(),
)


class FeedbackActionWizard(Wizard):
first_step_class = FeedbackRating

def __init__(self, request, index, inforequest):
self.inforequest = inforequest
super(FeedbackActionWizard, self).__init__(request, index)

def get_instance_id(self):
return u'{}-{}'.format(self.__class__.__name__, self.inforequest.pk)

def get_step_url(self, step, anchor=u''):
return reverse(u'inforequests:feedback_action',
kwargs=dict(inforequest=self.inforequest, step=step)) + anchor

def context(self, extra=None):
res = super(FeedbackActionWizard, self).context(extra)
res.update({
u'inforequest': self.inforequest
})
return res

def finish(self):
feedback = Feedback(
inforequest=self.inforequest,
content=self.values[u'content'],
rating=self.values[u'rating']
)
feedback.save()

return self.inforequest.get_absolute_url()
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations
import poleno.utils.date
import poleno.utils.misc


class Migration(migrations.Migration):

dependencies = [
('inforequests', '0022_inforequest_published'),
]

operations = [
migrations.CreateModel(
name='Feedback',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('content', models.TextField(blank=True)),
('created', models.DateTimeField(default=poleno.utils.date.utc_now)),
('inforequest', models.ForeignKey(to='inforequests.Inforequest', db_index=False)),
],
options={
'verbose_name_plural': 'Feedback',
},
bases=(poleno.utils.misc.FormatMixin, models.Model),
),
migrations.AlterIndexTogether(
name='feedback',
index_together=set([('created', 'id')]),
),
]
20 changes: 20 additions & 0 deletions chcemvediet/apps/inforequests/migrations/0024_feedback_rating.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


class Migration(migrations.Migration):

dependencies = [
('inforequests', '0023_auto_20231201_1635'),
]

operations = [
migrations.AddField(
model_name='feedback',
name='rating',
field=models.SmallIntegerField(default=None, blank=True, choices=[(0, 'Stra\u0161n\xfd'), (1, 'Ve\u013emi zl\xfd'), (2, 'Zl\xfd'), (3, 'Priemern\xfd'), (4, 'Dobr\xfd'), (5, 'Ve\u013emi dobr\xfd'), (6, 'Vynikaj\xfaci'), (7, 'Mimoriadny')]),
preserve_default=True,
),
]
1 change: 1 addition & 0 deletions chcemvediet/apps/inforequests/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
from .inforequestemail import InforequestEmail
from .branch import Branch
from .action import Action
from .feedback import Feedback
48 changes: 48 additions & 0 deletions chcemvediet/apps/inforequests/models/feedback.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# vim: expandtab
# -*- coding: utf-8 -*-
from django.db import models
from django.utils.translation import ugettext_lazy as _

from poleno.utils.date import utc_now
from poleno.utils.misc import FormatMixin
from poleno.utils.models import FieldChoices, QuerySet


class FeedbackQuerySet(QuerySet):
def order_by_pk(self):
return self.order_by(u'pk')


class Feedback(FormatMixin, models.Model):
# NOT NULL
inforequest = models.ForeignKey(u'Inforequest', db_index=False)

# May be empty
content = models.TextField(blank=True)

# NOT NULL
created = models.DateTimeField(default=utc_now)

RATING_LEVELS = FieldChoices(
(u'ATROCIOUS', 0, _(u'inforequests:Feedback:rating:ATROCIOUS')),
(u'VERY POOR', 1, _(u'inforequests:Feedback:rating:VERY_POOR')),
(u'POOR', 2, _(u'inforequests:Feedback:rating:POOR')),
(u'MEDIOCRE', 3, _(u'inforequests:Feedback:rating:MEDIOCRE')),
(u'GOOD', 4, _(u'inforequests:Feedback:rating:GOOD')),
(u'VERY GOOD', 5, _(u'inforequests:Feedback:rating:VERY_GOOD')),
(u'EXCELLENT', 6, _(u'inforequests:Feedback:rating:EXCELLENT')),
)

rating = models.SmallIntegerField(choices=RATING_LEVELS._choices, blank=True, default=None)

# Indexes:
# -- inforequest: ForeignKey
# -- created, id: index_together

objects = FeedbackQuerySet.as_manager()

class Meta:
verbose_name_plural = u'Feedback'
index_together = [
[u'created', u'id'],
]
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ <h1>{% trans 'inforequests:detail:heading' %}</h1>
{% include "inforequests/detail/request.html" %}
{% include "inforequests/detail/response.html" %}
{% include "inforequests/detail/branch/main.html" %}
{% include "inforequests/detail/feedback.html" %}
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{# vim: set filetype=htmldjango shiftwidth=2 :#}
{% load trans from i18n %}
{% load url from poleno.utils %}

{% comment %}
%
% Context:
% -- inforequest: chcemvediet.apps.inforequests.models.Inforequest
%
{% endcomment %}

<div class="chv-bar chv-bar-green">
<div class="chv-bar-icon">
<span class="chv-icon-stack">
<i class="chv-icon icon-circle"></i>
<i class="chv-icon chv-icon-inv chv-icon-half icon-help"></i>
</span>
</div>
<div class="chv-bar-heading">
{% trans 'inforequests:detail:feedback:heading' %}
</div>
</div>
<div class="text-center chv-bellow-1">
{% include "inforequests/detail/texts/feedback.html" %}
<a class="btn chv-btn-green"
href="{% url 'inforequests:feedback_action' inforequest=inforequest %}">
<i class="chv-icon chv-icon-lg icon-help"></i>
&nbsp;
{% trans 'inforequests:detail:feedback:button' %}
</a>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{# vim: set filetype=htmldjango shiftwidth=2 :#}

{% comment %}
%
% Context:
% -- inforequest: chcemvediet.apps.inforequests.models.Inforequest
%
{% endcomment %}

<p>
Chceme zlepšovať portál Chcemvedieť.sk a preto nás zaujíma váš názor. Pomohol vám portál pri odosielaní a prijímaní žiadostí? Boli ste spokojní s poskytovanými funkcionalitami? Alebo naopak, boli ste s niečim nespokojní? Máte nápady na zlepšenie a radi by ste sa o ne podelili? Budeme radi, ak nám dáte spätnú väzbu a pomôžete nám portál zlepšovať.
</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{# vim: set filetype=htmldjango shiftwidth=2 :#}

{% comment %}
%
% Context:
% -- wizard: chcemvediet.apps.inforequests.forms.feedback_action.FeedbackActionWizard
% -- step: chcemvediet.apps.inforequests.forms.feedback_action.FeedbackContent
% -- inforequest: chcemvediet.apps.inforequests.models.Inforequest
%
{% endcomment %}


<h4>Ako by ste zhodnotili portál?</h4>
<p>
Našim záujmom je zlepšovanie portálu a jeho funkcionalít. Zaujíma nás nie len toto,
s čím ste spokojní a ktoré funkcionality portálu vám pomáhajú, ale aj to, kde si myslíte, že
je treba nájsť zlepšenia.
</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{# vim: set filetype=htmldjango shiftwidth=2 :#}

{% comment %}
%
% Context:
% -- wizard: chcemvediet.apps.inforequests.forms.feedback_action.FeedbackActionWizard
% -- step: chcemvediet.apps.inforequests.forms.feedback_action.FeedbackContent
% -- inforequest: chcemvediet.apps.inforequests.models.Inforequest
%
{% endcomment %}


<h4>Ako by ste zhodnotili portál?</h4>
<p>
Našim záujmom je zlepšovanie portálu a jeho funkcionalít. Zaujíma nás nie len toto,
s čím ste spokojní a ktoré funkcionality portálu vám pomáhajú, ale aj to, kde si myslíte, že
je treba nájsť zlepšenia.
</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{# vim: set filetype=htmldjango shiftwidth=2 :#}
{% extends step.base_template %}
{% load trans from i18n %}

{% comment %}
%
% Context:
% -- wizard: chcemvediet.apps.inforequests.forms.feedback_action.FeedbackActionWizard
% -- step: chcemvediet.apps.inforequests.forms.feedback_action.FeedbackActionStep
% -- inforequest: chcemvediet.apps.inforequests.models.Inforequest
%
{% endcomment %}

{% block title %}
{% trans 'inforequests:feedback_action:title' %}
| {{ block.super }}
{% endblock %}

{% block header-heading %}
{% trans 'inforequests:feedback_action:heading' %}
{% endblock %}

{% block footer-cancel-href %}{{ inforequest.get_absolute_url }}{% endblock %}

{% block footer-finish-label %}
<i class="chv-icon chv-icon-lg icon-chevron-right"></i>
&nbsp;
{% trans 'inforequests:feedback_action:submit' %}
{% endblock %}

{% block body-plus-footer %}
<div class="row">
<div class="col-sm-8">
{{ block.super }}
</div>
</div>
{% endblock %}
Loading

0 comments on commit 42a2890

Please sign in to comment.