Skip to content

Commit

Permalink
prepare 0.5.10; minor improvements in the dynamic initial values feat…
Browse files Browse the repository at this point in the history
…ure; docs updated; licenses updated (year)
  • Loading branch information
barseghyanartur committed Aug 17, 2015
1 parent 18f7279 commit 5ac1786
Show file tree
Hide file tree
Showing 12 changed files with 173 additions and 58 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,17 @@ are used for versioning (schema follows below):
0.3.4 to 0.4).
- All backwards incompatible changes are mentioned in this document.

0.5.10
------
2015-08-18

- Minor improvements of the initial dynamic values feature.

0.5.9
-----
2015-08-17

- Fixes in the initial dynamic values.
- Minor fixes in the initial dynamic values feature.

0.5.8
-----
Expand Down
2 changes: 1 addition & 1 deletion LICENSE_GPL2.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.

django-fobi - A customisable, modular form builder application for Django.
Copyright (C) 2013-2014 Artur Barseghyan
Copyright (C) 2013-2015 Artur Barseghyan

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion LICENSE_LGPL_2.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ convey the exclusion of warranty; and each file should have at least the
"copyright" line and a pointer to where the full notice is found.

django-fobi - A customisable, modular form builder application for Django.
Copyright (C) 2013-2014 Artur Barseghyan
Copyright (C) 2013-2015 Artur Barseghyan

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
Expand Down
3 changes: 2 additions & 1 deletion QUICK_START.rst
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ your `settings` module.
TEMPLATE_CONTEXT_PROCESSORS = (
# ...
"django.core.context_processors.request",
"fobi.context_processors.theme",
"fobi.context_processors.theme", # Obligatory
"fobi.context_processors.dynamic_values", # Optional
# ...
)
Expand Down
55 changes: 45 additions & 10 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Main features and highlights
- Data export (`db_store
<https://github.com/barseghyanartur/django-fobi/tree/stable/src/fobi/contrib/plugins/form_handlers/db_store>`_
form handler plugin) into XLS/CSV format.
- Dynamic initial values for form elements.
- `Dynamic initial values`_ for form elements.

Roadmap
=======
Expand Down Expand Up @@ -1262,6 +1262,9 @@ in directory of each plugin for details.

Fields
~~~~~~
Fields marked with asterics (*) fall under the definition of text elements.
It's possible to provide `Dynamic initial values`_ for text elements.

- `Boolean (checkbox)
<https://github.com/barseghyanartur/django-fobi/tree/stable/src/fobi/contrib/plugins/form_elements/fields/boolean/>`_
- `Date
Expand All @@ -1272,21 +1275,21 @@ Fields
<https://github.com/barseghyanartur/django-fobi/tree/stable/src/fobi/contrib/plugins/form_elements/fields/date_drop_down/>`_
- `Decimal
<https://github.com/barseghyanartur/django-fobi/tree/master/src/fobi/contrib/plugins/form_elements/fields/decimal>`_
- `Email
- `Email*
<https://github.com/barseghyanartur/django-fobi/tree/stable/src/fobi/contrib/plugins/form_elements/fields/email/>`_
- `File
<https://github.com/barseghyanartur/django-fobi/tree/stable/src/fobi/contrib/plugins/form_elements/fields/file/>`_
- `Float
<https://github.com/barseghyanartur/django-fobi/tree/master/src/fobi/contrib/plugins/form_elements/fields/float>`_
- `Hidden
- `Hidden*
<https://github.com/barseghyanartur/django-fobi/tree/stable/src/fobi/contrib/plugins/form_elements/fields/hidden/>`_
- `Password
- `Password*
<https://github.com/barseghyanartur/django-fobi/tree/stable/src/fobi/contrib/plugins/form_elements/fields/password/>`_
- `Radio select (radio button)
<https://github.com/barseghyanartur/django-fobi/tree/stable/src/fobi/contrib/plugins/form_elements/fields/radio/>`_
- `Input
<https://github.com/barseghyanartur/django-fobi/tree/stable/src/fobi/contrib/plugins/form_elements/fields/input/>`_
- `IP address
- `IP address*
<https://github.com/barseghyanartur/django-fobi/tree/master/src/fobi/contrib/plugins/form_elements/fields/ip_address>`_
- `Integer
<https://github.com/barseghyanartur/django-fobi/tree/stable/src/fobi/contrib/plugins/form_elements/fields/integer/>`_
Expand All @@ -1298,17 +1301,17 @@ Fields
<https://github.com/barseghyanartur/django-fobi/tree/stable/src/fobi/contrib/plugins/form_elements/fields/select_model_object/>`_
- `Select multiple (drop-down)
<https://github.com/barseghyanartur/django-fobi/tree/stable/src/fobi/contrib/plugins/form_elements/fields/select_multiple/>`_
- `Slug
- `Slug*
<https://github.com/barseghyanartur/django-fobi/tree/master/src/fobi/contrib/plugins/form_elements/fields/slug>`_
- `Select multiple model objects (drop-down)
<https://github.com/barseghyanartur/django-fobi/tree/stable/src/fobi/contrib/plugins/form_elements/fields/select_multiple_model_objects/>`_
- `Text
- `Text*
<https://github.com/barseghyanartur/django-fobi/tree/stable/src/fobi/contrib/plugins/form_elements/fields/text/>`_
- `Textarea
- `Textarea*
<https://github.com/barseghyanartur/django-fobi/tree/stable/src/fobi/contrib/plugins/form_elements/fields/textarea/>`_
- `Time
<https://github.com/barseghyanartur/django-fobi/tree/master/src/fobi/contrib/plugins/form_elements/fields/time>`_
- `URL
- `URL*
<https://github.com/barseghyanartur/django-fobi/tree/stable/src/fobi/contrib/plugins/form_elements/fields/url/>`_

Content/presentation
Expand Down Expand Up @@ -1426,7 +1429,7 @@ http://127.0.0.1:8001/fobi/view/test-form/?fobi_initial_data&email=test@example.

Dynamic initial values
======================
It's possible to provide a dynamic initial value for any of the elements.
It's possible to provide a dynamic initial value for any of the text elements.
In order to do that, you should use the build-in context processor or make
your own one. The only requirement is that you should store all values that
should be exposes in the form as a dict for `fobi_dynamic_values` dictionary
Expand Down Expand Up @@ -1464,7 +1467,39 @@ Currently, the following variables are available in the
`fobi.context_processors.dynamic_values` context processor:

- request: Stripped HttpRequest object.

- request.path: A string representing the full path to the requested page,
not including the scheme or domain.
- request.get_full_path(): Returns the path, plus an appended query string,
if applicable.
- request.is_secure(): Returns True if the request is secure; that is, if
it was made with HTTPS.
- request.is_ajax(): Returns True if the request was made via an
XMLHttpRequest, by checking the HTTP_X_REQUESTED_WITH header for the
string 'XMLHttpRequest'.
- request.META: A stripped down standard Python dictionary containing the
available HTTP headers.

- HTTP_ACCEPT_ENCODING: Acceptable encodings for the response.
- HTTP_ACCEPT_LANGUAGE: Acceptable languages for the response.
- HTTP_HOST: The HTTP Host header sent by the client.
- HTTP_REFERER: The referring page, if any.
- HTTP_USER_AGENT: The client’s user-agent string.
- REMOTE_ADDR: The IP address of the client.

- request.user: Authenticated user.

- request.user.email:
- request.user.get_username(): Returns the username for the user. Since
the User model can be swapped out, you should use this method
instead of referencing the username attribute directly.
- request.user.get_full_name(): Returns the first_name plus the
last_name, with a space in between.
- request.user.get_short_name(): Returns the first_name.
- request.user.is_anonymous():

- now: datetime.datetime.now()

- today: datetime.date.today()

Submitted form element plugins values
Expand Down
4 changes: 2 additions & 2 deletions ROADMAP.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ change of the name of the "simple" theme into "django_admin_style" theme.
- Internally, make a date when form has been created. Also keep track of when
the form has been last edited.

0.5.9
-----
0.5.11
------
yyyy-mm-dd (upcoming).

- Export/import forms saved as JSON. Validate the imports and mention that
Expand Down
55 changes: 45 additions & 10 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Main features and highlights
- Data export (`db_store
<https://github.com/barseghyanartur/django-fobi/tree/stable/src/fobi/contrib/plugins/form_handlers/db_store>`_
form handler plugin) into XLS/CSV format.
- Dynamic initial values for form elements.
- `Dynamic initial values`_ for form elements.

Roadmap
=======
Expand Down Expand Up @@ -1262,6 +1262,9 @@ in directory of each plugin for details.

Fields
~~~~~~
Fields marked with asterics (*) fall under the definition of text elements.
It's possible to provide `Dynamic initial values`_ for text elements.

- `Boolean (checkbox)
<https://github.com/barseghyanartur/django-fobi/tree/stable/src/fobi/contrib/plugins/form_elements/fields/boolean/>`_
- `Date
Expand All @@ -1272,21 +1275,21 @@ Fields
<https://github.com/barseghyanartur/django-fobi/tree/stable/src/fobi/contrib/plugins/form_elements/fields/date_drop_down/>`_
- `Decimal
<https://github.com/barseghyanartur/django-fobi/tree/master/src/fobi/contrib/plugins/form_elements/fields/decimal>`_
- `Email
- `Email*
<https://github.com/barseghyanartur/django-fobi/tree/stable/src/fobi/contrib/plugins/form_elements/fields/email/>`_
- `File
<https://github.com/barseghyanartur/django-fobi/tree/stable/src/fobi/contrib/plugins/form_elements/fields/file/>`_
- `Float
<https://github.com/barseghyanartur/django-fobi/tree/master/src/fobi/contrib/plugins/form_elements/fields/float>`_
- `Hidden
- `Hidden*
<https://github.com/barseghyanartur/django-fobi/tree/stable/src/fobi/contrib/plugins/form_elements/fields/hidden/>`_
- `Password
- `Password*
<https://github.com/barseghyanartur/django-fobi/tree/stable/src/fobi/contrib/plugins/form_elements/fields/password/>`_
- `Radio select (radio button)
<https://github.com/barseghyanartur/django-fobi/tree/stable/src/fobi/contrib/plugins/form_elements/fields/radio/>`_
- `Input
<https://github.com/barseghyanartur/django-fobi/tree/stable/src/fobi/contrib/plugins/form_elements/fields/input/>`_
- `IP address
- `IP address*
<https://github.com/barseghyanartur/django-fobi/tree/master/src/fobi/contrib/plugins/form_elements/fields/ip_address>`_
- `Integer
<https://github.com/barseghyanartur/django-fobi/tree/stable/src/fobi/contrib/plugins/form_elements/fields/integer/>`_
Expand All @@ -1298,17 +1301,17 @@ Fields
<https://github.com/barseghyanartur/django-fobi/tree/stable/src/fobi/contrib/plugins/form_elements/fields/select_model_object/>`_
- `Select multiple (drop-down)
<https://github.com/barseghyanartur/django-fobi/tree/stable/src/fobi/contrib/plugins/form_elements/fields/select_multiple/>`_
- `Slug
- `Slug*
<https://github.com/barseghyanartur/django-fobi/tree/master/src/fobi/contrib/plugins/form_elements/fields/slug>`_
- `Select multiple model objects (drop-down)
<https://github.com/barseghyanartur/django-fobi/tree/stable/src/fobi/contrib/plugins/form_elements/fields/select_multiple_model_objects/>`_
- `Text
- `Text*
<https://github.com/barseghyanartur/django-fobi/tree/stable/src/fobi/contrib/plugins/form_elements/fields/text/>`_
- `Textarea
- `Textarea*
<https://github.com/barseghyanartur/django-fobi/tree/stable/src/fobi/contrib/plugins/form_elements/fields/textarea/>`_
- `Time
<https://github.com/barseghyanartur/django-fobi/tree/master/src/fobi/contrib/plugins/form_elements/fields/time>`_
- `URL
- `URL*
<https://github.com/barseghyanartur/django-fobi/tree/stable/src/fobi/contrib/plugins/form_elements/fields/url/>`_

Content/presentation
Expand Down Expand Up @@ -1426,7 +1429,7 @@ http://127.0.0.1:8001/fobi/view/test-form/?fobi_initial_data&email=test@example.

Dynamic initial values
======================
It's possible to provide a dynamic initial value for any of the elements.
It's possible to provide a dynamic initial value for any of the text elements.
In order to do that, you should use the build-in context processor or make
your own one. The only requirement is that you should store all values that
should be exposes in the form as a dict for `fobi_dynamic_values` dictionary
Expand Down Expand Up @@ -1464,7 +1467,39 @@ Currently, the following variables are available in the
`fobi.context_processors.dynamic_values` context processor:

- request: Stripped HttpRequest object.

- request.path: A string representing the full path to the requested page,
not including the scheme or domain.
- request.get_full_path(): Returns the path, plus an appended query string,
if applicable.
- request.is_secure(): Returns True if the request is secure; that is, if
it was made with HTTPS.
- request.is_ajax(): Returns True if the request was made via an
XMLHttpRequest, by checking the HTTP_X_REQUESTED_WITH header for the
string 'XMLHttpRequest'.
- request.META: A stripped down standard Python dictionary containing the
available HTTP headers.

- HTTP_ACCEPT_ENCODING: Acceptable encodings for the response.
- HTTP_ACCEPT_LANGUAGE: Acceptable languages for the response.
- HTTP_HOST: The HTTP Host header sent by the client.
- HTTP_REFERER: The referring page, if any.
- HTTP_USER_AGENT: The client’s user-agent string.
- REMOTE_ADDR: The IP address of the client.

- request.user: Authenticated user.

- request.user.email:
- request.user.get_username(): Returns the username for the user. Since
the User model can be swapped out, you should use this method
instead of referencing the username attribute directly.
- request.user.get_full_name(): Returns the first_name plus the
last_name, with a space in between.
- request.user.get_short_name(): Returns the first_name.
- request.user.is_anonymous():

- now: datetime.datetime.now()

- today: datetime.date.today()

Submitted form element plugins values
Expand Down
3 changes: 2 additions & 1 deletion docs/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ your `settings` module.
TEMPLATE_CONTEXT_PROCESSORS = (
# ...
"django.core.context_processors.request",
"fobi.context_processors.theme",
"fobi.context_processors.theme", # Obligatory
"fobi.context_processors.dynamic_values", # Optional
# ...
)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
for locale_dir in locale_dirs:
locale_files += [os.path.join(locale_dir, f) for f in os.listdir(locale_dir)]

version = '0.5.9'
version = '0.5.10'

install_requires = [
'Pillow>=2.0.0',
Expand Down
4 changes: 2 additions & 2 deletions src/fobi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
__title__ = 'django-fobi'
__version__ = '0.5.9'
__build__ = 0x00003e
__version__ = '0.5.10'
__build__ = 0x00003f
__author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>'
__copyright__ = '2014-2015 Artur Barseghyan'
__license__ = 'GPL 2.0/LGPL 2.1'
Expand Down
45 changes: 26 additions & 19 deletions src/fobi/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1164,25 +1164,32 @@ def _get_form_field_instances(self, form_element_entry=None, origin=None,
# as an initial value should put the current users' username
# as initial value in the form.
if 'initial' in field_kwargs and field_kwargs['initial']:
# For security reasons we're not using the original request
# here.
stripped_request = StrippedRequest(request)
context = RequestContext(stripped_request)

# In order to be sure, that no accidental sensitive data
# is exposed in the forms, we only vales from the
# fobi specific context processor. By automatically
# force-prefixing all dynamic value definitions with
# "fobi_dynamic_values." string. See the docs for
# more ("Dyamic initial values" section).
initial = field_kwargs['initial']

# For the moment, only string types are dynamic
if isinstance(initial, string_types):
initial = initial.replace("{{ ", "{{") \
.replace(" }}", "}}") \
.replace("{{", "{{fobi_dynamic_values.")
field_kwargs['initial'] = Template(initial).render(context)
try:

# For security reasons we're not using the original request
# here.
stripped_request = StrippedRequest(request)
context = RequestContext(stripped_request)

# In order to be sure, that no accidental sensitive data
# is exposed in the forms, we only vales from the
# fobi specific context processor. By automatically
# force-prefixing all dynamic value definitions with
# "fobi_dynamic_values." string. See the docs for
# more ("Dyamic initial values" section).
initial = field_kwargs['initial']

# For the moment, only string types are dynamic
if isinstance(initial, string_types):
initial = initial.replace("{{ ", "{{") \
.replace(" }}", "}}") \
.replace("{{",
"{{fobi_dynamic_values.")
field_kwargs['initial'] = \
Template(initial).render(context)

except Exception as err:
logger.debug(err)

# Data to update field instance kwargs with
kwargs_update = self.get_origin_kwargs_update_func_results(
Expand Down

0 comments on commit 5ac1786

Please sign in to comment.