-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add django-dynamic-form to the project #293
Closed
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b54536e
Add django-dynamic-form to the project
ZoltanOnody 727b5dc
basic functionality - one ticket can fill out a form only once
ZoltanOnody f48209b
Move dynamic-form admin to questionnaires
ZoltanOnody 343acdb
Design the templates for questionnaires
ZoltanOnody 8b97afe
Admin can set a questionnaire for a specific event with a deadline
ZoltanOnody 4af2666
Add slug for questionnaire
ZoltanOnody 9a553e8
render a message instead of 404 when user wants to answer the form again
ZoltanOnody 9f73805
Render a message instead 404 when user tries to resubmit the form
ZoltanOnody edcd840
merge
ZoltanOnody File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from django.contrib import admin | ||
from django.utils.translation import ugettext as _ | ||
|
||
from dynamic_forms.admin import FormModelAdmin, FormModelDataAdmin | ||
from dynamic_forms.models import FormModel, FormModelData | ||
|
||
from .models import FormForTicket, QuestionnaireForEvent | ||
|
||
|
||
@admin.register(FormForTicket) | ||
class FormForTicketAdmin(admin.ModelAdmin): | ||
readonly_fields = ['form_data', 'ticket', 'date_created'] | ||
list_display = ['ticket', 'form_data', 'date_created'] | ||
search_fields = ['ticket__first_name', 'ticket__last_name', 'form_data__value'] | ||
list_filter = ['ticket__type__event'] | ||
|
||
|
||
@admin.register(QuestionnaireForEvent) | ||
class QuestionnaireForEventAdmin(admin.ModelAdmin): | ||
list_display = ['slug', 'questionnaire', 'event', 'deadline'] | ||
search_fields = ['slug', 'questionnaire__name'] | ||
list_filter = ['event'] | ||
|
||
|
||
admin.site.unregister(FormModel) | ||
admin.site.unregister(FormModelData) | ||
|
||
|
||
class ProxyFormModel(FormModel): | ||
class Meta: | ||
proxy = True | ||
verbose_name = _('Questionnaire') | ||
verbose_name_plural = _('Questionnaires') | ||
|
||
|
||
class ProxyFormModelDate(FormModelData): | ||
class Meta: | ||
proxy = True | ||
verbose_name = _('Answer') | ||
verbose_name_plural = _('Answers') | ||
|
||
|
||
admin.site.register(ProxyFormModel, FormModelAdmin) | ||
admin.site.register(ProxyFormModelDate, FormModelDataAdmin) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class QuestionnairesConfig(AppConfig): | ||
name = 'questionnaires' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.10.4 on 2017-01-23 15:50 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import uuid | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
('dynamic_forms', '0006_auto_20170123_1550'), | ||
('konfera', '0029_auto_20170111_2105'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='FormForTicket', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('uuid', models.UUIDField(default=uuid.uuid4, editable=False)), | ||
('date_created', models.DateTimeField(auto_now_add=True, verbose_name='Created')), | ||
('date_modified', models.DateTimeField(auto_now=True, verbose_name='Last modified')), | ||
('form_data', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='dynamic_forms.FormModelData')), | ||
('ticket', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='konfera.Ticket')), | ||
], | ||
options={ | ||
'abstract': False, | ||
}, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.10.4 on 2017-01-24 11:31 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import uuid | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('dynamic_forms', '0006_auto_20170123_1550'), | ||
('konfera', '0029_auto_20170111_2105'), | ||
('questionnaires', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='QuestionnaireForEvent', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('uuid', models.UUIDField(default=uuid.uuid4, editable=False)), | ||
('date_created', models.DateTimeField(auto_now_add=True, verbose_name='Created')), | ||
('date_modified', models.DateTimeField(auto_now=True, verbose_name='Last modified')), | ||
('deadline', models.DateTimeField()), | ||
('event', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='konfera.Event')), | ||
], | ||
options={ | ||
'abstract': False, | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name='ProxyFormModel', | ||
fields=[ | ||
], | ||
options={ | ||
'verbose_name': 'Questionnaire', | ||
'proxy': True, | ||
'verbose_name_plural': 'Questionnaires', | ||
}, | ||
bases=('dynamic_forms.formmodel',), | ||
), | ||
migrations.CreateModel( | ||
name='ProxyFormModelDate', | ||
fields=[ | ||
], | ||
options={ | ||
'verbose_name': 'Answer', | ||
'proxy': True, | ||
'verbose_name_plural': 'Answers', | ||
}, | ||
bases=('dynamic_forms.formmodeldata',), | ||
), | ||
migrations.AlterModelOptions( | ||
name='formforticket', | ||
options={'verbose_name': 'Answer for a ticket', 'verbose_name_plural': 'Answers for tickets'}, | ||
), | ||
migrations.AddField( | ||
model_name='questionnaireforevent', | ||
name='questionnaire', | ||
field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='dynamic_forms.FormModel'), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.10.4 on 2017-01-24 14:17 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('konfera', '0029_auto_20170111_2105'), | ||
('questionnaires', '0002_auto_20170124_1131'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='questionnaireforevent', | ||
name='slug', | ||
field=models.SlugField(default='slug'), | ||
preserve_default=False, | ||
), | ||
migrations.AlterUniqueTogether( | ||
name='questionnaireforevent', | ||
unique_together=set([('event', 'slug')]), | ||
), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from django.db import models | ||
from django.core.validators import ValidationError | ||
from django.utils import timezone | ||
from django.utils.translation import ugettext as _ | ||
|
||
from konfera.models.abstract import KonferaModel | ||
|
||
|
||
class FormForTicket(KonferaModel, models.Model): | ||
form_data = models.ForeignKey('dynamic_forms.FormModelData', on_delete=models.CASCADE) | ||
ticket = models.ForeignKey('konfera.Ticket', on_delete=models.CASCADE) | ||
|
||
def save(self, *args, **kwargs): | ||
self.clean() | ||
super().save(*args, **kwargs) | ||
|
||
def clean(self): | ||
if FormForTicket.objects.filter(form_data__form=self.form_data.form, ticket=self.ticket).exists(): | ||
raise ValidationError(_('Form already submitted.')) | ||
super().clean() | ||
|
||
def __str__(self): | ||
return '{} - {}'.format(self.form_data.form.name, self.ticket) | ||
|
||
class Meta: | ||
verbose_name = _('Answer for a ticket') | ||
verbose_name_plural = _('Answers for tickets') | ||
|
||
|
||
class QuestionnaireManager(models.Manager): | ||
def active(self, event): | ||
return self.get_queryset().filter(event=event, deadline__gte=timezone.now()) | ||
|
||
|
||
class QuestionnaireForEvent(KonferaModel, models.Model): | ||
questionnaire = models.OneToOneField('dynamic_forms.FormModel', on_delete=models.CASCADE) | ||
event = models.ForeignKey('konfera.Event', on_delete=models.CASCADE) | ||
deadline = models.DateTimeField() | ||
slug = models.SlugField() | ||
|
||
def __str__(self): | ||
return _('Questionnaire {name} for {event}').format(name=self.questionnaire.name, event=self.event.title) | ||
|
||
class Meta: | ||
unique_together = [('event', 'slug')] | ||
|
||
objects = QuestionnaireManager() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
django-dynamic-forms-0.5.3 | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{% extends 'konfera/base.html' %} | ||
{% load i18n %} | ||
|
||
{% block content %} | ||
<h2>{{ name }}</h2> | ||
<form method="post" action="."> | ||
{% csrf_token %} | ||
{{ form.as_p }} | ||
<button type="submit" class="btn btn-primary">{% trans "Submit" %}</button> | ||
</form> | ||
{% endblock %} |
6 changes: 6 additions & 0 deletions
6
questionnaires/templates/questionnaires/form_already_submited.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{% extends 'konfera/base.html' %} | ||
|
||
|
||
{% block content %} | ||
<h1>You have already submitted the form</h1> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from django.conf.urls import url, include | ||
|
||
from . import views | ||
|
||
urlpatterns = [ | ||
url(r'^(?P<slug>\w+)/ticket/(?P<ticket_uuid>[\w, -]+)/$', views.ShowFormForTicket.as_view()), | ||
url(r'^df/', include('dynamic_forms.urls', namespace='dynamic_forms')), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from django.shortcuts import get_object_or_404, render | ||
|
||
from dynamic_forms.actions import dynamic_form_store_database | ||
from dynamic_forms.views import DynamicFormView | ||
|
||
from konfera.models import Ticket | ||
|
||
from .models import FormForTicket, QuestionnaireForEvent | ||
|
||
|
||
class ShowFormForTicket(DynamicFormView): | ||
|
||
def get_template_names(self): | ||
return ['questionnaires/form.html'] | ||
|
||
def get_success_url(self): | ||
return self.request.path | ||
|
||
def get_data(self): | ||
if 'ticket' not in self.kwargs: | ||
self.kwargs['ticket'] = get_object_or_404(Ticket, uuid=self.kwargs['ticket_uuid']) | ||
if 'model' not in self.kwargs: | ||
questionnaire = get_object_or_404( | ||
QuestionnaireForEvent.objects.active(self.kwargs['ticket'].type.event), | ||
slug=self.kwargs['slug'] | ||
) | ||
self.kwargs['model'] = questionnaire.questionnaire | ||
|
||
def dispatch(self, request, *args, **kwargs): | ||
self.get_data() | ||
|
||
if FormForTicket.objects.filter(form_data__form=self.kwargs['model'], ticket=self.kwargs['ticket']).exists(): | ||
return render(request, 'questionnaires/form_already_submited.html') | ||
|
||
return super().dispatch(request, *args, **kwargs) | ||
|
||
def form_valid(self, form): | ||
self.get_data() | ||
data = dynamic_form_store_database(self.kwargs['model'], form, self.request) | ||
FormForTicket.objects.create(form_data=data, ticket=self.kwargs['ticket']) | ||
return super().form_valid(form) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ django-sitetree==1.6.0 | |
mock==2.0.0 | ||
pytz==2016.7 | ||
Pillow==3.4.2 | ||
django-dynamic-forms-0.5.3 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please fix the typo |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please fix the typo