Skip to content

Commit

Permalink
Merge pull request #67 from moshthepitt/form-improvements
Browse files Browse the repository at this point in the history
Some improvements
  • Loading branch information
moshthepitt authored Feb 19, 2020
2 parents 6523c0b + 456f4b0 commit 7d40b2c
Show file tree
Hide file tree
Showing 10 changed files with 181 additions and 161 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ django-braces==1.14.0
django-crispy-forms==1.8.1
django-filter==2.2.0
django-tables2==2.2.1
django==3.0.2
django==3.0.3
pytz==2019.3 # via django
pyyaml==5.3
six==1.14.0 # via django-braces
Expand Down
45 changes: 23 additions & 22 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,56 +4,57 @@
#
# pip-compile requirements/dev.in
#
appdirs==1.4.3 # via black

appdirs==1.4.3 # via black, virtualenv
asgiref==3.2.3 # via django
aspy.yaml==1.3.0 # via pre-commit
astroid==2.3.3 # via pylint
attrs==19.3.0 # via black
autopep8==1.4.4
autopep8==1.5
backcall==0.1.0 # via ipython
black==19.10b0
certifi==2019.11.28 # via requests
cfgv==2.0.1 # via pre-commit
cfgv==3.0.0 # via pre-commit
chardet==3.0.4 # via requests
click==7.0 # via black
coverage==5.0.3
decorator==4.4.1 # via ipython, traitlets
defusedxml==0.6.0 # via python3-openid
distlib==0.3.0 # via virtualenv
django-allauth==0.41.0
django-braces==1.14.0
django-crispy-forms==1.8.1
django-filter==2.2.0
django-tables2==2.2.1
django==3.0.2 # via django-allauth, django-braces, django-filter, django-tables2, model-mommy
django==3.0.3 # via django-allauth, django-braces, django-filter, django-tables2, model-mommy
entrypoints==0.3 # via flake8
filelock==3.0.12 # via tox
filelock==3.0.12 # via tox, virtualenv
flake8==3.7.9
identify==1.4.10 # via pre-commit
identify==1.4.11 # via pre-commit
idna==2.8 # via requests
importlib-metadata==1.4.0 # via pluggy, pre-commit, tox
importlib-resources==1.0.2 # via pre-commit
importlib-metadata==1.5.0 # via pluggy, pre-commit, tox, virtualenv
importlib-resources==1.0.2 # via pre-commit, virtualenv
ipdb==0.12.3
ipython-genutils==0.2.0 # via traitlets
ipython==7.11.1 # via ipdb
ipython==7.12.0 # via ipdb
isort==4.3.21
jedi==0.15.2 # via ipython
jedi==0.16.0 # via ipython
lazy-object-proxy==1.4.3 # via astroid
mccabe==0.6.1 # via flake8, pylint
model-mommy==2.0.0
more-itertools==8.1.0 # via zipp
mypy-extensions==0.4.3 # via mypy
mypy==0.761
nodeenv==1.3.4 # via pre-commit
nodeenv==1.3.5 # via pre-commit
oauthlib==3.1.0 # via requests-oauthlib
packaging==20.0 # via tox
parso==0.5.2 # via jedi
packaging==20.1 # via tox
parso==0.6.1 # via jedi
pathspec==0.7.0 # via black
pep8==1.7.1
pexpect==4.7.0 # via ipython
pexpect==4.8.0 # via ipython
pickleshare==0.7.5 # via ipython
pluggy==0.13.1 # via tox
pre-commit==1.21.0
prompt-toolkit==3.0.2 # via ipython
pre-commit==2.0.1
prompt-toolkit==3.0.3 # via ipython
psycopg2-binary==2.8.4
ptyprocess==0.6.0 # via pexpect
py==1.8.1 # via tox
Expand All @@ -71,21 +72,21 @@ pyyaml==5.3 # via aspy.yaml, pre-commit
regex==2020.1.8 # via black
requests-oauthlib==1.3.0 # via django-allauth
requests==2.22.0 # via django-allauth, requests-oauthlib
six==1.14.0 # via astroid, cfgv, django-braces, packaging, pre-commit, tox, traitlets
six==1.14.0 # via astroid, django-braces, packaging, tox, traitlets, virtualenv
snowballstemmer==2.0.0 # via pydocstyle
sqlparse==0.3.0 # via django
tablib==1.0.0
toml==0.10.0 # via black, pre-commit, tox
tox==3.14.3
tox==3.14.4
traitlets==4.3.3 # via ipython
typed-ast==1.4.1 # via astroid, black, mypy
typing-extensions==3.7.4.1 # via mypy
urllib3==1.25.7 # via requests
virtualenv==16.7.9 # via pre-commit, tox
urllib3==1.25.8 # via requests
virtualenv==20.0.3 # via pre-commit, tox
wcwidth==0.1.8 # via prompt-toolkit
wrapt==1.11.2 # via astroid
yapf==0.29.0
zipp==1.0.0 # via importlib-metadata
zipp==2.2.0 # via importlib-metadata

# The following packages are considered to be unsafe in a requirements file:
# setuptools
2 changes: 2 additions & 0 deletions tests/artist_app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
custom_default_patterns = views.CustomDefaultActions().url_patterns()
patterns_42 = views.Artist42CRUD().url_patterns()
plainform_patterns = views.PlainFormCRUD().url_patterns()
create_artist_only_patterns = views.CreateOnlyCRUD().url_patterns()


urlpatterns = (
Expand All @@ -30,4 +31,5 @@
+ perms_crud_song_patterns
+ patterns_42
+ plainform_patterns
+ create_artist_only_patterns
)
10 changes: 10 additions & 0 deletions tests/artist_app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,3 +250,13 @@ class BandCRUD(VegaCRUDView):
model = Band
protected_actions: Union[None, List[str]] = None
permissions_actions: Union[None, List[str]] = None


class CreateOnlyCRUD(VegaCRUDView):
"""Vega CRUD view created with plain form."""

model = Artist
protected_actions: Union[None, List[str]] = None
permissions_actions: Union[None, List[str]] = None
actions = ["create"]
crud_path = "create-artist-only"
1 change: 0 additions & 1 deletion tests/test_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ def test_custom_views(self):

def test_custom_default_views(self):
"""Test custom default views."""

artist = mommy.make("artist_app.Artist")
url = reverse("custom-default-actions-list")
res = self.client.get(url)
Expand Down
17 changes: 16 additions & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from django.forms import CharField, ModelForm
from django.test import TestCase, override_settings

from crispy_forms.bootstrap import FormActions
from django_filters import FilterSet
from django_tables2 import Table
from model_mommy import mommy
Expand Down Expand Up @@ -38,10 +39,24 @@ def test_customize_modelform(self):
self.assertTrue(issubclass(custom_form_class, PlainArtistForm))
self.assertEqual("VegaCustomFormClass", custom_form_class.__name__)

# test that form kwargs have been set
try:
custom_form_class(**{settings.VEGA_MODELFORM_KWARG: dict()})
form = custom_form_class(
**{"request": None, settings.VEGA_MODELFORM_KWARG: dict()}
)
except TypeError:
self.fail("Form kwargs have not been set properly")
else:
self.assertTrue(hasattr(form, "helper"))
self.assertEqual(form.helper.form_method, "post")
self.assertEqual(form.helper.form_tag, True)
self.assertEqual(form.helper.form_show_labels, True)
self.assertEqual(form.helper.include_media, True)
self.assertEqual(form.helper.render_required_fields, True)
self.assertEqual(form.helper.html5_required, True)
self.assertEqual(form.helper.form_id, "artist-form")
self.assertEqual(form.helper.layout.fields[0], "name")
self.assertTrue(isinstance(form.helper.layout.fields[1], FormActions))

def test_get_modelform(self):
"""Test get_modelform"""
Expand Down
Loading

0 comments on commit 7d40b2c

Please sign in to comment.