Skip to content

Pull request for new django version. #253

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ local_settings.py
build/
dist/
forms_builder/example_project/static/
formproject/
Empty file modified forms_builder/example_project/manage.py
100755 → 100644
Empty file.
5 changes: 1 addition & 4 deletions forms_builder/forms/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,7 @@ def __init__(self, form, context, *args, **kwargs):

# Add identifying CSS classes to the field.
css_class = field_class.__name__.lower()
# Do not add the 'required' field to the CheckboxSelectMultiple because it will
# mean that all checkboxes have to be checked instead of the usual use case of
# "at least one".
if field.required and (field_widget != forms.CheckboxSelectMultiple):
if field.required:
css_class += " required"
if settings.USE_HTML5:
# Except Django version 1.10 this is necessary for all versions from 1.8 to 1.11.
Expand Down
4 changes: 2 additions & 2 deletions forms_builder/forms/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from django.db import models, migrations

from forms_builder.forms import fields, settings
from forms_builder.forms import settings


class Migration(migrations.Migration):
Expand All @@ -19,7 +19,7 @@ class Migration(migrations.Migration):
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('label', models.CharField(max_length=200, verbose_name='Label')),
('slug', models.SlugField(default='', max_length=100, verbose_name='Slug', blank=True)),
('field_type', models.IntegerField(verbose_name='Type', choices=fields.NAMES)),
('field_type', models.IntegerField(verbose_name='Type', choices=[(1, 'Single line text'), (2, 'Multi line text'), (3, 'Email'), (13, 'Number'), (14, 'URL'), (4, 'Check box'), (5, 'Check boxes'), (6, 'Drop down'), (7, 'Multi select'), (8, 'Radio buttons'), (9, 'File upload'), (10, 'Date'), (11, 'Date/time'), (15, 'Date of birth'), (12, 'Hidden')])),
('required', models.BooleanField(default=True, verbose_name='Required')),
('visible', models.BooleanField(default=True, verbose_name='Visible')),
('choices', models.CharField(help_text='Comma separated options where applicable. If an option itself contains commas, surround the option starting with the `character and ending with the ` character.', max_length=1000, verbose_name='Choices', blank=True)),
Expand Down
18 changes: 0 additions & 18 deletions forms_builder/forms/migrations/0003_auto_20180522_0820.py

This file was deleted.

8 changes: 5 additions & 3 deletions forms_builder/forms/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from django import VERSION as DJANGO_VERSION
from django.contrib.sites.models import Site
from django.core.exceptions import ValidationError

try:
from django.urls import reverse
Expand All @@ -11,7 +12,7 @@

from django.db import models
from django.db.models import Q
from django.utils.encoding import python_2_unicode_compatible
from six import python_2_unicode_compatible
from django.utils.translation import ugettext, ugettext_lazy as _
from future.builtins import str

Expand Down Expand Up @@ -138,8 +139,9 @@ def total_entries(self):
return self.total_entries
total_entries.admin_order_field = "total_entries"

# @models.permalink
def get_absolute_url(self):
return reverse("form_detail", kwargs={"slug": self.slug})
return reverse("form_detail", args=(self.slug,))

def admin_links(self):
kw = {"args": (self.id,)}
Expand Down Expand Up @@ -171,7 +173,7 @@ class AbstractField(models.Model):
"""

label = models.CharField(_("Label"), max_length=settings.LABEL_MAX_LENGTH)
slug = models.SlugField(_('Slug'), max_length=2000, blank=True,
slug = models.SlugField(_('Slug'), max_length=100, blank=True,
default="")
field_type = models.IntegerField(_("Type"), choices=fields.NAMES)
required = models.BooleanField(_("Required"), default=True)
Expand Down
8 changes: 0 additions & 8 deletions forms_builder/forms/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,6 @@ def test_field_validate_slug_names(self):
except IntegrityError:
self.fail("Slugs were not auto-unique")

def test_field_validate_slug_length(self):
max_slug_length = 2000
form = Form.objects.create(title="Test")
field = Field(form=form,
label='x' * (max_slug_length + 1), field_type=NAMES[0][0])
field.save()
self.assertLessEqual(len(field.slug), max_slug_length)

def test_field_default_ordering(self):
form = Form.objects.create(title="Test")
form.fields.create(label="second field",
Expand Down
6 changes: 1 addition & 5 deletions forms_builder/forms/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,12 @@ def unique_slug(manager, slug_field, slug):
Ensure slug is unique for the given manager, appending a digit
if it isn't.
"""
max_length = manager.model._meta.get_field(slug_field).max_length
slug = slug[:max_length]
i = 0
while True:
if i > 0:
if i > 1:
slug = slug.rsplit("-", 1)[0]
# We need to keep the slug length under the slug fields max length. We need to
# account for the length that is added by adding a random integer and `-`.
slug = "%s-%s" % (slug[:max_length - len(str(i)) - 1], i)
slug = "%s-%s" % (slug, i)
if not manager.filter(**{slug_field: slug}):
break
i += 1
Expand Down
7 changes: 4 additions & 3 deletions forms_builder/forms/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# For Django 1.8 compatibility
from django.core.urlresolvers import reverse
from django.http import HttpResponse, HttpResponseBadRequest
from django.shortcuts import get_object_or_404, redirect, render_to_response
from django.shortcuts import get_object_or_404, redirect, render
from django.template import RequestContext
from django.utils.http import urlquote
from django.views.generic.base import TemplateView
Expand All @@ -36,7 +36,7 @@ def get_context_data(self, **kwargs):
def get(self, request, *args, **kwargs):
context = self.get_context_data(**kwargs)
login_required = context["form"].login_required
if login_required and not request.user.is_authenticated:
if login_required and not request.user.is_authenticated():
path = urlquote(request.get_full_path())
bits = (settings.LOGIN_URL, REDIRECT_FIELD_NAME, path)
return redirect("%s?%s=%s" % bits)
Expand Down Expand Up @@ -120,4 +120,5 @@ def form_sent(request, slug, template="forms/form_sent.html"):
"""
published = Form.objects.published(for_user=request.user)
context = {"form": get_object_or_404(published, slug=slug)}
return render_to_response(template, context, RequestContext(request))
# return render(template, context)
return HttpResponse("Form submitted")
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@
"sphinx-me >= 0.1.2",
"unidecode",
"django-email-extras >= 0.2",
"django >= 1.8, < 2.2",
"django >= 2.0",
"future <= 0.15.0",
"six"
],
classifiers = [
"Development Status :: 5 - Production/Stable",
Expand Down