Skip to content

Commit

Permalink
Prepare 0.19.2 - Make it easier to get initial form data for ViewForm…
Browse files Browse the repository at this point in the history
…Entry view.
  • Loading branch information
barseghyanartur committed Jul 14, 2022
1 parent 874516d commit 5d98e92
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 8 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ are used for versioning (schema follows below):
0.3.4 to 0.4).
- All backwards incompatible changes are mentioned in this document.

0.19.2
------
2022-07-14

- Make it easier to get initial data for the `ViewFormEntry` view.
- Apply black and isort on entire code base.

0.19.1
------
2022-07-12
Expand Down
7 changes: 7 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ are used for versioning (schema follows below):
0.3.4 to 0.4).
- All backwards incompatible changes are mentioned in this document.

0.19.2
------
2022-07-14

- Make it easier to get initial data for the `ViewFormEntry` view.
- Apply black and isort on entire code base.

0.19.1
------
2022-07-12
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from distutils.version import LooseVersion
from setuptools import setup, find_packages

version = "0.19.1"
version = "0.19.2"

# ***************************************************************************
# ************************** Django version *********************************
Expand Down
2 changes: 1 addition & 1 deletion src/fobi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
__title__ = "django-fobi"
__version__ = "0.19.1"
__version__ = "0.19.2"
__author__ = "Artur Barseghyan <artur.barseghyan@gmail.com>"
__copyright__ = "2014-2022 Artur Barseghyan"
__license__ = "GPL 2.0/LGPL 2.1"
Expand Down
22 changes: 16 additions & 6 deletions src/fobi/views/class_based.py
Original file line number Diff line number Diff line change
Expand Up @@ -1609,6 +1609,20 @@ def get_essential_objects(
form_cls,
)

def get_initial_data(self, request, form_entry):
"""Get initial data.
:param request: HTTP request.
:param form_entry: Form entry object.
:return: Dictionary with initial form data.
"""
# Providing initial form data by feeding entire GET dictionary
# to the form, if ``GET_PARAM_INITIAL_DATA`` is present in the
# GET.
if GET_PARAM_INITIAL_DATA in request.GET:
return {"initial": request.GET}
return {}

def inactive_form_response(self, request, form_entry):
context = {
"form_entry": form_entry,
Expand Down Expand Up @@ -1650,12 +1664,8 @@ def get(self, request, *args, **kwargs):
request,
)

# Providing initial form data by feeding entire GET dictionary
# to the form, if ``GET_PARAM_INITIAL_DATA`` is present in the
# GET.
kwargs = {}
if GET_PARAM_INITIAL_DATA in request.GET:
kwargs = {"initial": request.GET}
# Get initial data.
kwargs = self.get_initial_data(request, form_entry)
form = form_cls(**kwargs)

# In debug mode, try to identify possible problems.
Expand Down

0 comments on commit 5d98e92

Please sign in to comment.