Skip to content

Compatible with Django v4 #257

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 6 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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ local_settings.py
build/
dist/
forms_builder/example_project/static/
forms_builder/example_project/
*.sqlite3

6 changes: 4 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
.. image:: https://secure.travis-ci.org/stephenmcd/django-forms-builder.png?branch=master
:target: http://travis-ci.org/stephenmcd/django-forms-builder

django-forms-builder

Comptible with Django v4 and backward comptible with older versions like v3
add 'django.contrib.sites' to installed apps
advance-django-forms-builder
====================

Created by `Stephen McDonald <http://twitter.com/stephen_mcd>`_
Expand Down
2 changes: 1 addition & 1 deletion forms_builder/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.14.0"
__version__ = "1.0.1"
16 changes: 0 additions & 16 deletions forms_builder/example_project/manage.py

This file was deleted.

178 changes: 109 additions & 69 deletions forms_builder/example_project/settings.py
Original file line number Diff line number Diff line change
@@ -1,93 +1,133 @@
from __future__ import absolute_import, unicode_literals
"""
Django settings for example_project project.

import os, sys
Generated by 'django-admin startproject' using Django 4.1.5.

For more information on this file, see
https://docs.djangoproject.com/en/4.1/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.1/ref/settings/
"""

from pathlib import Path
import os
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-5gyb2*ubhp@-g5tz47w%%o4&adp&-yco13m@x9f92*+rf_o#a#'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []

# Application definition

INSTALLED_APPS = [
'django.contrib.sites',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
# "forms.apps.FormsConfig",
"forms.apps.FormsConfig",
]

SITE_ID = 1
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
PROJECT_DIRNAME = PROJECT_ROOT.split(os.sep)[-1]
STATIC_URL = "/static/"
STATIC_ROOT = os.path.join(PROJECT_ROOT, STATIC_URL.strip("/"))
MEDIA_URL = STATIC_URL + "media/"
MEDIA_ROOT = os.path.join(PROJECT_ROOT, *MEDIA_URL.strip("/").split("/"))
ADMIN_MEDIA_PREFIX = STATIC_URL + "admin/"
ROOT_URLCONF = "%s.urls" % PROJECT_DIRNAME
TEMPLATE_DIRS = (os.path.join(PROJECT_ROOT, "templates"),)
SECRET_KEY = "asdfa4wtW#$Gse4aGdfs"
ADMINS = ()


MANAGERS = ADMINS
if "test" not in sys.argv:
LOGIN_URL = "/admin/"
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'dev.db',
}
}
ROOT_URLCONF = 'example_project.urls'
TEMPLATE_DIRS = [
BASE_DIR / "templates",
]

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'BACKEND':
'django.template.backends.django.DjangoTemplates',
'DIRS': [
os.path.join(PROJECT_ROOT, "templates")
BASE_DIR / "templates",
Path(__file__).resolve().parent / "templates",
],
'APP_DIRS': True,
'APP_DIRS':
True,
'OPTIONS': {
'context_processors': [
'django.contrib.auth.context_processors.auth',
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.template.context_processors.i18n',
'django.template.context_processors.media',
'django.template.context_processors.static',
'django.template.context_processors.tz',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

MIDDLEWARE = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)
# For Django 1.8 compatibility
MIDDLEWARE_CLASSES = MIDDLEWARE

TEMPLATE_CONTEXT_PROCESSORS = (
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.static",
"django.core.context_processors.media",
"django.core.context_processors.request",
)

INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.staticfiles',
'forms_builder.forms',
)
WSGI_APPLICATION = 'example_project.wsgi.application'

# Database
# https://docs.djangoproject.com/en/4.1/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}

# Password validation
# https://docs.djangoproject.com/en/4.1/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
'NAME':
'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME':
'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME':
'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME':
'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]

# Internationalization
# https://docs.djangoproject.com/en/4.1/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_TZ = True

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.1/howto/static-files/

FORMS_BUILDER_EXTRA_FIELDS = (
(100, "django.forms.BooleanField", "My cool checkbox"),
)
STATIC_URL = 'static/'

try:
from local_settings import *
except ImportError:
pass
# Default primary key field type
# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field

TEMPLATE_DEBUG = DEBUG
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
6 changes: 6 additions & 0 deletions forms_builder/example_project/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@

from forms_builder.forms.models import Form
from forms_builder.forms import urls as form_urls
# from django.urls import path, include

# urlpatterns = [
# path('admin/', admin.site.urls),
# path("forms", include("forms.urls"))
# ]


admin.autodiscover()
Expand Down
18 changes: 6 additions & 12 deletions forms_builder/forms/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
from __future__ import unicode_literals
from future.builtins import bytes, open

from csv import writer
from mimetypes import guess_type
from os.path import join
Expand All @@ -9,16 +6,13 @@

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 reverse, 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 _

from forms_builder.forms.forms import EntriesForm
from forms_builder.forms.models import Form, Field, FormEntry, FieldEntry
Expand Down Expand Up @@ -177,8 +171,8 @@ def info(request, message, fail_silently=True):
count = entries.count()
if count > 0:
entries.delete()
message = ungettext("1 entry deleted",
"%(count)s entries deleted", count)
message = ngettext("1 entry deleted",
"%(count)s entries deleted", count)
info(request, message % {"count": count})
template = "admin/forms/entries.html"
context = {"title": _("View Entries"), "entries_form": entries_form,
Expand Down
7 changes: 7 additions & 0 deletions forms_builder/forms/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.apps import AppConfig


class FormsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'forms_builder.forms'
app_label = 'forms'
12 changes: 3 additions & 9 deletions forms_builder/forms/fields.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
from __future__ import unicode_literals

from django.core.exceptions import ImproperlyConfigured
from django import forms
try:
from django.forms import SelectDateWidget
except ImportError:
# For Django 1.8 compatibility
from django.forms.extras import SelectDateWidget
from django.utils.translation import ugettext_lazy as _
from django.forms import SelectDateWidget
from django.utils.translation import gettext_lazy as _
from django.core.exceptions import ImproperlyConfigured

from forms_builder.forms.settings import USE_HTML5, EXTRA_FIELDS, EXTRA_WIDGETS
from forms_builder.forms.utils import html5_field, import_attr
Expand Down
Loading