Skip to content

Commit

Permalink
remove crispy forms
Browse files Browse the repository at this point in the history
  • Loading branch information
SunnyR committed Jun 7, 2024
1 parent 26335fc commit 4b7a635
Show file tree
Hide file tree
Showing 7 changed files with 1 addition and 144 deletions.
31 changes: 1 addition & 30 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ python = "~3.12"
django = "^4.2"
django-filter = "^24.2"
djangorestframework = "^3.15"
django-crispy-forms = "^2.1"
crispy-bootstrap3 = "^2024.1"

[tool.poetry.dev-dependencies]
pre-commit = "3.7.1"
Expand Down
2 changes: 0 additions & 2 deletions rest_framework_filters/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ class RestFrameworkFilterBackend(backends.DjangoFilterBackend):

@property
def template(self):
if compat.is_crispy():
return 'rest_framework_filters/crispy_form.html'
return 'rest_framework_filters/form.html'

@contextmanager
Expand Down
15 changes: 0 additions & 15 deletions rest_framework_filters/filterset.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,18 +377,3 @@ def clean(form):

return cleaned_data
return Form

@property
def form(self):
from django_filters import compat

form = super().form
if compat.is_crispy():
from crispy_forms.helper import FormHelper

form.helper = FormHelper(form)
form.helper.form_tag = False
form.helper.disable_csrf = True
form.helper.template_pack = 'bootstrap3'

return form

This file was deleted.

4 changes: 0 additions & 4 deletions tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
'rest_framework_filters',
'rest_framework',
'django_filters',
"crispy_forms",
"crispy_bootstrap3",
'tests.testapp',
)

Expand Down Expand Up @@ -51,5 +49,3 @@
STATIC_URL = '/static/'

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

CRISPY_TEMPLATE_PACK = 'bootstrap3'
73 changes: 0 additions & 73 deletions tests/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,79 +331,6 @@ def test_patch_for_rendering_handles_exception(self):
self.assertEqual(backend.get_filterset_class, original)


@modify_settings(INSTALLED_APPS={'append': ['crispy_forms']})
class BackendCrispyFormsRenderingTests(RenderMixin, APITestCase):

def test_crispy_forms_filterset_compatibility(self):
class SimpleCrispyFilterSet(FilterSet):
class Meta:
model = models.User
fields = ['username']

class SimpleViewSet(views.FilterFieldsUserViewSet):
filterset_class = SimpleCrispyFilterSet

self.assertHTMLEqual(self.render(SimpleViewSet), """
<h2>Field filters</h2>
<form method="get">
<div id="div_id_username" class="form-group">
<label for="id_username" class="control-label ">Username</label>
<div class=" controls">
<input type="text"
name="username"
class="form-control textinput textInput"
id="id_username">
</div>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
""")

def test_related_filterset_crispy_forms(self):
class UserFilter(FilterSet):
username = filters.CharFilter()

class NoteFilter(FilterSet):
author = filters.RelatedFilter(
filterset=UserFilter,
queryset=models.User.objects.all(),
label='Writer',
)

class RelatedViewSet(views.NoteViewSet):
filterset_class = NoteFilter

self.assertHTMLEqual(self.render(RelatedViewSet), """
<h2>Field filters</h2>
<form method="get">
<div id="div_id_author" class="form-group">
<label for="id_author" class="control-label ">Writer</label>
<div class=" controls">
<select name="author" class="select form-control" id="id_author">
<option value="" selected>---------</option>
</select>
</div>
</div>
<fieldset>
<legend>Writer</legend>
<div id="div_id_author__username" class="form-group">
<label for="id_author__username" class="control-label ">
Username
</label>
<div class=" controls">
<input type="text" class="form-control textinput textInput"
id="id_author__username" name="author__username">
</div>
</div>
</fieldset>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
""")


class ComplexFilterBackendTests(APITestCase):

@classmethod
Expand Down

0 comments on commit 4b7a635

Please sign in to comment.