Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
bb7cd3d
Update views.py
annabrodersen Jun 4, 2019
c820fdf
Resolve context attribute error
annabrodersen Jul 24, 2019
e7b913c
Using RequestContext class instance
annabrodersen Jul 24, 2019
cefb9a9
revert to last useable version
annabrodersen Jul 24, 2019
780ccb3
remove vagrant parenth
annabrodersen Jul 24, 2019
835cede
fixing context error with Requestcontext
annabrodersen Jul 24, 2019
ee3edf3
revert to original
annabrodersen Jul 24, 2019
68f3b76
changed djang dependency from <2.2 to <3.0
mpurnell1 Feb 12, 2021
b311ded
Added app_labels in all Meta classes
mpurnell1 Feb 12, 2021
c081e4d
Fixed reverses and added app_name
johnhh2 Feb 12, 2021
ef1bbf0
Merge branch 'django-2.2'
mpurnell1 Feb 12, 2021
2825de5
changed instance type of app_label
mpurnell1 Feb 12, 2021
066ad21
Correct value for app_label
mpurnell1 Feb 12, 2021
fb501d8
Updated reverse namespace reference
johnhh2 Feb 12, 2021
2b3d85e
Revert "Updated reverse namespace reference"
johnhh2 Feb 12, 2021
807d965
Changed re_path reference to url
johnhh2 Feb 12, 2021
d67b34d
Replaced deprecated allow_tags w/ formathtml
johnhh2 Feb 16, 2021
9b0abf9
Updated django dependency 1.8 => 1.9
mpurnell1 Feb 25, 2021
5b52400
Merge branch 'master' of github.com:farmafield-labs/django-forms-builder
mpurnell1 Feb 25, 2021
478ac5b
Corrected update to django 1.9
mpurnell1 Feb 25, 2021
1409706
Final fix for django 1.9 update
mpurnell1 Feb 25, 2021
6166363
Added testing for django 2.2
mpurnell1 Mar 22, 2021
eecb07f
First try at fixing failing tests
mpurnell1 Mar 22, 2021
a7e9ce1
More fixes for failing tests
mpurnell1 Mar 22, 2021
1445321
Corrected import
mpurnell1 Mar 22, 2021
86ab918
More test fixes
mpurnell1 Mar 22, 2021
c57105d
Last few fixes for tests
mpurnell1 Mar 22, 2021
930cf66
Updated django dependency 3.0 to 4.0
AidanKneller Feb 1, 2022
9713276
Merge pull request #1 from farmafield-labs/django-3.0
AidanKneller Feb 1, 2022
66fd854
Updated to be Django 3.0 compatible
AidanKneller Feb 2, 2022
1081796
Merge pull request #2 from farmafield-labs/django-3.0
AidanKneller Feb 2, 2022
e80f5be
Replaced render_to_response with render for Django 3
AidanKneller Feb 2, 2022
9fb34f8
Merge pull request #3 from farmafield-labs/django-3.0
AidanKneller Feb 2, 2022
8aa9f46
Change one instance of render back to render_to_response
mpurnell1 Feb 27, 2022
a28085b
Merge pull request #4 from farmafield-labs/django-3.0
mpurnell1 Feb 27, 2022
53c81e1
Add tests for django 3.0-3.2
mpurnell1 May 17, 2022
263199f
Update django dependency >4.0 to >4.2
mpurnell1 Jul 18, 2023
78e6d56
Remove deprecated kwargs
mpurnell1 Jul 18, 2023
51bf061
Change name of deprecated functions for Django 4.1 compatibility
mpurnell1 Jul 18, 2023
63c78af
Replace deprecated functions with correct ones
mpurnell1 Jul 18, 2023
4c5c856
Replace another deprecated function with the new one
mpurnell1 Jul 19, 2023
515e5ea
Update version of future
mpurnell1 Jul 21, 2023
484886f
Revert "Update version of future"
mpurnell1 Jul 28, 2023
3218bde
Fix code broken by Django 3.1 update
mpurnell1 May 16, 2024
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
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ env:
- DJANGO_VERSION=https://github.com/django/django/archive/stable/1.11.x.zip
- DJANGO_VERSION=https://github.com/django/django/archive/stable/2.0.x.zip
- DJANGO_VERSION=https://github.com/django/django/archive/stable/2.1.x.zip
- DJANGO_VERSION=https://github.com/django/django/archive/stable/2.2.x.zip
- DJANGO_VERSION=https://github.com/django/django/archive/stable/3.0.x.zip
- DJANGO_VERSION=https://github.com/django/django/archive/stable/3.1.x.zip
- DJANGO_VERSION=https://github.com/django/django/archive/stable/3.2.x.zip
python:
- "2.7"
- "3.4"
Expand All @@ -17,8 +21,12 @@ matrix:
env: DJANGO_VERSION=https://github.com/django/django/archive/stable/2.0.x.zip
- python: "2.7"
env: DJANGO_VERSION=https://github.com/django/django/archive/stable/2.1.x.zip
- python: "2.7"
env: DJANGO_VERSION=https://github.com/django/django/archive/stable/2.2.x.zip
- python: "3.4"
env: DJANGO_VERSION=https://github.com/django/django/archive/stable/2.1.x.zip
- python: "3.4"
env: DJANGO_VERSION=https://github.com/django/django/archive/stable/2.2.x.zip
install:
- pip install $DJANGO_VERSION
- pip install .
Expand Down
1 change: 1 addition & 0 deletions forms_builder/example_project/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.messages',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.staticfiles',
Expand Down
11 changes: 6 additions & 5 deletions forms_builder/example_project/urls.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from __future__ import unicode_literals

try:
from django.urls import re_path, include
from django.urls import include
except ImportError:
# For Django 1.8 compatibility
from django.conf.urls import url as re_path, include
from django.conf.urls import include
from django.conf.urls import url
from django.contrib import admin
from django.shortcuts import render

Expand All @@ -15,8 +16,8 @@
admin.autodiscover()

urlpatterns = [
re_path(r'^admin/', admin.site.urls),
re_path(r'^forms/', include(form_urls)),
re_path(r'^$', lambda request: render(request, "index.html",
url(r'^admin/', admin.site.urls),
url(r'^forms/', include(form_urls)),
url(r'^$', lambda request: render(request, "index.html",
{"forms": Form.objects.all()})),
]
17 changes: 8 additions & 9 deletions forms_builder/forms/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,16 @@

from django.contrib import admin
from django.core.files.storage import FileSystemStorage
try:
from django.urls import reverse, re_path
except ImportError:
# For django 1.8 compatiblity
from django.conf.urls import url as re_path
from django.core.urlresolvers import reverse
from django.urls import re_path
from django.db.models import Count
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render, get_object_or_404
from django.utils.translation import ungettext, ugettext_lazy as _

from django.utils.translation import ngettext, gettext_lazy as _
try:
from django.urls import reverse
except ImportError:
# For Django 1.8 compatibility
from django.core.urlresolvers import reverse
from forms_builder.forms.forms import EntriesForm
from forms_builder.forms.models import Form, Field, FormEntry, FieldEntry
from forms_builder.forms.settings import CSV_DELIMITER, UPLOAD_ROOT
Expand Down Expand Up @@ -177,7 +176,7 @@ def info(request, message, fail_silently=True):
count = entries.count()
if count > 0:
entries.delete()
message = ungettext("1 entry deleted",
message = ngettext("1 entry deleted",
"%(count)s entries deleted", count)
info(request, message % {"count": count})
template = "admin/forms/entries.html"
Expand Down
2 changes: 1 addition & 1 deletion forms_builder/forms/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
except ImportError:
# For Django 1.8 compatibility
from django.forms.extras import SelectDateWidget
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from forms_builder.forms.settings import USE_HTML5, EXTRA_FIELDS, EXTRA_WIDGETS
from forms_builder.forms.utils import html5_field, import_attr
Expand Down
6 changes: 3 additions & 3 deletions forms_builder/forms/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from django.core.urlresolvers import reverse
from django.template import Template
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from forms_builder.forms import fields
from forms_builder.forms.models import FormEntry, FieldEntry
Expand Down Expand Up @@ -202,9 +202,9 @@ 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
# 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".
# "at least one".
if field.required and (field_widget != forms.CheckboxSelectMultiple):
css_class += " required"
if settings.USE_HTML5:
Expand Down
21 changes: 13 additions & 8 deletions forms_builder/forms/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@

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

from forms_builder.forms import fields
Expand Down Expand Up @@ -97,6 +98,7 @@ class Meta:
verbose_name = _("Form")
verbose_name_plural = _("Forms")
abstract = True
app_label = "forms"

def __str__(self):
return str(self.title)
Expand All @@ -123,8 +125,9 @@ def published(self, for_user=None):
status = self.status == STATUS_PUBLISHED
publish_date = self.publish_date is None or self.publish_date <= now()
expiry_date = self.expiry_date is None or self.expiry_date >= now()
authenticated = for_user is not None and for_user.is_authenticated
if DJANGO_VERSION <= (1, 9):
if DJANGO_VERSION >= (1, 9):
authenticated = for_user is not None and for_user.is_authenticated
else:
# Django 1.8 compatibility, is_authenticated has to be called as a method.
authenticated = for_user is not None and for_user.is_authenticated()
login_required = (not self.login_required or authenticated)
Expand All @@ -139,7 +142,7 @@ def total_entries(self):
total_entries.admin_order_field = "total_entries"

def get_absolute_url(self):
return reverse("form_detail", kwargs={"slug": self.slug})
return reverse("forms:form_detail", kwargs={"slug": self.slug})

def admin_links(self):
kw = {"args": (self.id,)}
Expand All @@ -150,9 +153,8 @@ def admin_links(self):
(_("Export all entries"), reverse("admin:form_entries_export", **kw)),
]
for i, (text, url) in enumerate(links):
links[i] = "<a href='%s'>%s</a>" % (url, ugettext(text))
return "<br>".join(links)
admin_links.allow_tags = True
links[i] = "<a href='%s'>%s</a>" % (url, gettext(text))
return format_html("<br>".join(links))
admin_links.short_description = ""


Expand Down Expand Up @@ -193,6 +195,7 @@ class Meta:
verbose_name = _("Field")
verbose_name_plural = _("Fields")
abstract = True
app_label = "forms"

def __str__(self):
return str(self.label)
Expand Down Expand Up @@ -239,6 +242,7 @@ class Meta:
verbose_name = _("Form entry")
verbose_name_plural = _("Form entries")
abstract = True
app_label = "forms"


class AbstractFieldEntry(models.Model):
Expand All @@ -254,6 +258,7 @@ class Meta:
verbose_name = _("Form field entry")
verbose_name_plural = _("Form field entries")
abstract = True
app_label = "forms"


###################################################
Expand Down
4 changes: 2 additions & 2 deletions forms_builder/forms/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

from django.dispatch import Signal

form_invalid = Signal(providing_args=["form"])
form_valid = Signal(providing_args=["form", "entry"])
form_invalid = Signal()
form_valid = Signal()
8 changes: 3 additions & 5 deletions forms_builder/forms/urls.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
from __future__ import unicode_literals
try:
from django.urls import re_path
except ImportError:
# For Django 1.8 compatibility
from django.conf.urls import url as re_path

from django.urls import re_path

from forms_builder.forms import views

app_name="forms"

urlpatterns = [
re_path(r"(?P<slug>.*)/sent/$", views.form_sent, name="form_sent"),
Expand Down
20 changes: 10 additions & 10 deletions forms_builder/forms/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
# 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
from email_extras.utils import send_mail_template
from urllib.parse import quote

from forms_builder.forms.forms import FormForForm
from forms_builder.forms.models import Form
Expand All @@ -37,10 +37,10 @@ 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:
path = urlquote(request.get_full_path())
path = quote(request.get_full_path())
bits = (settings.LOGIN_URL, REDIRECT_FIELD_NAME, path)
return redirect("%s?%s=%s" % bits)
return self.render_to_response(context)
return self.render(request, context)

def post(self, request, *args, **kwargs):
published = Form.objects.published(for_user=request.user)
Expand All @@ -60,14 +60,14 @@ def post(self, request, *args, **kwargs):
entry = form_for_form.save()
form_valid.send(sender=request, form=form_for_form, entry=entry)
self.send_emails(request, form_for_form, form, entry, attachments)
if not self.request.is_ajax():
if not self.request.headers.get("x-requested-with") == "XMLHttpRequest": # is_ajax
return redirect(form.redirect_url or
reverse("form_sent", kwargs={"slug": form.slug}))
reverse("forms:form_sent", kwargs={"slug": form.slug}))
context = {"form": form, "form_for_form": form_for_form}
return self.render_to_response(context)
return self.render(request, context)

def render_to_response(self, context, **kwargs):
if self.request.method == "POST" and self.request.is_ajax():
def render(self, request, context, **kwargs):
if self.request.method == "POST" and self.request.headers.get("x-requested-with") == "XMLHttpRequest": # is_ajax
json_context = json.dumps({
"errors": context["form_for_form"].errors,
"form": context["form_for_form"].as_p(),
Expand Down Expand Up @@ -120,4 +120,4 @@ 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(request, template, context=context)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"sphinx-me >= 0.1.2",
"unidecode",
"django-email-extras >= 0.2",
"django >= 1.8, < 2.2",
"django >= 1.9, <4.2",
"future <= 0.15.0",
],
classifiers = [
Expand Down