Skip to content

Commit

Permalink
Merge b5d1cd0 into 8da378d
Browse files Browse the repository at this point in the history
  • Loading branch information
AltusBarry committed Aug 1, 2019
2 parents 8da378d + b5d1cd0 commit d6979fe
Show file tree
Hide file tree
Showing 19 changed files with 155 additions and 128 deletions.
37 changes: 30 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,36 @@
language: python

matrix:
include:
- python: 2.7
env: TOXENV=django110
- python: 2.7
env: TOXENV=django111
- python: 3.5
env: TOXENV=django2
include:
- python: "2.7"
env: TOXENV=django111-py27

- python: "3.5"
env: TOXENV=django111-py35
- python: "3.5"
env: TOXENV=django21-py35
- python: "3.5"
env: TOXENV=django22-py35

- python: "3.6"
env: TOXENV=django111-py36
- python: "3.6"
env: TOXENV=django21-py36
- python: "3.6"
env: TOXENV=django22-py36

- python: "3.7"
sudo: required
dist: xenial
env: TOXENV=django111-py37
- python: "3.7"
sudo: required
dist: xenial
env: TOXENV=django21-py37
- python: "3.7"
sudo: required
dist: xenial
env: TOXENV=django22-py37

install:
- pip install tox
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ Changelog

next
----
#. Django 2.0 and Python 3.5 support.
#. Added Django 2.1 and 2.2 along with Python 3.5, 3.6, 3.7 support.
#. Remove Django 1.10 support.

0.2.3
-----
Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ Settings

FORMFACTORY["field-types"]
Control the form fields types that can be selected in Admin.
Supports adding none Django fields: ``("<module_for_field>", "<display_name>")``
Supports adding non Django fields: ``("<module_for_field>", "<display_name>")``
eg. ``("formfactory.fields.ParagraphField", "ParagraphField")``

FORMFACTORY["widget-types"]
Control the form widget types that can be selected in Admin.
Supports adding none Django widgets: ``("<module_for_widget>", "<display_name>")``
Supports adding non Django widgets: ``("<module_for_widget>", "<display_name>")``
eg. ``("formfactory.widgets.ParagraphWidget", "ParagraphWidget")``

Widgets and Fields
Expand Down
8 changes: 8 additions & 0 deletions formfactory/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
class FormFactory(forms.Form):
"""Builds a form class from defined fields passed to it by the Form model.
"""

# TODO: Update uuid in __init__. Forms are readied up during django
# startup, meaning the uuid is only set once and not updated for each form
# instance.
uuid = forms.UUIDField(
initial=str(uuid4()), widget=forms.HiddenInput
)
Expand Down Expand Up @@ -43,6 +47,10 @@ def __init__(self, *args, **kwargs):
# Models aren't ready when the file is initially processed.
from formfactory import models
field_through = models.FieldGroupThrough

# TODO: Duplicate field groups and fields allowed. Has possible
# unintended side effect that only the last field value is ever stored
# using the default store data action.
for field_group in defined_field_groups:

fields = utils.order_by_through(
Expand Down
7 changes: 6 additions & 1 deletion formfactory/fields.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import markdown

import django
from django.forms.fields import Field
from django.utils.text import mark_safe
from django.utils.translation import ugettext as _

if django.VERSION[0] < 2:
from django.utils.text import mark_safe
else:
from django.utils.safestring import mark_safe

from formfactory import widgets


Expand Down
55 changes: 53 additions & 2 deletions formfactory/models.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
import importlib
import markdown

import django
from django import forms
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.db import models
from django.urls import reverse
from django.utils.text import mark_safe
from django.utils.translation import ugettext as _

if django.VERSION[0] < 2:
from django.utils.text import mark_safe
else:
from django.utils.safestring import mark_safe


from simplemde.fields import SimpleMDEField

from formfactory import (
_registry, actions, clean_methods, factory, SETTINGS, validators, utils
SETTINGS,
_registry,
actions,
clean_methods,
factory,
utils,
validators,
)


Expand All @@ -29,8 +41,10 @@ def _FIELD_TYPES():
fields = fields + ((content_type, field),)
return fields


FIELD_TYPES = _FIELD_TYPES()


def _WIDGET_TYPES():
widgets = ()
for content_type, widget in SETTINGS["widget-types"]:
Expand All @@ -39,6 +53,7 @@ def _WIDGET_TYPES():
widgets = widgets + ((content_type, widget),)
return widgets


WIDGET_TYPES = _WIDGET_TYPES()

ERROR_MESSAGES = tuple(
Expand Down Expand Up @@ -71,6 +86,8 @@ class Meta(object):
def __unicode__(self):
return "%s (%s)" % (self.form.title, self.uuid)

__str__ = __unicode__


class FormDataItem(models.Model):
"""A basic store for form data items.
Expand All @@ -90,6 +107,8 @@ class Action(models.Model):
def __unicode__(self):
return self.action

__str__ = __unicode__

@property
def as_function(self):
return _registry["actions"][self.action]
Expand All @@ -103,6 +122,8 @@ class Validator(models.Model):
def __unicode__(self):
return self.validator

__str__ = __unicode__

@property
def as_function(self):
return _registry["validators"][self.validator]
Expand All @@ -116,6 +137,8 @@ class CleanMethod(models.Model):
def __unicode__(self):
return self.clean_method

__str__ = __unicode__

@property
def as_function(self):
return _registry["clean_methods"][self.clean_method]
Expand All @@ -132,6 +155,8 @@ class Meta(object):
def __unicode__(self):
return "%s: %s" % (self.key, self.value)

__str__ = __unicode__


class ActionParam(models.Model):
"""Defines a constant that can be passed to the action function.
Expand All @@ -145,6 +170,8 @@ class ActionParam(models.Model):
def __unicode__(self):
return "%s:%s" % (self.key, self.value)

__str__ = __unicode__


class FormActionThrough(models.Model):
"""Through table for form actions which defines an order.
Expand All @@ -161,6 +188,8 @@ class Meta(object):
def __unicode__(self):
return "%s (%s)" % (self.action.action, self.order)

__str__ = __unicode__


class BaseFormModel(models.Model):
"""Form model which encompasses a set of form fields and defines an action
Expand Down Expand Up @@ -214,6 +243,8 @@ class Meta(object):
def __unicode__(self):
return self.title

__str__ = __unicode__

def get_absolute_url(self):
if self.enable_csrf:
return reverse(
Expand Down Expand Up @@ -265,6 +296,8 @@ class Wizard(BaseFormModel):
def __unicode__(self):
return self.title

__str__ = __unicode__

def absolute_url(self):
return self.get_absolute_url()

Expand All @@ -287,6 +320,8 @@ class Meta(object):
def __unicode__(self):
return "%s (%s)" % (self.form.title, self.order)

__str__ = __unicode__


class WizardActionThrough(models.Model):
"""Through table for wizard actions with a defined order.
Expand All @@ -303,6 +338,8 @@ class Meta(object):
def __unicode__(self):
return "%s (%s)" % (self.action.action, self.order)

__str__ = __unicode__


class FieldChoice(models.Model):
"""Defines options for select or multiselect field types.
Expand All @@ -316,6 +353,8 @@ class Meta(object):
def __unicode__(self):
return "%s:%s" % (self.label, self.value)

__str__ = __unicode__


class FormFieldGroup(models.Model):
"""Enable the grouping of fields and how that field should be rendered.
Expand All @@ -334,6 +373,8 @@ class FormFieldGroup(models.Model):
def __unicode__(self):
return self.title

__str__ = __unicode__


class FieldGroupFormThrough(models.Model):
"""Through table for field groups forms with a defined order.
Expand All @@ -350,6 +391,8 @@ class Meta(object):
def __unicode__(self):
return "%s (%s)" % (self.field_group.title, self.order)

__str__ = __unicode__


class FormField(models.Model):
"""Defines a form field with all options and required attributes.
Expand Down Expand Up @@ -399,6 +442,8 @@ class FormField(models.Model):
def __unicode__(self):
return self.title

__str__ = __unicode__

@property
def get_field_meta(self):
"""
Expand Down Expand Up @@ -452,6 +497,8 @@ class Meta(object):
def __unicode__(self):
return "%s (%s)" % (self.field.title, self.order)

__str__ = __unicode__


class FormFieldErrorMessageProxy(FormField.error_messages.through):
class Meta:
Expand All @@ -461,6 +508,8 @@ class Meta:
def __unicode__(self):
return str(self.customerrormessage)

__str__ = __unicode__


class FormFieldValidatorProxy(FormField.additional_validators.through):
class Meta:
Expand All @@ -469,3 +518,5 @@ class Meta:

def __unicode__(self):
return str(self.validator)

__str__ = __unicode__
5 changes: 0 additions & 5 deletions formfactory/tests/requirements/110.txt

This file was deleted.

14 changes: 12 additions & 2 deletions formfactory/tests/requirements/111.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
Django>=1.11,<2.0
django-formtools==2.0
#django-formtools==2.0
#django-test-without-migrations==0.6
#Markdown==2.6.7
#django-simplemde==0.0.9


django-formtools==2.1
django-test-without-migrations==0.6
Markdown==2.6.7
django-simplemde==0.0.9
django-simplemde==0.1.2
djangorestframework-extras>=0.2.1,<0.3
#djangorestframework-jwt==1.8.0
djangorestframework==3.8.2
six==1.10.0
5 changes: 0 additions & 5 deletions formfactory/tests/requirements/19.txt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
Django>=2.0rc1<3.0
Django>=2.1<2.2
django-formtools==2.1
django-test-without-migrations==0.6
Markdown==2.6.7
django-simplemde==0.1.2
django-simplemde==0.1.3
djangorestframework-extras>=0.2.1,<0.3
#djangorestframework-jwt==1.8.0
djangorestframework==3.8.2
six==1.10.0

9 changes: 9 additions & 0 deletions formfactory/tests/requirements/22.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Django>=2.2<3.0
django-formtools==2.1
django-test-without-migrations==0.6
Markdown==2.6.7
django-simplemde==0.1.3
djangorestframework-extras>=0.2.1,<0.3
#djangorestframework-jwt==1.8.0
djangorestframework==3.8.2
six==1.10.0
Loading

0 comments on commit d6979fe

Please sign in to comment.