Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into multiple-text-field
- Loading branch information
Showing
49 changed files
with
1,165 additions
and
214 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
docs/_build | ||
formly.egg-info | ||
dist | ||
*.pyc | ||
.coverage | ||
.tox | ||
.python-version | ||
.eggs/ | ||
|
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
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
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,25 @@ | ||
from django import forms | ||
from django.core.exceptions import ValidationError | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
|
||
class LimitedMultipleChoiceField(forms.MultipleChoiceField): | ||
def __init__(self, *args, **kwargs): | ||
self.maximum_choices = kwargs.pop("maximum_choices") | ||
|
||
self.default_error_messages.update({ | ||
'maximum_choices': _('You may select at most %(maximum)d choices (%(selected)d selected)') | ||
}) | ||
|
||
super(LimitedMultipleChoiceField, self).__init__(*args, **kwargs) | ||
|
||
def validate(self, value): | ||
super(LimitedMultipleChoiceField, self).validate(value) | ||
|
||
selected_count = len(value) | ||
if self.maximum_choices and selected_count > self.maximum_choices: | ||
raise ValidationError( | ||
self.error_messages['maximum_choices'], | ||
code='maximum_choices', | ||
params={'maximum': self.maximum_choices, 'selected': selected_count}, | ||
) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from django.forms.widgets import RadioSelect | ||
|
||
|
||
class LikertSelect(RadioSelect): | ||
""" | ||
This class differentiates Likert-scale radio selects | ||
from "normal" radio selects for presentation purposes. | ||
""" | ||
pass | ||
|
||
|
||
class RatingSelect(RadioSelect): | ||
pass |
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,45 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.10.4 on 2016-12-06 14:01 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('formly', '0003_auto_20160816_2022'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='LikertChoice', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('label', models.CharField(max_length=100)), | ||
('score', models.IntegerField()), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name='LikertScale', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(max_length=100)), | ||
], | ||
), | ||
migrations.AlterField( | ||
model_name='field', | ||
name='field_type', | ||
field=models.IntegerField(choices=[(0, 'Free Response - One Line'), (1, 'Free Response - Box'), (2, 'Multiple Choice - Pick One'), (4, 'Multiple Choice - Pick One (Dropdown)'), (5, 'Multiple Choice - Can select multiple answers'), (3, 'Date'), (6, 'File Upload'), (7, 'True/False'), (8, 'Multiple Free Responses - Single Lines'), (9, 'Likert Scale')]), | ||
), | ||
migrations.AddField( | ||
model_name='likertchoice', | ||
name='scale', | ||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='choices', to='formly.LikertScale'), | ||
), | ||
migrations.AlterUniqueTogether( | ||
name='likertchoice', | ||
unique_together=set([('scale', 'label'), ('scale', 'score')]), | ||
), | ||
] |
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,21 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.10.4 on 2016-12-06 14:08 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('formly', '0004_auto_20161206_1401'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='field', | ||
name='scale', | ||
field=models.ForeignKey(default=None, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='fields', to='formly.LikertScale'), | ||
), | ||
] |
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,21 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.10.4 on 2016-12-06 14:15 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('formly', '0005_field_scale'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='field', | ||
name='scale', | ||
field=models.ForeignKey(blank=True, default=None, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='fields', to='formly.LikertScale'), | ||
), | ||
] |
25 changes: 25 additions & 0 deletions
25
formly/migrations/0007_help_text_and_label_to_textfield.py
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,25 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.11.1 on 2017-05-11 16:06 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('formly', '0006_auto_20161206_1415'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='field', | ||
name='help_text', | ||
field=models.TextField(blank=True), | ||
), | ||
migrations.AlterField( | ||
model_name='field', | ||
name='label', | ||
field=models.TextField(), | ||
), | ||
] |
Oops, something went wrong.