From 4cf22a9ceef1f8fa385c29473ffc57e58d8cfb91 Mon Sep 17 00:00:00 2001 From: Artur Barseghyan Date: Thu, 17 Nov 2016 00:07:06 +0100 Subject: [PATCH] prepare 0.10; added additional args to submit_plugin_form_data; added tests for mailchimp importer plugin; moving plugins to base submodules, having them only registered in fobi_form_elements submodule; disable google analytics in tests; helper scripts updated; multiple pep8 fixes; minor fixes --- CHANGELOG.rst | 27 ++ README.rst | 8 +- ROADMAP.rst | 2 +- TODOS.rst | 2 + docs/index.rst | 8 +- .../simple/admin_tools_dashboard/__init__.py | 137 ++++--- examples/simple/admin_tools_dashboard/conf.py | 16 +- examples/simple/admin_tools_dashboard/menu.py | 57 +-- examples/simple/bar/models.py | 2 +- examples/simple/context_processors.py | 9 +- examples/simple/customauth/__init__.py | 2 +- examples/simple/customauth/admin.py | 8 +- examples/simple/foo/fobi_form_callbacks.py | 2 +- .../fobi_form_elements.py | 3 +- .../fobi_form_elements.py | 3 +- .../override_simple_theme/fobi_themes.py | 2 +- examples/simple/settings/base.py | 147 ++++---- .../settings/bootstrap3_theme_captcha.py | 6 +- .../settings/bootstrap3_theme_django_1_10.py | 5 +- .../bootstrap3_theme_django_1_7_captcha.py | 4 +- .../bootstrap3_theme_django_1_7_djangocms.py | 26 +- .../bootstrap3_theme_django_1_7_feincms.py | 14 +- .../settings/bootstrap3_theme_django_1_8.py | 4 +- .../settings/bootstrap3_theme_djangocms.py | 26 +- .../settings/bootstrap3_theme_djangocms_2.py | 41 ++- .../settings/bootstrap3_theme_feincms.py | 19 +- .../simple/settings/bootstrap3_theme_mptt.py | 12 +- .../bootstrap3_theme_python_3_django_1_8.py | 15 +- .../settings/bootstrap3_theme_recaptcha.py | 12 +- .../djangocms_admin_style_theme_djangocms.py | 19 +- examples/simple/settings/foundation5.py | 6 +- .../settings/foundation5_theme_django_1_10.py | 12 +- .../settings/foundation5_theme_django_1_8.py | 11 +- .../settings/foundation5_theme_django_1_9.py | 13 +- .../settings/foundation5_theme_feincms.py | 6 +- examples/simple/settings/settings_test.py | 19 +- examples/simple/settings/simple.py | 6 +- examples/simple/settings/test.py | 28 +- .../simple/templates/bootstrap3/base.html | 4 +- scripts/pycodestyle.sh | 2 + scripts/pycodestyle_example.sh | 2 + setup.py | 2 +- src/fobi/__init__.py | 4 +- src/fobi/base.py | 38 +- .../content/content_image/base.py | 86 +++++ .../content_image/fobi_form_elements.py | 79 +--- .../content/content_text/base.py | 46 +++ .../content_text/fobi_form_elements.py | 39 +- .../content/content_video/base.py | 51 +++ .../content_video/fobi_form_elements.py | 44 +-- .../form_elements/fields/boolean/base.py | 34 ++ .../fields/boolean/fobi_form_elements.py | 29 +- .../fields/checkbox_select_multiple/base.py | 91 +++++ .../fobi_form_elements.py | 86 +---- .../plugins/form_elements/fields/date/base.py | 72 ++++ .../fields/date/fobi_form_elements.py | 64 +--- .../fields/date_drop_down/base.py | 54 +++ .../date_drop_down/fobi_form_elements.py | 46 +-- .../form_elements/fields/datetime/base.py | 73 ++++ .../fields/datetime/fobi_form_elements.py | 64 +--- .../form_elements/fields/decimal/base.py | 60 +++ .../fields/decimal/fobi_form_elements.py | 52 +-- .../form_elements/fields/email/base.py | 53 +++ .../fields/email/fobi_form_elements.py | 44 +-- .../plugins/form_elements/fields/file/base.py | 74 ++++ .../fields/file/fobi_form_elements.py | 66 +--- .../form_elements/fields/float/base.py | 52 +++ .../fields/float/fobi_form_elements.py | 45 +-- .../form_elements/fields/hidden/base.py | 45 +++ .../fields/hidden/fobi_form_elements.py | 38 +- .../form_elements/fields/input/base.py | 88 +++++ .../fields/input/fobi_form_elements.py | 81 +--- .../form_elements/fields/integer/base.py | 52 +++ .../fields/integer/fobi_form_elements.py | 45 +-- .../form_elements/fields/ip_address/base.py | 47 +++ .../fields/ip_address/fobi_form_elements.py | 42 +-- .../form_elements/fields/null_boolean/base.py | 42 +++ .../fields/null_boolean/fobi_form_elements.py | 35 +- .../form_elements/fields/password/base.py | 47 +++ .../fields/password/fobi_form_elements.py | 40 +- .../form_elements/fields/radio/base.py | 88 +++++ .../fields/radio/fobi_form_elements.py | 79 +--- .../form_elements/fields/range_select/base.py | 61 +++ .../fields/range_select/fobi_form_elements.py | 54 +-- .../form_elements/fields/regex/base.py | 49 +++ .../fields/regex/fobi_form_elements.py | 42 +-- .../form_elements/fields/regex/forms.py | 3 +- .../form_elements/fields/select/base.py | 87 +++++ .../fields/select/fobi_form_elements.py | 78 +--- .../fields/select_model_object/base.py | 107 ++++++ .../select_model_object/fobi_form_elements.py | 97 +---- .../fields/select_mptt_model_object/base.py | 107 ++++++ .../fobi_form_elements.py | 97 +---- .../fields/select_multiple/base.py | 98 +++++ .../select_multiple/fobi_form_elements.py | 88 +---- .../select_multiple_model_objects/base.py | 118 ++++++ .../fobi_form_elements.py | 108 +----- .../base.py | 118 ++++++ .../fobi_form_elements.py | 108 +----- .../fields/select_multiple_with_max/base.py | 99 +++++ .../fobi_form_elements.py | 89 +---- .../form_elements/fields/slider/base.py | 210 +++++++++++ .../fields/slider/fobi_form_elements.py | 204 +--------- .../plugins/form_elements/fields/slug/base.py | 47 +++ .../fields/slug/fobi_form_elements.py | 40 +- .../plugins/form_elements/fields/text/base.py | 47 +++ .../fields/text/fobi_form_elements.py | 40 +- .../form_elements/fields/text/forms.py | 3 +- .../form_elements/fields/textarea/base.py | 44 +++ .../fields/textarea/fobi_form_elements.py | 37 +- .../plugins/form_elements/fields/time/base.py | 72 ++++ .../fields/time/fobi_form_elements.py | 64 +--- .../plugins/form_elements/fields/url/base.py | 58 +++ .../fields/url/fobi_form_elements.py | 51 +-- .../security/captcha/fobi_form_elements.py | 2 + .../form_elements/security/honeypot/base.py | 48 +++ .../security/honeypot/fobi_form_elements.py | 43 +-- .../security/recaptcha/fobi_form_elements.py | 2 + .../plugins/form_elements/test/dummy/base.py | 46 +++ .../test/dummy/fobi_form_elements.py | 39 +- src/fobi/helpers.py | 1 + src/fobi/models.py | 4 +- src/fobi/tests/data.py | 347 ++++++++++++++---- src/fobi/tests/helpers.py | 74 ++-- .../tests/test_browser_build_dynamic_forms.py | 72 ++-- src/fobi/tests/test_core.py | 13 +- src/fobi/tests/test_dynamic_forms.py | 9 +- .../tests/test_form_importers_mailchimp.py | 263 +++---------- src/fobi/tests/test_sortable_dict.py | 2 +- src/fobi/validators.py | 6 +- src/fobi/views.py | 17 +- 131 files changed, 3592 insertions(+), 2885 deletions(-) create mode 100755 scripts/pycodestyle.sh create mode 100755 scripts/pycodestyle_example.sh create mode 100644 src/fobi/contrib/plugins/form_elements/content/content_image/base.py create mode 100644 src/fobi/contrib/plugins/form_elements/content/content_text/base.py create mode 100644 src/fobi/contrib/plugins/form_elements/content/content_video/base.py create mode 100644 src/fobi/contrib/plugins/form_elements/fields/boolean/base.py create mode 100644 src/fobi/contrib/plugins/form_elements/fields/checkbox_select_multiple/base.py create mode 100644 src/fobi/contrib/plugins/form_elements/fields/date/base.py create mode 100644 src/fobi/contrib/plugins/form_elements/fields/date_drop_down/base.py create mode 100644 src/fobi/contrib/plugins/form_elements/fields/datetime/base.py create mode 100644 src/fobi/contrib/plugins/form_elements/fields/decimal/base.py create mode 100644 src/fobi/contrib/plugins/form_elements/fields/email/base.py create mode 100644 src/fobi/contrib/plugins/form_elements/fields/file/base.py create mode 100644 src/fobi/contrib/plugins/form_elements/fields/float/base.py create mode 100644 src/fobi/contrib/plugins/form_elements/fields/hidden/base.py create mode 100644 src/fobi/contrib/plugins/form_elements/fields/input/base.py create mode 100644 src/fobi/contrib/plugins/form_elements/fields/integer/base.py create mode 100644 src/fobi/contrib/plugins/form_elements/fields/ip_address/base.py create mode 100644 src/fobi/contrib/plugins/form_elements/fields/null_boolean/base.py create mode 100644 src/fobi/contrib/plugins/form_elements/fields/password/base.py create mode 100644 src/fobi/contrib/plugins/form_elements/fields/radio/base.py create mode 100644 src/fobi/contrib/plugins/form_elements/fields/range_select/base.py create mode 100644 src/fobi/contrib/plugins/form_elements/fields/regex/base.py create mode 100644 src/fobi/contrib/plugins/form_elements/fields/select/base.py create mode 100644 src/fobi/contrib/plugins/form_elements/fields/select_model_object/base.py create mode 100644 src/fobi/contrib/plugins/form_elements/fields/select_mptt_model_object/base.py create mode 100644 src/fobi/contrib/plugins/form_elements/fields/select_multiple/base.py create mode 100644 src/fobi/contrib/plugins/form_elements/fields/select_multiple_model_objects/base.py create mode 100644 src/fobi/contrib/plugins/form_elements/fields/select_multiple_mptt_model_objects/base.py create mode 100644 src/fobi/contrib/plugins/form_elements/fields/select_multiple_with_max/base.py create mode 100644 src/fobi/contrib/plugins/form_elements/fields/slider/base.py create mode 100644 src/fobi/contrib/plugins/form_elements/fields/slug/base.py create mode 100644 src/fobi/contrib/plugins/form_elements/fields/text/base.py create mode 100644 src/fobi/contrib/plugins/form_elements/fields/textarea/base.py create mode 100644 src/fobi/contrib/plugins/form_elements/fields/time/base.py create mode 100644 src/fobi/contrib/plugins/form_elements/fields/url/base.py create mode 100644 src/fobi/contrib/plugins/form_elements/security/honeypot/base.py create mode 100644 src/fobi/contrib/plugins/form_elements/test/dummy/base.py diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 3d35479b..e5b875c4 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -15,6 +15,33 @@ are used for versioning (schema follows below): 0.3.4 to 0.4). - All backwards incompatible changes are mentioned in this document. +0.10 +---- +2016-11-16 + +Note, that this release contains minor backwards incompatible changes, that may +break your code. Two additional arguments have been added to the +`submit_plugin_form_data` method of the form element plugins. If you have +written custom form element plugins - update your code. + +Note, that this release contain minor backwards incompatible changes, that +may break your existing code (your data is left intact). If you have written +custom form element plugins you should update your code! + +- Added `form_entry_elements` and `kwargs` to the `submit_plugin_form_data` + method of the form element plugins. Make sure to update your custom + plugins if you have written any. +- Added tests for mailchimp integration plugin. +- Moving all plugins to base submodules of the correspondent sub + packages. +- Add missing whitespace toe the `help_text` of the `title` field of + `FormEntry` and `FormWizardEntry` models. +- Disable GoogleAnalytics while testing (guess what - this change speeds up + selenium tests twice). +- Docs updated. +- Helper scripts updated. +- Multiple pep8 fixes. + 0.9.17 ------ 2016-11-13 diff --git a/README.rst b/README.rst index 03ba6e19..77fe5550 100644 --- a/README.rst +++ b/README.rst @@ -102,7 +102,7 @@ Roadmap ======= Some of the upcoming/in-development features/improvements are: -- Integration with `django-rest-framework` (in version 0.10). +- Integration with `django-rest-framework` (in version 0.11). See the `TODOS `_ for the full list of planned-, pending- in-development- or to-be-implemented @@ -429,12 +429,16 @@ following arguments: - `request` (django.http.HttpRequest): The Django HTTP request. - `form` (django.forms.Form): Form object (a valid one, which contains the ``cleaned_data`` attribute). +- `form_element_entries` (fobi.models.FormElementEntry): Form element entries + for the `form_entry` given. +- **kwargs: Additional arguments. Example (taken from fobi.contrib.plugins.form_elements.fields.file): .. code-block:: python - def submit_plugin_form_data(self, form_entry, request, form): + def submit_plugin_form_data(self, form_entry, request, form, + form_element_entries=None, **kwargs): """Submit plugin form data.""" # Get the file path file_path = form.cleaned_data.get(self.data.name, None) diff --git a/ROADMAP.rst b/ROADMAP.rst index bc9bf6e7..131679c7 100644 --- a/ROADMAP.rst +++ b/ROADMAP.rst @@ -1,6 +1,6 @@ Roadmap of upcoming releases ============================ -0.10 +0.11 ---- yyyy-mm-ddd (upcoming). diff --git a/TODOS.rst b/TODOS.rst index 12ea98a3..6b38a5b6 100644 --- a/TODOS.rst +++ b/TODOS.rst @@ -45,6 +45,8 @@ Regarding the form wizards - Add selenium tests for form wizards. - Make `foundation5` and `django-admin-theme` themes to reflect the latest GUI changes (form wizards). +- Make sure captcha plugins are usable with form wizards (at the moment they + are being invalidated on the last step). Roadmap ------- diff --git a/docs/index.rst b/docs/index.rst index f7a15489..f8c82521 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -102,7 +102,7 @@ Roadmap ======= Some of the upcoming/in-development features/improvements are: -- Integration with `django-rest-framework` (in version 0.10). +- Integration with `django-rest-framework` (in version 0.11). See the `TODOS `_ for the full list of planned-, pending- in-development- or to-be-implemented @@ -429,12 +429,16 @@ following arguments: - `request` (django.http.HttpRequest): The Django HTTP request. - `form` (django.forms.Form): Form object (a valid one, which contains the ``cleaned_data`` attribute). +- `form_element_entries` (fobi.models.FormElementEntry): Form element entries + for the `form_entry` given. +- **kwargs: Additional arguments. Example (taken from fobi.contrib.plugins.form_elements.fields.file): .. code-block:: python - def submit_plugin_form_data(self, form_entry, request, form): + def submit_plugin_form_data(self, form_entry, request, form, + form_element_entries=None, **kwargs): """Submit plugin form data.""" # Get the file path file_path = form.cleaned_data.get(self.data.name, None) diff --git a/examples/simple/admin_tools_dashboard/__init__.py b/examples/simple/admin_tools_dashboard/__init__.py index d34f6eb5..2acccc1e 100644 --- a/examples/simple/admin_tools_dashboard/__init__.py +++ b/examples/simple/admin_tools_dashboard/__init__.py @@ -1,5 +1,5 @@ """ -This file was generated with the customdashboard management command, it +This file was generated with the custom dashboard management command, it contains the two classes for the main dashboard and app index dashboard. You can customize these classes as you want. @@ -7,83 +7,110 @@ To activate your index dashboard add the following to your settings.py:: ADMIN_TOOLS_INDEX_DASHBOARD = 'admin_tools_dashboard.CustomIndexDashboard' And to activate the app index dashboard:: - ADMIN_TOOLS_APP_INDEX_DASHBOARD = 'admin_tools_dashboard.CustomAppIndexDashboard' + ADMIN_TOOLS_APP_INDEX_DASHBOARD = \ + 'admin_tools_dashboard.CustomAppIndexDashboard' """ - from django.conf import settings -from django.utils.translation import ugettext, ugettext_lazy as _ +from django.utils.translation import ugettext_lazy as _ from admin_tools.dashboard import modules, Dashboard, AppIndexDashboard -from admin_tools.utils import get_admin_site_name +# from admin_tools.utils import get_admin_site_name from . import conf + class CustomIndexDashboard(Dashboard): - """ - Custom index dashboard. - """ + """Custom index dashboard.""" + columns = 3 def init_with_context(self, context): - ## Foo - #self.children.append(modules.ModelList(_('Foo'), - # models = conf.foo_apps, - # collapsible = False, - # deletable = False - #)) + # Foo + # self.children.append( + # modules.ModelList( + # _('Foo'), + # models=conf.foo_apps, + # collapsible=False, + # deletable=False + # ) + # ) # Fobi - self.children.append(modules.Group( - title = _('Fobi'), - display = 'stacked', - children = [ - modules.ModelList(_('Plugins'), models=conf.fobi_plugins, collapsible=False, deletable=False), - modules.ModelList(_('Forms'), models=conf.fobi_forms, collapsible=False, deletable=False), - modules.ModelList(_('Data'), models=conf.fobi_data, collapsible=False, deletable=False), - ] - )) + self.children.append( + modules.Group( + title=_('Fobi'), + display='stacked', + children=[ + modules.ModelList( + _('Plugins'), + models=conf.fobi_plugins, + collapsible=False, + deletable=False + ), + modules.ModelList( + _('Forms'), + models=conf.fobi_forms, + collapsible=False, + deletable=False + ), + modules.ModelList( + _('Data'), + models=conf.fobi_data, + collapsible=False, + deletable=False + ), + ] + ) + ) if 'feincms' in settings.INSTALLED_APPS: # FeinCMS pages - self.children.append(modules.AppList( - _('FeinCMS Pages'), - models = conf.feincms_pages, - collapsible = False, - deletable = False - )) + self.children.append( + modules.AppList( + _('FeinCMS Pages'), + models=conf.feincms_pages, + collapsible=False, + deletable=False + ) + ) if 'cms' in settings.INSTALLED_APPS: # DjangoCMS pages - self.children.append(modules.AppList( - _('DjangoCMS Pages'), - models = conf.djangocms_pages, - collapsible = False, - deletable = False - )) + self.children.append( + modules.AppList( + _('DjangoCMS Pages'), + models=conf.djangocms_pages, + collapsible=False, + deletable=False + ) + ) # Append an app list module for "Administration" - self.children.append(modules.AppList( - _('Administration'), - models = conf.django_contrib_apps, - collapsible = False, - deletable = False - )) + self.children.append( + modules.AppList( + _('Administration'), + models=conf.django_contrib_apps, + collapsible=False, + deletable=False + ) + ) # Append an app list module for "Administration" - self.children.append(modules.AppList( - _('Other apps'), - models = conf.other_apps, - collapsible = False, - deletable = False - )) + self.children.append( + modules.AppList( + _('Other apps'), + models=conf.other_apps, + collapsible=False, + deletable=False + ) + ) # Append a recent actions module self.children.append(modules.RecentActions(_('Recent Actions'), 10)) + class CustomAppIndexDashboard(AppIndexDashboard): - """ - Custom app index dashboard for netcommunities. - """ + """Custom app index dashboard.""" # We disable title because its redundant with the model list module title = '' @@ -91,14 +118,14 @@ class CustomAppIndexDashboard(AppIndexDashboard): def __init__(self, *args, **kwargs): AppIndexDashboard.__init__(self, *args, **kwargs) - self.children.append(modules.RecentActions( + self.children.append( + modules.RecentActions( _('Recent Actions'), include_list=self.get_app_content_types(), limit=10 - )) + ) + ) def init_with_context(self, context): - """ - Use this method if you need to access the request context. - """ + """Use this method if you need to access the request context.""" return super(CustomAppIndexDashboard, self).init_with_context(context) diff --git a/examples/simple/admin_tools_dashboard/conf.py b/examples/simple/admin_tools_dashboard/conf.py index 780111a7..193e9d83 100644 --- a/examples/simple/admin_tools_dashboard/conf.py +++ b/examples/simple/admin_tools_dashboard/conf.py @@ -2,19 +2,23 @@ # ************ Foo ************** # ******************************* foo_apps = [ - 'foo.models.*', 'bar.models.*', + 'foo.models.*', + 'bar.models.*', ] # ******************************* # ************ Fobi ************* # ******************************* fobi_plugins = [ - 'fobi.models.FormElement', 'fobi.models.FormHandler' + 'fobi.models.FormElement', + 'fobi.models.FormHandler' ] fobi_forms = [ - 'fobi.models.FormWizardEntry', 'fobi.models.FormEntry', - 'fobi.models.FormElementEntry', 'fobi.models.FormFieldsetEntry', + 'fobi.models.FormWizardEntry', + 'fobi.models.FormEntry', + 'fobi.models.FormElementEntry', + 'fobi.models.FormFieldsetEntry', 'fobi.models.FormHandlerEntry', ] @@ -33,5 +37,7 @@ djangocms_pages = [ # ******************************* # ************ Django *********** # ******************************* -django_contrib_apps = ['django.contrib.*',] +django_contrib_apps = [ + 'django.contrib.*', +] other_apps = foo_apps diff --git a/examples/simple/admin_tools_dashboard/menu.py b/examples/simple/admin_tools_dashboard/menu.py index 3a7e268c..157e8153 100644 --- a/examples/simple/admin_tools_dashboard/menu.py +++ b/examples/simple/admin_tools_dashboard/menu.py @@ -27,39 +27,50 @@ class CustomMenu(Menu): ] # Foo - self.children.append(items.ModelList(_('Foo'), - models=conf.foo_apps - )) + self.children.append( + items.ModelList( + _('Foo'), + models=conf.foo_apps + ) + ) # Fobi - self.children.append(items.MenuItem( - _('Fobi'), - children=[ - items.ModelList(_('Plugins'), models=conf.fobi_plugins), - items.ModelList(_('Forms'), models=conf.fobi_forms), - items.ModelList(_('Data'), models=conf.fobi_data), - ] - )) + self.children.append( + items.MenuItem( + _('Fobi'), + children=[ + items.ModelList(_('Plugins'), models=conf.fobi_plugins), + items.ModelList(_('Forms'), models=conf.fobi_forms), + items.ModelList(_('Data'), models=conf.fobi_data), + ] + ) + ) if 'feincms' in settings.INSTALLED_APPS: # FeinCMS pages integration - self.children.append(items.AppList( - _('FeinCMS Pages'), - models=conf.feincms_pages - )) + self.children.append( + items.AppList( + _('FeinCMS Pages'), + models=conf.feincms_pages + ) + ) if 'cms' in settings.INSTALLED_APPS: # DjangoCMS pages integration - self.children.append(items.AppList( - _('DjangoCMS Pages'), - models=conf.djangocms_pages - )) + self.children.append( + items.AppList( + _('DjangoCMS Pages'), + models=conf.djangocms_pages + ) + ) # append an app list module for "Administration" - self.children.append(items.AppList( - _('Administration'), - models=['django.contrib.*',] - )) + self.children.append( + items.AppList( + _('Administration'), + models=['django.contrib.*'] + ) + ) def init_with_context(self, context): """Use this method if you need to access the request context.""" diff --git a/examples/simple/bar/models.py b/examples/simple/bar/models.py index c509b8db..a96a4317 100644 --- a/examples/simple/bar/models.py +++ b/examples/simple/bar/models.py @@ -19,7 +19,7 @@ class Genre(MPTTModel): """MPTT meta.""" # level_attr = 'mptt_level' - order_insertion_by=['name'] + order_insertion_by = ['name'] def __str__(self): return self.name diff --git a/examples/simple/context_processors.py b/examples/simple/context_processors.py index 0e0620ba..25aad7c5 100644 --- a/examples/simple/context_processors.py +++ b/examples/simple/context_processors.py @@ -1,6 +1,13 @@ -__all__ = ('disable_admin_tools',) +from django.conf import settings + +__all__ = ('disable_admin_tools', 'testing',) def disable_admin_tools(request): """Disable admin tools.""" return {'ADMIN_TOOLS_DISABLED': True} + + +def testing(request): + """Put `testing` into context.""" + return {'testing': settings.TESTING} diff --git a/examples/simple/customauth/__init__.py b/examples/simple/customauth/__init__.py index 512b7328..1800d4bf 100644 --- a/examples/simple/customauth/__init__.py +++ b/examples/simple/customauth/__init__.py @@ -1 +1 @@ -from customauth.models import MyUser \ No newline at end of file +from .models import MyUser diff --git a/examples/simple/customauth/admin.py b/examples/simple/customauth/admin.py index 7f7f74e3..56aea2a9 100644 --- a/examples/simple/customauth/admin.py +++ b/examples/simple/customauth/admin.py @@ -93,11 +93,9 @@ class MyUserAdmin(UserAdmin): # add_fieldsets is not a standard ModelAdmin attribute. UserAdmin # overrides get_fieldsets to use this attribute when creating a user. add_fieldsets = ( - (None, { - 'classes': ('wide',), - 'fields': ('username', 'email', 'first_name', 'last_name', - 'date_of_birth', 'password1', 'password2')} - ) + (None, {'classes': ('wide',), + 'fields': ('username', 'email', 'first_name', 'last_name', + 'date_of_birth', 'password1', 'password2')}), ) search_fields = ('email',) ordering = ('email',) diff --git a/examples/simple/foo/fobi_form_callbacks.py b/examples/simple/foo/fobi_form_callbacks.py index 1e09b81e..3f3eb10a 100644 --- a/examples/simple/foo/fobi_form_callbacks.py +++ b/examples/simple/foo/fobi_form_callbacks.py @@ -13,7 +13,7 @@ from fobi.constants import ( logger = logging.getLogger('fobi') -__all__= ( +__all__ = ( 'SaveAsFooItem', 'DummyInvalidCallback', ) diff --git a/examples/simple/override_radio_plugin/fobi_form_elements.py b/examples/simple/override_radio_plugin/fobi_form_elements.py index 347221fb..9d21a1e1 100644 --- a/examples/simple/override_radio_plugin/fobi_form_elements.py +++ b/examples/simple/override_radio_plugin/fobi_form_elements.py @@ -38,7 +38,8 @@ class RadioInputPlugin(FormFieldPlugin): return [(self.data.name, ChoiceField, field_kwargs)] - def submit_plugin_form_data(self, form_entry, request, form): + def submit_plugin_form_data(self, form_entry, request, form, + form_element_entries=None, **kwargs): """Submit plugin form data/process. :param fobi.models.FormEntry form_entry: Instance of diff --git a/examples/simple/override_select_model_object_plugin/fobi_form_elements.py b/examples/simple/override_select_model_object_plugin/fobi_form_elements.py index 2353f2d3..0123ec17 100644 --- a/examples/simple/override_select_model_object_plugin/fobi_form_elements.py +++ b/examples/simple/override_select_model_object_plugin/fobi_form_elements.py @@ -40,7 +40,8 @@ class SelectModelObjectInputPlugin(FormFieldPlugin): return [(self.data.name, ModelChoiceField, field_kwargs)] - def submit_plugin_form_data(self, form_entry, request, form): + def submit_plugin_form_data(self, form_entry, request, form, + form_element_entries=None, **kwargs): """Submit plugin form data/process. :param fobi.models.FormEntry form_entry: Instance of diff --git a/examples/simple/override_simple_theme/fobi_themes.py b/examples/simple/override_simple_theme/fobi_themes.py index 752f425a..67c9b143 100644 --- a/examples/simple/override_simple_theme/fobi_themes.py +++ b/examples/simple/override_simple_theme/fobi_themes.py @@ -8,7 +8,7 @@ __all__ = ('MySimpleTheme',) class MySimpleTheme(SimpleTheme): """Overriding the "simple" theme.""" - html_classes = ['my-simple-theme',] + html_classes = ['my-simple-theme'] base_view_template = 'override_simple_theme/base_view.html' form_ajax = 'override_simple_theme/snippets/form_ajax.html' form_snippet_template_name = \ diff --git a/examples/simple/settings/base.py b/examples/simple/settings/base.py index 58415c6a..5b46b8a0 100644 --- a/examples/simple/settings/base.py +++ b/examples/simple/settings/base.py @@ -4,8 +4,18 @@ from nine.versions import ( DJANGO_GTE_1_7, DJANGO_GTE_1_8, DJANGO_LTE_1_7, DJANGO_GTE_1_9, DJANGO_GTE_1_10 ) -PROJECT_DIR = lambda base : os.path.abspath(os.path.join(os.path.dirname(__file__), base).replace('\\','/')) -gettext = lambda s: s + + +def project_dir(base): + return os.path.abspath( + os.path.join(os.path.dirname(__file__), base).replace('\\', '/') + ) + +PROJECT_DIR = project_dir + + +def gettext(s): + return s # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(__file__)) @@ -22,13 +32,18 @@ MANAGERS = ADMINS DATABASES = { 'default': { - 'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'. - 'NAME': PROJECT_DIR('../../db/example.db'), # Or path to database file if using sqlite3. + # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'. + 'ENGINE': 'django.db.backends.sqlite3', + # Or path to database file if using sqlite3. + 'NAME': PROJECT_DIR('../../db/example.db'), # The following settings are not used with sqlite3: 'USER': '', 'PASSWORD': '', - 'HOST': '', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP. - 'PORT': '', # Set to empty string for default. + # Empty for localhost through domain sockets or '127.0.0.1' for + # localhost through TCP. + 'HOST': '', + # Set to empty string for default. + 'PORT': '', } } @@ -47,7 +62,7 @@ TIME_ZONE = 'America/Chicago' LANGUAGE_CODE = 'en' LANGUAGES = ( - ('en', gettext("English")), # Main language! + ('en', gettext("English")), # Main language! ('hy', gettext("Armenian")), ('nl', gettext("Dutch")), ('ru', gettext("Russian")), @@ -67,7 +82,8 @@ USE_L10N = True # If you set this to False, Django will not use timezone-aware datetimes. USE_TZ = True -# Absolute filesystem path to the directory that will hold user-uploaded files. +# Absolute filesystem path to the directory that will hold user-uploaded +# files. # Example: "/var/www/example.com/media/" MEDIA_ROOT = PROJECT_DIR(os.path.join('..', '..', 'media')) @@ -115,7 +131,7 @@ if DJANGO_GTE_1_10: { 'BACKEND': 'django.template.backends.django.DjangoTemplates', # 'APP_DIRS': True, - 'DIRS': [PROJECT_DIR(os.path.join('..', 'templates')),], + 'DIRS': [PROJECT_DIR(os.path.join('..', 'templates'))], 'OPTIONS': { 'context_processors': [ "django.template.context_processors.debug", @@ -128,6 +144,7 @@ if DJANGO_GTE_1_10: "django.contrib.messages.context_processors.messages", "fobi.context_processors.theme", # Important! "fobi.context_processors.dynamic_values", # Optional + "context_processors.testing", # Testing ], 'loaders': [ 'django.template.loaders.filesystem.Loader', @@ -144,7 +161,7 @@ elif DJANGO_GTE_1_8: { 'BACKEND': 'django.template.backends.django.DjangoTemplates', # 'APP_DIRS': True, - 'DIRS': [PROJECT_DIR(os.path.join('..', 'templates')),], + 'DIRS': [PROJECT_DIR(os.path.join('..', 'templates'))], 'OPTIONS': { 'context_processors': [ "django.contrib.auth.context_processors.auth", @@ -155,8 +172,9 @@ elif DJANGO_GTE_1_8: "django.template.context_processors.tz", "django.contrib.messages.context_processors.messages", "django.template.context_processors.request", - "fobi.context_processors.theme", # Important! - "fobi.context_processors.dynamic_values", # Optional + "fobi.context_processors.theme", # Important! + "fobi.context_processors.dynamic_values", # Optional + "context_processors.testing", # Testing ], 'loaders': [ 'django.template.loaders.filesystem.Loader', @@ -171,7 +189,8 @@ elif DJANGO_GTE_1_8: else: TEMPLATE_DEBUG = DEBUG_TEMPLATE - # List of callables that know how to import templates from various sources. + # List of callables that know how to import templates from various + # sources. TEMPLATE_LOADERS = [ 'django.template.loaders.filesystem.Loader', 'django.template.loaders.app_directories.Loader', @@ -190,12 +209,14 @@ else: "django.core.context_processors.tz", "django.contrib.messages.context_processors.messages", "django.core.context_processors.request", - "fobi.context_processors.theme", # Important! - "fobi.context_processors.dynamic_values", # Optional + "fobi.context_processors.theme", # Important! + "fobi.context_processors.dynamic_values", # Optional + "context_processors.testing", # Testing ) TEMPLATE_DIRS = ( - # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". + # Put strings here, like "/home/html/django_templates" or + # "C:/www/django/templates". # Always use forward slashes, even on Windows. # Don't forget to use absolute paths, not relative paths. PROJECT_DIR(os.path.join('..', 'templates')), @@ -203,7 +224,6 @@ else: MIDDLEWARE_CLASSES = [ 'django.contrib.sessions.middleware.SessionMiddleware', - # 'localeurl.middleware.LocaleURLMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', @@ -212,9 +232,6 @@ MIDDLEWARE_CLASSES = [ # 'django.middleware.clickjacking.XFrameOptionsMiddleware', ] -# if DJANGO_GTE_1_8: -# MIDDLEWARE_CLASSES.remove('localeurl.middleware.LocaleURLMiddleware') - ROOT_URLCONF = 'urls' # Python dotted path to the WSGI application used by Django's runserver. @@ -245,7 +262,6 @@ INSTALLED_APPS = [ # 'tinymce', # TinyMCE 'easy_thumbnails', # Thumbnailer 'registration', # Auth views and registration app - # 'localeurl', # Locale URL # *********************************************************************** # *********************************************************************** @@ -339,17 +355,23 @@ INSTALLED_APPS = [ # *********************************************************************** 'fobi.contrib.themes.bootstrap3', # Bootstrap 3 theme # DateTime widget - 'fobi.contrib.themes.bootstrap3.widgets.form_elements.datetime_bootstrap3_widget', - 'fobi.contrib.themes.bootstrap3.widgets.form_elements.date_bootstrap3_widget', + 'fobi.contrib.themes.bootstrap3.widgets.form_elements.' + 'datetime_bootstrap3_widget', + + 'fobi.contrib.themes.bootstrap3.widgets.form_elements.' + 'date_bootstrap3_widget', # SliderPercentage widget - 'fobi.contrib.themes.bootstrap3.widgets.form_elements.slider_bootstrap3_widget', + 'fobi.contrib.themes.bootstrap3.widgets.form_elements.' + 'slider_bootstrap3_widget', # *********************************************************************** # ************************ Foundation 5 theme *************************** # *********************************************************************** 'fobi.contrib.themes.foundation5', # Foundation 5 theme - 'fobi.contrib.themes.foundation5.widgets.form_handlers.db_store_foundation5_widget', + + 'fobi.contrib.themes.foundation5.widgets.form_handlers.' + 'db_store_foundation5_widget', # *********************************************************************** # **************************** Simple theme ***************************** @@ -374,9 +396,6 @@ INSTALLED_APPS = [ if DJANGO_LTE_1_7: INSTALLED_APPS.append('south') -# if DJANGO_GTE_1_8: -# INSTALLED_APPS.remove('localeurl') - # LOGIN_URL = '/accounts/login/' # LOGIN_REDIRECT_URL = '/fobi/' # Important for passing the selenium tests @@ -384,23 +403,12 @@ if DJANGO_LTE_1_7: LOGIN_URL = '/en/accounts/login/' LOGIN_REDIRECT_URL = '/en/fobi/' # Important for passing the selenium tests -#LOGIN_URL = '/accounts/login/' -#LOGIN_ERROR_URL = '/accounts/login/' -#LOGOUT_URL = '/accounts/logout/' +# LOGIN_URL = '/accounts/login/' +# LOGIN_ERROR_URL = '/accounts/login/' +# LOGOUT_URL = '/accounts/logout/' -# if not DJANGO_GTE_1_8: -# # Tell localeurl to use sessions for language store. -# LOCALEURL_USE_SESSION = True -# -# # localeurl locale independent paths (language code won't be appended) -# LOCALE_INDEPENDENT_PATHS = ( -# r'^/sitemap.*\.xml$', # Global regex for all XML sitemaps -# r'^/admin/', -# #r'^/dashboard/', -# ) - -PACKAGE_NAME_FILEBROWSER = "filebrowser_safe" # Just for tests -PACKAGE_NAME_GRAPPELLI = "grappelli_safe" # Just for tests +PACKAGE_NAME_FILEBROWSER = "filebrowser_safe" # Just for tests +PACKAGE_NAME_GRAPPELLI = "grappelli_safe" # Just for tests MIGRATION_MODULES = { 'fobi': 'migrations', @@ -431,8 +439,10 @@ FOBI_CUSTOM_THEME_DATA = { ], 'success_page_template_choices': [ ( - 'fobi/bootstrap3_extras/embed_form_entry_submitted_ajax.html', - gettext("Custom bootstrap3 embed form entry submitted template") + 'fobi/bootstrap3_extras/embed_form_entry_' + 'submitted_ajax.html', + gettext("Custom bootstrap3 embed form entry submitted " + "template") ), ], }, @@ -445,8 +455,10 @@ FOBI_CUSTOM_THEME_DATA = { ], 'success_page_template_choices': [ ( - 'fobi/bootstrap3_extras/embed_form_entry_submitted_ajax.html', - gettext("Custom bootstrap3 embed form entry submitted template") + 'fobi/bootstrap3_extras/embed_form_entry_submitted_' + 'ajax.html', + gettext("Custom bootstrap3 embed form entry submitted " + "template") ), ], }, @@ -467,8 +479,10 @@ FOBI_CUSTOM_THEME_DATA = { ], 'success_page_template_choices': [ ( - 'fobi/foundation5_extras/embed_form_entry_submitted_ajax.html', - gettext("Custom foundation5 embed form entry submitted template") + 'fobi/foundation5_extras/embed_form_entry_submitted_' + 'ajax.html', + gettext("Custom foundation5 embed form entry submitted " + "template") ), ], }, @@ -481,8 +495,10 @@ FOBI_CUSTOM_THEME_DATA = { ], 'success_page_template_choices': [ ( - 'fobi/foundation5_extras/embed_form_entry_submitted_ajax.html', - gettext("Custom foundation5 embed form entry submitted template") + 'fobi/foundation5_extras/embed_form_entry_submitted_' + 'ajax.html', + gettext("Custom foundation5 embed form entry submitted " + "template") ), ], }, @@ -505,7 +521,8 @@ FOBI_THEME_FOOTER_TEXT = gettext('© django-fobi example site 2014-2015') # django-admin-tools custom dashboard ADMIN_TOOLS_INDEX_DASHBOARD = 'admin_tools_dashboard.CustomIndexDashboard' -ADMIN_TOOLS_APP_INDEX_DASHBOARD = 'admin_tools_dashboard.CustomAppIndexDashboard' +ADMIN_TOOLS_APP_INDEX_DASHBOARD = \ + 'admin_tools_dashboard.CustomAppIndexDashboard' ADMIN_TOOLS_MENU = 'admin_tools_dashboard.menu.CustomMenu' SOUTH_MIGRATION_MODULES = { @@ -537,7 +554,8 @@ LOGGING = { }, 'formatters': { 'verbose': { - 'format': '\n%(levelname)s %(asctime)s [%(pathname)s:%(lineno)s] %(message)s' + 'format': '\n%(levelname)s %(asctime)s [%(pathname)s:%(lineno)s] ' + '%(message)s' }, 'simple': { 'format': '\n%(levelname)s %(message)s' @@ -555,32 +573,32 @@ LOGGING = { 'formatter': 'verbose' }, 'all_log': { - 'level':'DEBUG', - 'class':'logging.handlers.RotatingFileHandler', + 'level': 'DEBUG', + 'class': 'logging.handlers.RotatingFileHandler', 'filename': PROJECT_DIR("../../logs/all.log"), 'maxBytes': 1048576, 'backupCount': 99, 'formatter': 'verbose', }, 'django_log': { - 'level':'DEBUG', - 'class':'logging.handlers.RotatingFileHandler', + 'level': 'DEBUG', + 'class': 'logging.handlers.RotatingFileHandler', 'filename': PROJECT_DIR("../../logs/django.log"), 'maxBytes': 1048576, 'backupCount': 99, 'formatter': 'verbose', }, 'django_request_log': { - 'level':'DEBUG', - 'class':'logging.handlers.RotatingFileHandler', + 'level': 'DEBUG', + 'class': 'logging.handlers.RotatingFileHandler', 'filename': PROJECT_DIR("../../logs/django_request.log"), 'maxBytes': 1048576, 'backupCount': 99, 'formatter': 'verbose', }, 'fobi_log': { - 'level':'DEBUG', - 'class':'logging.handlers.RotatingFileHandler', + 'level': 'DEBUG', + 'class': 'logging.handlers.RotatingFileHandler', 'filename': PROJECT_DIR("../../logs/fobi.log"), 'maxBytes': 1048576, 'backupCount': 99, @@ -635,6 +653,9 @@ if DJANGO_GTE_1_7 or DJANGO_GTE_1_8: # For Selenium tests FIREFOX_BIN_PATH = '' +# Testing mode +TESTING = False + # Do not put any settings below this line try: from .local_settings import * @@ -665,7 +686,7 @@ if DEBUG: try: # Make sure the django-template-debug is installed. You can then # in templates use it as follows: - # + # # {% load debug_tags %} # {% set_trace %} import template_debug diff --git a/examples/simple/settings/bootstrap3_theme_captcha.py b/examples/simple/settings/bootstrap3_theme_captcha.py index 2794b9c4..2d8ed0dd 100644 --- a/examples/simple/settings/bootstrap3_theme_captcha.py +++ b/examples/simple/settings/bootstrap3_theme_captcha.py @@ -4,8 +4,10 @@ INSTALLED_APPS = list(INSTALLED_APPS) try: INSTALLED_APPS.append('captcha') - INSTALLED_APPS.append('fobi.contrib.plugins.form_elements.security.captcha') + INSTALLED_APPS.append( + 'fobi.contrib.plugins.form_elements.security.captcha' + ) except Exception as e: pass -#FOBI_DEFAULT_THEME = 'simple' +# FOBI_DEFAULT_THEME = 'simple' diff --git a/examples/simple/settings/bootstrap3_theme_django_1_10.py b/examples/simple/settings/bootstrap3_theme_django_1_10.py index e1b4f27c..4a5d0b53 100644 --- a/examples/simple/settings/bootstrap3_theme_django_1_10.py +++ b/examples/simple/settings/bootstrap3_theme_django_1_10.py @@ -5,8 +5,7 @@ INSTALLED_APPS = list(INSTALLED_APPS) try: INSTALLED_APPS.remove('south') if 'south' in INSTALLED_APPS else None INSTALLED_APPS.remove('tinymce') if 'tinymce' in INSTALLED_APPS else None - INSTALLED_APPS.remove('localeurl') if 'localeurl' in INSTALLED_APPS else None -except Exception as e: +except Exception as err: pass try: @@ -16,5 +15,5 @@ try: if 'admin_tools.menu' in INSTALLED_APPS else None INSTALLED_APPS.remove('admin_tools.dashboard') \ if 'admin_tools.dashboard' in INSTALLED_APPS else None -except Exception as e: +except Exception as err: pass diff --git a/examples/simple/settings/bootstrap3_theme_django_1_7_captcha.py b/examples/simple/settings/bootstrap3_theme_django_1_7_captcha.py index 73b1f4c3..0a479970 100755 --- a/examples/simple/settings/bootstrap3_theme_django_1_7_captcha.py +++ b/examples/simple/settings/bootstrap3_theme_django_1_7_captcha.py @@ -6,6 +6,8 @@ try: INSTALLED_APPS.remove('south') if 'south' in INSTALLED_APPS else None INSTALLED_APPS.remove('tinymce') if 'tinymce' in INSTALLED_APPS else None INSTALLED_APPS.append('captcha') - INSTALLED_APPS.append('fobi.contrib.plugins.form_elements.security.captcha') + INSTALLED_APPS.append( + 'fobi.contrib.plugins.form_elements.security.captcha' + ) except Exception as e: pass diff --git a/examples/simple/settings/bootstrap3_theme_django_1_7_djangocms.py b/examples/simple/settings/bootstrap3_theme_django_1_7_djangocms.py index 458af220..b955c070 100644 --- a/examples/simple/settings/bootstrap3_theme_django_1_7_djangocms.py +++ b/examples/simple/settings/bootstrap3_theme_django_1_7_djangocms.py @@ -2,40 +2,40 @@ from .base import * INSTALLED_APPS = list(INSTALLED_APPS) INSTALLED_APPS += [ - 'cms', # DjangoCMS + 'cms', # DjangoCMS 'mptt', 'menus', 'sekizai', - #'djangocms_admin_style', + # 'djangocms_admin_style', # Some plugins 'djangocms_picture', 'djangocms_snippet', - 'fobi.contrib.apps.djangocms_integration', # Fobi DjangoCMS app + 'fobi.contrib.apps.djangocms_integration', # Fobi DjangoCMS app - #'djangocms_page', # Example + # 'djangocms_page', # Example ] try: INSTALLED_APPS.remove('south') if 'south' in INSTALLED_APPS else None - #INSTALLED_APPS.remove('admin_tools') \ + # INSTALLED_APPS.remove('admin_tools') \ # if 'admin_tools' in INSTALLED_APPS else None - #INSTALLED_APPS.remove('admin_tools.menu') \ + # INSTALLED_APPS.remove('admin_tools.menu') \ # if 'admin_tools.menu' in INSTALLED_APPS else None INSTALLED_APPS.remove('admin_tools.dashboard') \ if 'admin_tools.dashboard' in INSTALLED_APPS else None -except Exception as e: +except Exception as err: pass MIDDLEWARE_CLASSES = list(MIDDLEWARE_CLASSES) MIDDLEWARE_CLASSES += [ - #'django.middleware.cache.UpdateCacheMiddleware', + # 'django.middleware.cache.UpdateCacheMiddleware', 'cms.middleware.page.CurrentPageMiddleware', 'cms.middleware.user.CurrentUserMiddleware', 'cms.middleware.toolbar.ToolbarMiddleware', 'cms.middleware.language.LanguageCookieMiddleware', - #'django.middleware.cache.FetchFromCacheMiddleware', + # 'django.middleware.cache.FetchFromCacheMiddleware', ] TEMPLATE_CONTEXT_PROCESSORS = list(TEMPLATE_CONTEXT_PROCESSORS) @@ -46,8 +46,8 @@ TEMPLATE_CONTEXT_PROCESSORS += [ ] FOBI_DEFAULT_THEME = 'bootstrap3' -#FOBI_DEFAULT_THEME = 'foundation5' -#FOBI_DEFAULT_THEME = 'simple' +# FOBI_DEFAULT_THEME = 'foundation5' +# FOBI_DEFAULT_THEME = 'simple' CMS_TEMPLATES = ( ('cms_page/{0}/page_with_sidebar.html'.format(FOBI_DEFAULT_THEME), @@ -63,6 +63,6 @@ MIGRATION_MODULES = { LANGUAGE_CODE = 'en' -#FEINCMS_RICHTEXT_INIT_CONTEXT = { +# FEINCMS_RICHTEXT_INIT_CONTEXT = { # 'TINYMCE_JS_URL': STATIC_URL + 'tiny_mce/tiny_mce.js', -#} +# } diff --git a/examples/simple/settings/bootstrap3_theme_django_1_7_feincms.py b/examples/simple/settings/bootstrap3_theme_django_1_7_feincms.py index 212b37d2..13371298 100644 --- a/examples/simple/settings/bootstrap3_theme_django_1_7_feincms.py +++ b/examples/simple/settings/bootstrap3_theme_django_1_7_feincms.py @@ -4,17 +4,19 @@ INSTALLED_APPS = list(INSTALLED_APPS) try: INSTALLED_APPS.remove('south') if 'south' in INSTALLED_APPS else None - #INSTALLED_APPS.remove('tinymce') if 'tinymce' in INSTALLED_APPS else None - INSTALLED_APPS.remove('admin_tools.dashboard') if 'admin_tools.dashboard' in INSTALLED_APPS else None + # INSTALLED_APPS.remove('tinymce') if 'tinymce' in INSTALLED_APPS else None + INSTALLED_APPS.remove('admin_tools.dashboard') \ + if 'admin_tools.dashboard' in INSTALLED_APPS \ + else None INSTALLED_APPS += [ - 'feincms', # FeinCMS + 'feincms', # FeinCMS - 'fobi.contrib.apps.feincms_integration', # Fobi FeinCMS app + 'fobi.contrib.apps.feincms_integration', # Fobi FeinCMS app - 'page', # Example + 'page', # Example ] -except Exception as e: +except Exception as err: pass diff --git a/examples/simple/settings/bootstrap3_theme_django_1_8.py b/examples/simple/settings/bootstrap3_theme_django_1_8.py index 780c3631..4a5d0b53 100644 --- a/examples/simple/settings/bootstrap3_theme_django_1_8.py +++ b/examples/simple/settings/bootstrap3_theme_django_1_8.py @@ -5,7 +5,7 @@ INSTALLED_APPS = list(INSTALLED_APPS) try: INSTALLED_APPS.remove('south') if 'south' in INSTALLED_APPS else None INSTALLED_APPS.remove('tinymce') if 'tinymce' in INSTALLED_APPS else None -except Exception as e: +except Exception as err: pass try: @@ -15,5 +15,5 @@ try: if 'admin_tools.menu' in INSTALLED_APPS else None INSTALLED_APPS.remove('admin_tools.dashboard') \ if 'admin_tools.dashboard' in INSTALLED_APPS else None -except Exception as e: +except Exception as err: pass diff --git a/examples/simple/settings/bootstrap3_theme_djangocms.py b/examples/simple/settings/bootstrap3_theme_djangocms.py index 2cb234c8..b2025f47 100644 --- a/examples/simple/settings/bootstrap3_theme_djangocms.py +++ b/examples/simple/settings/bootstrap3_theme_djangocms.py @@ -2,39 +2,39 @@ from .base import * INSTALLED_APPS = list(INSTALLED_APPS) INSTALLED_APPS += [ - 'cms', # DjangoCMS + 'cms', # DjangoCMS 'mptt', 'menus', 'sekizai', - #'djangocms_admin_style', + # 'djangocms_admin_style', # Some plugins 'djangocms_picture', 'djangocms_snippet', - 'fobi.contrib.apps.djangocms_integration', # Fobi DjangoCMS app + 'fobi.contrib.apps.djangocms_integration', # Fobi DjangoCMS app - #'djangocms_page', # Example + # 'djangocms_page', # Example ] try: - #INSTALLED_APPS.remove('admin_tools') \ + # INSTALLED_APPS.remove('admin_tools') \ # if 'admin_tools' in INSTALLED_APPS else None - #INSTALLED_APPS.remove('admin_tools.menu') \ + # INSTALLED_APPS.remove('admin_tools.menu') \ # if 'admin_tools.menu' in INSTALLED_APPS else None INSTALLED_APPS.remove('admin_tools.dashboard') \ if 'admin_tools.dashboard' in INSTALLED_APPS else None -except Exception as e: +except Exception as err: pass MIDDLEWARE_CLASSES = list(MIDDLEWARE_CLASSES) MIDDLEWARE_CLASSES += [ - #'django.middleware.cache.UpdateCacheMiddleware', + # 'django.middleware.cache.UpdateCacheMiddleware', 'cms.middleware.page.CurrentPageMiddleware', 'cms.middleware.user.CurrentUserMiddleware', 'cms.middleware.toolbar.ToolbarMiddleware', 'cms.middleware.language.LanguageCookieMiddleware', - #'django.middleware.cache.FetchFromCacheMiddleware', + # 'django.middleware.cache.FetchFromCacheMiddleware', ] TEMPLATE_CONTEXT_PROCESSORS = list(TEMPLATE_CONTEXT_PROCESSORS) @@ -45,8 +45,8 @@ TEMPLATE_CONTEXT_PROCESSORS += [ ] FOBI_DEFAULT_THEME = 'bootstrap3' -#FOBI_DEFAULT_THEME = 'foundation5' -#FOBI_DEFAULT_THEME = 'simple' +# FOBI_DEFAULT_THEME = 'foundation5' +# FOBI_DEFAULT_THEME = 'simple' CMS_TEMPLATES = ( ('cms_page/{0}/page_with_sidebar.html'.format(FOBI_DEFAULT_THEME), @@ -62,6 +62,6 @@ MIGRATION_MODULES = { LANGUAGE_CODE = 'en' -#FEINCMS_RICHTEXT_INIT_CONTEXT = { +# FEINCMS_RICHTEXT_INIT_CONTEXT = { # 'TINYMCE_JS_URL': STATIC_URL + 'tiny_mce/tiny_mce.js', -#} +# } diff --git a/examples/simple/settings/bootstrap3_theme_djangocms_2.py b/examples/simple/settings/bootstrap3_theme_djangocms_2.py index 8652f926..bb8a476b 100644 --- a/examples/simple/settings/bootstrap3_theme_djangocms_2.py +++ b/examples/simple/settings/bootstrap3_theme_djangocms_2.py @@ -2,63 +2,68 @@ from .base import * DATABASES = { 'default': { - 'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'. - 'NAME': PROJECT_DIR('../db/example_djangocms_2.db'), # Or path to database file if using sqlite3. + # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'. + 'ENGINE': 'django.db.backends.sqlite3', + # Or path to database file if using sqlite3. + 'NAME': PROJECT_DIR('../db/example_djangocms_2.db'), # The following settings are not used with sqlite3: 'USER': '', 'PASSWORD': '', - 'HOST': '', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP. - 'PORT': '', # Set to empty string for default. + # Empty for localhost through domain sockets or '127.0.0.1' for + # localhost through TCP. + 'HOST': '', + # Set to empty string for default. + 'PORT': '', } } INSTALLED_APPS = list(INSTALLED_APPS) INSTALLED_APPS += [ - 'cms', # DjangoCMS + 'cms', # DjangoCMS 'mptt', 'menus', 'sekizai', - #'djangocms_admin_style', + # 'djangocms_admin_style', # Some plugins 'cms.plugins.picture', 'cms.plugins.snippet', - 'fobi.contrib.apps.djangocms_integration', # Fobi DjangoCMS app + 'fobi.contrib.apps.djangocms_integration', # Fobi DjangoCMS app - #'djangocms_page', # Example + # 'djangocms_page', # Example ] try: - #INSTALLED_APPS.remove('admin_tools') \ + # INSTALLED_APPS.remove('admin_tools') \ # if 'admin_tools' in INSTALLED_APPS else None - #INSTALLED_APPS.remove('admin_tools.menu') \ + # INSTALLED_APPS.remove('admin_tools.menu') \ # if 'admin_tools.menu' in INSTALLED_APPS else None INSTALLED_APPS.remove('admin_tools.dashboard') \ if 'admin_tools.dashboard' in INSTALLED_APPS else None -except Exception as e: +except Exception as err: pass MIDDLEWARE_CLASSES = list(MIDDLEWARE_CLASSES) MIDDLEWARE_CLASSES += [ - #'django.middleware.cache.UpdateCacheMiddleware', + # 'django.middleware.cache.UpdateCacheMiddleware', 'cms.middleware.page.CurrentPageMiddleware', 'cms.middleware.user.CurrentUserMiddleware', 'cms.middleware.toolbar.ToolbarMiddleware', 'cms.middleware.language.LanguageCookieMiddleware', - #'django.middleware.cache.FetchFromCacheMiddleware', + # 'django.middleware.cache.FetchFromCacheMiddleware', ] TEMPLATE_CONTEXT_PROCESSORS = list(TEMPLATE_CONTEXT_PROCESSORS) TEMPLATE_CONTEXT_PROCESSORS += [ 'cms.context_processors.media', 'sekizai.context_processors.sekizai', - #'cms.context_processors.cms_settings', + # 'cms.context_processors.cms_settings', ] FOBI_DEFAULT_THEME = 'bootstrap3' -#FOBI_DEFAULT_THEME = 'foundation5' -#FOBI_DEFAULT_THEME = 'simple' +# FOBI_DEFAULT_THEME = 'foundation5' +# FOBI_DEFAULT_THEME = 'simple' CMS_TEMPLATES = ( ('cms_page/{0}/page_with_sidebar.html'.format(FOBI_DEFAULT_THEME), @@ -74,6 +79,6 @@ MIGRATION_MODULES = { LANGUAGE_CODE = 'en' -#FEINCMS_RICHTEXT_INIT_CONTEXT = { +# FEINCMS_RICHTEXT_INIT_CONTEXT = { # 'TINYMCE_JS_URL': STATIC_URL + 'tiny_mce/tiny_mce.js', -#} +# } diff --git a/examples/simple/settings/bootstrap3_theme_feincms.py b/examples/simple/settings/bootstrap3_theme_feincms.py index 254797b2..92d2beae 100644 --- a/examples/simple/settings/bootstrap3_theme_feincms.py +++ b/examples/simple/settings/bootstrap3_theme_feincms.py @@ -2,18 +2,23 @@ from .base import * INSTALLED_APPS = list(INSTALLED_APPS) INSTALLED_APPS += [ - 'feincms', # FeinCMS + 'feincms', # FeinCMS - 'fobi.contrib.apps.feincms_integration', # Fobi FeinCMS app + 'fobi.contrib.apps.feincms_integration', # Fobi FeinCMS app - 'page', # Example + 'page', # Example ] try: - #INSTALLED_APPS.remove('admin_tools') if 'admin_tools' in INSTALLED_APPS else None - #INSTALLED_APPS.remove('admin_tools.menu') if 'admin_tools.menu' in INSTALLED_APPS else None - INSTALLED_APPS.remove('admin_tools.dashboard') if 'admin_tools.dashboard' in INSTALLED_APPS else None -except Exception as e: + # INSTALLED_APPS.remove('admin_tools') \ + # if 'admin_tools' in INSTALLED_APPS \ + # else None + # INSTALLED_APPS.remove('admin_tools.menu') \ + # if 'admin_tools.menu' in INSTALLED_APPS \ + # else None + INSTALLED_APPS.remove('admin_tools.dashboard') \ + if 'admin_tools.dashboard' in INSTALLED_APPS else None +except Exception as err: pass FEINCMS_RICHTEXT_INIT_CONTEXT = { diff --git a/examples/simple/settings/bootstrap3_theme_mptt.py b/examples/simple/settings/bootstrap3_theme_mptt.py index fe705e9d..0d091236 100644 --- a/examples/simple/settings/bootstrap3_theme_mptt.py +++ b/examples/simple/settings/bootstrap3_theme_mptt.py @@ -5,7 +5,13 @@ INSTALLED_APPS = list(INSTALLED_APPS) try: INSTALLED_APPS.append('mptt') INSTALLED_APPS.append('bar') - INSTALLED_APPS.append('fobi.contrib.plugins.form_elements.fields.select_mptt_model_object') - INSTALLED_APPS.append('fobi.contrib.plugins.form_elements.fields.select_multiple_mptt_model_objects') -except Exception as e: + INSTALLED_APPS.append( + 'fobi.contrib.plugins.form_elements.fields.' + 'select_mptt_model_object' + ) + INSTALLED_APPS.append( + 'fobi.contrib.plugins.form_elements.fields.' + 'select_multiple_mptt_model_objects' + ) +except Exception as err: pass diff --git a/examples/simple/settings/bootstrap3_theme_python_3_django_1_8.py b/examples/simple/settings/bootstrap3_theme_python_3_django_1_8.py index ba1a5d2d..f9dd3f48 100644 --- a/examples/simple/settings/bootstrap3_theme_python_3_django_1_8.py +++ b/examples/simple/settings/bootstrap3_theme_python_3_django_1_8.py @@ -5,7 +5,7 @@ INSTALLED_APPS = list(INSTALLED_APPS) try: INSTALLED_APPS.remove('south') if 'south' in INSTALLED_APPS else None INSTALLED_APPS.remove('tinymce') if 'tinymce' in INSTALLED_APPS else None -except Exception as e: +except Exception as err: pass try: @@ -15,11 +15,12 @@ try: if 'admin_tools.menu' in INSTALLED_APPS else None INSTALLED_APPS.remove('admin_tools.dashboard') \ if 'admin_tools.dashboard' in INSTALLED_APPS else None -except Exception as e: +except Exception as err: pass -#INSTALLED_APPS.remove('fobi.contrib.plugins.form_handlers.http_repost') -#INSTALLED_APPS.remove('fobi.contrib.plugins.form_handlers.mail') -#INSTALLED_APPS.remove('fobi.contrib.themes.foundation5') -#INSTALLED_APPS.remove('fobi.contrib.themes.foundation5.widgets.form_handlers.db_store_foundation5_widget') -#INSTALLED_APPS.remove('fobi.contrib.themes.simple') +# INSTALLED_APPS.remove('fobi.contrib.plugins.form_handlers.http_repost') +# INSTALLED_APPS.remove('fobi.contrib.plugins.form_handlers.mail') +# INSTALLED_APPS.remove('fobi.contrib.themes.foundation5') +# INSTALLED_APPS.remove('fobi.contrib.themes.foundation5.widgets.' +# 'form_handlers.db_store_foundation5_widget') +# INSTALLED_APPS.remove('fobi.contrib.themes.simple') diff --git a/examples/simple/settings/bootstrap3_theme_recaptcha.py b/examples/simple/settings/bootstrap3_theme_recaptcha.py index 218f2ec3..57d0de82 100644 --- a/examples/simple/settings/bootstrap3_theme_recaptcha.py +++ b/examples/simple/settings/bootstrap3_theme_recaptcha.py @@ -4,11 +4,13 @@ INSTALLED_APPS = list(INSTALLED_APPS) try: INSTALLED_APPS.append('captcha') - INSTALLED_APPS.append('fobi.contrib.plugins.form_elements.security.recaptcha') -except Exception as e: + INSTALLED_APPS.append( + 'fobi.contrib.plugins.form_elements.security.recaptcha' + ) +except Exception as err: pass -#RECAPTCHA_PUBLIC_KEY = '' -#RECAPTCHA_PRIVATE_KEY = '' +# RECAPTCHA_PUBLIC_KEY = '' +# RECAPTCHA_PRIVATE_KEY = '' RECAPTCHA_USE_SSL = True -#FOBI_DEFAULT_THEME = 'simple' +# FOBI_DEFAULT_THEME = 'simple' diff --git a/examples/simple/settings/djangocms_admin_style_theme_djangocms.py b/examples/simple/settings/djangocms_admin_style_theme_djangocms.py index 7198d115..43a1202e 100644 --- a/examples/simple/settings/djangocms_admin_style_theme_djangocms.py +++ b/examples/simple/settings/djangocms_admin_style_theme_djangocms.py @@ -1,20 +1,22 @@ +from nine.versions import DJANGO_GTE_1_8 + from .base import * INSTALLED_APPS = list(INSTALLED_APPS) INSTALLED_APPS.remove('django.contrib.admin') INSTALLED_APPS += [ - 'cms', # DjangoCMS + 'cms', # DjangoCMS 'mptt', 'menus', 'sekizai', - #'djangocms_admin_style', + # 'djangocms_admin_style', # Some plugins 'djangocms_picture', 'djangocms_snippet', 'treebeard', - 'fobi.contrib.apps.djangocms_integration', # Fobi DjangoCMS app + 'fobi.contrib.apps.djangocms_integration', # Fobi DjangoCMS app # Django-CMS admin style 'djangocms_admin_style', @@ -34,15 +36,14 @@ except Exception as e: MIDDLEWARE_CLASSES = list(MIDDLEWARE_CLASSES) MIDDLEWARE_CLASSES += [ - #'django.middleware.cache.UpdateCacheMiddleware', + # 'django.middleware.cache.UpdateCacheMiddleware', 'cms.middleware.page.CurrentPageMiddleware', 'cms.middleware.user.CurrentUserMiddleware', 'cms.middleware.toolbar.ToolbarMiddleware', 'cms.middleware.language.LanguageCookieMiddleware', - #'django.middleware.cache.FetchFromCacheMiddleware', + # 'django.middleware.cache.FetchFromCacheMiddleware', ] -from nine.versions import DJANGO_GTE_1_8 if DJANGO_GTE_1_8: TEMPLATES[0]['OPTIONS']['context_processors'] += [ 'cms.context_processors.cms_settings', @@ -57,9 +58,9 @@ else: 'cms.context_processors.cms_settings', ] -#FOBI_DEFAULT_THEME = 'bootstrap3' -#FOBI_DEFAULT_THEME = 'foundation5' -#FOBI_DEFAULT_THEME = 'simple' +# FOBI_DEFAULT_THEME = 'bootstrap3' +# FOBI_DEFAULT_THEME = 'foundation5' +# FOBI_DEFAULT_THEME = 'simple' FOBI_DEFAULT_THEME = 'djangocms_admin_style_theme' CMS_TEMPLATES = ( diff --git a/examples/simple/settings/foundation5.py b/examples/simple/settings/foundation5.py index 822e422d..0399c27f 100644 --- a/examples/simple/settings/foundation5.py +++ b/examples/simple/settings/foundation5.py @@ -5,8 +5,10 @@ FOBI_DEFAULT_THEME = 'foundation5' INSTALLED_APPS = list(INSTALLED_APPS) INSTALLED_APPS.append( - 'fobi.contrib.themes.foundation5.widgets.form_elements.date_foundation5_widget' + 'fobi.contrib.themes.foundation5.widgets.form_elements.' + 'date_foundation5_widget' ) INSTALLED_APPS.append( - 'fobi.contrib.themes.foundation5.widgets.form_elements.datetime_foundation5_widget' + 'fobi.contrib.themes.foundation5.widgets.form_elements.' + 'datetime_foundation5_widget' ) diff --git a/examples/simple/settings/foundation5_theme_django_1_10.py b/examples/simple/settings/foundation5_theme_django_1_10.py index 26ebe70e..1fd04236 100644 --- a/examples/simple/settings/foundation5_theme_django_1_10.py +++ b/examples/simple/settings/foundation5_theme_django_1_10.py @@ -5,8 +5,7 @@ INSTALLED_APPS = list(INSTALLED_APPS) try: INSTALLED_APPS.remove('south') if 'south' in INSTALLED_APPS else None INSTALLED_APPS.remove('tinymce') if 'tinymce' in INSTALLED_APPS else None - INSTALLED_APPS.remove('localeurl') if 'localeurl' in INSTALLED_APPS else None -except Exception as e: +except Exception as err: pass try: @@ -16,7 +15,7 @@ try: if 'admin_tools.menu' in INSTALLED_APPS else None INSTALLED_APPS.remove('admin_tools.dashboard') \ if 'admin_tools.dashboard' in INSTALLED_APPS else None -except Exception as e: +except Exception as err: pass FOBI_DEFAULT_THEME = 'foundation5' @@ -24,9 +23,10 @@ FOBI_DEFAULT_THEME = 'foundation5' INSTALLED_APPS = list(INSTALLED_APPS) INSTALLED_APPS.append( - 'fobi.contrib.themes.foundation5.widgets.form_elements.date_foundation5_widget' + 'fobi.contrib.themes.foundation5.widgets.form_elements.' + 'date_foundation5_widget' ) INSTALLED_APPS.append( - 'fobi.contrib.themes.foundation5.widgets.form_elements.datetime_foundation5_widget' + 'fobi.contrib.themes.foundation5.widgets.form_elements.' + 'datetime_foundation5_widget' ) - diff --git a/examples/simple/settings/foundation5_theme_django_1_8.py b/examples/simple/settings/foundation5_theme_django_1_8.py index 1e0fb6d1..1fd04236 100644 --- a/examples/simple/settings/foundation5_theme_django_1_8.py +++ b/examples/simple/settings/foundation5_theme_django_1_8.py @@ -5,7 +5,7 @@ INSTALLED_APPS = list(INSTALLED_APPS) try: INSTALLED_APPS.remove('south') if 'south' in INSTALLED_APPS else None INSTALLED_APPS.remove('tinymce') if 'tinymce' in INSTALLED_APPS else None -except Exception as e: +except Exception as err: pass try: @@ -15,7 +15,7 @@ try: if 'admin_tools.menu' in INSTALLED_APPS else None INSTALLED_APPS.remove('admin_tools.dashboard') \ if 'admin_tools.dashboard' in INSTALLED_APPS else None -except Exception as e: +except Exception as err: pass FOBI_DEFAULT_THEME = 'foundation5' @@ -23,9 +23,10 @@ FOBI_DEFAULT_THEME = 'foundation5' INSTALLED_APPS = list(INSTALLED_APPS) INSTALLED_APPS.append( - 'fobi.contrib.themes.foundation5.widgets.form_elements.date_foundation5_widget' + 'fobi.contrib.themes.foundation5.widgets.form_elements.' + 'date_foundation5_widget' ) INSTALLED_APPS.append( - 'fobi.contrib.themes.foundation5.widgets.form_elements.datetime_foundation5_widget' + 'fobi.contrib.themes.foundation5.widgets.form_elements.' + 'datetime_foundation5_widget' ) - diff --git a/examples/simple/settings/foundation5_theme_django_1_9.py b/examples/simple/settings/foundation5_theme_django_1_9.py index 1f4d4a0e..1fd04236 100644 --- a/examples/simple/settings/foundation5_theme_django_1_9.py +++ b/examples/simple/settings/foundation5_theme_django_1_9.py @@ -5,9 +5,7 @@ INSTALLED_APPS = list(INSTALLED_APPS) try: INSTALLED_APPS.remove('south') if 'south' in INSTALLED_APPS else None INSTALLED_APPS.remove('tinymce') if 'tinymce' in INSTALLED_APPS else None - INSTALLED_APPS.remove( - 'localeurl') if 'localeurl' in INSTALLED_APPS else None -except Exception as e: +except Exception as err: pass try: @@ -17,7 +15,7 @@ try: if 'admin_tools.menu' in INSTALLED_APPS else None INSTALLED_APPS.remove('admin_tools.dashboard') \ if 'admin_tools.dashboard' in INSTALLED_APPS else None -except Exception as e: +except Exception as err: pass FOBI_DEFAULT_THEME = 'foundation5' @@ -25,9 +23,10 @@ FOBI_DEFAULT_THEME = 'foundation5' INSTALLED_APPS = list(INSTALLED_APPS) INSTALLED_APPS.append( - 'fobi.contrib.themes.foundation5.widgets.form_elements.date_foundation5_widget' + 'fobi.contrib.themes.foundation5.widgets.form_elements.' + 'date_foundation5_widget' ) INSTALLED_APPS.append( - 'fobi.contrib.themes.foundation5.widgets.form_elements.datetime_foundation5_widget' + 'fobi.contrib.themes.foundation5.widgets.form_elements.' + 'datetime_foundation5_widget' ) - diff --git a/examples/simple/settings/foundation5_theme_feincms.py b/examples/simple/settings/foundation5_theme_feincms.py index b6d7ff33..479d2857 100644 --- a/examples/simple/settings/foundation5_theme_feincms.py +++ b/examples/simple/settings/foundation5_theme_feincms.py @@ -2,11 +2,11 @@ from .base import * INSTALLED_APPS = list(INSTALLED_APPS) INSTALLED_APPS += [ - 'feincms', # FeinCMS + 'feincms', # FeinCMS - 'fobi.contrib.apps.feincms_integration', # Fobi FeinCMS app + 'fobi.contrib.apps.feincms_integration', # Fobi FeinCMS app - 'page', # Example + 'page', # Example ] FEINCMS_RICHTEXT_INIT_CONTEXT = { diff --git a/examples/simple/settings/settings_test.py b/examples/simple/settings/settings_test.py index aeb277b3..1aaa3285 100644 --- a/examples/simple/settings/settings_test.py +++ b/examples/simple/settings/settings_test.py @@ -19,7 +19,8 @@ LOGGING = { }, 'formatters': { 'verbose': { - 'format': '\n%(levelname)s %(asctime)s [%(pathname)s:%(lineno)s] %(message)s' + 'format': '\n%(levelname)s %(asctime)s [%(pathname)s:%(lineno)s] ' + '%(message)s' }, 'simple': { 'format': '\n%(levelname)s %(message)s' @@ -37,32 +38,32 @@ LOGGING = { 'formatter': 'verbose' }, 'all_log': { - 'level':'ERROR', - 'class':'logging.handlers.RotatingFileHandler', + 'level': 'ERROR', + 'class': 'logging.handlers.RotatingFileHandler', 'filename': PROJECT_DIR("../../logs/all.log"), 'maxBytes': 1048576, 'backupCount': 99, 'formatter': 'verbose', }, 'django_log': { - 'level':'ERROR', - 'class':'logging.handlers.RotatingFileHandler', + 'level': 'ERROR', + 'class': 'logging.handlers.RotatingFileHandler', 'filename': PROJECT_DIR("../../logs/django.log"), 'maxBytes': 1048576, 'backupCount': 99, 'formatter': 'verbose', }, 'django_request_log': { - 'level':'ERROR', - 'class':'logging.handlers.RotatingFileHandler', + 'level': 'ERROR', + 'class': 'logging.handlers.RotatingFileHandler', 'filename': PROJECT_DIR("../../logs/django_request.log"), 'maxBytes': 1048576, 'backupCount': 99, 'formatter': 'verbose', }, 'fobi_log': { - 'level':'ERROR', - 'class':'logging.handlers.RotatingFileHandler', + 'level': 'ERROR', + 'class': 'logging.handlers.RotatingFileHandler', 'filename': PROJECT_DIR("../../logs/fobi.log"), 'maxBytes': 1048576, 'backupCount': 99, diff --git a/examples/simple/settings/simple.py b/examples/simple/settings/simple.py index 5c26bab1..e9e0828b 100644 --- a/examples/simple/settings/simple.py +++ b/examples/simple/settings/simple.py @@ -3,6 +3,6 @@ from .base import * FOBI_DEFAULT_THEME = 'simple' INSTALLED_APPS = list(INSTALLED_APPS) -#INSTALLED_APPS.remove('admin_tools') -#INSTALLED_APPS.remove('admin_tools.menu') -#INSTALLED_APPS.remove('admin_tools.dashboard') +# INSTALLED_APPS.remove('admin_tools') +# INSTALLED_APPS.remove('admin_tools.menu') +# INSTALLED_APPS.remove('admin_tools.dashboard') diff --git a/examples/simple/settings/test.py b/examples/simple/settings/test.py index 3070d432..c03406ce 100644 --- a/examples/simple/settings/test.py +++ b/examples/simple/settings/test.py @@ -1,18 +1,18 @@ # Use in `tox`. +from nine import versions from .base import * +TESTING = True + INSTALLED_APPS = list(INSTALLED_APPS) -from nine import versions - - if versions.DJANGO_1_5: try: INSTALLED_APPS.append( 'south') if 'south' not in INSTALLED_APPS else None - except Exception as e: + except Exception as err: pass elif versions.DJANGO_1_6: @@ -20,7 +20,7 @@ elif versions.DJANGO_1_6: try: INSTALLED_APPS.append( 'south') if 'south' not in INSTALLED_APPS else None - except Exception as e: + except Exception as err: pass @@ -30,7 +30,7 @@ elif versions.DJANGO_1_7: INSTALLED_APPS.remove('south') if 'south' in INSTALLED_APPS else None INSTALLED_APPS.remove( 'tinymce') if 'tinymce' in INSTALLED_APPS else None - except Exception as e: + except Exception as err: pass elif versions.DJANGO_1_8: @@ -39,7 +39,7 @@ elif versions.DJANGO_1_8: INSTALLED_APPS.remove('south') if 'south' in INSTALLED_APPS else None INSTALLED_APPS.remove( 'tinymce') if 'tinymce' in INSTALLED_APPS else None - except Exception as e: + except Exception as err: pass try: @@ -49,7 +49,7 @@ elif versions.DJANGO_1_8: if 'admin_tools.menu' in INSTALLED_APPS else None INSTALLED_APPS.remove('admin_tools.dashboard') \ if 'admin_tools.dashboard' in INSTALLED_APPS else None - except Exception as e: + except Exception as err: pass elif versions.DJANGO_1_9: @@ -58,9 +58,7 @@ elif versions.DJANGO_1_9: INSTALLED_APPS.remove('south') if 'south' in INSTALLED_APPS else None INSTALLED_APPS.remove( 'tinymce') if 'tinymce' in INSTALLED_APPS else None - INSTALLED_APPS.remove( - 'localeurl') if 'localeurl' in INSTALLED_APPS else None - except Exception as e: + except Exception as err: pass try: @@ -70,7 +68,7 @@ elif versions.DJANGO_1_9: if 'admin_tools.menu' in INSTALLED_APPS else None INSTALLED_APPS.remove('admin_tools.dashboard') \ if 'admin_tools.dashboard' in INSTALLED_APPS else None - except Exception as e: + except Exception as err: pass elif versions.DJANGO_1_10: @@ -79,9 +77,7 @@ elif versions.DJANGO_1_10: INSTALLED_APPS.remove('south') if 'south' in INSTALLED_APPS else None INSTALLED_APPS.remove( 'tinymce') if 'tinymce' in INSTALLED_APPS else None - INSTALLED_APPS.remove( - 'localeurl') if 'localeurl' in INSTALLED_APPS else None - except Exception as e: + except Exception as err: pass try: @@ -91,7 +87,7 @@ elif versions.DJANGO_1_10: if 'admin_tools.menu' in INSTALLED_APPS else None INSTALLED_APPS.remove('admin_tools.dashboard') \ if 'admin_tools.dashboard' in INSTALLED_APPS else None - except Exception as e: + except Exception as err: pass LOGGING = {} diff --git a/examples/simple/templates/bootstrap3/base.html b/examples/simple/templates/bootstrap3/base.html index 513ea1aa..2776fd3d 100644 --- a/examples/simple/templates/bootstrap3/base.html +++ b/examples/simple/templates/bootstrap3/base.html @@ -2,5 +2,5 @@ {% block theme-javascripts %} {{ block.super }} - {% include "google_analytics.html" %} -{% endblock theme-javascripts %} \ No newline at end of file + {% if not testing %}{% include "google_analytics.html" %}{% endif %} +{% endblock theme-javascripts %} diff --git a/scripts/pycodestyle.sh b/scripts/pycodestyle.sh new file mode 100755 index 00000000..1290c9a6 --- /dev/null +++ b/scripts/pycodestyle.sh @@ -0,0 +1,2 @@ +reset +pycodestyle src/fobi/ --exclude src/fobi/migrations/,src/fobi/south_migrations/,src/fobi/contrib/plugins/form_handlers/db_store/migrations/ diff --git a/scripts/pycodestyle_example.sh b/scripts/pycodestyle_example.sh new file mode 100755 index 00000000..e0094c32 --- /dev/null +++ b/scripts/pycodestyle_example.sh @@ -0,0 +1,2 @@ +reset +pycodestyle examples/simple/ --exclude examples/simple/page/migrations/,examples/simple/page/south_migrations/,examples/simple/lund/fobi_addons/migrations/,examples/simple/wsgi.py diff --git a/setup.py b/setup.py index ceb289c9..4c9aef20 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ import sys from distutils.version import LooseVersion from setuptools import setup, find_packages -version = '0.9.17' +version = '0.10' # *************************************************************************** # ************************** Django version ********************************* diff --git a/src/fobi/__init__.py b/src/fobi/__init__.py index 9f80bdc3..08f09df0 100644 --- a/src/fobi/__init__.py +++ b/src/fobi/__init__.py @@ -1,6 +1,6 @@ __title__ = 'django-fobi' -__version__ = '0.9.17' -__build__ = 0x000072 +__version__ = '0.10' +__build__ = 0x000073 __author__ = 'Artur Barseghyan ' __copyright__ = '2014-2016 Artur Barseghyan' __license__ = 'GPL 2.0/LGPL 2.1' diff --git a/src/fobi/base.py b/src/fobi/base.py index dcd38858..5c53501d 100644 --- a/src/fobi/base.py +++ b/src/fobi/base.py @@ -1535,9 +1535,8 @@ class FormElementPlugin(BasePlugin): logger.debug(str(err)) return {} - # def _submit_plugin_form_data(self, form_entry, request, form, - # form_element_entries=None, **kwargs): - def _submit_plugin_form_data(self, form_entry, request, form): + def _submit_plugin_form_data(self, form_entry, request, form, + form_element_entries=None, **kwargs): """Submit plugin form data (internal method). Do not override this method. Use ``submit_plugin_form_data``, @@ -1550,14 +1549,15 @@ class FormElementPlugin(BasePlugin): ``fobi.models.FormEntry``. :param django.http.HttpRequest request: :param django.forms.Form form: + :param iterable form_element_entries: """ if DEBUG: return self.submit_plugin_form_data( form_entry=form_entry, request=request, form=form, - # form_element_entries=None, - # **kwargs + form_element_entries=form_element_entries, + **kwargs ) else: try: @@ -1565,15 +1565,14 @@ class FormElementPlugin(BasePlugin): form_entry=form_entry, request=request, form=form, - # form_element_entries=None, - # **kwargs + form_element_entries=form_element_entries, + **kwargs ) except Exception as e: logger.debug(str(e)) - # def submit_plugin_form_data(self, form_entry, request, form, - # form_element_entries=None, **kwargs): - def submit_plugin_form_data(self, form_entry, request, form): + def submit_plugin_form_data(self, form_entry, request, form, + form_element_entries=None, **kwargs): """Submit plugin form data. Called on form submission (when user actually @@ -1583,6 +1582,7 @@ class FormElementPlugin(BasePlugin): ``fobi.models.FormEntry``. :param django.http.HttpRequest request: :param django.forms.Form form: + :param iterable form_element_entries: """ @@ -2420,29 +2420,27 @@ def validate_form_element_plugin_uid(plugin_uid): return validate_plugin_uid(form_element_plugin_registry, plugin_uid) -# def submit_plugin_form_data(form_entry, request, form, -# form_element_entries=None, **kwargs): -def submit_plugin_form_data(form_entry, request, form): +def submit_plugin_form_data(form_entry, request, form, + form_element_entries=None, **kwargs): """Submit plugin form data for all plugins. :param fobi.models.FormEntry form_entry: Instance of ``fobi.models.FormEntry``. :param django.http.HttpRequest request: :param django.forms.Form form: + :param iterable form_element_entries: """ - # if not form_element_entries: - # form_element_entries = form_entry.formelemententry_set.all() - # for form_element_entry in form_element_entries: - - for form_element_entry in form_entry.formelemententry_set.all(): + if not form_element_entries: + form_element_entries = form_entry.formelemententry_set.all() + for form_element_entry in form_element_entries: # Get the plugin. form_element_plugin = form_element_entry.get_plugin(request=request) updated_form = form_element_plugin._submit_plugin_form_data( form_entry=form_entry, request=request, form=form, - # form_element_entries=form_element_entries, - # **kwargs + form_element_entries=form_element_entries, + **kwargs ) if updated_form: form = updated_form diff --git a/src/fobi/contrib/plugins/form_elements/content/content_image/base.py b/src/fobi/contrib/plugins/form_elements/content/content_image/base.py new file mode 100644 index 00000000..73413aee --- /dev/null +++ b/src/fobi/contrib/plugins/form_elements/content/content_image/base.py @@ -0,0 +1,86 @@ +from __future__ import absolute_import + +from uuid import uuid4 + +from django.conf import settings +from django.template.loader import render_to_string +from django.utils.translation import ugettext_lazy as _ + +from nonefield.fields import NoneField + +from fobi.base import FormElementPlugin +from fobi.helpers import delete_file, clone_file + +from . import UID +from .forms import ContentImageForm +from .helpers import get_crop_filter +from .settings import ( + FIT_METHOD_FIT_WIDTH, FIT_METHOD_FIT_HEIGHT, IMAGES_UPLOAD_DIR +) + +__title__ = 'fobi.contrib.plugins.form_elements.content.content_image.base' +__author__ = 'Artur Barseghyan ' +__copyright__ = '2014-2016 Artur Barseghyan' +__license__ = 'GPL 2.0/LGPL 2.1' +__all__ = ('ContentImagePlugin',) + + +class ContentImagePlugin(FormElementPlugin): + """Content image plugin.""" + + uid = UID + name = _("Content image") + group = _("Content") + form = ContentImageForm + + def post_processor(self): + """Post process data. + + Always the same. + """ + self.data.name = "{0}_{1}".format(self.uid, uuid4()) + + def delete_plugin_data(self): + """Delete uploaded file.""" + delete_file(self.data.file) + + def clone_plugin_data(self, entry): + """Clone plugin data. + + Clone plugin data, which means we make a copy of the original image. + + TODO: Perhaps rely more on data of ``form_element_entry``? + """ + cloned_image = clone_file( + IMAGES_UPLOAD_DIR, self.data.file, relative_path=True + ) + return self.get_cloned_plugin_data(update={'file': cloned_image}) + + def get_form_field_instances(self, request=None, form_entry=None, + form_element_entries=None, **kwargs): + """Get form field instances.""" + width, height = self.data.size.split('x') + crop = get_crop_filter(self.data.fit_method) + + if FIT_METHOD_FIT_WIDTH == self.data.fit_method: + thumb_size = (width, 0) + elif FIT_METHOD_FIT_HEIGHT == self.data.fit_method: + thumb_size = (0, height) + else: + thumb_size = (width, height) + + context = { + 'plugin': self, + 'MEDIA_URL': settings.MEDIA_URL, + 'crop': crop, + 'thumb_size': thumb_size + } + rendered_image = render_to_string('content_image/render.html', context) + + field_kwargs = { + 'initial': rendered_image, + 'required': False, + 'label': '', + } + + return [(self.data.name, NoneField, field_kwargs)] diff --git a/src/fobi/contrib/plugins/form_elements/content/content_image/fobi_form_elements.py b/src/fobi/contrib/plugins/form_elements/content/content_image/fobi_form_elements.py index e23c9377..2f5f7358 100644 --- a/src/fobi/contrib/plugins/form_elements/content/content_image/fobi_form_elements.py +++ b/src/fobi/contrib/plugins/form_elements/content/content_image/fobi_form_elements.py @@ -1,20 +1,8 @@ -from uuid import uuid4 +from __future__ import absolute_import -from django.conf import settings -from django.template.loader import render_to_string -from django.utils.translation import ugettext_lazy as _ +from fobi.base import form_element_plugin_registry -from nonefield.fields import NoneField - -from fobi.base import FormElementPlugin, form_element_plugin_registry -from fobi.helpers import delete_file, clone_file - -from . import UID -from .forms import ContentImageForm -from .helpers import get_crop_filter -from .settings import ( - FIT_METHOD_FIT_WIDTH, FIT_METHOD_FIT_HEIGHT, IMAGES_UPLOAD_DIR -) +from .base import ContentImagePlugin __title__ = 'fobi.contrib.plugins.form_elements.content.content_image.' \ 'fobi_form_elements' @@ -24,65 +12,4 @@ __license__ = 'GPL 2.0/LGPL 2.1' __all__ = ('ContentImagePlugin',) -class ContentImagePlugin(FormElementPlugin): - """Content image plugin.""" - - uid = UID - name = _("Content image") - group = _("Content") - form = ContentImageForm - - def post_processor(self): - """Post process data. - - Always the same. - """ - self.data.name = "{0}_{1}".format(self.uid, uuid4()) - - def delete_plugin_data(self): - """Delete uploaded file.""" - delete_file(self.data.file) - - def clone_plugin_data(self, entry): - """Clone plugin data. - - Clone plugin data, which means we make a copy of the original image. - - TODO: Perhaps rely more on data of ``form_element_entry``? - """ - cloned_image = clone_file( - IMAGES_UPLOAD_DIR, self.data.file, relative_path=True - ) - return self.get_cloned_plugin_data(update={'file': cloned_image}) - - def get_form_field_instances(self, request=None, form_entry=None, - form_element_entries=None, **kwargs): - """Get form field instances.""" - width, height = self.data.size.split('x') - crop = get_crop_filter(self.data.fit_method) - - if FIT_METHOD_FIT_WIDTH == self.data.fit_method: - thumb_size = (width, 0) - elif FIT_METHOD_FIT_HEIGHT == self.data.fit_method: - thumb_size = (0, height) - else: - thumb_size = (width, height) - - context = { - 'plugin': self, - 'MEDIA_URL': settings.MEDIA_URL, - 'crop': crop, - 'thumb_size': thumb_size - } - rendered_image = render_to_string('content_image/render.html', context) - - field_kwargs = { - 'initial': rendered_image, - 'required': False, - 'label': '', - } - - return [(self.data.name, NoneField, field_kwargs)] - - form_element_plugin_registry.register(ContentImagePlugin) diff --git a/src/fobi/contrib/plugins/form_elements/content/content_text/base.py b/src/fobi/contrib/plugins/form_elements/content/content_text/base.py new file mode 100644 index 00000000..062b2d18 --- /dev/null +++ b/src/fobi/contrib/plugins/form_elements/content/content_text/base.py @@ -0,0 +1,46 @@ +from __future__ import absolute_import + +from uuid import uuid4 + +from django.utils.encoding import smart_str +from django.utils.translation import ugettext_lazy as _ + +from nonefield.fields import NoneField + +from fobi.base import FormElementPlugin + +from . import UID +from .forms import ContentTextForm + +__title__ = 'fobi.contrib.plugins.form_elements.content.content_text.base' +__author__ = 'Artur Barseghyan ' +__copyright__ = '2014-2016 Artur Barseghyan' +__license__ = 'GPL 2.0/LGPL 2.1' +__all__ = ('ContentTextPlugin',) + + +class ContentTextPlugin(FormElementPlugin): + """Content text plugin.""" + + uid = UID + name = _("Content text") + group = _("Content") + form = ContentTextForm + + def post_processor(self): + """Post process data. + + Always the same. + """ + self.data.name = "{0}_{1}".format(self.uid, uuid4()) + + def get_form_field_instances(self, request=None, form_entry=None, + form_element_entries=None, **kwargs): + """Get form field instances.""" + field_kwargs = { + 'initial': "

{0}

".format(smart_str(self.data.text)), + 'required': False, + 'label': '', + } + + return [(self.data.name, NoneField, field_kwargs)] diff --git a/src/fobi/contrib/plugins/form_elements/content/content_text/fobi_form_elements.py b/src/fobi/contrib/plugins/form_elements/content/content_text/fobi_form_elements.py index ca854754..268bd5b2 100644 --- a/src/fobi/contrib/plugins/form_elements/content/content_text/fobi_form_elements.py +++ b/src/fobi/contrib/plugins/form_elements/content/content_text/fobi_form_elements.py @@ -1,14 +1,8 @@ -from uuid import uuid4 +from __future__ import absolute_import -from django.utils.encoding import smart_str -from django.utils.translation import ugettext_lazy as _ +from fobi.base import form_element_plugin_registry -from nonefield.fields import NoneField - -from fobi.base import FormElementPlugin, form_element_plugin_registry - -from . import UID -from .forms import ContentTextForm +from .base import ContentTextPlugin __title__ = 'fobi.contrib.plugins.form_elements.content.content_text.' \ 'fobi_form_elements' @@ -18,31 +12,4 @@ __license__ = 'GPL 2.0/LGPL 2.1' __all__ = ('ContentTextPlugin',) -class ContentTextPlugin(FormElementPlugin): - """Content text plugin.""" - - uid = UID - name = _("Content text") - group = _("Content") - form = ContentTextForm - - def post_processor(self): - """Post process data. - - Always the same. - """ - self.data.name = "{0}_{1}".format(self.uid, uuid4()) - - def get_form_field_instances(self, request=None, form_entry=None, - form_element_entries=None, **kwargs): - """Get form field instances.""" - field_kwargs = { - 'initial': "

{0}

".format(smart_str(self.data.text)), - 'required': False, - 'label': '', - } - - return [(self.data.name, NoneField, field_kwargs)] - - form_element_plugin_registry.register(ContentTextPlugin) diff --git a/src/fobi/contrib/plugins/form_elements/content/content_video/base.py b/src/fobi/contrib/plugins/form_elements/content/content_video/base.py new file mode 100644 index 00000000..2032e057 --- /dev/null +++ b/src/fobi/contrib/plugins/form_elements/content/content_video/base.py @@ -0,0 +1,51 @@ +from __future__ import absolute_import + +from uuid import uuid4 + +from django.utils.translation import ugettext_lazy as _ + +from vishap import render_video + +from nonefield.fields import NoneField + +from fobi.base import FormElementPlugin + +from . import UID +from .forms import ContentVideoForm + +__title__ = 'fobi.contrib.plugins.form_elements.content.content_video.base' +__author__ = 'Artur Barseghyan ' +__copyright__ = '2014-2016 Artur Barseghyan' +__license__ = 'GPL 2.0/LGPL 2.1' +__all__ = ('ContentVideoPlugin',) + + +class ContentVideoPlugin(FormElementPlugin): + """Content video plugin.""" + + uid = UID + name = _("Content video") + group = _("Content") + form = ContentVideoForm + + def post_processor(self): + """Process plugin data. + + Always the same. + """ + self.data.name = "{0}_{1}".format(self.uid, uuid4()) + + def get_form_field_instances(self, request=None, form_entry=None, + form_element_entries=None, **kwargs): + """Get form field instances.""" + width, height = self.data.size.split('x') + + field_kwargs = { + 'initial': '
{0}
'.format( + render_video(self.data.url, width, height) + ), + 'required': False, + 'label': '', + } + + return [(self.data.name, NoneField, field_kwargs)] diff --git a/src/fobi/contrib/plugins/form_elements/content/content_video/fobi_form_elements.py b/src/fobi/contrib/plugins/form_elements/content/content_video/fobi_form_elements.py index c9465ebc..91da92b8 100644 --- a/src/fobi/contrib/plugins/form_elements/content/content_video/fobi_form_elements.py +++ b/src/fobi/contrib/plugins/form_elements/content/content_video/fobi_form_elements.py @@ -1,15 +1,8 @@ -from uuid import uuid4 +from __future__ import absolute_import -from django.utils.translation import ugettext_lazy as _ +from fobi.base import form_element_plugin_registry -from vishap import render_video - -from nonefield.fields import NoneField - -from fobi.base import FormElementPlugin, form_element_plugin_registry - -from . import UID -from .forms import ContentVideoForm +from .base import ContentVideoPlugin __title__ = 'fobi.contrib.plugins.form_elements.content.content_video.' \ 'fobi_form_elements' @@ -19,35 +12,4 @@ __license__ = 'GPL 2.0/LGPL 2.1' __all__ = ('ContentVideoPlugin',) -class ContentVideoPlugin(FormElementPlugin): - """Content video plugin.""" - - uid = UID - name = _("Content video") - group = _("Content") - form = ContentVideoForm - - def post_processor(self): - """Process plugin data. - - Always the same. - """ - self.data.name = "{0}_{1}".format(self.uid, uuid4()) - - def get_form_field_instances(self, request=None, form_entry=None, - form_element_entries=None, **kwargs): - """Get form field instances.""" - width, height = self.data.size.split('x') - - field_kwargs = { - 'initial': '
{0}
'.format( - render_video(self.data.url, width, height) - ), - 'required': False, - 'label': '', - } - - return [(self.data.name, NoneField, field_kwargs)] - - form_element_plugin_registry.register(ContentVideoPlugin) diff --git a/src/fobi/contrib/plugins/form_elements/fields/boolean/base.py b/src/fobi/contrib/plugins/form_elements/fields/boolean/base.py new file mode 100644 index 00000000..1a5ce71f --- /dev/null +++ b/src/fobi/contrib/plugins/form_elements/fields/boolean/base.py @@ -0,0 +1,34 @@ +from django.forms.fields import BooleanField +from django.utils.translation import ugettext_lazy as _ + +from fobi.base import FormFieldPlugin + +from . import UID +from .forms import BooleanSelectForm + +__title__ = 'fobi.contrib.plugins.form_elements.fields.boolean.base' +__author__ = 'Artur Barseghyan ' +__copyright__ = '2014-2016 Artur Barseghyan' +__license__ = 'GPL 2.0/LGPL 2.1' +__all__ = ('BooleanSelectPlugin',) + + +class BooleanSelectPlugin(FormFieldPlugin): + """Boolean select plugin.""" + + uid = UID + name = _("Boolean") + group = _("Fields") + form = BooleanSelectForm + + def get_form_field_instances(self, request=None, form_entry=None, + form_element_entries=None, **kwargs): + """Get form field instances.""" + field_kwargs = { + 'label': self.data.label, + 'help_text': self.data.help_text, + 'initial': self.data.initial, + 'required': self.data.required, + } + + return [(self.data.name, BooleanField, field_kwargs)] diff --git a/src/fobi/contrib/plugins/form_elements/fields/boolean/fobi_form_elements.py b/src/fobi/contrib/plugins/form_elements/fields/boolean/fobi_form_elements.py index af42d223..a36623f2 100644 --- a/src/fobi/contrib/plugins/form_elements/fields/boolean/fobi_form_elements.py +++ b/src/fobi/contrib/plugins/form_elements/fields/boolean/fobi_form_elements.py @@ -1,10 +1,8 @@ -from django.forms.fields import BooleanField -from django.utils.translation import ugettext_lazy as _ +from __future__ import absolute_import -from fobi.base import FormFieldPlugin, form_element_plugin_registry +from fobi.base import form_element_plugin_registry -from . import UID -from .forms import BooleanSelectForm +from .base import BooleanSelectPlugin __title__ = 'fobi.contrib.plugins.form_elements.fields.boolean.' \ 'fobi_form_elements' @@ -14,25 +12,4 @@ __license__ = 'GPL 2.0/LGPL 2.1' __all__ = ('BooleanSelectPlugin',) -class BooleanSelectPlugin(FormFieldPlugin): - """Boolean select plugin.""" - - uid = UID - name = _("Boolean") - group = _("Fields") - form = BooleanSelectForm - - def get_form_field_instances(self, request=None, form_entry=None, - form_element_entries=None, **kwargs): - """Get form field instances.""" - field_kwargs = { - 'label': self.data.label, - 'help_text': self.data.help_text, - 'initial': self.data.initial, - 'required': self.data.required, - } - - return [(self.data.name, BooleanField, field_kwargs)] - - form_element_plugin_registry.register(BooleanSelectPlugin) diff --git a/src/fobi/contrib/plugins/form_elements/fields/checkbox_select_multiple/base.py b/src/fobi/contrib/plugins/form_elements/fields/checkbox_select_multiple/base.py new file mode 100644 index 00000000..a13cac3a --- /dev/null +++ b/src/fobi/contrib/plugins/form_elements/fields/checkbox_select_multiple/base.py @@ -0,0 +1,91 @@ +from django.forms.fields import MultipleChoiceField +from django.forms.widgets import CheckboxSelectMultiple +from django.utils.translation import ugettext_lazy as _ + +from fobi.base import FormFieldPlugin, get_theme +from fobi.constants import SUBMIT_VALUE_AS_VAL, SUBMIT_VALUE_AS_REPR +from fobi.helpers import get_select_field_choices, safe_text + +from . import UID +from .forms import CheckboxSelectMultipleInputForm +from .settings import SUBMIT_VALUE_AS + +theme = get_theme(request=None, as_instance=True) + +__title__ = 'fobi.contrib.plugins.form_elements.fields.' \ + 'checkbox_select_multiple.fobi_form_elements' +__author__ = 'Artur Barseghyan ' +__copyright__ = '2014-2016 Artur Barseghyan' +__license__ = 'GPL 2.0/LGPL 2.1' +__all__ = ('CheckboxSelectMultipleInputPlugin',) + + +class CheckboxSelectMultipleInputPlugin(FormFieldPlugin): + """Checkbox select multiple field plugin.""" + + uid = UID + name = _("Checkbox select multiple") + group = _("Fields") + form = CheckboxSelectMultipleInputForm + + def get_form_field_instances(self, request=None, form_entry=None, + form_element_entries=None, **kwargs): + """Get form field instances.""" + choices = get_select_field_choices(self.data.choices) + + field_kwargs = { + 'label': self.data.label, + 'help_text': self.data.help_text, + 'initial': self.data.initial, + 'required': self.data.required, + 'choices': choices, + 'widget': CheckboxSelectMultiple( + attrs={'class': theme.form_element_html_class} + ), + } + + return [(self.data.name, MultipleChoiceField, field_kwargs)] + + def submit_plugin_form_data(self, form_entry, request, form, + form_element_entries=None, **kwargs): + """Submit plugin form data/process. + + :param fobi.models.FormEntry form_entry: Instance of + ``fobi.models.FormEntry``. + :param django.http.HttpRequest request: + :param django.forms.Form form: + """ + # In case if we should submit value as is, we don't return anything. + # In other cases, we proceed further. + if SUBMIT_VALUE_AS != SUBMIT_VALUE_AS_VAL: + # Get the object + values = form.cleaned_data.get(self.data.name, None) + + # Get choices + choices = dict(get_select_field_choices(self.data.choices)) + + # Returned value + ret_values = [] + + for value in values: + # Handle the submitted form value + + if value in choices: + label = safe_text(choices.get(value)) + + # Should be returned as repr + if SUBMIT_VALUE_AS == SUBMIT_VALUE_AS_REPR: + value = label + # Should be returned as mix + else: + value = "{0} ({1})".format(label, value) + + ret_values.append(value) + + # Overwrite ``cleaned_data`` of the ``form`` with object + # qualifier. + form.cleaned_data[self.data.name] = ret_values + + # It's critically important to return the ``form`` with updated + # ``cleaned_data`` + return form diff --git a/src/fobi/contrib/plugins/form_elements/fields/checkbox_select_multiple/fobi_form_elements.py b/src/fobi/contrib/plugins/form_elements/fields/checkbox_select_multiple/fobi_form_elements.py index 2834aa69..12ae2c15 100644 --- a/src/fobi/contrib/plugins/form_elements/fields/checkbox_select_multiple/fobi_form_elements.py +++ b/src/fobi/contrib/plugins/form_elements/fields/checkbox_select_multiple/fobi_form_elements.py @@ -1,18 +1,8 @@ -from django.forms.fields import MultipleChoiceField -from django.forms.widgets import CheckboxSelectMultiple -from django.utils.translation import ugettext_lazy as _ +from __future__ import absolute_import -from fobi.base import FormFieldPlugin, form_element_plugin_registry, get_theme -from fobi.constants import ( - SUBMIT_VALUE_AS_VAL, SUBMIT_VALUE_AS_REPR -) -from fobi.helpers import get_select_field_choices, safe_text +from fobi.base import form_element_plugin_registry -from . import UID -from .forms import CheckboxSelectMultipleInputForm -from .settings import SUBMIT_VALUE_AS - -theme = get_theme(request=None, as_instance=True) +from .base import CheckboxSelectMultipleInputPlugin __title__ = 'fobi.contrib.plugins.form_elements.fields.' \ 'checkbox_select_multiple.fobi_form_elements' @@ -22,74 +12,4 @@ __license__ = 'GPL 2.0/LGPL 2.1' __all__ = ('CheckboxSelectMultipleInputPlugin',) -class CheckboxSelectMultipleInputPlugin(FormFieldPlugin): - """Checkbox select multiple field plugin.""" - - uid = UID - name = _("Checkbox select multiple") - group = _("Fields") - form = CheckboxSelectMultipleInputForm - - def get_form_field_instances(self, request=None, form_entry=None, - form_element_entries=None, **kwargs): - """Get form field instances.""" - choices = get_select_field_choices(self.data.choices) - - field_kwargs = { - 'label': self.data.label, - 'help_text': self.data.help_text, - 'initial': self.data.initial, - 'required': self.data.required, - 'choices': choices, - 'widget': CheckboxSelectMultiple( - attrs={'class': theme.form_element_html_class} - ), - } - - return [(self.data.name, MultipleChoiceField, field_kwargs)] - - def submit_plugin_form_data(self, form_entry, request, form): - """Submit plugin form data/process. - - :param fobi.models.FormEntry form_entry: Instance of - ``fobi.models.FormEntry``. - :param django.http.HttpRequest request: - :param django.forms.Form form: - """ - # In case if we should submit value as is, we don't return anything. - # In other cases, we proceed further. - if SUBMIT_VALUE_AS != SUBMIT_VALUE_AS_VAL: - # Get the object - values = form.cleaned_data.get(self.data.name, None) - - # Get choices - choices = dict(get_select_field_choices(self.data.choices)) - - # Returned value - ret_values = [] - - for value in values: - # Handle the submitted form value - - if value in choices: - label = safe_text(choices.get(value)) - - # Should be returned as repr - if SUBMIT_VALUE_AS == SUBMIT_VALUE_AS_REPR: - value = label - # Should be returned as mix - else: - value = "{0} ({1})".format(label, value) - - ret_values.append(value) - - # Overwrite ``cleaned_data`` of the ``form`` with object - # qualifier. - form.cleaned_data[self.data.name] = ret_values - - # It's critically important to return the ``form`` with updated - # ``cleaned_data`` - return form - - form_element_plugin_registry.register(CheckboxSelectMultipleInputPlugin) diff --git a/src/fobi/contrib/plugins/form_elements/fields/date/base.py b/src/fobi/contrib/plugins/form_elements/fields/date/base.py new file mode 100644 index 00000000..4027644d --- /dev/null +++ b/src/fobi/contrib/plugins/form_elements/fields/date/base.py @@ -0,0 +1,72 @@ +from __future__ import absolute_import + +from django.forms.fields import DateField +from django.forms.widgets import DateInput +from django.utils.translation import ugettext_lazy as _ + +from fobi.base import FormFieldPlugin, get_theme + +from . import UID +from .forms import DateInputForm + +__title__ = 'fobi.contrib.plugins.form_elements.fields.date.base' +__author__ = 'Artur Barseghyan ' +__copyright__ = '2014-2016 Artur Barseghyan' +__license__ = 'GPL 2.0/LGPL 2.1' +__all__ = ('DateInputPlugin',) + +theme = get_theme(request=None, as_instance=True) + + +class DateInputPlugin(FormFieldPlugin): + """Date field plugin.""" + + uid = UID + name = _("Date") + group = _("Fields") + form = DateInputForm + + def get_form_field_instances(self, request=None, form_entry=None, + form_element_entries=None, **kwargs): + """Get form field instances.""" + widget_attrs = { + 'class': theme.form_element_html_class, + 'type': 'date', + } + + field_kwargs = { + 'label': self.data.label, + 'help_text': self.data.help_text, + 'initial': self.data.initial, + # 'input_formats': self.data.input_formats, + 'required': self.data.required, + 'widget': DateInput(attrs=widget_attrs), + } + # if self.data.input_formats: + # kwargs['input_formats'] = self.data.input_formats + + return [(self.data.name, DateField, field_kwargs)] + + def submit_plugin_form_data(self, form_entry, request, form, + form_element_entries=None, **kwargs): + """Submit plugin form data/process. + + :param fobi.models.FormEntry form_entry: Instance of + ``fobi.models.FormEntry``. + :param django.http.HttpRequest request: + :param django.forms.Form form: + """ + # In case if we should submit value as is, we don't return anything. + # In other cases, we proceed further. + + # Get the object + value = form.cleaned_data.get(self.data.name, None) + try: + value = value.strftime("%Y-%m-%d") + except Exception as err: + pass + + # Overwrite ``cleaned_data`` of the ``form`` with object qualifier. + form.cleaned_data[self.data.name] = value + + return form diff --git a/src/fobi/contrib/plugins/form_elements/fields/date/fobi_form_elements.py b/src/fobi/contrib/plugins/form_elements/fields/date/fobi_form_elements.py index 9fe33b04..95e96704 100644 --- a/src/fobi/contrib/plugins/form_elements/fields/date/fobi_form_elements.py +++ b/src/fobi/contrib/plugins/form_elements/fields/date/fobi_form_elements.py @@ -1,13 +1,8 @@ from __future__ import absolute_import -from django.forms.fields import DateField -from django.forms.widgets import DateInput -from django.utils.translation import ugettext_lazy as _ +from fobi.base import form_element_plugin_registry -from fobi.base import FormFieldPlugin, form_element_plugin_registry, get_theme - -from . import UID -from .forms import DateInputForm +from .base import DateInputPlugin __title__ = 'fobi.contrib.plugins.form_elements.fields.date.fobi_form_elements' __author__ = 'Artur Barseghyan ' @@ -15,60 +10,5 @@ __copyright__ = '2014-2016 Artur Barseghyan' __license__ = 'GPL 2.0/LGPL 2.1' __all__ = ('DateInputPlugin',) -theme = get_theme(request=None, as_instance=True) - - -class DateInputPlugin(FormFieldPlugin): - """Date field plugin.""" - - uid = UID - name = _("Date") - group = _("Fields") - form = DateInputForm - - def get_form_field_instances(self, request=None, form_entry=None, - form_element_entries=None, **kwargs): - """Get form field instances.""" - widget_attrs = { - 'class': theme.form_element_html_class, - 'type': 'date', - } - - field_kwargs = { - 'label': self.data.label, - 'help_text': self.data.help_text, - 'initial': self.data.initial, - # 'input_formats': self.data.input_formats, - 'required': self.data.required, - 'widget': DateInput(attrs=widget_attrs), - } - # if self.data.input_formats: - # kwargs['input_formats'] = self.data.input_formats - - return [(self.data.name, DateField, field_kwargs)] - - def submit_plugin_form_data(self, form_entry, request, form): - """Submit plugin form data/process. - - :param fobi.models.FormEntry form_entry: Instance of - ``fobi.models.FormEntry``. - :param django.http.HttpRequest request: - :param django.forms.Form form: - """ - # In case if we should submit value as is, we don't return anything. - # In other cases, we proceed further. - - # Get the object - value = form.cleaned_data.get(self.data.name, None) - try: - value = value.strftime("%Y-%m-%d") - except Exception as err: - pass - - # Overwrite ``cleaned_data`` of the ``form`` with object qualifier. - form.cleaned_data[self.data.name] = value - - return form - form_element_plugin_registry.register(DateInputPlugin) diff --git a/src/fobi/contrib/plugins/form_elements/fields/date_drop_down/base.py b/src/fobi/contrib/plugins/form_elements/fields/date_drop_down/base.py new file mode 100644 index 00000000..383c2ebc --- /dev/null +++ b/src/fobi/contrib/plugins/form_elements/fields/date_drop_down/base.py @@ -0,0 +1,54 @@ +from __future__ import absolute_import + +from django.forms.extras.widgets import SelectDateWidget +from django.forms.fields import DateField +from django.utils.translation import ugettext_lazy as _ + +from fobi.base import FormFieldPlugin, get_theme + +from . import UID +from .forms import DateDropDownInputForm + +__title__ = 'fobi.contrib.plugins.form_elements.fields.' \ + 'date_drop_down.base' +__author__ = 'Artur Barseghyan ' +__copyright__ = '2014-2016 Artur Barseghyan' +__license__ = 'GPL 2.0/LGPL 2.1' +__all__ = ('DateDropDownInputPlugin',) + + +theme = get_theme(request=None, as_instance=True) + + +class DateDropDownInputPlugin(FormFieldPlugin): + """Date drop down field plugin.""" + + uid = UID + name = _("Date drop down") + group = _("Fields") + form = DateDropDownInputForm + + def get_form_field_instances(self, request=None, form_entry=None, + form_element_entries=None, **kwargs): + """Get form field instances.""" + widget_attrs = { + 'class': theme.form_element_html_class, + 'type': 'date', + } + + years = None + if self.data.year_min and self.data.year_max: + years = range(self.data.year_min, self.data.year_max) + + field_kwargs = { + 'label': self.data.label, + 'help_text': self.data.help_text, + 'initial': self.data.initial, + # 'input_formats': self.data.input_formats, + 'required': self.data.required, + 'widget': SelectDateWidget(attrs=widget_attrs, years=years), + } + # if self.data.input_formats: + # kwargs['input_formats'] = self.data.input_formats + + return [(self.data.name, DateField, field_kwargs)] diff --git a/src/fobi/contrib/plugins/form_elements/fields/date_drop_down/fobi_form_elements.py b/src/fobi/contrib/plugins/form_elements/fields/date_drop_down/fobi_form_elements.py index a007664c..573d0c48 100644 --- a/src/fobi/contrib/plugins/form_elements/fields/date_drop_down/fobi_form_elements.py +++ b/src/fobi/contrib/plugins/form_elements/fields/date_drop_down/fobi_form_elements.py @@ -1,11 +1,8 @@ -from django.forms.extras.widgets import SelectDateWidget -from django.forms.fields import DateField -from django.utils.translation import ugettext_lazy as _ +from __future__ import absolute_import -from fobi.base import FormFieldPlugin, form_element_plugin_registry, get_theme +from fobi.base import form_element_plugin_registry -from . import UID -from .forms import DateDropDownInputForm +from .base import DateDropDownInputPlugin __title__ = 'fobi.contrib.plugins.form_elements.fields.' \ 'date_drop_down.fobi_form_elements' @@ -15,41 +12,4 @@ __license__ = 'GPL 2.0/LGPL 2.1' __all__ = ('DateDropDownInputPlugin',) -theme = get_theme(request=None, as_instance=True) - - -class DateDropDownInputPlugin(FormFieldPlugin): - """Date drop down field plugin.""" - - uid = UID - name = _("Date drop down") - group = _("Fields") - form = DateDropDownInputForm - - def get_form_field_instances(self, request=None, form_entry=None, - form_element_entries=None, **kwargs): - """Get form field instances.""" - widget_attrs = { - 'class': theme.form_element_html_class, - 'type': 'date', - } - - years = None - if self.data.year_min and self.data.year_max: - years = range(self.data.year_min, self.data.year_max) - - field_kwargs = { - 'label': self.data.label, - 'help_text': self.data.help_text, - 'initial': self.data.initial, - # 'input_formats': self.data.input_formats, - 'required': self.data.required, - 'widget': SelectDateWidget(attrs=widget_attrs, years=years), - } - # if self.data.input_formats: - # kwargs['input_formats'] = self.data.input_formats - - return [(self.data.name, DateField, field_kwargs)] - - form_element_plugin_registry.register(DateDropDownInputPlugin) diff --git a/src/fobi/contrib/plugins/form_elements/fields/datetime/base.py b/src/fobi/contrib/plugins/form_elements/fields/datetime/base.py new file mode 100644 index 00000000..00c4502b --- /dev/null +++ b/src/fobi/contrib/plugins/form_elements/fields/datetime/base.py @@ -0,0 +1,73 @@ +from __future__ import absolute_import + +from django.forms.fields import DateTimeField +from django.forms.widgets import DateTimeInput +from django.utils.translation import ugettext_lazy as _ + +from fobi.base import FormFieldPlugin, get_theme + +from . import UID +from .forms import DateTimeInputForm + +__title__ = 'fobi.contrib.plugins.form_elements.fields.' \ + 'datetime.base' +__author__ = 'Artur Barseghyan ' +__copyright__ = '2014-2016 Artur Barseghyan' +__license__ = 'GPL 2.0/LGPL 2.1' +__all__ = ('DateTimeInputPlugin',) + +theme = get_theme(request=None, as_instance=True) + + +class DateTimeInputPlugin(FormFieldPlugin): + """DateTime field plugin.""" + + uid = UID + name = _("DateTime") + group = _("Fields") + form = DateTimeInputForm + + def get_form_field_instances(self, request=None, form_entry=None, + form_element_entries=None, **kwargs): + """Get form field instances.""" + widget_attrs = { + 'class': theme.form_element_html_class, + 'type': 'datetime', + } + + field_kwargs = { + 'label': self.data.label, + 'help_text': self.data.help_text, + 'initial': self.data.initial, + # 'input_formats': self.data.input_formats, + 'required': self.data.required, + 'widget': DateTimeInput(attrs=widget_attrs), + } + # if self.data.input_formats: + # kwargs['input_formats'] = self.data.input_formats + + return [(self.data.name, DateTimeField, field_kwargs)] + + def submit_plugin_form_data(self, form_entry, request, form, + form_element_entries=None, **kwargs): + """Submit plugin form data/process. + + :param fobi.models.FormEntry form_entry: Instance of + ``fobi.models.FormEntry``. + :param django.http.HttpRequest request: + :param django.forms.Form form: + """ + # In case if we should submit value as is, we don't return anything. + # In other cases, we proceed further. + + # Get the object + value = form.cleaned_data.get(self.data.name, None) + try: + value = value.strftime("%Y-%m-%d %H:%M:%S") + except Exception as err: + pass + + # Overwrite ``cleaned_data`` of the ``form`` with object qualifier. + form.cleaned_data[self.data.name] = value + + return form diff --git a/src/fobi/contrib/plugins/form_elements/fields/datetime/fobi_form_elements.py b/src/fobi/contrib/plugins/form_elements/fields/datetime/fobi_form_elements.py index 44df3f82..55726982 100644 --- a/src/fobi/contrib/plugins/form_elements/fields/datetime/fobi_form_elements.py +++ b/src/fobi/contrib/plugins/form_elements/fields/datetime/fobi_form_elements.py @@ -1,13 +1,8 @@ from __future__ import absolute_import -from django.forms.fields import DateTimeField -from django.forms.widgets import DateTimeInput -from django.utils.translation import ugettext_lazy as _ +from fobi.base import form_element_plugin_registry -from fobi.base import FormFieldPlugin, form_element_plugin_registry, get_theme - -from . import UID -from .forms import DateTimeInputForm +from .base import DateTimeInputPlugin __title__ = 'fobi.contrib.plugins.form_elements.fields.' \ 'datetime.fobi_form_elements' @@ -16,60 +11,5 @@ __copyright__ = '2014-2016 Artur Barseghyan' __license__ = 'GPL 2.0/LGPL 2.1' __all__ = ('DateTimeInputPlugin',) -theme = get_theme(request=None, as_instance=True) - - -class DateTimeInputPlugin(FormFieldPlugin): - """DateTime field plugin.""" - - uid = UID - name = _("DateTime") - group = _("Fields") - form = DateTimeInputForm - - def get_form_field_instances(self, request=None, form_entry=None, - form_element_entries=None, **kwargs): - """Get form field instances.""" - widget_attrs = { - 'class': theme.form_element_html_class, - 'type': 'datetime', - } - - field_kwargs = { - 'label': self.data.label, - 'help_text': self.data.help_text, - 'initial': self.data.initial, - # 'input_formats': self.data.input_formats, - 'required': self.data.required, - 'widget': DateTimeInput(attrs=widget_attrs), - } - # if self.data.input_formats: - # kwargs['input_formats'] = self.data.input_formats - - return [(self.data.name, DateTimeField, field_kwargs)] - - def submit_plugin_form_data(self, form_entry, request, form): - """Submit plugin form data/process. - - :param fobi.models.FormEntry form_entry: Instance of - ``fobi.models.FormEntry``. - :param django.http.HttpRequest request: - :param django.forms.Form form: - """ - # In case if we should submit value as is, we don't return anything. - # In other cases, we proceed further. - - # Get the object - value = form.cleaned_data.get(self.data.name, None) - try: - value = value.strftime("%Y-%m-%d %H:%M:%S") - except Exception as err: - pass - - # Overwrite ``cleaned_data`` of the ``form`` with object qualifier. - form.cleaned_data[self.data.name] = value - - return form - form_element_plugin_registry.register(DateTimeInputPlugin) diff --git a/src/fobi/contrib/plugins/form_elements/fields/decimal/base.py b/src/fobi/contrib/plugins/form_elements/fields/decimal/base.py new file mode 100644 index 00000000..be12489b --- /dev/null +++ b/src/fobi/contrib/plugins/form_elements/fields/decimal/base.py @@ -0,0 +1,60 @@ +from __future__ import absolute_import + +from django.forms.fields import DecimalField +from django.utils.translation import ugettext_lazy as _ + +from fobi.base import FormFieldPlugin, get_theme +from fobi.widgets import NumberInput + +from . import UID +from .forms import DecimalInputForm + +__title__ = 'fobi.contrib.plugins.form_elements.fields.' \ + 'decimal.base' +__author__ = 'Artur Barseghyan ' +__copyright__ = '2014-2016 Artur Barseghyan' +__license__ = 'GPL 2.0/LGPL 2.1' +__all__ = ('DecimalInputPlugin',) + +theme = get_theme(request=None, as_instance=True) + + +class DecimalInputPlugin(FormFieldPlugin): + """Decimal input plugin.""" + + uid = UID + name = _("Decimal") + group = _("Fields") + form = DecimalInputForm + + def get_form_field_instances(self, request=None, form_entry=None, + form_element_entries=None, **kwargs): + """Get form field instances.""" + widget_attrs = { + 'class': theme.form_element_html_class, + 'type': 'number', + 'placeholder': self.data.placeholder, + } + field_kwargs = { + 'label': self.data.label, + 'help_text': self.data.help_text, + 'initial': self.data.initial, + 'required': self.data.required, + } + if self.data.max_value: + field_kwargs['max_value'] = self.data.max_value + widget_attrs['max'] = self.data.max_value + if self.data.min_value: + field_kwargs['min_value'] = self.data.min_value + widget_attrs['min'] = self.data.min_value + + if self.data.max_digits: + field_kwargs['max_digits'] = self.data.max_digits + widget_attrs['max'] = self.data.max_value + if self.data.decimal_places: + field_kwargs['decimal_places'] = self.data.decimal_places + widget_attrs['min'] = self.data.min_value + + field_kwargs['widget'] = NumberInput(attrs=widget_attrs) + + return [(self.data.name, DecimalField, field_kwargs)] diff --git a/src/fobi/contrib/plugins/form_elements/fields/decimal/fobi_form_elements.py b/src/fobi/contrib/plugins/form_elements/fields/decimal/fobi_form_elements.py index 21b45b08..6fe2c7e4 100644 --- a/src/fobi/contrib/plugins/form_elements/fields/decimal/fobi_form_elements.py +++ b/src/fobi/contrib/plugins/form_elements/fields/decimal/fobi_form_elements.py @@ -1,13 +1,8 @@ from __future__ import absolute_import -from django.forms.fields import DecimalField -from django.utils.translation import ugettext_lazy as _ +from fobi.base import form_element_plugin_registry -from fobi.base import FormFieldPlugin, form_element_plugin_registry, get_theme -from fobi.widgets import NumberInput - -from . import UID -from .forms import DecimalInputForm +from .base import DecimalInputPlugin __title__ = 'fobi.contrib.plugins.form_elements.fields.' \ 'decimal.fobi_form_elements' @@ -16,48 +11,5 @@ __copyright__ = '2014-2016 Artur Barseghyan' __license__ = 'GPL 2.0/LGPL 2.1' __all__ = ('DecimalInputPlugin',) -theme = get_theme(request=None, as_instance=True) - - -class DecimalInputPlugin(FormFieldPlugin): - """Decimal input plugin.""" - - uid = UID - name = _("Decimal") - group = _("Fields") - form = DecimalInputForm - - def get_form_field_instances(self, request=None, form_entry=None, - form_element_entries=None, **kwargs): - """Get form field instances.""" - widget_attrs = { - 'class': theme.form_element_html_class, - 'type': 'number', - 'placeholder': self.data.placeholder, - } - field_kwargs = { - 'label': self.data.label, - 'help_text': self.data.help_text, - 'initial': self.data.initial, - 'required': self.data.required, - } - if self.data.max_value: - field_kwargs['max_value'] = self.data.max_value - widget_attrs['max'] = self.data.max_value - if self.data.min_value: - field_kwargs['min_value'] = self.data.min_value - widget_attrs['min'] = self.data.min_value - - if self.data.max_digits: - field_kwargs['max_digits'] = self.data.max_digits - widget_attrs['max'] = self.data.max_value - if self.data.decimal_places: - field_kwargs['decimal_places'] = self.data.decimal_places - widget_attrs['min'] = self.data.min_value - - field_kwargs['widget'] = NumberInput(attrs=widget_attrs) - - return [(self.data.name, DecimalField, field_kwargs)] - form_element_plugin_registry.register(DecimalInputPlugin) diff --git a/src/fobi/contrib/plugins/form_elements/fields/email/base.py b/src/fobi/contrib/plugins/form_elements/fields/email/base.py new file mode 100644 index 00000000..f8980558 --- /dev/null +++ b/src/fobi/contrib/plugins/form_elements/fields/email/base.py @@ -0,0 +1,53 @@ +from __future__ import absolute_import + +from django.forms.fields import EmailField +from django.forms.widgets import TextInput +from django.utils.translation import ugettext_lazy as _ + +from fobi.base import FormFieldPlugin, get_theme + +from . import UID +from .forms import EmailInputForm + +__title__ = 'fobi.contrib.plugins.form_elements.fields.' \ + 'email.fobi_form_elements' +__author__ = 'Artur Barseghyan ' +__copyright__ = '2014-2016 Artur Barseghyan' +__license__ = 'GPL 2.0/LGPL 2.1' +__all__ = ('EmailInputPlugin',) + +theme = get_theme(request=None, as_instance=True) + + +class EmailInputPlugin(FormFieldPlugin): + """Email input plugin.""" + + uid = UID + name = _("Email") + group = _("Fields") + form = EmailInputForm + + def get_form_field_instances(self, request=None, form_entry=None, + form_element_entries=None, **kwargs): + """Get form field instances.""" + widget_attrs = { + 'class': theme.form_element_html_class, + 'type': 'email', + 'placeholder': self.data.placeholder, + } + + field_kwargs = { + 'label': self.data.label, + 'help_text': self.data.help_text, + 'initial': self.data.initial, + 'required': self.data.required, + 'widget': TextInput(attrs=widget_attrs), + } + if self.data.max_length: + field_kwargs['max_length'] = self.data.max_length + + return [(self.data.name, EmailField, field_kwargs)] + + +# For backwards compatibility +EmailPlugin = EmailInputPlugin diff --git a/src/fobi/contrib/plugins/form_elements/fields/email/fobi_form_elements.py b/src/fobi/contrib/plugins/form_elements/fields/email/fobi_form_elements.py index aadeb46c..3da5bdd1 100644 --- a/src/fobi/contrib/plugins/form_elements/fields/email/fobi_form_elements.py +++ b/src/fobi/contrib/plugins/form_elements/fields/email/fobi_form_elements.py @@ -1,13 +1,8 @@ from __future__ import absolute_import -from django.forms.fields import EmailField -from django.forms.widgets import TextInput -from django.utils.translation import ugettext_lazy as _ +from fobi.base import form_element_plugin_registry -from fobi.base import FormFieldPlugin, form_element_plugin_registry, get_theme - -from . import UID -from .forms import EmailInputForm +from .base import EmailInputPlugin __title__ = 'fobi.contrib.plugins.form_elements.fields.' \ 'email.fobi_form_elements' @@ -16,40 +11,5 @@ __copyright__ = '2014-2016 Artur Barseghyan' __license__ = 'GPL 2.0/LGPL 2.1' __all__ = ('EmailInputPlugin',) -theme = get_theme(request=None, as_instance=True) - - -class EmailInputPlugin(FormFieldPlugin): - """Email input plugin.""" - - uid = UID - name = _("Email") - group = _("Fields") - form = EmailInputForm - - def get_form_field_instances(self, request=None, form_entry=None, - form_element_entries=None, **kwargs): - """Get form field instances.""" - widget_attrs = { - 'class': theme.form_element_html_class, - 'type': 'email', - 'placeholder': self.data.placeholder, - } - - field_kwargs = { - 'label': self.data.label, - 'help_text': self.data.help_text, - 'initial': self.data.initial, - 'required': self.data.required, - 'widget': TextInput(attrs=widget_attrs), - } - if self.data.max_length: - field_kwargs['max_length'] = self.data.max_length - - return [(self.data.name, EmailField, field_kwargs)] - - -# For backwards compatibility -EmailPlugin = EmailInputPlugin form_element_plugin_registry.register(EmailInputPlugin) diff --git a/src/fobi/contrib/plugins/form_elements/fields/file/base.py b/src/fobi/contrib/plugins/form_elements/fields/file/base.py new file mode 100644 index 00000000..172dc3f2 --- /dev/null +++ b/src/fobi/contrib/plugins/form_elements/fields/file/base.py @@ -0,0 +1,74 @@ +from __future__ import absolute_import + +import os + +from django.forms.fields import FileField +from django.forms.widgets import ClearableFileInput +from django.utils.translation import ugettext_lazy as _ +from django.conf import settings + +from fobi.base import FormFieldPlugin +from fobi.helpers import handle_uploaded_file + +from . import UID +from .forms import FileInputForm +from .settings import FILES_UPLOAD_DIR + +__title__ = 'fobi.contrib.plugins.form_elements.fields.file.base' +__author__ = 'Artur Barseghyan ' +__copyright__ = '2014-2016 Artur Barseghyan' +__license__ = 'GPL 2.0/LGPL 2.1' +__all__ = ('FileInputPlugin',) + + +class FileInputPlugin(FormFieldPlugin): + """File field plugin.""" + + uid = UID + name = _("File") + group = _("Fields") + form = FileInputForm + + def get_form_field_instances(self, request=None, form_entry=None, + form_element_entries=None, **kwargs): + """Get form field instances.""" + field_kwargs = { + 'label': self.data.label, + 'help_text': self.data.help_text, + 'initial': self.data.initial, + 'required': self.data.required, + 'widget': ClearableFileInput(attrs={}), + } + if self.data.max_length: + field_kwargs['max_length'] = self.data.max_length + + return [(self.data.name, FileField, field_kwargs)] + + def submit_plugin_form_data(self, form_entry, request, form, + form_element_entries=None, **kwargs): + """Submit plugin form data/process file upload. + + Handling the posted data for file plugin when form is submitted. + This method affects the original form and that's why it returns it. + + :param fobi.models.FormEntry form_entry: Instance + of ``fobi.models.FormEntry``. + :param django.http.HttpRequest request: + :param django.forms.Form form: + """ + # Get the file path + file_path = form.cleaned_data.get(self.data.name, None) + if file_path: + # Handle the upload + saved_file = handle_uploaded_file(FILES_UPLOAD_DIR, file_path) + # Overwrite ``cleaned_data`` of the ``form`` with path to moved + # file. + file_relative_url = saved_file.replace(os.path.sep, '/') + form.cleaned_data[self.data.name] = "{0}{1}".format( + settings.MEDIA_URL, + file_relative_url + ) + + # It's critically important to return the ``form`` with updated + # ``cleaned_data`` + return form diff --git a/src/fobi/contrib/plugins/form_elements/fields/file/fobi_form_elements.py b/src/fobi/contrib/plugins/form_elements/fields/file/fobi_form_elements.py index 354e9786..c442bbf2 100644 --- a/src/fobi/contrib/plugins/form_elements/fields/file/fobi_form_elements.py +++ b/src/fobi/contrib/plugins/form_elements/fields/file/fobi_form_elements.py @@ -1,16 +1,8 @@ -import os +from __future__ import absolute_import -from django.forms.fields import FileField -from django.forms.widgets import ClearableFileInput -from django.utils.translation import ugettext_lazy as _ -from django.conf import settings +from fobi.base import form_element_plugin_registry -from fobi.base import FormFieldPlugin, form_element_plugin_registry -from fobi.helpers import handle_uploaded_file - -from . import UID -from .forms import FileInputForm -from .settings import FILES_UPLOAD_DIR +from .base import FileInputPlugin __title__ = 'fobi.contrib.plugins.form_elements.fields.file.fobi_form_elements' __author__ = 'Artur Barseghyan ' @@ -19,56 +11,4 @@ __license__ = 'GPL 2.0/LGPL 2.1' __all__ = ('FileInputPlugin',) -class FileInputPlugin(FormFieldPlugin): - """File field plugin.""" - - uid = UID - name = _("File") - group = _("Fields") - form = FileInputForm - - def get_form_field_instances(self, request=None, form_entry=None, - form_element_entries=None, **kwargs): - """Get form field instances.""" - field_kwargs = { - 'label': self.data.label, - 'help_text': self.data.help_text, - 'initial': self.data.initial, - 'required': self.data.required, - 'widget': ClearableFileInput(attrs={}), - } - if self.data.max_length: - field_kwargs['max_length'] = self.data.max_length - - return [(self.data.name, FileField, field_kwargs)] - - def submit_plugin_form_data(self, form_entry, request, form): - """Submit plugin form data/process file upload. - - Handling the posted data for file plugin when form is submitted. - This method affects the original form and that's why it returns it. - - :param fobi.models.FormEntry form_entry: Instance - of ``fobi.models.FormEntry``. - :param django.http.HttpRequest request: - :param django.forms.Form form: - """ - # Get the file path - file_path = form.cleaned_data.get(self.data.name, None) - if file_path: - # Handle the upload - saved_file = handle_uploaded_file(FILES_UPLOAD_DIR, file_path) - # Overwrite ``cleaned_data`` of the ``form`` with path to moved - # file. - file_relative_url = saved_file.replace(os.path.sep, '/') - form.cleaned_data[self.data.name] = "{0}{1}".format( - settings.MEDIA_URL, - file_relative_url - ) - - # It's critically important to return the ``form`` with updated - # ``cleaned_data`` - return form - - form_element_plugin_registry.register(FileInputPlugin) diff --git a/src/fobi/contrib/plugins/form_elements/fields/float/base.py b/src/fobi/contrib/plugins/form_elements/fields/float/base.py new file mode 100644 index 00000000..96b6d71b --- /dev/null +++ b/src/fobi/contrib/plugins/form_elements/fields/float/base.py @@ -0,0 +1,52 @@ +from __future__ import absolute_import + +from django.forms.fields import FloatField +from django.utils.translation import ugettext_lazy as _ + +from fobi.base import FormFieldPlugin, get_theme +from fobi.widgets import NumberInput + +from . import UID +from .forms import FloatInputForm + +__title__ = 'fobi.contrib.plugins.form_elements.fields.float.base' +__author__ = 'Artur Barseghyan ' +__copyright__ = '2014-2016 Artur Barseghyan' +__license__ = 'GPL 2.0/LGPL 2.1' +__all__ = ('FloatInputPlugin',) + +theme = get_theme(request=None, as_instance=True) + + +class FloatInputPlugin(FormFieldPlugin): + """Float input plugin.""" + + uid = UID + name = _("Float") + group = _("Fields") + form = FloatInputForm + + def get_form_field_instances(self, request=None, form_entry=None, + form_element_entries=None, **kwargs): + """Get form field instances.""" + widget_attrs = { + 'class': theme.form_element_html_class, + 'type': 'number', + 'placeholder': self.data.placeholder, + } + field_kwargs = { + 'label': self.data.label, + 'help_text': self.data.help_text, + 'initial': self.data.initial, + 'required': self.data.required, + } + if self.data.max_value: + field_kwargs['max_value'] = self.data.max_value + widget_attrs['max'] = self.data.max_value + if self.data.min_value: + field_kwargs['min_value'] = self.data.min_value + widget_attrs['min'] = self.data.min_value + + field_kwargs['widget'] = NumberInput(attrs=widget_attrs) + + return [(self.data.name, FloatField, field_kwargs)] diff --git a/src/fobi/contrib/plugins/form_elements/fields/float/fobi_form_elements.py b/src/fobi/contrib/plugins/form_elements/fields/float/fobi_form_elements.py index 096c1ad6..ed62aba5 100644 --- a/src/fobi/contrib/plugins/form_elements/fields/float/fobi_form_elements.py +++ b/src/fobi/contrib/plugins/form_elements/fields/float/fobi_form_elements.py @@ -1,11 +1,8 @@ -from django.forms.fields import FloatField -from django.utils.translation import ugettext_lazy as _ +from __future__ import absolute_import -from fobi.base import FormFieldPlugin, form_element_plugin_registry, get_theme -from fobi.widgets import NumberInput +from fobi.base import form_element_plugin_registry -from . import UID -from .forms import FloatInputForm +from .base import FloatInputPlugin __title__ = 'fobi.contrib.plugins.form_elements.fields.' \ 'float.fobi_form_elements' @@ -14,41 +11,5 @@ __copyright__ = '2014-2016 Artur Barseghyan' __license__ = 'GPL 2.0/LGPL 2.1' __all__ = ('FloatInputPlugin',) -theme = get_theme(request=None, as_instance=True) - - -class FloatInputPlugin(FormFieldPlugin): - """Float input plugin.""" - - uid = UID - name = _("Float") - group = _("Fields") - form = FloatInputForm - - def get_form_field_instances(self, request=None, form_entry=None, - form_element_entries=None, **kwargs): - """Get form field instances.""" - widget_attrs = { - 'class': theme.form_element_html_class, - 'type': 'number', - 'placeholder': self.data.placeholder, - } - field_kwargs = { - 'label': self.data.label, - 'help_text': self.data.help_text, - 'initial': self.data.initial, - 'required': self.data.required, - } - if self.data.max_value: - field_kwargs['max_value'] = self.data.max_value - widget_attrs['max'] = self.data.max_value - if self.data.min_value: - field_kwargs['min_value'] = self.data.min_value - widget_attrs['min'] = self.data.min_value - - field_kwargs['widget'] = NumberInput(attrs=widget_attrs) - - return [(self.data.name, FloatField, field_kwargs)] - form_element_plugin_registry.register(FloatInputPlugin) diff --git a/src/fobi/contrib/plugins/form_elements/fields/hidden/base.py b/src/fobi/contrib/plugins/form_elements/fields/hidden/base.py new file mode 100644 index 00000000..c79837c9 --- /dev/null +++ b/src/fobi/contrib/plugins/form_elements/fields/hidden/base.py @@ -0,0 +1,45 @@ +from __future__ import absolute_import + +from django.forms.fields import CharField +from django.forms.widgets import HiddenInput +from django.utils.translation import ugettext_lazy as _ + +from fobi.base import FormFieldPlugin, get_theme + +from . import UID +from .forms import HiddenInputForm + +__title__ = 'fobi.contrib.plugins.form_elements.fields.hidden.base' +__author__ = 'Artur Barseghyan ' +__copyright__ = '2014-2016 Artur Barseghyan' +__license__ = 'GPL 2.0/LGPL 2.1' +__all__ = ('HiddenInputPlugin',) + +theme = get_theme(request=None, as_instance=True) + + +class HiddenInputPlugin(FormFieldPlugin): + """Hidden field plugin.""" + + uid = UID + name = _("Hidden") + group = _("Fields") + form = HiddenInputForm + is_hidden = True + + def get_form_field_instances(self, request=None, form_entry=None, + form_element_entries=None, **kwargs): + """Get form field instances.""" + field_kwargs = { + 'label': self.data.label, + 'initial': self.data.initial, + 'required': self.data.required, + 'widget': HiddenInput( + attrs={'class': theme.form_element_html_class} + ), + } + if self.data.max_length: + field_kwargs['max_length'] = self.data.max_length + + return [(self.data.name, CharField, field_kwargs)] + # return [(self.data.name, (CharField, TextInput), kwargs)] diff --git a/src/fobi/contrib/plugins/form_elements/fields/hidden/fobi_form_elements.py b/src/fobi/contrib/plugins/form_elements/fields/hidden/fobi_form_elements.py index 98f5b33e..23cf99e1 100644 --- a/src/fobi/contrib/plugins/form_elements/fields/hidden/fobi_form_elements.py +++ b/src/fobi/contrib/plugins/form_elements/fields/hidden/fobi_form_elements.py @@ -1,11 +1,8 @@ -from django.forms.fields import CharField -from django.forms.widgets import HiddenInput # , TextInput -from django.utils.translation import ugettext_lazy as _ +from __future__ import absolute_import -from fobi.base import FormFieldPlugin, form_element_plugin_registry, get_theme +from fobi.base import form_element_plugin_registry -from . import UID -from .forms import HiddenInputForm +from .base import HiddenInputPlugin __title__ = 'fobi.contrib.plugins.form_elements.fields.' \ 'hidden.fobi_form_elements' @@ -14,34 +11,5 @@ __copyright__ = '2014-2016 Artur Barseghyan' __license__ = 'GPL 2.0/LGPL 2.1' __all__ = ('HiddenInputPlugin',) -theme = get_theme(request=None, as_instance=True) - - -class HiddenInputPlugin(FormFieldPlugin): - """Hidden field plugin.""" - - uid = UID - name = _("Hidden") - group = _("Fields") - form = HiddenInputForm - is_hidden = True - - def get_form_field_instances(self, request=None, form_entry=None, - form_element_entries=None, **kwargs): - """Get form field instances.""" - field_kwargs = { - 'label': self.data.label, - 'initial': self.data.initial, - 'required': self.data.required, - 'widget': HiddenInput( - attrs={'class': theme.form_element_html_class} - ), - } - if self.data.max_length: - field_kwargs['max_length'] = self.data.max_length - - return [(self.data.name, CharField, field_kwargs)] - # return [(self.data.name, (CharField, TextInput), kwargs)] - form_element_plugin_registry.register(HiddenInputPlugin) diff --git a/src/fobi/contrib/plugins/form_elements/fields/input/base.py b/src/fobi/contrib/plugins/form_elements/fields/input/base.py new file mode 100644 index 00000000..ff6c2409 --- /dev/null +++ b/src/fobi/contrib/plugins/form_elements/fields/input/base.py @@ -0,0 +1,88 @@ +from __future__ import absolute_import + +from django.forms.fields import Field +from django.forms.widgets import TextInput +from django.utils.translation import ugettext_lazy as _ + +from fobi.base import FormFieldPlugin, get_theme + +from . import UID +from .forms import InputForm + +__title__ = 'fobi.contrib.plugins.form_elements.fields.input.base' +__author__ = 'Artur Barseghyan ' +__copyright__ = '2014-2016 Artur Barseghyan' +__license__ = 'GPL 2.0/LGPL 2.1' +__all__ = ('InputPlugin',) + +theme = get_theme(request=None, as_instance=True) + + +class InputPlugin(FormFieldPlugin): + """Input field plugin.""" + + uid = UID + name = _("Input") + group = _("Fields") + form = InputForm + + def get_form_field_instances(self, request=None, form_entry=None, + form_element_entries=None, **kwargs): + """Get form field instances.""" + widget_attrs = { + 'class': theme.form_element_html_class, + 'placeholder': self.data.placeholder, + 'type': self.data.type_value, + } + + if self.data.autocomplete_value: + widget_attrs.update({'autocomplete': 'on'}) + + if self.data.autofocus_value: + widget_attrs.update({'autofocus': 'autofocus'}) + + if self.data.disabled_value: + widget_attrs.update({'disabled': 'disabled'}) + + # if self.data.formnovalidate_value: + # widget_attrs.update({'formnovalidate': 'formnovalidate'}) + + if self.data.list_value: + widget_attrs.update({'list': self.data.list_value}) + + if self.data.max_value: + widget_attrs.update({'max': self.data.max_value}) + + if self.data.min_value: + widget_attrs.update({'min': self.data.min_value}) + + if self.data.multiple_value: + widget_attrs.update({'multiple': 'multiple'}) + + if self.data.pattern_value: + widget_attrs.update({'pattern': self.data.pattern_value}) + + if self.data.readonly_value: + widget_attrs.update({'readonly': 'readonly'}) + + if self.data.step_value: + widget_attrs.update({'step': self.data.step_value}) + + if self.data.type_value and self.data.type_value in ('submit', + 'button', + 'reset',): + widget_attrs.update({'value': self.data.label}) + + field_kwargs = { + 'label': self.data.label + if self.data.type_value not in ('submit', 'button', 'reset',) + else '', + 'help_text': self.data.help_text, + 'initial': self.data.initial, + 'required': self.data.required, + 'widget': TextInput(attrs=widget_attrs), + } + # if self.data.max_length: + # kwargs['max_length'] = self.data.max_length + + return [(self.data.name, Field, field_kwargs)] diff --git a/src/fobi/contrib/plugins/form_elements/fields/input/fobi_form_elements.py b/src/fobi/contrib/plugins/form_elements/fields/input/fobi_form_elements.py index 7825b6bb..191aca0e 100644 --- a/src/fobi/contrib/plugins/form_elements/fields/input/fobi_form_elements.py +++ b/src/fobi/contrib/plugins/form_elements/fields/input/fobi_form_elements.py @@ -1,11 +1,8 @@ -from django.forms.fields import Field -from django.forms.widgets import TextInput -from django.utils.translation import ugettext_lazy as _ +from __future__ import absolute_import -from fobi.base import FormFieldPlugin, form_element_plugin_registry, get_theme +from fobi.base import form_element_plugin_registry -from . import UID -from .forms import InputForm +from .base import InputPlugin __title__ = 'fobi.contrib.plugins.form_elements.fields.' \ 'input.fobi_form_elements' @@ -14,77 +11,5 @@ __copyright__ = '2014-2016 Artur Barseghyan' __license__ = 'GPL 2.0/LGPL 2.1' __all__ = ('InputPlugin',) -theme = get_theme(request=None, as_instance=True) - - -class InputPlugin(FormFieldPlugin): - """Input field plugin.""" - - uid = UID - name = _("Input") - group = _("Fields") - form = InputForm - - def get_form_field_instances(self, request=None, form_entry=None, - form_element_entries=None, **kwargs): - """Get form field instances.""" - widget_attrs = { - 'class': theme.form_element_html_class, - 'placeholder': self.data.placeholder, - 'type': self.data.type_value, - } - - if self.data.autocomplete_value: - widget_attrs.update({'autocomplete': 'on'}) - - if self.data.autofocus_value: - widget_attrs.update({'autofocus': 'autofocus'}) - - if self.data.disabled_value: - widget_attrs.update({'disabled': 'disabled'}) - - # if self.data.formnovalidate_value: - # widget_attrs.update({'formnovalidate': 'formnovalidate'}) - - if self.data.list_value: - widget_attrs.update({'list': self.data.list_value}) - - if self.data.max_value: - widget_attrs.update({'max': self.data.max_value}) - - if self.data.min_value: - widget_attrs.update({'min': self.data.min_value}) - - if self.data.multiple_value: - widget_attrs.update({'multiple': 'multiple'}) - - if self.data.pattern_value: - widget_attrs.update({'pattern': self.data.pattern_value}) - - if self.data.readonly_value: - widget_attrs.update({'readonly': 'readonly'}) - - if self.data.step_value: - widget_attrs.update({'step': self.data.step_value}) - - if self.data.type_value and self.data.type_value in ('submit', - 'button', - 'reset',): - widget_attrs.update({'value': self.data.label}) - - field_kwargs = { - 'label': self.data.label - if self.data.type_value not in ('submit', 'button', 'reset',) - else '', - 'help_text': self.data.help_text, - 'initial': self.data.initial, - 'required': self.data.required, - 'widget': TextInput(attrs=widget_attrs), - } - # if self.data.max_length: - # kwargs['max_length'] = self.data.max_length - - return [(self.data.name, Field, field_kwargs)] - form_element_plugin_registry.register(InputPlugin) diff --git a/src/fobi/contrib/plugins/form_elements/fields/integer/base.py b/src/fobi/contrib/plugins/form_elements/fields/integer/base.py new file mode 100644 index 00000000..5f9430d5 --- /dev/null +++ b/src/fobi/contrib/plugins/form_elements/fields/integer/base.py @@ -0,0 +1,52 @@ +from __future__ import absolute_import + +from django.forms.fields import IntegerField +from django.utils.translation import ugettext_lazy as _ + +from fobi.base import FormFieldPlugin, get_theme +from fobi.widgets import NumberInput + +from . import UID +from .forms import IntegerInputForm + +__title__ = 'fobi.contrib.plugins.form_elements.fields.integer.base' +__author__ = 'Artur Barseghyan ' +__copyright__ = '2014-2016 Artur Barseghyan' +__license__ = 'GPL 2.0/LGPL 2.1' +__all__ = ('IntegerInputPlugin',) + +theme = get_theme(request=None, as_instance=True) + + +class IntegerInputPlugin(FormFieldPlugin): + """Integer input plugin.""" + + uid = UID + name = _("Integer") + group = _("Fields") + form = IntegerInputForm + + def get_form_field_instances(self, request=None, form_entry=None, + form_element_entries=None, **kwargs): + """Get form field instances.""" + widget_attrs = { + 'class': theme.form_element_html_class, + 'type': 'number', + 'placeholder': self.data.placeholder, + } + field_kwargs = { + 'label': self.data.label, + 'help_text': self.data.help_text, + 'initial': self.data.initial, + 'required': self.data.required, + } + if self.data.max_value: + field_kwargs['max_value'] = self.data.max_value + widget_attrs['max'] = self.data.max_value + if self.data.min_value: + field_kwargs['min_value'] = self.data.min_value + widget_attrs['min'] = self.data.min_value + + field_kwargs['widget'] = NumberInput(attrs=widget_attrs) + + return [(self.data.name, IntegerField, field_kwargs)] diff --git a/src/fobi/contrib/plugins/form_elements/fields/integer/fobi_form_elements.py b/src/fobi/contrib/plugins/form_elements/fields/integer/fobi_form_elements.py index 97eb49a6..f065bed5 100644 --- a/src/fobi/contrib/plugins/form_elements/fields/integer/fobi_form_elements.py +++ b/src/fobi/contrib/plugins/form_elements/fields/integer/fobi_form_elements.py @@ -1,11 +1,8 @@ -from django.forms.fields import IntegerField # , DecimalField, FloatField -from django.utils.translation import ugettext_lazy as _ +from __future__ import absolute_import -from fobi.base import FormFieldPlugin, form_element_plugin_registry, get_theme -from fobi.widgets import NumberInput +from fobi.base import form_element_plugin_registry -from . import UID -from .forms import IntegerInputForm +from .base import IntegerInputPlugin __title__ = 'fobi.contrib.plugins.form_elements.fields.' \ 'integer.fobi_form_elements' @@ -14,41 +11,5 @@ __copyright__ = '2014-2016 Artur Barseghyan' __license__ = 'GPL 2.0/LGPL 2.1' __all__ = ('IntegerInputPlugin',) -theme = get_theme(request=None, as_instance=True) - - -class IntegerInputPlugin(FormFieldPlugin): - """Integer input plugin.""" - - uid = UID - name = _("Integer") - group = _("Fields") - form = IntegerInputForm - - def get_form_field_instances(self, request=None, form_entry=None, - form_element_entries=None, **kwargs): - """Get form field instances.""" - widget_attrs = { - 'class': theme.form_element_html_class, - 'type': 'number', - 'placeholder': self.data.placeholder, - } - field_kwargs = { - 'label': self.data.label, - 'help_text': self.data.help_text, - 'initial': self.data.initial, - 'required': self.data.required, - } - if self.data.max_value: - field_kwargs['max_value'] = self.data.max_value - widget_attrs['max'] = self.data.max_value - if self.data.min_value: - field_kwargs['min_value'] = self.data.min_value - widget_attrs['min'] = self.data.min_value - - field_kwargs['widget'] = NumberInput(attrs=widget_attrs) - - return [(self.data.name, IntegerField, field_kwargs)] - form_element_plugin_registry.register(IntegerInputPlugin) diff --git a/src/fobi/contrib/plugins/form_elements/fields/ip_address/base.py b/src/fobi/contrib/plugins/form_elements/fields/ip_address/base.py new file mode 100644 index 00000000..44e612ca --- /dev/null +++ b/src/fobi/contrib/plugins/form_elements/fields/ip_address/base.py @@ -0,0 +1,47 @@ +from __future__ import absolute_import + +from django.forms.fields import GenericIPAddressField +from django.forms.widgets import TextInput +from django.utils.translation import ugettext_lazy as _ + +from fobi.base import FormFieldPlugin, get_theme + +from . import UID +from .forms import IPAddressInputForm + +__title__ = 'fobi.contrib.plugins.form_elements.fields.ip_address.base' +__author__ = 'Artur Barseghyan ' +__copyright__ = '2014-2016 Artur Barseghyan' +__license__ = 'GPL 2.0/LGPL 2.1' +__all__ = ('IPAddressInputPlugin',) + +theme = get_theme(request=None, as_instance=True) + + +class IPAddressInputPlugin(FormFieldPlugin): + """IP address field plugin.""" + + uid = UID + name = _("IP address") + group = _("Fields") + form = IPAddressInputForm + + def get_form_field_instances(self, request=None, form_entry=None, + form_element_entries=None, **kwargs): + """Get form field instances.""" + widget_attrs = { + 'class': theme.form_element_html_class, + 'placeholder': self.data.placeholder, + } + + field_kwargs = { + 'label': self.data.label, + 'help_text': self.data.help_text, + 'initial': self.data.initial, + 'required': self.data.required, + 'widget': TextInput(attrs=widget_attrs), + } + if self.data.max_length: + field_kwargs['max_length'] = self.data.max_length + + return [(self.data.name, GenericIPAddressField, field_kwargs)] diff --git a/src/fobi/contrib/plugins/form_elements/fields/ip_address/fobi_form_elements.py b/src/fobi/contrib/plugins/form_elements/fields/ip_address/fobi_form_elements.py index 45d50c0b..3abc01ce 100644 --- a/src/fobi/contrib/plugins/form_elements/fields/ip_address/fobi_form_elements.py +++ b/src/fobi/contrib/plugins/form_elements/fields/ip_address/fobi_form_elements.py @@ -1,13 +1,8 @@ +from __future__ import absolute_import +from fobi.base import form_element_plugin_registry -from django.forms.fields import GenericIPAddressField -from django.forms.widgets import TextInput -from django.utils.translation import ugettext_lazy as _ - -from fobi.base import FormFieldPlugin, form_element_plugin_registry, get_theme - -from . import UID -from .forms import IPAddressInputForm +from .base import IPAddressInputPlugin __title__ = 'fobi.contrib.plugins.form_elements.fields.' \ 'ip_address.fobi_form_elements' @@ -16,36 +11,5 @@ __copyright__ = '2014-2016 Artur Barseghyan' __license__ = 'GPL 2.0/LGPL 2.1' __all__ = ('IPAddressInputPlugin',) -theme = get_theme(request=None, as_instance=True) - - -class IPAddressInputPlugin(FormFieldPlugin): - """IP address field plugin.""" - - uid = UID - name = _("IP address") - group = _("Fields") - form = IPAddressInputForm - - def get_form_field_instances(self, request=None, form_entry=None, - form_element_entries=None, **kwargs): - """Get form field instances.""" - widget_attrs = { - 'class': theme.form_element_html_class, - 'placeholder': self.data.placeholder, - } - - field_kwargs = { - 'label': self.data.label, - 'help_text': self.data.help_text, - 'initial': self.data.initial, - 'required': self.data.required, - 'widget': TextInput(attrs=widget_attrs), - } - if self.data.max_length: - field_kwargs['max_length'] = self.data.max_length - - return [(self.data.name, GenericIPAddressField, field_kwargs)] - form_element_plugin_registry.register(IPAddressInputPlugin) diff --git a/src/fobi/contrib/plugins/form_elements/fields/null_boolean/base.py b/src/fobi/contrib/plugins/form_elements/fields/null_boolean/base.py new file mode 100644 index 00000000..aa74e1a5 --- /dev/null +++ b/src/fobi/contrib/plugins/form_elements/fields/null_boolean/base.py @@ -0,0 +1,42 @@ +from __future__ import absolute_import + +from django.forms.fields import NullBooleanField +from django.forms.widgets import NullBooleanSelect +from django.utils.translation import ugettext_lazy as _ + +from fobi.base import FormFieldPlugin, get_theme + +from . import UID +from .forms import NullBooleanSelectForm + +__title__ = 'fobi.contrib.plugins.form_elements.fields.null_boolean.base' +__author__ = 'Artur Barseghyan ' +__copyright__ = '2014-2016 Artur Barseghyan' +__license__ = 'GPL 2.0/LGPL 2.1' +__all__ = ('NullBooleanSelectPlugin',) + +theme = get_theme(request=None, as_instance=True) + + +class NullBooleanSelectPlugin(FormFieldPlugin): + """Null boolean select plugin.""" + + uid = UID + name = _("Null boolean") + group = _("Fields") + form = NullBooleanSelectForm + + def get_form_field_instances(self, request=None, form_entry=None, + form_element_entries=None, **kwargs): + """Get form field instances.""" + field_kwargs = { + 'label': self.data.label, + 'help_text': self.data.help_text, + 'initial': self.data.initial, + 'required': self.data.required, + 'widget': NullBooleanSelect( + attrs={'class': theme.form_element_html_class} + ), + } + + return [(self.data.name, NullBooleanField, field_kwargs)] diff --git a/src/fobi/contrib/plugins/form_elements/fields/null_boolean/fobi_form_elements.py b/src/fobi/contrib/plugins/form_elements/fields/null_boolean/fobi_form_elements.py index fec42fdd..0ffa2428 100644 --- a/src/fobi/contrib/plugins/form_elements/fields/null_boolean/fobi_form_elements.py +++ b/src/fobi/contrib/plugins/form_elements/fields/null_boolean/fobi_form_elements.py @@ -1,11 +1,8 @@ -from django.forms.fields import NullBooleanField -from django.forms.widgets import NullBooleanSelect -from django.utils.translation import ugettext_lazy as _ +from __future__ import absolute_import -from fobi.base import FormFieldPlugin, form_element_plugin_registry, get_theme +from fobi.base import form_element_plugin_registry -from . import UID -from .forms import NullBooleanSelectForm +from .base import NullBooleanSelectPlugin __title__ = 'fobi.contrib.plugins.form_elements.fields.' \ 'null_boolean.fobi_form_elements' @@ -14,31 +11,5 @@ __copyright__ = '2014-2016 Artur Barseghyan' __license__ = 'GPL 2.0/LGPL 2.1' __all__ = ('NullBooleanSelectPlugin',) -theme = get_theme(request=None, as_instance=True) - - -class NullBooleanSelectPlugin(FormFieldPlugin): - """Null boolean select plugin.""" - - uid = UID - name = _("Null boolean") - group = _("Fields") - form = NullBooleanSelectForm - - def get_form_field_instances(self, request=None, form_entry=None, - form_element_entries=None, **kwargs): - """Get form field instances.""" - field_kwargs = { - 'label': self.data.label, - 'help_text': self.data.help_text, - 'initial': self.data.initial, - 'required': self.data.required, - 'widget': NullBooleanSelect( - attrs={'class': theme.form_element_html_class} - ), - } - - return [(self.data.name, NullBooleanField, field_kwargs)] - form_element_plugin_registry.register(NullBooleanSelectPlugin) diff --git a/src/fobi/contrib/plugins/form_elements/fields/password/base.py b/src/fobi/contrib/plugins/form_elements/fields/password/base.py new file mode 100644 index 00000000..0e9ffdc8 --- /dev/null +++ b/src/fobi/contrib/plugins/form_elements/fields/password/base.py @@ -0,0 +1,47 @@ +from __future__ import absolute_import + +from django.forms.fields import CharField +from django.forms.widgets import PasswordInput +from django.utils.translation import ugettext_lazy as _ + +from fobi.base import FormFieldPlugin, get_theme + +from . import UID +from .forms import PasswordInputForm + +__title__ = 'fobi.contrib.plugins.form_elements.fields.password.base' +__author__ = 'Artur Barseghyan ' +__copyright__ = '2014-2016 Artur Barseghyan' +__license__ = 'GPL 2.0/LGPL 2.1' +__all__ = ('PasswordInputPlugin',) + +theme = get_theme(request=None, as_instance=True) + + +class PasswordInputPlugin(FormFieldPlugin): + """Password field plugin.""" + + uid = UID + name = _("Password") + group = _("Fields") + form = PasswordInputForm + + def get_form_field_instances(self, request=None, form_entry=None, + form_element_entries=None, **kwargs): + """Get form field instances.""" + widget_attrs = { + 'class': theme.form_element_html_class, + 'placeholder': self.data.placeholder, + } + + field_kwargs = { + 'label': self.data.label, + 'help_text': self.data.help_text, + 'initial': self.data.initial, + 'required': self.data.required, + 'widget': PasswordInput(attrs=widget_attrs), + } + if self.data.max_length: + field_kwargs['max_length'] = self.data.max_length + + return [(self.data.name, CharField, field_kwargs)] diff --git a/src/fobi/contrib/plugins/form_elements/fields/password/fobi_form_elements.py b/src/fobi/contrib/plugins/form_elements/fields/password/fobi_form_elements.py index 84cebb6a..39727b93 100644 --- a/src/fobi/contrib/plugins/form_elements/fields/password/fobi_form_elements.py +++ b/src/fobi/contrib/plugins/form_elements/fields/password/fobi_form_elements.py @@ -1,11 +1,8 @@ -from django.forms.fields import CharField -from django.forms.widgets import PasswordInput -from django.utils.translation import ugettext_lazy as _ +from __future__ import absolute_import -from fobi.base import FormFieldPlugin, form_element_plugin_registry, get_theme +from fobi.base import form_element_plugin_registry -from . import UID -from .forms import PasswordInputForm +from .base import PasswordInputPlugin __title__ = 'fobi.contrib.plugins.form_elements.fields.' \ 'password.fobi_form_elements' @@ -14,36 +11,5 @@ __copyright__ = '2014-2016 Artur Barseghyan' __license__ = 'GPL 2.0/LGPL 2.1' __all__ = ('PasswordInputPlugin',) -theme = get_theme(request=None, as_instance=True) - - -class PasswordInputPlugin(FormFieldPlugin): - """Password field plugin.""" - - uid = UID - name = _("Password") - group = _("Fields") - form = PasswordInputForm - - def get_form_field_instances(self, request=None, form_entry=None, - form_element_entries=None, **kwargs): - """Get form field instances.""" - widget_attrs = { - 'class': theme.form_element_html_class, - 'placeholder': self.data.placeholder, - } - - field_kwargs = { - 'label': self.data.label, - 'help_text': self.data.help_text, - 'initial': self.data.initial, - 'required': self.data.required, - 'widget': PasswordInput(attrs=widget_attrs), - } - if self.data.max_length: - field_kwargs['max_length'] = self.data.max_length - - return [(self.data.name, CharField, field_kwargs)] - form_element_plugin_registry.register(PasswordInputPlugin) diff --git a/src/fobi/contrib/plugins/form_elements/fields/radio/base.py b/src/fobi/contrib/plugins/form_elements/fields/radio/base.py new file mode 100644 index 00000000..4579fce2 --- /dev/null +++ b/src/fobi/contrib/plugins/form_elements/fields/radio/base.py @@ -0,0 +1,88 @@ +from __future__ import absolute_import + +from django.forms.fields import ChoiceField +from django.forms.widgets import RadioSelect +from django.utils.translation import ugettext_lazy as _ + +from fobi.base import FormFieldPlugin, get_theme +from fobi.constants import ( + SUBMIT_VALUE_AS_VAL, + SUBMIT_VALUE_AS_REPR +) +from fobi.helpers import get_select_field_choices, safe_text + +from . import UID +from .forms import RadioInputForm +from .settings import SUBMIT_VALUE_AS + +__title__ = 'fobi.contrib.plugins.form_elements.fields.radio.base' +__author__ = 'Artur Barseghyan ' +__copyright__ = '2014-2016 Artur Barseghyan' +__license__ = 'GPL 2.0/LGPL 2.1' +__all__ = ('RadioInputPlugin',) + +theme = get_theme(request=None, as_instance=True) + + +class RadioInputPlugin(FormFieldPlugin): + """Radio field plugin.""" + + uid = UID + name = _("Radio") + group = _("Fields") + form = RadioInputForm + + def get_form_field_instances(self, request=None, form_entry=None, + form_element_entries=None, **kwargs): + """Get form field instances.""" + choices = get_select_field_choices(self.data.choices) + + widget_attrs = {'class': theme.form_radio_element_html_class} + field_kwargs = { + 'label': self.data.label, + 'help_text': self.data.help_text, + 'initial': self.data.initial, + 'required': self.data.required, + 'choices': choices, + 'widget': RadioSelect(attrs=widget_attrs), + } + + return [(self.data.name, ChoiceField, field_kwargs)] + + def submit_plugin_form_data(self, form_entry, request, form, + form_element_entries=None, **kwargs): + """Submit plugin form data/process. + + :param fobi.models.FormEntry form_entry: Instance of + ``fobi.models.FormEntry``. + :param django.http.HttpRequest request: + :param django.forms.Form form: + """ + # In case if we should submit value as is, we don't return anything. + # In other cases, we proceed further. + if SUBMIT_VALUE_AS != SUBMIT_VALUE_AS_VAL: + # Get the object + value = form.cleaned_data.get(self.data.name, None) + + # Get choices + choices = dict(get_select_field_choices(self.data.choices)) + + if value in choices: + # Handle the submitted form value + + label = safe_text(choices.get(value)) + + # Should be returned as repr + if SUBMIT_VALUE_AS == SUBMIT_VALUE_AS_REPR: + value = label + # Should be returned as mix + else: + value = "{0} ({1})".format(label, value) + + # Overwrite ``cleaned_data`` of the ``form`` with object + # qualifier. + form.cleaned_data[self.data.name] = value + + # It's critically important to return the ``form`` with updated + # ``cleaned_data`` + return form diff --git a/src/fobi/contrib/plugins/form_elements/fields/radio/fobi_form_elements.py b/src/fobi/contrib/plugins/form_elements/fields/radio/fobi_form_elements.py index 96d57032..854dfd2e 100644 --- a/src/fobi/contrib/plugins/form_elements/fields/radio/fobi_form_elements.py +++ b/src/fobi/contrib/plugins/form_elements/fields/radio/fobi_form_elements.py @@ -1,16 +1,8 @@ -from django.forms.fields import ChoiceField -from django.forms.widgets import RadioSelect -from django.utils.translation import ugettext_lazy as _ +from __future__ import absolute_import -from fobi.base import FormFieldPlugin, form_element_plugin_registry, get_theme -from fobi.constants import ( - SUBMIT_VALUE_AS_VAL, SUBMIT_VALUE_AS_REPR -) -from fobi.helpers import get_select_field_choices, safe_text +from fobi.base import form_element_plugin_registry -from . import UID -from .forms import RadioInputForm -from .settings import SUBMIT_VALUE_AS +from .base import RadioInputPlugin __title__ = 'fobi.contrib.plugins.form_elements.fields.' \ 'radio.fobi_form_elements' @@ -19,70 +11,5 @@ __copyright__ = '2014-2016 Artur Barseghyan' __license__ = 'GPL 2.0/LGPL 2.1' __all__ = ('RadioInputPlugin',) -theme = get_theme(request=None, as_instance=True) - - -class RadioInputPlugin(FormFieldPlugin): - """Radio field plugin.""" - - uid = UID - name = _("Radio") - group = _("Fields") - form = RadioInputForm - - def get_form_field_instances(self, request=None, form_entry=None, - form_element_entries=None, **kwargs): - """Get form field instances.""" - choices = get_select_field_choices(self.data.choices) - - widget_attrs = {'class': theme.form_radio_element_html_class} - field_kwargs = { - 'label': self.data.label, - 'help_text': self.data.help_text, - 'initial': self.data.initial, - 'required': self.data.required, - 'choices': choices, - 'widget': RadioSelect(attrs=widget_attrs), - } - - return [(self.data.name, ChoiceField, field_kwargs)] - - def submit_plugin_form_data(self, form_entry, request, form): - """Submit plugin form data/process. - - :param fobi.models.FormEntry form_entry: Instance of - ``fobi.models.FormEntry``. - :param django.http.HttpRequest request: - :param django.forms.Form form: - """ - # In case if we should submit value as is, we don't return anything. - # In other cases, we proceed further. - if SUBMIT_VALUE_AS != SUBMIT_VALUE_AS_VAL: - # Get the object - value = form.cleaned_data.get(self.data.name, None) - - # Get choices - choices = dict(get_select_field_choices(self.data.choices)) - - if value in choices: - # Handle the submitted form value - - label = safe_text(choices.get(value)) - - # Should be returned as repr - if SUBMIT_VALUE_AS == SUBMIT_VALUE_AS_REPR: - value = label - # Should be returned as mix - else: - value = "{0} ({1})".format(label, value) - - # Overwrite ``cleaned_data`` of the ``form`` with object - # qualifier. - form.cleaned_data[self.data.name] = value - - # It's critically important to return the ``form`` with updated - # ``cleaned_data`` - return form - form_element_plugin_registry.register(RadioInputPlugin) diff --git a/src/fobi/contrib/plugins/form_elements/fields/range_select/base.py b/src/fobi/contrib/plugins/form_elements/fields/range_select/base.py new file mode 100644 index 00000000..9114ccce --- /dev/null +++ b/src/fobi/contrib/plugins/form_elements/fields/range_select/base.py @@ -0,0 +1,61 @@ +from __future__ import absolute_import + +from django.forms.fields import ChoiceField +from django.forms.widgets import Select +from django.utils.translation import ugettext_lazy as _ + +from fobi.base import FormFieldPlugin, get_theme + +from . import UID +from .forms import RangeSelectInputForm +from .settings import ( + INITIAL, + INITIAL_MAX_VALUE, + INITIAL_MIN_VALUE, + # MAX_VALUE, + # MIN_VALUE, + STEP +) + +__title__ = 'fobi.contrib.plugins.form_elements.fields.range_select.base' +__author__ = 'Artur Barseghyan ' +__copyright__ = '2014-2016 Artur Barseghyan' +__license__ = 'GPL 2.0/LGPL 2.1' +__all__ = ('RangeSelectInputPlugin',) + +theme = get_theme(request=None, as_instance=True) + + +class RangeSelectInputPlugin(FormFieldPlugin): + """Range select input plugin.""" + + uid = UID + name = _("Range select") + group = _("Fields") + form = RangeSelectInputForm + + def get_form_field_instances(self, request=None, form_entry=None, + form_element_entries=None, **kwargs): + """Get form field instances.""" + initial = self.data.initial if self.data.initial else INITIAL + max_value = self.data.max_value \ + if self.data.max_value \ + else INITIAL_MAX_VALUE + min_value = self.data.min_value \ + if self.data.min_value \ + else INITIAL_MIN_VALUE + step = self.data.step if self.data.step else STEP + + _choices = range(min_value, max_value+1, step) + choices = zip(_choices, _choices) + + field_kwargs = { + 'label': self.data.label, + 'help_text': self.data.help_text, + 'initial': initial, + 'required': self.data.required, + 'choices': choices, + 'widget': Select(attrs={'class': theme.form_element_html_class}), + } + + return [(self.data.name, ChoiceField, field_kwargs)] diff --git a/src/fobi/contrib/plugins/form_elements/fields/range_select/fobi_form_elements.py b/src/fobi/contrib/plugins/form_elements/fields/range_select/fobi_form_elements.py index 84a8966e..36718e20 100644 --- a/src/fobi/contrib/plugins/form_elements/fields/range_select/fobi_form_elements.py +++ b/src/fobi/contrib/plugins/form_elements/fields/range_select/fobi_form_elements.py @@ -1,19 +1,8 @@ -from django.forms.fields import ChoiceField -from django.forms.widgets import Select -from django.utils.translation import ugettext_lazy as _ +from __future__ import absolute_import -from fobi.base import FormFieldPlugin, form_element_plugin_registry, get_theme +from fobi.base import form_element_plugin_registry -from . import UID -from .forms import RangeSelectInputForm -from .settings import ( - INITIAL, - INITIAL_MAX_VALUE, - INITIAL_MIN_VALUE, - # MAX_VALUE, - # MIN_VALUE, - STEP -) +from .base import RangeSelectInputPlugin __title__ = 'fobi.contrib.plugins.form_elements.fields.range_select.' \ 'fobi_form_elements' @@ -22,42 +11,5 @@ __copyright__ = '2014-2016 Artur Barseghyan' __license__ = 'GPL 2.0/LGPL 2.1' __all__ = ('RangeSelectInputPlugin',) -theme = get_theme(request=None, as_instance=True) - - -class RangeSelectInputPlugin(FormFieldPlugin): - """Range select input plugin.""" - - uid = UID - name = _("Range select") - group = _("Fields") - form = RangeSelectInputForm - - def get_form_field_instances(self, request=None, form_entry=None, - form_element_entries=None, **kwargs): - """Get form field instances.""" - initial = self.data.initial if self.data.initial else INITIAL - max_value = self.data.max_value \ - if self.data.max_value \ - else INITIAL_MAX_VALUE - min_value = self.data.min_value \ - if self.data.min_value \ - else INITIAL_MIN_VALUE - step = self.data.step if self.data.step else STEP - - _choices = range(min_value, max_value+1, step) - choices = zip(_choices, _choices) - - field_kwargs = { - 'label': self.data.label, - 'help_text': self.data.help_text, - 'initial': initial, - 'required': self.data.required, - 'choices': choices, - 'widget': Select(attrs={'class': theme.form_element_html_class}), - } - - return [(self.data.name, ChoiceField, field_kwargs)] - form_element_plugin_registry.register(RangeSelectInputPlugin) diff --git a/src/fobi/contrib/plugins/form_elements/fields/regex/base.py b/src/fobi/contrib/plugins/form_elements/fields/regex/base.py new file mode 100644 index 00000000..03e16db2 --- /dev/null +++ b/src/fobi/contrib/plugins/form_elements/fields/regex/base.py @@ -0,0 +1,49 @@ +from __future__ import absolute_import + +from django.forms.fields import RegexField +from django.forms.widgets import TextInput +from django.utils.translation import ugettext_lazy as _ + +from fobi.base import FormFieldPlugin, get_theme + +from . import UID +from .forms import RegexInputForm + +__title__ = 'fobi.contrib.plugins.form_elements.fields.regex.base' +__author__ = 'Artur Barseghyan ' +__copyright__ = '2014-2016 Artur Barseghyan' +__license__ = 'GPL 2.0/LGPL 2.1' +__all__ = ('RegexInputPlugin',) + +theme = get_theme(request=None, as_instance=True) + + +class RegexInputPlugin(FormFieldPlugin): + """Regex field plugin.""" + + uid = UID + name = _("Regex") + group = _("Fields") + form = RegexInputForm + + def get_form_field_instances(self, request=None, form_entry=None, + form_element_entries=None, **kwargs): + """Get form field instances.""" + widget_attrs = { + 'class': theme.form_element_html_class, + 'placeholder': self.data.placeholder, + } + + field_kwargs = { + 'label': self.data.label, + 'help_text': self.data.help_text, + 'regex': self.data.regex, + 'initial': self.data.initial, + 'required': self.data.required, + 'widget': TextInput(attrs=widget_attrs), + } + + if self.data.max_length: + field_kwargs['max_length'] = self.data.max_length + + return [(self.data.name, RegexField, field_kwargs)] diff --git a/src/fobi/contrib/plugins/form_elements/fields/regex/fobi_form_elements.py b/src/fobi/contrib/plugins/form_elements/fields/regex/fobi_form_elements.py index 4f281f4c..69ef11c9 100644 --- a/src/fobi/contrib/plugins/form_elements/fields/regex/fobi_form_elements.py +++ b/src/fobi/contrib/plugins/form_elements/fields/regex/fobi_form_elements.py @@ -1,13 +1,8 @@ from __future__ import absolute_import -from django.forms.fields import RegexField -from django.forms.widgets import TextInput -from django.utils.translation import ugettext_lazy as _ +from fobi.base import form_element_plugin_registry -from fobi.base import FormFieldPlugin, form_element_plugin_registry, get_theme - -from . import UID -from .forms import RegexInputForm +from .base import RegexInputPlugin __title__ = 'fobi.contrib.plugins.form_elements.fields.' \ 'regex.fobi_form_elements' @@ -16,38 +11,5 @@ __copyright__ = '2014-2016 Artur Barseghyan' __license__ = 'GPL 2.0/LGPL 2.1' __all__ = ('RegexInputPlugin',) -theme = get_theme(request=None, as_instance=True) - - -class RegexInputPlugin(FormFieldPlugin): - """Regex field plugin.""" - - uid = UID - name = _("Regex") - group = _("Fields") - form = RegexInputForm - - def get_form_field_instances(self, request=None, form_entry=None, - form_element_entries=None, **kwargs): - """Get form field instances.""" - widget_attrs = { - 'class': theme.form_element_html_class, - 'placeholder': self.data.placeholder, - } - - field_kwargs = { - 'label': self.data.label, - 'help_text': self.data.help_text, - 'regex': self.data.regex, - 'initial': self.data.initial, - 'required': self.data.required, - 'widget': TextInput(attrs=widget_attrs), - } - - if self.data.max_length: - field_kwargs['max_length'] = self.data.max_length - - return [(self.data.name, RegexField, field_kwargs)] - form_element_plugin_registry.register(RegexInputPlugin) diff --git a/src/fobi/contrib/plugins/form_elements/fields/regex/forms.py b/src/fobi/contrib/plugins/form_elements/fields/regex/forms.py index 85ad6be0..38e3829e 100644 --- a/src/fobi/contrib/plugins/form_elements/fields/regex/forms.py +++ b/src/fobi/contrib/plugins/form_elements/fields/regex/forms.py @@ -100,6 +100,7 @@ class RegexInputForm(forms.Form, BaseFormFieldPluginForm): ) def clean(self): + """Validation.""" super(RegexInputForm, self).clean() max_length = self.cleaned_data.get('max_length', DEFAULT_MAX_LENGTH) @@ -111,4 +112,4 @@ class RegexInputForm(forms.Form, BaseFormFieldPluginForm): 'initial', _("Ensure this value has at most {0} characters " "(it has {1}).".format(max_length, len_initial)) - ) \ No newline at end of file + ) diff --git a/src/fobi/contrib/plugins/form_elements/fields/select/base.py b/src/fobi/contrib/plugins/form_elements/fields/select/base.py new file mode 100644 index 00000000..1380a097 --- /dev/null +++ b/src/fobi/contrib/plugins/form_elements/fields/select/base.py @@ -0,0 +1,87 @@ +from __future__ import absolute_import + +from django.forms.fields import ChoiceField +from django.forms.widgets import Select +from django.utils.translation import ugettext_lazy as _ + +from fobi.base import FormFieldPlugin, get_theme +from fobi.constants import ( + SUBMIT_VALUE_AS_VAL, + SUBMIT_VALUE_AS_REPR +) +from fobi.helpers import get_select_field_choices, safe_text + +from . import UID +from .forms import SelectInputForm +from .settings import SUBMIT_VALUE_AS + +__title__ = 'fobi.contrib.plugins.form_elements.fields.select.base' +__author__ = 'Artur Barseghyan ' +__copyright__ = '2014-2016 Artur Barseghyan' +__license__ = 'GPL 2.0/LGPL 2.1' +__all__ = ('SelectInputPlugin',) + +theme = get_theme(request=None, as_instance=True) + + +class SelectInputPlugin(FormFieldPlugin): + """Select field plugin.""" + + uid = UID + name = _("Select") + group = _("Fields") + form = SelectInputForm + + def get_form_field_instances(self, request=None, form_entry=None, + form_element_entries=None, **kwargs): + """Get form field instances.""" + choices = get_select_field_choices(self.data.choices) + + field_kwargs = { + 'label': self.data.label, + 'help_text': self.data.help_text, + 'initial': self.data.initial, + 'required': self.data.required, + 'choices': choices, + 'widget': Select(attrs={'class': theme.form_element_html_class}), + } + + return [(self.data.name, ChoiceField, field_kwargs)] + + def submit_plugin_form_data(self, form_entry, request, form, + form_element_entries=None, **kwargs): + """Submit plugin form data/process. + + :param fobi.models.FormEntry form_entry: Instance of + ``fobi.models.FormEntry``. + :param django.http.HttpRequest request: + :param django.forms.Form form: + """ + # In case if we should submit value as is, we don't return anything. + # In other cases, we proceed further. + if SUBMIT_VALUE_AS != SUBMIT_VALUE_AS_VAL: + # Get the object + value = form.cleaned_data.get(self.data.name, None) + + # Get choices + choices = dict(get_select_field_choices(self.data.choices)) + + if value in choices: + # Handle the submitted form value + + label = safe_text(choices.get(value)) + + # Should be returned as repr + if SUBMIT_VALUE_AS == SUBMIT_VALUE_AS_REPR: + value = label + # Should be returned as mix + else: + value = "{0} ({1})".format(label, value) + + # Overwrite ``cleaned_data`` of the ``form`` with object + # qualifier. + form.cleaned_data[self.data.name] = value + + # It's critically important to return the ``form`` with + # updated ``cleaned_data`` + return form diff --git a/src/fobi/contrib/plugins/form_elements/fields/select/fobi_form_elements.py b/src/fobi/contrib/plugins/form_elements/fields/select/fobi_form_elements.py index c0f77614..0db1d61f 100644 --- a/src/fobi/contrib/plugins/form_elements/fields/select/fobi_form_elements.py +++ b/src/fobi/contrib/plugins/form_elements/fields/select/fobi_form_elements.py @@ -1,16 +1,8 @@ -from django.forms.fields import ChoiceField -from django.forms.widgets import Select -from django.utils.translation import ugettext_lazy as _ +from __future__ import absolute_import -from fobi.base import FormFieldPlugin, form_element_plugin_registry, get_theme -from fobi.constants import ( - SUBMIT_VALUE_AS_VAL, SUBMIT_VALUE_AS_REPR -) -from fobi.helpers import get_select_field_choices, safe_text +from fobi.base import form_element_plugin_registry -from . import UID -from .forms import SelectInputForm -from .settings import SUBMIT_VALUE_AS +from .base import SelectInputPlugin __title__ = 'fobi.contrib.plugins.form_elements.fields.' \ 'select.fobi_form_elements' @@ -19,69 +11,5 @@ __copyright__ = '2014-2016 Artur Barseghyan' __license__ = 'GPL 2.0/LGPL 2.1' __all__ = ('SelectInputPlugin',) -theme = get_theme(request=None, as_instance=True) - - -class SelectInputPlugin(FormFieldPlugin): - """Select field plugin.""" - - uid = UID - name = _("Select") - group = _("Fields") - form = SelectInputForm - - def get_form_field_instances(self, request=None, form_entry=None, - form_element_entries=None, **kwargs): - """Get form field instances.""" - choices = get_select_field_choices(self.data.choices) - - field_kwargs = { - 'label': self.data.label, - 'help_text': self.data.help_text, - 'initial': self.data.initial, - 'required': self.data.required, - 'choices': choices, - 'widget': Select(attrs={'class': theme.form_element_html_class}), - } - - return [(self.data.name, ChoiceField, field_kwargs)] - - def submit_plugin_form_data(self, form_entry, request, form): - """Submit plugin form data/process. - - :param fobi.models.FormEntry form_entry: Instance of - ``fobi.models.FormEntry``. - :param django.http.HttpRequest request: - :param django.forms.Form form: - """ - # In case if we should submit value as is, we don't return anything. - # In other cases, we proceed further. - if SUBMIT_VALUE_AS != SUBMIT_VALUE_AS_VAL: - # Get the object - value = form.cleaned_data.get(self.data.name, None) - - # Get choices - choices = dict(get_select_field_choices(self.data.choices)) - - if value in choices: - # Handle the submitted form value - - label = safe_text(choices.get(value)) - - # Should be returned as repr - if SUBMIT_VALUE_AS == SUBMIT_VALUE_AS_REPR: - value = label - # Should be returned as mix - else: - value = "{0} ({1})".format(label, value) - - # Overwrite ``cleaned_data`` of the ``form`` with object - # qualifier. - form.cleaned_data[self.data.name] = value - - # It's critically important to return the ``form`` with - # updated ``cleaned_data`` - return form - form_element_plugin_registry.register(SelectInputPlugin) diff --git a/src/fobi/contrib/plugins/form_elements/fields/select_model_object/base.py b/src/fobi/contrib/plugins/form_elements/fields/select_model_object/base.py new file mode 100644 index 00000000..76230d20 --- /dev/null +++ b/src/fobi/contrib/plugins/form_elements/fields/select_model_object/base.py @@ -0,0 +1,107 @@ +from __future__ import absolute_import + +from django.forms.models import ModelChoiceField +from django.forms.widgets import Select +from django.utils.translation import ugettext_lazy as _ + +from nine.versions import DJANGO_GTE_1_7 + +from fobi.base import FormFieldPlugin, get_theme +from fobi.constants import ( + SUBMIT_VALUE_AS_VAL, + SUBMIT_VALUE_AS_REPR +) +from fobi.helpers import ( + safe_text, + get_app_label_and_model_name, + get_model_name_for_object +) + +from . import UID +from .forms import SelectModelObjectInputForm +from .settings import SUBMIT_VALUE_AS + +if DJANGO_GTE_1_7: + from django.apps import apps + + get_model = apps.get_model +else: + from django.db.models import get_model + +__title__ = 'fobi.contrib.plugins.form_elements.fields.' \ + 'select_model_object.base' +__author__ = 'Artur Barseghyan ' +__copyright__ = '2014-2016 Artur Barseghyan' +__license__ = 'GPL 2.0/LGPL 2.1' +__all__ = ('SelectModelObjectInputPlugin',) + +theme = get_theme(request=None, as_instance=True) + + +class SelectModelObjectInputPlugin(FormFieldPlugin): + """Select model object field plugin.""" + + uid = UID + name = _("Select model object") + group = _("Fields") + form = SelectModelObjectInputForm + + def get_form_field_instances(self, request=None, form_entry=None, + form_element_entries=None, **kwargs): + """Get form field instances.""" + app_label, model_name = get_app_label_and_model_name(self.data.model) + model = get_model(app_label, model_name) + queryset = model._default_manager.all() + + field_kwargs = { + 'label': self.data.label, + 'help_text': self.data.help_text, + 'initial': self.data.initial, + 'required': self.data.required, + 'queryset': queryset, + 'widget': Select(attrs={'class': theme.form_element_html_class}), + } + + return [(self.data.name, ModelChoiceField, field_kwargs)] + + def submit_plugin_form_data(self, form_entry, request, form, + form_element_entries=None, **kwargs): + """Submit plugin form data/process. + + :param fobi.models.FormEntry form_entry: Instance of + ``fobi.models.FormEntry``. + :param django.http.HttpRequest request: + :param django.forms.Form form: + """ + # In case if we should submit value as is, we don't return anything. + # In other cases, we proceed further. + + # Get the object + obj = form.cleaned_data.get(self.data.name, None) + if obj: + value = None + # Should be returned as repr + if SUBMIT_VALUE_AS == SUBMIT_VALUE_AS_REPR: + value = safe_text(obj) + elif SUBMIT_VALUE_AS == SUBMIT_VALUE_AS_VAL: + value = '{0}.{1}.{2}'.format( + obj._meta.app_label, + get_model_name_for_object(obj), + obj.pk + ) + else: + # Handle the submitted form value + value = '{0}.{1}.{2}.{3}'.format( + obj._meta.app_label, + get_model_name_for_object(obj), + obj.pk, + safe_text(obj) + ) + + # Overwrite ``cleaned_data`` of the ``form`` with object + # qualifier. + form.cleaned_data[self.data.name] = value + + # It's critically important to return the ``form`` with updated + # ``cleaned_data`` + return form diff --git a/src/fobi/contrib/plugins/form_elements/fields/select_model_object/fobi_form_elements.py b/src/fobi/contrib/plugins/form_elements/fields/select_model_object/fobi_form_elements.py index b24bf424..d0ac88e5 100644 --- a/src/fobi/contrib/plugins/form_elements/fields/select_model_object/fobi_form_elements.py +++ b/src/fobi/contrib/plugins/form_elements/fields/select_model_object/fobi_form_elements.py @@ -1,29 +1,8 @@ -from django.forms.models import ModelChoiceField -from django.forms.widgets import Select -from django.utils.translation import ugettext_lazy as _ +from __future__ import absolute_import -from nine.versions import DJANGO_GTE_1_7 +from fobi.base import form_element_plugin_registry -from fobi.base import FormFieldPlugin, form_element_plugin_registry, get_theme -from fobi.constants import ( - SUBMIT_VALUE_AS_VAL, SUBMIT_VALUE_AS_REPR -) -from fobi.helpers import ( - safe_text, - get_app_label_and_model_name, - get_model_name_for_object -) - -from . import UID -from .forms import SelectModelObjectInputForm -from .settings import SUBMIT_VALUE_AS - -if DJANGO_GTE_1_7: - from django.apps import apps - - get_model = apps.get_model -else: - from django.db.models import get_model +from .base import SelectModelObjectInputPlugin __title__ = 'fobi.contrib.plugins.form_elements.fields.' \ 'select_model_object.fobi_form_elements' @@ -32,75 +11,5 @@ __copyright__ = '2014-2016 Artur Barseghyan' __license__ = 'GPL 2.0/LGPL 2.1' __all__ = ('SelectModelObjectInputPlugin',) -theme = get_theme(request=None, as_instance=True) - - -class SelectModelObjectInputPlugin(FormFieldPlugin): - """Select model object field plugin.""" - - uid = UID - name = _("Select model object") - group = _("Fields") - form = SelectModelObjectInputForm - - def get_form_field_instances(self, request=None, form_entry=None, - form_element_entries=None, **kwargs): - """Get form field instances.""" - app_label, model_name = get_app_label_and_model_name(self.data.model) - model = get_model(app_label, model_name) - queryset = model._default_manager.all() - - field_kwargs = { - 'label': self.data.label, - 'help_text': self.data.help_text, - 'initial': self.data.initial, - 'required': self.data.required, - 'queryset': queryset, - 'widget': Select(attrs={'class': theme.form_element_html_class}), - } - - return [(self.data.name, ModelChoiceField, field_kwargs)] - - def submit_plugin_form_data(self, form_entry, request, form): - """Submit plugin form data/process. - - :param fobi.models.FormEntry form_entry: Instance of - ``fobi.models.FormEntry``. - :param django.http.HttpRequest request: - :param django.forms.Form form: - """ - # In case if we should submit value as is, we don't return anything. - # In other cases, we proceed further. - - # Get the object - obj = form.cleaned_data.get(self.data.name, None) - if obj: - value = None - # Should be returned as repr - if SUBMIT_VALUE_AS == SUBMIT_VALUE_AS_REPR: - value = safe_text(obj) - elif SUBMIT_VALUE_AS == SUBMIT_VALUE_AS_VAL: - value = '{0}.{1}.{2}'.format( - obj._meta.app_label, - get_model_name_for_object(obj), - obj.pk - ) - else: - # Handle the submitted form value - value = '{0}.{1}.{2}.{3}'.format( - obj._meta.app_label, - get_model_name_for_object(obj), - obj.pk, - safe_text(obj) - ) - - # Overwrite ``cleaned_data`` of the ``form`` with object - # qualifier. - form.cleaned_data[self.data.name] = value - - # It's critically important to return the ``form`` with updated - # ``cleaned_data`` - return form - form_element_plugin_registry.register(SelectModelObjectInputPlugin) diff --git a/src/fobi/contrib/plugins/form_elements/fields/select_mptt_model_object/base.py b/src/fobi/contrib/plugins/form_elements/fields/select_mptt_model_object/base.py new file mode 100644 index 00000000..01d77437 --- /dev/null +++ b/src/fobi/contrib/plugins/form_elements/fields/select_mptt_model_object/base.py @@ -0,0 +1,107 @@ +from __future__ import absolute_import + +from django.forms.widgets import Select +from django.utils.translation import ugettext_lazy as _ + +from mptt.fields import TreeNodeChoiceField + +from fobi.base import FormFieldPlugin, get_theme +from fobi.constants import ( + SUBMIT_VALUE_AS_VAL, + SUBMIT_VALUE_AS_REPR +) +from fobi.helpers import ( + safe_text, + get_app_label_and_model_name, + get_model_name_for_object +) + +from nine.versions import DJANGO_GTE_1_7 + +from . import UID +from .forms import SelectMPTTModelObjectInputForm +from .settings import SUBMIT_VALUE_AS + +if DJANGO_GTE_1_7: + from django.apps import apps + + get_model = apps.get_model +else: + from django.db.models import get_model + +__title__ = 'fobi.contrib.plugins.form_elements.fields.' \ + 'select_mptt_model_object.base' +__author__ = 'Artur Barseghyan ' +__copyright__ = '2014-2016 Artur Barseghyan' +__license__ = 'GPL 2.0/LGPL 2.1' +__all__ = ('SelectMPTTModelObjectInputPlugin',) + +theme = get_theme(request=None, as_instance=True) + + +class SelectMPTTModelObjectInputPlugin(FormFieldPlugin): + """Select MPTT model object field plugin.""" + + uid = UID + name = _("Select MPTT model object") + group = _("Fields") + form = SelectMPTTModelObjectInputForm + + def get_form_field_instances(self, request=None, form_entry=None, + form_element_entries=None, **kwargs): + """Get form field instances.""" + app_label, model_name = get_app_label_and_model_name(self.data.model) + model = get_model(app_label, model_name) + queryset = model._default_manager.all() + + field_kwargs = { + 'label': self.data.label, + 'help_text': self.data.help_text, + 'initial': self.data.initial, + 'required': self.data.required, + 'queryset': queryset, + 'widget': Select(attrs={'class': theme.form_element_html_class}), + } + + return [(self.data.name, TreeNodeChoiceField, field_kwargs)] + + def submit_plugin_form_data(self, form_entry, request, form, + form_element_entries=None, **kwargs): + """Submit plugin form data/process. + + :param fobi.models.FormEntry form_entry: Instance of + ``fobi.models.FormEntry``. + :param django.http.HttpRequest request: + :param django.forms.Form form: + """ + # In case if we should submit value as is, we don't return anything. + # In other cases, we proceed further. + + # Get the object + obj = form.cleaned_data.get(self.data.name, None) + if obj: + value = None + # Should be returned as repr + if SUBMIT_VALUE_AS == SUBMIT_VALUE_AS_REPR: + value = safe_text(obj) + elif SUBMIT_VALUE_AS == SUBMIT_VALUE_AS_VAL: + value = '{0}.{1}.{2}'.format( + obj._meta.app_label, + get_model_name_for_object(obj), + obj.pk + ) + else: + # Handle the submitted form value + value = '{0}.{1}.{2}.{3}'.format( + obj._meta.app_label, + get_model_name_for_object(obj), + obj.pk, + safe_text(obj) + ) + + # Overwrite ``cleaned_data`` of the ``form`` with object qualifier. + form.cleaned_data[self.data.name] = value + + # It's critically important to return the ``form`` with updated + # ``cleaned_data`` + return form diff --git a/src/fobi/contrib/plugins/form_elements/fields/select_mptt_model_object/fobi_form_elements.py b/src/fobi/contrib/plugins/form_elements/fields/select_mptt_model_object/fobi_form_elements.py index 033367df..76d740b7 100644 --- a/src/fobi/contrib/plugins/form_elements/fields/select_mptt_model_object/fobi_form_elements.py +++ b/src/fobi/contrib/plugins/form_elements/fields/select_mptt_model_object/fobi_form_elements.py @@ -1,30 +1,8 @@ -from django.forms.widgets import Select -from django.utils.translation import ugettext_lazy as _ +from __future__ import absolute_import -from mptt.fields import TreeNodeChoiceField +from fobi.base import form_element_plugin_registry -from fobi.base import FormFieldPlugin, form_element_plugin_registry, get_theme -from fobi.constants import ( - SUBMIT_VALUE_AS_VAL, SUBMIT_VALUE_AS_REPR -) -from fobi.helpers import ( - safe_text, - get_app_label_and_model_name, - get_model_name_for_object -) - -from nine.versions import DJANGO_GTE_1_7 - -from . import UID -from .forms import SelectMPTTModelObjectInputForm -from .settings import SUBMIT_VALUE_AS - -if DJANGO_GTE_1_7: - from django.apps import apps - - get_model = apps.get_model -else: - from django.db.models import get_model +from .base import SelectMPTTModelObjectInputPlugin __title__ = 'fobi.contrib.plugins.form_elements.fields.' \ 'select_mptt_model_object.fobi_form_elements' @@ -33,74 +11,5 @@ __copyright__ = '2014-2016 Artur Barseghyan' __license__ = 'GPL 2.0/LGPL 2.1' __all__ = ('SelectMPTTModelObjectInputPlugin',) -theme = get_theme(request=None, as_instance=True) - - -class SelectMPTTModelObjectInputPlugin(FormFieldPlugin): - """Select MPTT model object field plugin.""" - - uid = UID - name = _("Select MPTT model object") - group = _("Fields") - form = SelectMPTTModelObjectInputForm - - def get_form_field_instances(self, request=None, form_entry=None, - form_element_entries=None, **kwargs): - """Get form field instances.""" - app_label, model_name = get_app_label_and_model_name(self.data.model) - model = get_model(app_label, model_name) - queryset = model._default_manager.all() - - field_kwargs = { - 'label': self.data.label, - 'help_text': self.data.help_text, - 'initial': self.data.initial, - 'required': self.data.required, - 'queryset': queryset, - 'widget': Select(attrs={'class': theme.form_element_html_class}), - } - - return [(self.data.name, TreeNodeChoiceField, field_kwargs)] - - def submit_plugin_form_data(self, form_entry, request, form): - """Submit plugin form data/process. - - :param fobi.models.FormEntry form_entry: Instance of - ``fobi.models.FormEntry``. - :param django.http.HttpRequest request: - :param django.forms.Form form: - """ - # In case if we should submit value as is, we don't return anything. - # In other cases, we proceed further. - - # Get the object - obj = form.cleaned_data.get(self.data.name, None) - if obj: - value = None - # Should be returned as repr - if SUBMIT_VALUE_AS == SUBMIT_VALUE_AS_REPR: - value = safe_text(obj) - elif SUBMIT_VALUE_AS == SUBMIT_VALUE_AS_VAL: - value = '{0}.{1}.{2}'.format( - obj._meta.app_label, - get_model_name_for_object(obj), - obj.pk - ) - else: - # Handle the submitted form value - value = '{0}.{1}.{2}.{3}'.format( - obj._meta.app_label, - get_model_name_for_object(obj), - obj.pk, - safe_text(obj) - ) - - # Overwrite ``cleaned_data`` of the ``form`` with object qualifier. - form.cleaned_data[self.data.name] = value - - # It's critically important to return the ``form`` with updated - # ``cleaned_data`` - return form - form_element_plugin_registry.register(SelectMPTTModelObjectInputPlugin) diff --git a/src/fobi/contrib/plugins/form_elements/fields/select_multiple/base.py b/src/fobi/contrib/plugins/form_elements/fields/select_multiple/base.py new file mode 100644 index 00000000..1a977691 --- /dev/null +++ b/src/fobi/contrib/plugins/form_elements/fields/select_multiple/base.py @@ -0,0 +1,98 @@ +from __future__ import absolute_import + +from django.forms.fields import MultipleChoiceField +from django.forms.widgets import SelectMultiple +from django.utils.translation import ugettext_lazy as _ + +from fobi.base import FormFieldPlugin, get_theme +from fobi.constants import ( + SUBMIT_VALUE_AS_VAL, + SUBMIT_VALUE_AS_REPR +) +from fobi.helpers import get_select_field_choices, safe_text + +from . import UID +from .forms import SelectMultipleInputForm +from .settings import SUBMIT_VALUE_AS + +__title__ = 'fobi.contrib.plugins.form_elements.fields.' \ + 'select_multiple.base' +__author__ = 'Artur Barseghyan ' +__copyright__ = '2014-2016 Artur Barseghyan' +__license__ = 'GPL 2.0/LGPL 2.1' +__all__ = ('SelectMultipleInputPlugin',) + +theme = get_theme(request=None, as_instance=True) + + +class SelectMultipleInputPlugin(FormFieldPlugin): + """Select multiple field plugin.""" + + uid = UID + name = _("Select multiple") + group = _("Fields") + form = SelectMultipleInputForm + + def get_form_field_instances(self, request=None, form_entry=None, + form_element_entries=None, **kwargs): + """Get form field instances.""" + choices = get_select_field_choices(self.data.choices) + + field_kwargs = { + 'label': self.data.label, + 'help_text': self.data.help_text, + 'initial': self.data.initial, + 'required': self.data.required, + 'choices': choices, + 'widget': SelectMultiple( + attrs={'class': theme.form_element_html_class} + ), + } + + return [(self.data.name, MultipleChoiceField, field_kwargs)] + + def submit_plugin_form_data(self, form_entry, request, form, + form_element_entries=None, **kwargs): + """ + Submit plugin form data/process. + + :param fobi.models.FormEntry form_entry: Instance of + ``fobi.models.FormEntry``. + :param django.http.HttpRequest request: + :param django.forms.Form form: + """ + # In case if we should submit value as is, we don't return anything. + # In other cases, we proceed further. + if SUBMIT_VALUE_AS != SUBMIT_VALUE_AS_VAL: + # Get the object + values = form.cleaned_data.get(self.data.name, None) + + # Get choices + choices = dict(get_select_field_choices(self.data.choices)) + + # Returned value + ret_values = [] + + for value in values: + # Handle the submitted form value + + if value in choices: + label = safe_text(choices.get(value)) + + # Should be returned as repr + if SUBMIT_VALUE_AS == SUBMIT_VALUE_AS_REPR: + value = label + # Should be returned as mix + else: + value = "{0} ({1})".format(label, value) + + ret_values.append(value) + + # Overwrite ``cleaned_data`` of the ``form`` with object + # qualifier. + if ret_values: + form.cleaned_data[self.data.name] = ret_values + + # It's critically important to return the ``form`` with updated + # ``cleaned_data`` + return form diff --git a/src/fobi/contrib/plugins/form_elements/fields/select_multiple/fobi_form_elements.py b/src/fobi/contrib/plugins/form_elements/fields/select_multiple/fobi_form_elements.py index b8e1f45d..af262108 100644 --- a/src/fobi/contrib/plugins/form_elements/fields/select_multiple/fobi_form_elements.py +++ b/src/fobi/contrib/plugins/form_elements/fields/select_multiple/fobi_form_elements.py @@ -1,16 +1,8 @@ -from django.forms.fields import MultipleChoiceField -from django.forms.widgets import SelectMultiple -from django.utils.translation import ugettext_lazy as _ +from __future__ import absolute_import -from fobi.base import FormFieldPlugin, form_element_plugin_registry, get_theme -from fobi.constants import ( - SUBMIT_VALUE_AS_VAL, SUBMIT_VALUE_AS_REPR -) -from fobi.helpers import get_select_field_choices, safe_text +from fobi.base import form_element_plugin_registry -from . import UID -from .forms import SelectMultipleInputForm -from .settings import SUBMIT_VALUE_AS +from .base import SelectMultipleInputPlugin __title__ = 'fobi.contrib.plugins.form_elements.fields.' \ 'select_multiple.fobi_form_elements' @@ -19,79 +11,5 @@ __copyright__ = '2014-2016 Artur Barseghyan' __license__ = 'GPL 2.0/LGPL 2.1' __all__ = ('SelectMultipleInputPlugin',) -theme = get_theme(request=None, as_instance=True) - - -class SelectMultipleInputPlugin(FormFieldPlugin): - """Select multiple field plugin.""" - - uid = UID - name = _("Select multiple") - group = _("Fields") - form = SelectMultipleInputForm - - def get_form_field_instances(self, request=None, form_entry=None, - form_element_entries=None, **kwargs): - """Get form field instances.""" - choices = get_select_field_choices(self.data.choices) - - field_kwargs = { - 'label': self.data.label, - 'help_text': self.data.help_text, - 'initial': self.data.initial, - 'required': self.data.required, - 'choices': choices, - 'widget': SelectMultiple( - attrs={'class': theme.form_element_html_class} - ), - } - - return [(self.data.name, MultipleChoiceField, field_kwargs)] - - def submit_plugin_form_data(self, form_entry, request, form): - """ - Submit plugin form data/process. - - :param fobi.models.FormEntry form_entry: Instance of - ``fobi.models.FormEntry``. - :param django.http.HttpRequest request: - :param django.forms.Form form: - """ - # In case if we should submit value as is, we don't return anything. - # In other cases, we proceed further. - if SUBMIT_VALUE_AS != SUBMIT_VALUE_AS_VAL: - # Get the object - values = form.cleaned_data.get(self.data.name, None) - - # Get choices - choices = dict(get_select_field_choices(self.data.choices)) - - # Returned value - ret_values = [] - - for value in values: - # Handle the submitted form value - - if value in choices: - label = safe_text(choices.get(value)) - - # Should be returned as repr - if SUBMIT_VALUE_AS == SUBMIT_VALUE_AS_REPR: - value = label - # Should be returned as mix - else: - value = "{0} ({1})".format(label, value) - - ret_values.append(value) - - # Overwrite ``cleaned_data`` of the ``form`` with object - # qualifier. - if ret_values: - form.cleaned_data[self.data.name] = ret_values - - # It's critically important to return the ``form`` with updated - # ``cleaned_data`` - return form - form_element_plugin_registry.register(SelectMultipleInputPlugin) diff --git a/src/fobi/contrib/plugins/form_elements/fields/select_multiple_model_objects/base.py b/src/fobi/contrib/plugins/form_elements/fields/select_multiple_model_objects/base.py new file mode 100644 index 00000000..24b714d0 --- /dev/null +++ b/src/fobi/contrib/plugins/form_elements/fields/select_multiple_model_objects/base.py @@ -0,0 +1,118 @@ +from __future__ import absolute_import + +import simplejson as json + +from django.forms.models import ModelMultipleChoiceField +from django.forms.widgets import SelectMultiple +from django.utils.translation import ugettext_lazy as _ + +from fobi.base import FormFieldPlugin, get_theme +from fobi.constants import ( + SUBMIT_VALUE_AS_VAL, + SUBMIT_VALUE_AS_REPR +) +from fobi.helpers import ( + safe_text, + get_app_label_and_model_name, + get_model_name_for_object +) + +from nine.versions import DJANGO_GTE_1_7 + +from . import UID +from .forms import SelectMultipleModelObjectsInputForm +from .settings import SUBMIT_VALUE_AS + +if DJANGO_GTE_1_7: + from django.apps import apps + get_model = apps.get_model +else: + from django.db.models import get_model + +__title__ = 'fobi.contrib.plugins.form_elements.fields.' \ + 'select_multiple_model_objects.fobi_form_elements' +__author__ = 'Artur Barseghyan ' +__copyright__ = '2014-2016 Artur Barseghyan' +__license__ = 'GPL 2.0/LGPL 2.1' +__all__ = ('SelectMultipleModelObjectsInputPlugin',) + +theme = get_theme(request=None, as_instance=True) + + +class SelectMultipleModelObjectsInputPlugin(FormFieldPlugin): + """Select multiple model objects field plugin.""" + + uid = UID + name = _("Select multiple model objects") + group = _("Fields") + form = SelectMultipleModelObjectsInputForm + + def get_form_field_instances(self, request=None, form_entry=None, + form_element_entries=None, **kwargs): + """Get form field instances.""" + app_label, model_name = get_app_label_and_model_name(self.data.model) + model = get_model(app_label, model_name) + queryset = model._default_manager.all() + + field_kwargs = { + 'label': self.data.label, + 'help_text': self.data.help_text, + 'initial': self.data.initial, + 'required': self.data.required, + 'queryset': queryset, + 'widget': SelectMultiple( + attrs={'class': theme.form_element_html_class} + ), + } + + return [(self.data.name, ModelMultipleChoiceField, field_kwargs)] + + def submit_plugin_form_data(self, form_entry, request, form, + form_element_entries=None, **kwargs): + """ + Submit plugin form data/process. + + :param fobi.models.FormEntry form_entry: Instance of + ``fobi.models.FormEntry``. + :param django.http.HttpRequest request: + :param django.forms.Form form: + """ + # In case if we should submit value as is, we don't return anything. + # In other cases, we proceed further. + + # Get the object + objs = form.cleaned_data.get(self.data.name, []) + + values = [] + + for obj in objs: + if obj: + value = None + # Should be returned as repr + if SUBMIT_VALUE_AS == SUBMIT_VALUE_AS_REPR: + value = safe_text(obj) + elif SUBMIT_VALUE_AS == SUBMIT_VALUE_AS_VAL: + value = '{0}.{1}.{2}'.format( + obj._meta.app_label, + get_model_name_for_object(obj), + obj.pk + ) + else: + # Handle the submitted form value + value = '{0}.{1}.{2}.{3}'.format( + obj._meta.app_label, + get_model_name_for_object(obj), + obj.pk, + safe_text(obj) + ) + values.append(value) + + # Overwrite ``cleaned_data`` of the ``form`` with object qualifier. + if values: + form.cleaned_data[self.data.name] = json.dumps(values) + else: + del form.cleaned_data[self.data.name] + + # It's critically important to return the ``form`` with updated + # ``cleaned_data`` + return form diff --git a/src/fobi/contrib/plugins/form_elements/fields/select_multiple_model_objects/fobi_form_elements.py b/src/fobi/contrib/plugins/form_elements/fields/select_multiple_model_objects/fobi_form_elements.py index 0debdf35..da043ad8 100644 --- a/src/fobi/contrib/plugins/form_elements/fields/select_multiple_model_objects/fobi_form_elements.py +++ b/src/fobi/contrib/plugins/form_elements/fields/select_multiple_model_objects/fobi_form_elements.py @@ -1,30 +1,8 @@ -import simplejson as json +from __future__ import absolute_import -from django.forms.models import ModelMultipleChoiceField -from django.forms.widgets import SelectMultiple -from django.utils.translation import ugettext_lazy as _ +from fobi.base import form_element_plugin_registry -from fobi.base import FormFieldPlugin, form_element_plugin_registry, get_theme -from fobi.constants import ( - SUBMIT_VALUE_AS_VAL, SUBMIT_VALUE_AS_REPR -) -from fobi.helpers import ( - safe_text, - get_app_label_and_model_name, - get_model_name_for_object -) - -from nine.versions import DJANGO_GTE_1_7 - -from . import UID -from .forms import SelectMultipleModelObjectsInputForm -from .settings import SUBMIT_VALUE_AS - -if DJANGO_GTE_1_7: - from django.apps import apps - get_model = apps.get_model -else: - from django.db.models import get_model +from .base import SelectMultipleModelObjectsInputPlugin __title__ = 'fobi.contrib.plugins.form_elements.fields.' \ 'select_multiple_model_objects.fobi_form_elements' @@ -33,85 +11,5 @@ __copyright__ = '2014-2016 Artur Barseghyan' __license__ = 'GPL 2.0/LGPL 2.1' __all__ = ('SelectMultipleModelObjectsInputPlugin',) -theme = get_theme(request=None, as_instance=True) - - -class SelectMultipleModelObjectsInputPlugin(FormFieldPlugin): - """Select multiple model objects field plugin.""" - - uid = UID - name = _("Select multiple model objects") - group = _("Fields") - form = SelectMultipleModelObjectsInputForm - - def get_form_field_instances(self, request=None, form_entry=None, - form_element_entries=None, **kwargs): - """Get form field instances.""" - app_label, model_name = get_app_label_and_model_name(self.data.model) - model = get_model(app_label, model_name) - queryset = model._default_manager.all() - - field_kwargs = { - 'label': self.data.label, - 'help_text': self.data.help_text, - 'initial': self.data.initial, - 'required': self.data.required, - 'queryset': queryset, - 'widget': SelectMultiple( - attrs={'class': theme.form_element_html_class} - ), - } - - return [(self.data.name, ModelMultipleChoiceField, field_kwargs)] - - def submit_plugin_form_data(self, form_entry, request, form): - """ - Submit plugin form data/process. - - :param fobi.models.FormEntry form_entry: Instance of - ``fobi.models.FormEntry``. - :param django.http.HttpRequest request: - :param django.forms.Form form: - """ - # In case if we should submit value as is, we don't return anything. - # In other cases, we proceed further. - - # Get the object - objs = form.cleaned_data.get(self.data.name, []) - - values = [] - - for obj in objs: - if obj: - value = None - # Should be returned as repr - if SUBMIT_VALUE_AS == SUBMIT_VALUE_AS_REPR: - value = safe_text(obj) - elif SUBMIT_VALUE_AS == SUBMIT_VALUE_AS_VAL: - value = '{0}.{1}.{2}'.format( - obj._meta.app_label, - get_model_name_for_object(obj), - obj.pk - ) - else: - # Handle the submitted form value - value = '{0}.{1}.{2}.{3}'.format( - obj._meta.app_label, - get_model_name_for_object(obj), - obj.pk, - safe_text(obj) - ) - values.append(value) - - # Overwrite ``cleaned_data`` of the ``form`` with object qualifier. - if values: - form.cleaned_data[self.data.name] = json.dumps(values) - else: - del form.cleaned_data[self.data.name] - - # It's critically important to return the ``form`` with updated - # ``cleaned_data`` - return form - form_element_plugin_registry.register(SelectMultipleModelObjectsInputPlugin) diff --git a/src/fobi/contrib/plugins/form_elements/fields/select_multiple_mptt_model_objects/base.py b/src/fobi/contrib/plugins/form_elements/fields/select_multiple_mptt_model_objects/base.py new file mode 100644 index 00000000..72529cde --- /dev/null +++ b/src/fobi/contrib/plugins/form_elements/fields/select_multiple_mptt_model_objects/base.py @@ -0,0 +1,118 @@ +from __future__ import absolute_import + +import simplejson as json + +from django.forms.widgets import SelectMultiple +from django.utils.translation import ugettext_lazy as _ + +from mptt.fields import TreeNodeMultipleChoiceField + +from fobi.base import FormFieldPlugin, get_theme +from fobi.constants import ( + SUBMIT_VALUE_AS_VAL, + SUBMIT_VALUE_AS_REPR +) +from fobi.helpers import ( + safe_text, + get_app_label_and_model_name, + get_model_name_for_object +) + +from nine.versions import DJANGO_GTE_1_7 + +from . import UID +from .forms import SelectMultipleMPTTModelObjectsInputForm +from .settings import SUBMIT_VALUE_AS + +if DJANGO_GTE_1_7: + from django.apps import apps + get_model = apps.get_model +else: + from django.db.models import get_model + +__title__ = 'fobi.contrib.plugins.form_elements.fields.' \ + 'select_multiple_mptt_model_objects.base' +__author__ = 'Artur Barseghyan ' +__copyright__ = '2014-2016 Artur Barseghyan' +__license__ = 'GPL 2.0/LGPL 2.1' +__all__ = ('SelectMultipleMPTTModelObjectsInputPlugin',) + +theme = get_theme(request=None, as_instance=True) + + +class SelectMultipleMPTTModelObjectsInputPlugin(FormFieldPlugin): + """Select multiple MPTT model object field plugin.""" + + uid = UID + name = _("Select multiple MPTT model objects") + group = _("Fields") + form = SelectMultipleMPTTModelObjectsInputForm + + def get_form_field_instances(self, request=None, form_entry=None, + form_element_entries=None, **kwargs): + """Get form field instances.""" + app_label, model_name = get_app_label_and_model_name(self.data.model) + model = get_model(app_label, model_name) + queryset = model._default_manager.all() + + field_kwargs = { + 'label': self.data.label, + 'help_text': self.data.help_text, + 'initial': self.data.initial, + 'required': self.data.required, + 'queryset': queryset, + 'widget': SelectMultiple( + attrs={'class': theme.form_element_html_class} + ), + } + + return [(self.data.name, TreeNodeMultipleChoiceField, field_kwargs)] + + def submit_plugin_form_data(self, form_entry, request, form, + form_element_entries=None, **kwargs): + """Submit plugin form data/process. + + :param fobi.models.FormEntry form_entry: Instance of + ``fobi.models.FormEntry``. + :param django.http.HttpRequest request: + :param django.forms.Form form: + """ + # In case if we should submit value as is, we don't return anything. + # In other cases, we proceed further. + + # Get the object + objs = form.cleaned_data.get(self.data.name, []) + + values = [] + + for obj in objs: + if obj: + value = None + # Should be returned as repr + if SUBMIT_VALUE_AS == SUBMIT_VALUE_AS_REPR: + value = safe_text(obj) + elif SUBMIT_VALUE_AS == SUBMIT_VALUE_AS_VAL: + value = '{0}.{1}.{2}'.format( + obj._meta.app_label, + get_model_name_for_object(obj), + obj.pk + ) + else: + # Handle the submitted form value + value = '{0}.{1}.{2}.{3}'.format( + obj._meta.app_label, + get_model_name_for_object(obj), + obj.pk, + safe_text(obj) + ) + values.append(value) + + # Overwrite ``cleaned_data`` of the ``form`` with object qualifier. + if values: + form.cleaned_data[self.data.name] = json.dumps(values) + else: + del form.cleaned_data[self.data.name] + + # It's critically important to return the ``form`` with updated + # ``cleaned_data`` + return form diff --git a/src/fobi/contrib/plugins/form_elements/fields/select_multiple_mptt_model_objects/fobi_form_elements.py b/src/fobi/contrib/plugins/form_elements/fields/select_multiple_mptt_model_objects/fobi_form_elements.py index 94d0c2c1..f67cf7f2 100644 --- a/src/fobi/contrib/plugins/form_elements/fields/select_multiple_mptt_model_objects/fobi_form_elements.py +++ b/src/fobi/contrib/plugins/form_elements/fields/select_multiple_mptt_model_objects/fobi_form_elements.py @@ -1,31 +1,8 @@ -import simplejson as json +from __future__ import absolute_import -from django.forms.widgets import SelectMultiple -from django.utils.translation import ugettext_lazy as _ +from fobi.base import form_element_plugin_registry -from mptt.fields import TreeNodeMultipleChoiceField - -from fobi.base import FormFieldPlugin, form_element_plugin_registry, get_theme -from fobi.constants import ( - SUBMIT_VALUE_AS_VAL, SUBMIT_VALUE_AS_REPR - ) -from fobi.helpers import ( - safe_text, - get_app_label_and_model_name, - get_model_name_for_object -) - -from nine.versions import DJANGO_GTE_1_7 - -from . import UID -from .forms import SelectMultipleMPTTModelObjectsInputForm -from .settings import SUBMIT_VALUE_AS - -if DJANGO_GTE_1_7: - from django.apps import apps - get_model = apps.get_model -else: - from django.db.models import get_model +from .base import SelectMultipleMPTTModelObjectsInputPlugin __title__ = 'fobi.contrib.plugins.form_elements.fields.' \ 'select_multiple_mptt_model_objects.fobi_form_elements' @@ -34,85 +11,6 @@ __copyright__ = '2014-2016 Artur Barseghyan' __license__ = 'GPL 2.0/LGPL 2.1' __all__ = ('SelectMultipleMPTTModelObjectsInputPlugin',) -theme = get_theme(request=None, as_instance=True) - - -class SelectMultipleMPTTModelObjectsInputPlugin(FormFieldPlugin): - """Select multiple MPTT model object field plugin.""" - - uid = UID - name = _("Select multiple MPTT model objects") - group = _("Fields") - form = SelectMultipleMPTTModelObjectsInputForm - - def get_form_field_instances(self, request=None, form_entry=None, - form_element_entries=None, **kwargs): - """Get form field instances.""" - app_label, model_name = get_app_label_and_model_name(self.data.model) - model = get_model(app_label, model_name) - queryset = model._default_manager.all() - - field_kwargs = { - 'label': self.data.label, - 'help_text': self.data.help_text, - 'initial': self.data.initial, - 'required': self.data.required, - 'queryset': queryset, - 'widget': SelectMultiple( - attrs={'class': theme.form_element_html_class} - ), - } - - return [(self.data.name, TreeNodeMultipleChoiceField, field_kwargs)] - - def submit_plugin_form_data(self, form_entry, request, form): - """Submit plugin form data/process. - - :param fobi.models.FormEntry form_entry: Instance of - ``fobi.models.FormEntry``. - :param django.http.HttpRequest request: - :param django.forms.Form form: - """ - # In case if we should submit value as is, we don't return anything. - # In other cases, we proceed further. - - # Get the object - objs = form.cleaned_data.get(self.data.name, []) - - values = [] - - for obj in objs: - if obj: - value = None - # Should be returned as repr - if SUBMIT_VALUE_AS == SUBMIT_VALUE_AS_REPR: - value = safe_text(obj) - elif SUBMIT_VALUE_AS == SUBMIT_VALUE_AS_VAL: - value = '{0}.{1}.{2}'.format( - obj._meta.app_label, - get_model_name_for_object(obj), - obj.pk - ) - else: - # Handle the submitted form value - value = '{0}.{1}.{2}.{3}'.format( - obj._meta.app_label, - get_model_name_for_object(obj), - obj.pk, - safe_text(obj) - ) - values.append(value) - - # Overwrite ``cleaned_data`` of the ``form`` with object qualifier. - if values: - form.cleaned_data[self.data.name] = json.dumps(values) - else: - del form.cleaned_data[self.data.name] - - # It's critically important to return the ``form`` with updated - # ``cleaned_data`` - return form - form_element_plugin_registry.register( SelectMultipleMPTTModelObjectsInputPlugin diff --git a/src/fobi/contrib/plugins/form_elements/fields/select_multiple_with_max/base.py b/src/fobi/contrib/plugins/form_elements/fields/select_multiple_with_max/base.py new file mode 100644 index 00000000..006b78be --- /dev/null +++ b/src/fobi/contrib/plugins/form_elements/fields/select_multiple_with_max/base.py @@ -0,0 +1,99 @@ +from __future__ import absolute_import + +from django.forms.widgets import SelectMultiple +from django.utils.translation import ugettext_lazy as _ + +from fobi.base import FormFieldPlugin, get_theme +from fobi.constants import ( + SUBMIT_VALUE_AS_VAL, + SUBMIT_VALUE_AS_REPR +) +from fobi.helpers import get_select_field_choices, safe_text + +from . import UID +from .fields import MultipleChoiceWithMaxField +from .forms import SelectMultipleWithMaxInputForm +from .settings import SUBMIT_VALUE_AS + +__title__ = 'fobi.contrib.plugins.form_elements.fields.' \ + 'select_multiple_with_max.base' +__author__ = 'Artur Barseghyan ' +__copyright__ = '2014-2016 Artur Barseghyan' +__license__ = 'GPL 2.0/LGPL 2.1' +__all__ = ('SelectMultipleWithMaxInputPlugin',) + +theme = get_theme(request=None, as_instance=True) + + +class SelectMultipleWithMaxInputPlugin(FormFieldPlugin): + """Select multiple with max field plugin.""" + + uid = UID + name = _("Select multiple with max") + group = _("Fields") + form = SelectMultipleWithMaxInputForm + + def get_form_field_instances(self, request=None, form_entry=None, + form_element_entries=None, **kwargs): + """Get form field instances.""" + choices = get_select_field_choices(self.data.choices) + + field_kwargs = { + 'label': self.data.label, + 'help_text': self.data.help_text, + 'initial': self.data.initial, + 'required': self.data.required, + 'choices': choices, + 'widget': SelectMultiple( + attrs={'class': theme.form_element_html_class} + ), + } + + if self.data.max_choices: + field_kwargs['max_choices'] = self.data.max_choices + + return [(self.data.name, MultipleChoiceWithMaxField, field_kwargs)] + + def submit_plugin_form_data(self, form_entry, request, form, + form_element_entries=None, **kwargs): + """Submit plugin form data/process. + + :param fobi.models.FormEntry form_entry: Instance of + ``fobi.models.FormEntry``. + :param django.http.HttpRequest request: + :param django.forms.Form form: + """ + # In case if we should submit value as is, we don't return anything. + # In other cases, we proceed further. + if SUBMIT_VALUE_AS != SUBMIT_VALUE_AS_VAL: + # Get the object + values = form.cleaned_data.get(self.data.name, None) + + # Get choices + choices = dict(get_select_field_choices(self.data.choices)) + + # Returned value + ret_values = [] + + for value in values: + # Handle the submitted form value + + if value in choices: + label = safe_text(choices.get(value)) + + # Should be returned as repr + if SUBMIT_VALUE_AS == SUBMIT_VALUE_AS_REPR: + value = label + # Should be returned as mix + else: + value = "{0} ({1})".format(label, value) + + ret_values.append(value) + + # Overwrite ``cleaned_data`` of the ``form`` with object + # qualifier. + form.cleaned_data[self.data.name] = ret_values + + # It's critically important to return the ``form`` with updated + # ``cleaned_data`` + return form diff --git a/src/fobi/contrib/plugins/form_elements/fields/select_multiple_with_max/fobi_form_elements.py b/src/fobi/contrib/plugins/form_elements/fields/select_multiple_with_max/fobi_form_elements.py index 2fbab69a..8f2dd1f3 100644 --- a/src/fobi/contrib/plugins/form_elements/fields/select_multiple_with_max/fobi_form_elements.py +++ b/src/fobi/contrib/plugins/form_elements/fields/select_multiple_with_max/fobi_form_elements.py @@ -1,16 +1,8 @@ -from django.forms.widgets import SelectMultiple -from django.utils.translation import ugettext_lazy as _ +from __future__ import absolute_import -from fobi.base import FormFieldPlugin, form_element_plugin_registry, get_theme -from fobi.constants import ( - SUBMIT_VALUE_AS_VAL, SUBMIT_VALUE_AS_REPR -) -from fobi.helpers import get_select_field_choices, safe_text +from fobi.base import form_element_plugin_registry -from . import UID -from .fields import MultipleChoiceWithMaxField -from .forms import SelectMultipleWithMaxInputForm -from .settings import SUBMIT_VALUE_AS +from .base import SelectMultipleWithMaxInputPlugin __title__ = 'fobi.contrib.plugins.form_elements.fields.' \ 'select_multiple_with_max.fobi_form_elements' @@ -19,80 +11,5 @@ __copyright__ = '2014-2016 Artur Barseghyan' __license__ = 'GPL 2.0/LGPL 2.1' __all__ = ('SelectMultipleWithMaxInputPlugin',) -theme = get_theme(request=None, as_instance=True) - - -class SelectMultipleWithMaxInputPlugin(FormFieldPlugin): - """Select multiple with max field plugin.""" - - uid = UID - name = _("Select multiple with max") - group = _("Fields") - form = SelectMultipleWithMaxInputForm - - def get_form_field_instances(self, request=None, form_entry=None, - form_element_entries=None, **kwargs): - """Get form field instances.""" - choices = get_select_field_choices(self.data.choices) - - field_kwargs = { - 'label': self.data.label, - 'help_text': self.data.help_text, - 'initial': self.data.initial, - 'required': self.data.required, - 'choices': choices, - 'widget': SelectMultiple( - attrs={'class': theme.form_element_html_class} - ), - } - - if self.data.max_choices: - field_kwargs['max_choices'] = self.data.max_choices - - return [(self.data.name, MultipleChoiceWithMaxField, field_kwargs)] - - def submit_plugin_form_data(self, form_entry, request, form): - """Submit plugin form data/process. - - :param fobi.models.FormEntry form_entry: Instance of - ``fobi.models.FormEntry``. - :param django.http.HttpRequest request: - :param django.forms.Form form: - """ - # In case if we should submit value as is, we don't return anything. - # In other cases, we proceed further. - if SUBMIT_VALUE_AS != SUBMIT_VALUE_AS_VAL: - # Get the object - values = form.cleaned_data.get(self.data.name, None) - - # Get choices - choices = dict(get_select_field_choices(self.data.choices)) - - # Returned value - ret_values = [] - - for value in values: - # Handle the submitted form value - - if value in choices: - label = safe_text(choices.get(value)) - - # Should be returned as repr - if SUBMIT_VALUE_AS == SUBMIT_VALUE_AS_REPR: - value = label - # Should be returned as mix - else: - value = "{0} ({1})".format(label, value) - - ret_values.append(value) - - # Overwrite ``cleaned_data`` of the ``form`` with object - # qualifier. - form.cleaned_data[self.data.name] = ret_values - - # It's critically important to return the ``form`` with updated - # ``cleaned_data`` - return form - form_element_plugin_registry.register(SelectMultipleWithMaxInputPlugin) diff --git a/src/fobi/contrib/plugins/form_elements/fields/slider/base.py b/src/fobi/contrib/plugins/form_elements/fields/slider/base.py new file mode 100644 index 00000000..2f2dc1a6 --- /dev/null +++ b/src/fobi/contrib/plugins/form_elements/fields/slider/base.py @@ -0,0 +1,210 @@ +from __future__ import absolute_import + +from six import text_type + +from django.forms.fields import ChoiceField + +from django.utils.html import format_html +from django.utils.safestring import mark_safe +from django.utils.translation import ugettext_lazy as _ + +from nine import versions + +from fobi.base import ( + FormFieldPlugin, + get_theme +) +from fobi.helpers import get_select_field_choices +from fobi.widgets import RichSelectInverseQuotes + +from . import UID +from .constants import ( + SLIDER_DEFAULT_TOOLTIP, + SLIDER_DEFAULT_HANDLE, + SLIDER_SHOW_ENDPOINTS_AS_LABELED_TICKS, + SLIDER_SHOW_ENDPOINTS_AS_TICKS, + SLIDER_DEFAULT_SHOW_ENDPOINTS_AS +) +from .forms import SliderInputForm +from .helpers import generate_ticks +from .settings import ( + INITIAL, + INITIAL_MAX_VALUE, + INITIAL_MIN_VALUE, + # MAX_VALUE, + # MIN_VALUE, + STEP +) + +if versions.DJANGO_GTE_1_7: + from django.forms.utils import flatatt +else: + from django.forms.util import flatatt + +__title__ = 'fobi.contrib.plugins.form_elements.fields.slider.base' +__author__ = 'Artur Barseghyan ' +__copyright__ = '2014-2016 Artur Barseghyan' +__license__ = 'GPL 2.0/LGPL 2.1' +__all__ = ('SliderInputPlugin',) + +theme = get_theme(request=None, as_instance=True) + + +class SliderInputPlugin(FormFieldPlugin): + """Slider field plugin.""" + + uid = UID + name = _("Slider") + group = _("Fields") + form = SliderInputForm + html_classes = ['slider'] + + def get_form_field_instances(self, request=None, form_entry=None, + form_element_entries=None, **kwargs): + """Get form field instances.""" + initial = self.data.initial if self.data.initial else INITIAL + max_value = self.data.max_value \ + if self.data.max_value \ + else INITIAL_MAX_VALUE + min_value = self.data.min_value \ + if self.data.min_value \ + else INITIAL_MIN_VALUE + step = self.data.step if self.data.step else STEP + tooltip = self.data.tooltip \ + if self.data.tooltip \ + else SLIDER_DEFAULT_TOOLTIP + handle = self.data.handle \ + if self.data.handle \ + else SLIDER_DEFAULT_HANDLE + + custom_ticks = get_select_field_choices(self.data.custom_ticks, + key_type=int, + value_type=text_type) \ + if self.data.custom_ticks \ + else [] + + _choices = range(min_value, max_value+1, step) + choices = zip(_choices, _choices) + + # slider_html_class = "slider-no-background" \ + # if self.data.disable_slider_background \ + # else "slider" + slider_html_class = "slider" + + widget_attrs = { + 'class': "{0} {1}".format( + slider_html_class, + theme.form_element_html_class + ), + 'data-slider-min': min_value, + 'data-slider-max': max_value, + 'data-slider-step': step, + 'data-slider-value': initial, + 'data-slider-tooltip': tooltip, + 'data-slider-handle': handle, + } + + show_endpoints_as = self.data.show_endpoints_as \ + if self.data.show_endpoints_as \ + else SLIDER_DEFAULT_SHOW_ENDPOINTS_AS + + prepend_html_list = [] + append_html_list = [] + + # Show endpoints as labeled ticks + if SLIDER_SHOW_ENDPOINTS_AS_LABELED_TICKS == show_endpoints_as: + + if custom_ticks: + ticks_data = generate_ticks(custom_ticks) + else: + ticks_data = generate_ticks([ + (min_value, self.data.label_start), + (max_value, self.data.label_end), + ]) + # label_start = self.data.label_start \ + # if self.data.label_start \ + # else text_type(min_value) + # + # label_end = self.data.label_end \ + # if self.data.label_end \ + # else text_type(max_value) + + # widget_attrs.update({ + # 'data-slider-ticks': "[{0}, {1}]".format( + # min_value, max_value + # ), + # 'data-slider-ticks-labels': '["{0!s}", "{1!s}"]'.format( + # label_start.encode('utf8'), label_end.encode('utf8') + # ), + # }) + + widget_attrs.update(ticks_data) + + # Show endpoints as ticks + elif SLIDER_SHOW_ENDPOINTS_AS_TICKS == show_endpoints_as: + + if custom_ticks: + ticks_data = generate_ticks(custom_ticks, empty_labels=True) + else: + ticks_data = generate_ticks([ + (min_value, ""), + (max_value, ""), + ]) + + # widget_attrs.update({ + # 'data-slider-ticks': "[{0}, {1}]".format( + # min_value, max_value + # ), + # 'data-slider-ticks-labels': '["{0}", "{1}"]'.format( + # "", "" + # ), + # }) + + widget_attrs.update(ticks_data) + + # Show endpoints as labels + else: + + if self.data.label_start: + prepend_html_list.append( + format_html( + " ", + flatatt({'class': "slider-endpoint-label-start"}) + ) + ) + prepend_html_list.append(format_html(self.data.label_start)) + prepend_html_list.append(format_html(" ")) + + if self.data.label_end: + append_html_list.append( + format_html( + " ", + flatatt({'class': "slider-endpoint-label-end"}) + ) + ) + append_html_list.append(format_html(self.data.label_end)) + append_html_list.append(format_html(" ")) + + widget_kwargs = {'attrs': widget_attrs} + + # For showing endpoints as labels + if prepend_html_list: + widget_kwargs.update({ + 'prepend_html': mark_safe(''.join(prepend_html_list)), + }) + + if append_html_list: + widget_kwargs.update({ + 'append_html': mark_safe(''.join(append_html_list)), + }) + + field_kwargs = { + 'label': self.data.label, + 'help_text': self.data.help_text, + 'initial': initial, + 'required': self.data.required, + 'choices': choices, + 'widget': RichSelectInverseQuotes(**widget_kwargs), + } + + return [(self.data.name, ChoiceField, field_kwargs)] diff --git a/src/fobi/contrib/plugins/form_elements/fields/slider/fobi_form_elements.py b/src/fobi/contrib/plugins/form_elements/fields/slider/fobi_form_elements.py index a1e0d73f..b290bbb5 100644 --- a/src/fobi/contrib/plugins/form_elements/fields/slider/fobi_form_elements.py +++ b/src/fobi/contrib/plugins/form_elements/fields/slider/fobi_form_elements.py @@ -1,44 +1,8 @@ -from six import text_type +from __future__ import absolute_import -from django.forms.fields import ChoiceField +from fobi.base import form_element_plugin_registry -from django.utils.html import format_html -from django.utils.safestring import mark_safe -from django.utils.translation import ugettext_lazy as _ - -from nine import versions - -from fobi.base import ( - FormFieldPlugin, - form_element_plugin_registry, - get_theme -) -from fobi.helpers import get_select_field_choices -from fobi.widgets import RichSelectInverseQuotes - -from . import UID -from .constants import ( - SLIDER_DEFAULT_TOOLTIP, - SLIDER_DEFAULT_HANDLE, - SLIDER_SHOW_ENDPOINTS_AS_LABELED_TICKS, - SLIDER_SHOW_ENDPOINTS_AS_TICKS, - SLIDER_DEFAULT_SHOW_ENDPOINTS_AS -) -from .forms import SliderInputForm -from .helpers import generate_ticks -from .settings import ( - INITIAL, - INITIAL_MAX_VALUE, - INITIAL_MIN_VALUE, - # MAX_VALUE, - # MIN_VALUE, - STEP -) - -if versions.DJANGO_GTE_1_7: - from django.forms.utils import flatatt -else: - from django.forms.util import flatatt +from .base import SliderInputPlugin __title__ = 'fobi.contrib.plugins.form_elements.fields.slider.' \ 'fobi_form_elements' @@ -47,167 +11,5 @@ __copyright__ = '2014-2016 Artur Barseghyan' __license__ = 'GPL 2.0/LGPL 2.1' __all__ = ('SliderInputPlugin',) -theme = get_theme(request=None, as_instance=True) - - -class SliderInputPlugin(FormFieldPlugin): - """Slider field plugin.""" - - uid = UID - name = _("Slider") - group = _("Fields") - form = SliderInputForm - html_classes = ['slider'] - - def get_form_field_instances(self, request=None, form_entry=None, - form_element_entries=None, **kwargs): - """Get form field instances.""" - initial = self.data.initial if self.data.initial else INITIAL - max_value = self.data.max_value \ - if self.data.max_value \ - else INITIAL_MAX_VALUE - min_value = self.data.min_value \ - if self.data.min_value \ - else INITIAL_MIN_VALUE - step = self.data.step if self.data.step else STEP - tooltip = self.data.tooltip \ - if self.data.tooltip \ - else SLIDER_DEFAULT_TOOLTIP - handle = self.data.handle \ - if self.data.handle \ - else SLIDER_DEFAULT_HANDLE - - custom_ticks = get_select_field_choices(self.data.custom_ticks, - key_type=int, - value_type=text_type) \ - if self.data.custom_ticks \ - else [] - - _choices = range(min_value, max_value+1, step) - choices = zip(_choices, _choices) - - # slider_html_class = "slider-no-background" \ - # if self.data.disable_slider_background \ - # else "slider" - slider_html_class = "slider" - - widget_attrs = { - 'class': "{0} {1}".format( - slider_html_class, - theme.form_element_html_class - ), - 'data-slider-min': min_value, - 'data-slider-max': max_value, - 'data-slider-step': step, - 'data-slider-value': initial, - 'data-slider-tooltip': tooltip, - 'data-slider-handle': handle, - } - - show_endpoints_as = self.data.show_endpoints_as \ - if self.data.show_endpoints_as \ - else SLIDER_DEFAULT_SHOW_ENDPOINTS_AS - - prepend_html_list = [] - append_html_list = [] - - # Show endpoints as labeled ticks - if SLIDER_SHOW_ENDPOINTS_AS_LABELED_TICKS == show_endpoints_as: - - if custom_ticks: - ticks_data = generate_ticks(custom_ticks) - else: - ticks_data = generate_ticks([ - (min_value, self.data.label_start), - (max_value, self.data.label_end), - ]) - # label_start = self.data.label_start \ - # if self.data.label_start \ - # else text_type(min_value) - # - # label_end = self.data.label_end \ - # if self.data.label_end \ - # else text_type(max_value) - - # widget_attrs.update({ - # 'data-slider-ticks': "[{0}, {1}]".format( - # min_value, max_value - # ), - # 'data-slider-ticks-labels': '["{0!s}", "{1!s}"]'.format( - # label_start.encode('utf8'), label_end.encode('utf8') - # ), - # }) - - widget_attrs.update(ticks_data) - - # Show endpoints as ticks - elif SLIDER_SHOW_ENDPOINTS_AS_TICKS == show_endpoints_as: - - if custom_ticks: - ticks_data = generate_ticks(custom_ticks, empty_labels=True) - else: - ticks_data = generate_ticks([ - (min_value, ""), - (max_value, ""), - ]) - - # widget_attrs.update({ - # 'data-slider-ticks': "[{0}, {1}]".format( - # min_value, max_value - # ), - # 'data-slider-ticks-labels': '["{0}", "{1}"]'.format( - # "", "" - # ), - # }) - - widget_attrs.update(ticks_data) - - # Show endpoints as labels - else: - - if self.data.label_start: - prepend_html_list.append( - format_html( - " ", - flatatt({'class': "slider-endpoint-label-start"}) - ) - ) - prepend_html_list.append(format_html(self.data.label_start)) - prepend_html_list.append(format_html(" ")) - - if self.data.label_end: - append_html_list.append( - format_html( - " ", - flatatt({'class': "slider-endpoint-label-end"}) - ) - ) - append_html_list.append(format_html(self.data.label_end)) - append_html_list.append(format_html(" ")) - - widget_kwargs = {'attrs': widget_attrs} - - # For showing endpoints as labels - if prepend_html_list: - widget_kwargs.update({ - 'prepend_html': mark_safe(''.join(prepend_html_list)), - }) - - if append_html_list: - widget_kwargs.update({ - 'append_html': mark_safe(''.join(append_html_list)), - }) - - field_kwargs = { - 'label': self.data.label, - 'help_text': self.data.help_text, - 'initial': initial, - 'required': self.data.required, - 'choices': choices, - 'widget': RichSelectInverseQuotes(**widget_kwargs), - } - - return [(self.data.name, ChoiceField, field_kwargs)] - form_element_plugin_registry.register(SliderInputPlugin) diff --git a/src/fobi/contrib/plugins/form_elements/fields/slug/base.py b/src/fobi/contrib/plugins/form_elements/fields/slug/base.py new file mode 100644 index 00000000..b65bd0fc --- /dev/null +++ b/src/fobi/contrib/plugins/form_elements/fields/slug/base.py @@ -0,0 +1,47 @@ +from __future__ import absolute_import + +from django.forms.fields import SlugField +from django.forms.widgets import TextInput +from django.utils.translation import ugettext_lazy as _ + +from fobi.base import FormFieldPlugin, get_theme + +from . import UID +from .forms import SlugInputForm + +__title__ = 'fobi.contrib.plugins.form_elements.fields.slug.base' +__author__ = 'Artur Barseghyan ' +__copyright__ = '2014-2016 Artur Barseghyan' +__license__ = 'GPL 2.0/LGPL 2.1' +__all__ = ('SlugInputPlugin',) + +theme = get_theme(request=None, as_instance=True) + + +class SlugInputPlugin(FormFieldPlugin): + """Slug field plugin.""" + + uid = UID + name = _("Slug") + group = _("Fields") + form = SlugInputForm + + def get_form_field_instances(self, request=None, form_entry=None, + form_element_entries=None, **kwargs): + """Get form field instances.""" + widget_attrs = { + 'class': theme.form_element_html_class, + 'placeholder': self.data.placeholder, + } + + field_kwargs = { + 'label': self.data.label, + 'help_text': self.data.help_text, + 'initial': self.data.initial, + 'required': self.data.required, + 'widget': TextInput(attrs=widget_attrs), + } + if self.data.max_length: + field_kwargs['max_length'] = self.data.max_length + + return [(self.data.name, SlugField, field_kwargs)] diff --git a/src/fobi/contrib/plugins/form_elements/fields/slug/fobi_form_elements.py b/src/fobi/contrib/plugins/form_elements/fields/slug/fobi_form_elements.py index 26ac9610..f3dcadfc 100644 --- a/src/fobi/contrib/plugins/form_elements/fields/slug/fobi_form_elements.py +++ b/src/fobi/contrib/plugins/form_elements/fields/slug/fobi_form_elements.py @@ -1,11 +1,8 @@ -from django.forms.fields import SlugField -from django.forms.widgets import TextInput -from django.utils.translation import ugettext_lazy as _ +from __future__ import absolute_import -from fobi.base import FormFieldPlugin, form_element_plugin_registry, get_theme +from fobi.base import form_element_plugin_registry -from . import UID -from .forms import SlugInputForm +from .base import SlugInputPlugin __title__ = 'fobi.contrib.plugins.form_elements.fields.slug.fobi_form_elements' __author__ = 'Artur Barseghyan ' @@ -13,36 +10,5 @@ __copyright__ = '2014-2016 Artur Barseghyan' __license__ = 'GPL 2.0/LGPL 2.1' __all__ = ('SlugInputPlugin',) -theme = get_theme(request=None, as_instance=True) - - -class SlugInputPlugin(FormFieldPlugin): - """Slug field plugin.""" - - uid = UID - name = _("Slug") - group = _("Fields") - form = SlugInputForm - - def get_form_field_instances(self, request=None, form_entry=None, - form_element_entries=None, **kwargs): - """Get form field instances.""" - widget_attrs = { - 'class': theme.form_element_html_class, - 'placeholder': self.data.placeholder, - } - - field_kwargs = { - 'label': self.data.label, - 'help_text': self.data.help_text, - 'initial': self.data.initial, - 'required': self.data.required, - 'widget': TextInput(attrs=widget_attrs), - } - if self.data.max_length: - field_kwargs['max_length'] = self.data.max_length - - return [(self.data.name, SlugField, field_kwargs)] - form_element_plugin_registry.register(SlugInputPlugin) diff --git a/src/fobi/contrib/plugins/form_elements/fields/text/base.py b/src/fobi/contrib/plugins/form_elements/fields/text/base.py new file mode 100644 index 00000000..3e89f02b --- /dev/null +++ b/src/fobi/contrib/plugins/form_elements/fields/text/base.py @@ -0,0 +1,47 @@ +from __future__ import absolute_import + +from django.forms.fields import CharField +from django.forms.widgets import TextInput +from django.utils.translation import ugettext_lazy as _ + +from fobi.base import FormFieldPlugin, get_theme + +from . import UID +from .forms import TextInputForm + +__title__ = 'fobi.contrib.plugins.form_elements.fields.text.base' +__author__ = 'Artur Barseghyan ' +__copyright__ = '2014-2016 Artur Barseghyan' +__license__ = 'GPL 2.0/LGPL 2.1' +__all__ = ('TextInputPlugin',) + +theme = get_theme(request=None, as_instance=True) + + +class TextInputPlugin(FormFieldPlugin): + """Text field plugin.""" + + uid = UID + name = _("Text") + group = _("Fields") + form = TextInputForm + + def get_form_field_instances(self, request=None, form_entry=None, + form_element_entries=None, **kwargs): + """Get form field instances.""" + widget_attrs = { + 'class': theme.form_element_html_class, + 'placeholder': self.data.placeholder, + } + + field_kwargs = { + 'label': self.data.label, + 'help_text': self.data.help_text, + 'initial': self.data.initial, + 'required': self.data.required, + 'widget': TextInput(attrs=widget_attrs), + } + if self.data.max_length: + field_kwargs['max_length'] = self.data.max_length + + return [(self.data.name, CharField, field_kwargs)] diff --git a/src/fobi/contrib/plugins/form_elements/fields/text/fobi_form_elements.py b/src/fobi/contrib/plugins/form_elements/fields/text/fobi_form_elements.py index 9ab469f3..4e07e2e5 100644 --- a/src/fobi/contrib/plugins/form_elements/fields/text/fobi_form_elements.py +++ b/src/fobi/contrib/plugins/form_elements/fields/text/fobi_form_elements.py @@ -1,11 +1,8 @@ -from django.forms.fields import CharField -from django.forms.widgets import TextInput -from django.utils.translation import ugettext_lazy as _ +from __future__ import absolute_import -from fobi.base import FormFieldPlugin, form_element_plugin_registry, get_theme +from fobi.base import form_element_plugin_registry -from . import UID -from .forms import TextInputForm +from .base import TextInputPlugin __title__ = 'fobi.contrib.plugins.form_elements.fields.text.fobi_form_elements' __author__ = 'Artur Barseghyan ' @@ -13,36 +10,5 @@ __copyright__ = '2014-2016 Artur Barseghyan' __license__ = 'GPL 2.0/LGPL 2.1' __all__ = ('TextInputPlugin',) -theme = get_theme(request=None, as_instance=True) - - -class TextInputPlugin(FormFieldPlugin): - """Text field plugin.""" - - uid = UID - name = _("Text") - group = _("Fields") - form = TextInputForm - - def get_form_field_instances(self, request=None, form_entry=None, - form_element_entries=None, **kwargs): - """Get form field instances.""" - widget_attrs = { - 'class': theme.form_element_html_class, - 'placeholder': self.data.placeholder, - } - - field_kwargs = { - 'label': self.data.label, - 'help_text': self.data.help_text, - 'initial': self.data.initial, - 'required': self.data.required, - 'widget': TextInput(attrs=widget_attrs), - } - if self.data.max_length: - field_kwargs['max_length'] = self.data.max_length - - return [(self.data.name, CharField, field_kwargs)] - form_element_plugin_registry.register(TextInputPlugin) diff --git a/src/fobi/contrib/plugins/form_elements/fields/text/forms.py b/src/fobi/contrib/plugins/form_elements/fields/text/forms.py index a0f23483..8d53d0c7 100644 --- a/src/fobi/contrib/plugins/form_elements/fields/text/forms.py +++ b/src/fobi/contrib/plugins/form_elements/fields/text/forms.py @@ -80,6 +80,7 @@ class TextInputForm(forms.Form, BaseFormFieldPluginForm): ) def clean(self): + """Validation.""" super(TextInputForm, self).clean() max_length = self.cleaned_data.get('max_length', DEFAULT_MAX_LENGTH) @@ -91,4 +92,4 @@ class TextInputForm(forms.Form, BaseFormFieldPluginForm): 'initial', _("Ensure this value has at most {0} characters " "(it has {1}).".format(max_length, len_initial)) - ) \ No newline at end of file + ) diff --git a/src/fobi/contrib/plugins/form_elements/fields/textarea/base.py b/src/fobi/contrib/plugins/form_elements/fields/textarea/base.py new file mode 100644 index 00000000..9f2a1e3a --- /dev/null +++ b/src/fobi/contrib/plugins/form_elements/fields/textarea/base.py @@ -0,0 +1,44 @@ +from __future__ import absolute_import + +from django.forms.fields import CharField +from django.forms.widgets import Textarea +from django.utils.translation import ugettext_lazy as _ + +from fobi.base import FormFieldPlugin, get_theme + +from . import UID +from .forms import TextareaForm + +__title__ = 'fobi.contrib.plugins.form_elements.fields.textarea.base' +__author__ = 'Artur Barseghyan ' +__copyright__ = '2014-2016 Artur Barseghyan' +__license__ = 'GPL 2.0/LGPL 2.1' +__all__ = ('TextInputPlugin',) + +theme = get_theme(request=None, as_instance=True) + + +class TextareaPlugin(FormFieldPlugin): + """Textarea field plugin.""" + + uid = UID + name = _("Textarea") + group = _("Fields") + form = TextareaForm + + def get_form_field_instances(self, request=None, form_entry=None, + form_element_entries=None, **kwargs): + """Get form field instances.""" + widget_attrs = { + 'class': theme.form_element_html_class, + 'placeholder': self.data.placeholder, + } + field_kwargs = { + 'label': self.data.label, + 'help_text': self.data.help_text, + 'initial': self.data.initial, + 'required': self.data.required, + 'widget': Textarea(attrs=widget_attrs) + } + + return [(self.data.name, CharField, field_kwargs)] diff --git a/src/fobi/contrib/plugins/form_elements/fields/textarea/fobi_form_elements.py b/src/fobi/contrib/plugins/form_elements/fields/textarea/fobi_form_elements.py index 3f99ecc5..219159dd 100644 --- a/src/fobi/contrib/plugins/form_elements/fields/textarea/fobi_form_elements.py +++ b/src/fobi/contrib/plugins/form_elements/fields/textarea/fobi_form_elements.py @@ -1,11 +1,8 @@ -from django.forms.fields import CharField -from django.forms.widgets import Textarea -from django.utils.translation import ugettext_lazy as _ +from __future__ import absolute_import -from fobi.base import FormFieldPlugin, form_element_plugin_registry, get_theme +from fobi.base import form_element_plugin_registry -from . import UID -from .forms import TextareaForm +from .base import TextareaPlugin __title__ = 'fobi.contrib.plugins.form_elements.fields.' \ 'textarea.fobi_form_elements' @@ -14,33 +11,5 @@ __copyright__ = '2014-2016 Artur Barseghyan' __license__ = 'GPL 2.0/LGPL 2.1' __all__ = ('TextInputPlugin',) -theme = get_theme(request=None, as_instance=True) - - -class TextareaPlugin(FormFieldPlugin): - """Textarea field plugin.""" - - uid = UID - name = _("Textarea") - group = _("Fields") - form = TextareaForm - - def get_form_field_instances(self, request=None, form_entry=None, - form_element_entries=None, **kwargs): - """Get form field instances.""" - widget_attrs = { - 'class': theme.form_element_html_class, - 'placeholder': self.data.placeholder, - } - field_kwargs = { - 'label': self.data.label, - 'help_text': self.data.help_text, - 'initial': self.data.initial, - 'required': self.data.required, - 'widget': Textarea(attrs=widget_attrs) - } - - return [(self.data.name, CharField, field_kwargs)] - form_element_plugin_registry.register(TextareaPlugin) diff --git a/src/fobi/contrib/plugins/form_elements/fields/time/base.py b/src/fobi/contrib/plugins/form_elements/fields/time/base.py new file mode 100644 index 00000000..2ef918e3 --- /dev/null +++ b/src/fobi/contrib/plugins/form_elements/fields/time/base.py @@ -0,0 +1,72 @@ +from __future__ import absolute_import + +from django.forms.fields import TimeField +from django.forms.widgets import TextInput +from django.utils.translation import ugettext_lazy as _ + +from fobi.base import FormFieldPlugin, get_theme + +from . import UID +from .forms import TimeInputForm + +__title__ = 'fobi.contrib.plugins.form_elements.fields.time.base' +__author__ = 'Artur Barseghyan ' +__copyright__ = '2014-2016 Artur Barseghyan' +__license__ = 'GPL 2.0/LGPL 2.1' +__all__ = ('TimeInputPlugin',) + +theme = get_theme(request=None, as_instance=True) + + +class TimeInputPlugin(FormFieldPlugin): + """Time field plugin.""" + + uid = UID + name = _("Time") + group = _("Fields") + form = TimeInputForm + + def get_form_field_instances(self, request=None, form_entry=None, + form_element_entries=None, **kwargs): + """Get form field instances.""" + widget_attrs = { + 'class': theme.form_element_html_class, + 'type': 'time', + } + + field_kwargs = { + 'label': self.data.label, + 'help_text': self.data.help_text, + 'initial': self.data.initial, + # 'input_formats': self.data.input_formats, + 'required': self.data.required, + 'widget': TextInput(attrs=widget_attrs), + } + # if self.data.input_formats: + # kwargs['input_formats'] = self.data.input_formats + + return [(self.data.name, TimeField, field_kwargs)] + + def submit_plugin_form_data(self, form_entry, request, form, + form_element_entries=None, **kwargs): + """Submit plugin form data/process. + + :param fobi.models.FormEntry form_entry: Instance of + ``fobi.models.FormEntry``. + :param django.http.HttpRequest request: + :param django.forms.Form form: + """ + # In case if we should submit value as is, we don't return anything. + # In other cases, we proceed further. + + # Get the object + value = form.cleaned_data.get(self.data.name, None) + try: + value = value.strftime("%H:%M:%S") + except Exception as err: + pass + + # Overwrite ``cleaned_data`` of the ``form`` with object qualifier. + form.cleaned_data[self.data.name] = value + + return form diff --git a/src/fobi/contrib/plugins/form_elements/fields/time/fobi_form_elements.py b/src/fobi/contrib/plugins/form_elements/fields/time/fobi_form_elements.py index cfe280ac..b38ca229 100644 --- a/src/fobi/contrib/plugins/form_elements/fields/time/fobi_form_elements.py +++ b/src/fobi/contrib/plugins/form_elements/fields/time/fobi_form_elements.py @@ -1,13 +1,8 @@ from __future__ import absolute_import -from django.forms.fields import TimeField -from django.forms.widgets import TextInput -from django.utils.translation import ugettext_lazy as _ +from fobi.base import form_element_plugin_registry -from fobi.base import FormFieldPlugin, form_element_plugin_registry, get_theme - -from . import UID -from .forms import TimeInputForm +from .base import TimeInputPlugin __title__ = 'fobi.contrib.plugins.form_elements.fields.' \ 'time.fobi_form_elements' @@ -16,60 +11,5 @@ __copyright__ = '2014-2016 Artur Barseghyan' __license__ = 'GPL 2.0/LGPL 2.1' __all__ = ('TimeInputPlugin',) -theme = get_theme(request=None, as_instance=True) - - -class TimeInputPlugin(FormFieldPlugin): - """Time field plugin.""" - - uid = UID - name = _("Time") - group = _("Fields") - form = TimeInputForm - - def get_form_field_instances(self, request=None, form_entry=None, - form_element_entries=None, **kwargs): - """Get form field instances.""" - widget_attrs = { - 'class': theme.form_element_html_class, - 'type': 'time', - } - - field_kwargs = { - 'label': self.data.label, - 'help_text': self.data.help_text, - 'initial': self.data.initial, - # 'input_formats': self.data.input_formats, - 'required': self.data.required, - 'widget': TextInput(attrs=widget_attrs), - } - # if self.data.input_formats: - # kwargs['input_formats'] = self.data.input_formats - - return [(self.data.name, TimeField, field_kwargs)] - - def submit_plugin_form_data(self, form_entry, request, form): - """Submit plugin form data/process. - - :param fobi.models.FormEntry form_entry: Instance of - ``fobi.models.FormEntry``. - :param django.http.HttpRequest request: - :param django.forms.Form form: - """ - # In case if we should submit value as is, we don't return anything. - # In other cases, we proceed further. - - # Get the object - value = form.cleaned_data.get(self.data.name, None) - try: - value = value.strftime("%H:%M:%S") - except Exception as err: - pass - - # Overwrite ``cleaned_data`` of the ``form`` with object qualifier. - form.cleaned_data[self.data.name] = value - - return form - form_element_plugin_registry.register(TimeInputPlugin) diff --git a/src/fobi/contrib/plugins/form_elements/fields/url/base.py b/src/fobi/contrib/plugins/form_elements/fields/url/base.py new file mode 100644 index 00000000..4494fb06 --- /dev/null +++ b/src/fobi/contrib/plugins/form_elements/fields/url/base.py @@ -0,0 +1,58 @@ +from __future__ import absolute_import + +from django.forms.fields import URLField + +try: + from django.forms.widgets import URLInput +except ImportError: + from django.forms.widgets import TextInput + + class URLInput(TextInput): + """URL input.""" + + input_type = 'url' + +from django.utils.translation import ugettext_lazy as _ + +from fobi.base import FormFieldPlugin, get_theme + +from . import UID +from .forms import URLInputForm + +__title__ = 'fobi.contrib.plugins.form_elements.fields.url.base' +__author__ = 'Artur Barseghyan ' +__copyright__ = '2014-2016 Artur Barseghyan' +__license__ = 'GPL 2.0/LGPL 2.1' +__all__ = ('URLInputPlugin',) + +theme = get_theme(request=None, as_instance=True) + + +class URLInputPlugin(FormFieldPlugin): + """URL input plugin.""" + + uid = UID + name = _("URL") + group = _("Fields") + form = URLInputForm + + def get_form_field_instances(self, request=None, form_entry=None, + form_element_entries=None, **kwargs): + """Get form field instances.""" + widget_attrs = { + 'class': theme.form_element_html_class, + 'type': 'url', + 'placeholder': self.data.placeholder, + } + + field_kwargs = { + 'label': self.data.label, + 'help_text': self.data.help_text, + 'initial': self.data.initial, + 'required': self.data.required, + 'widget': URLInput(attrs=widget_attrs), + } + if self.data.max_length: + field_kwargs['max_length'] = self.data.max_length + + return [(self.data.name, URLField, field_kwargs)] diff --git a/src/fobi/contrib/plugins/form_elements/fields/url/fobi_form_elements.py b/src/fobi/contrib/plugins/form_elements/fields/url/fobi_form_elements.py index 88b7608e..eee5cd3b 100644 --- a/src/fobi/contrib/plugins/form_elements/fields/url/fobi_form_elements.py +++ b/src/fobi/contrib/plugins/form_elements/fields/url/fobi_form_elements.py @@ -1,21 +1,8 @@ -from django.forms.fields import URLField +from __future__ import absolute_import -try: - from django.forms.widgets import URLInput -except ImportError: - from django.forms.widgets import TextInput +from fobi.base import form_element_plugin_registry - class URLInput(TextInput): - """URL input.""" - - input_type = 'url' - -from django.utils.translation import ugettext_lazy as _ - -from fobi.base import FormFieldPlugin, form_element_plugin_registry, get_theme - -from . import UID -from .forms import URLInputForm +from .base import URLInputPlugin __title__ = 'fobi.contrib.plugins.form_elements.fields.url.fobi_form_elements' __author__ = 'Artur Barseghyan ' @@ -23,37 +10,5 @@ __copyright__ = '2014-2016 Artur Barseghyan' __license__ = 'GPL 2.0/LGPL 2.1' __all__ = ('URLInputPlugin',) -theme = get_theme(request=None, as_instance=True) - - -class URLInputPlugin(FormFieldPlugin): - """URL input plugin.""" - - uid = UID - name = _("URL") - group = _("Fields") - form = URLInputForm - - def get_form_field_instances(self, request=None, form_entry=None, - form_element_entries=None, **kwargs): - """Get form field instances.""" - widget_attrs = { - 'class': theme.form_element_html_class, - 'type': 'url', - 'placeholder': self.data.placeholder, - } - - field_kwargs = { - 'label': self.data.label, - 'help_text': self.data.help_text, - 'initial': self.data.initial, - 'required': self.data.required, - 'widget': URLInput(attrs=widget_attrs), - } - if self.data.max_length: - field_kwargs['max_length'] = self.data.max_length - - return [(self.data.name, URLField, field_kwargs)] - form_element_plugin_registry.register(URLInputPlugin) diff --git a/src/fobi/contrib/plugins/form_elements/security/captcha/fobi_form_elements.py b/src/fobi/contrib/plugins/form_elements/security/captcha/fobi_form_elements.py index 29c71c57..b995851c 100644 --- a/src/fobi/contrib/plugins/form_elements/security/captcha/fobi_form_elements.py +++ b/src/fobi/contrib/plugins/form_elements/security/captcha/fobi_form_elements.py @@ -1,3 +1,5 @@ +from __future__ import absolute_import + import logging from django.utils.translation import ugettext_lazy as _ diff --git a/src/fobi/contrib/plugins/form_elements/security/honeypot/base.py b/src/fobi/contrib/plugins/form_elements/security/honeypot/base.py new file mode 100644 index 00000000..ea42dcf2 --- /dev/null +++ b/src/fobi/contrib/plugins/form_elements/security/honeypot/base.py @@ -0,0 +1,48 @@ +from __future__ import absolute_import + +from django.forms.widgets import HiddenInput +from django.utils.translation import ugettext_lazy as _ + +from fobi.base import FormElementPlugin, get_theme + +from . import UID +from .fields import HoneypotField +from .forms import HoneypotInputForm + +__title__ = 'fobi.contrib.plugins.form_elements.security.honeypot.base' +__author__ = 'Artur Barseghyan ' +__copyright__ = '2014-2016 Artur Barseghyan' +__license__ = 'GPL 2.0/LGPL 2.1' +__all__ = ('HoneypotInputPlugin',) + +theme = get_theme(request=None, as_instance=True) + + +class HoneypotInputPlugin(FormElementPlugin): + """Honeypot field plugin.""" + + uid = UID + name = _("Honeypot") + group = _("Security") + form = HoneypotInputForm + is_hidden = True + + def get_form_field_instances(self, request=None, form_entry=None, + form_element_entries=None, **kwargs): + """Get form field instances.""" + + field_kwargs = { + 'label': self.data.label, + 'initial': self.data.initial, + # 'help_text': self.data.help_text, + 'required': self.data.required, + 'widget': HiddenInput( + attrs={'class': theme.form_element_html_class} + ), + } + + if self.data.max_length: + field_kwargs['max_length'] = self.data.max_length + + # return [(self.data.name, (HoneypotField, TextInput), kwargs)] + return [(self.data.name, HoneypotField, field_kwargs)] diff --git a/src/fobi/contrib/plugins/form_elements/security/honeypot/fobi_form_elements.py b/src/fobi/contrib/plugins/form_elements/security/honeypot/fobi_form_elements.py index b1e04de8..9f2a6458 100644 --- a/src/fobi/contrib/plugins/form_elements/security/honeypot/fobi_form_elements.py +++ b/src/fobi/contrib/plugins/form_elements/security/honeypot/fobi_form_elements.py @@ -1,13 +1,8 @@ -from django.forms.widgets import HiddenInput -from django.utils.translation import ugettext_lazy as _ +from __future__ import absolute_import -from fobi.base import ( - FormElementPlugin, form_element_plugin_registry, get_theme -) +from fobi.base import form_element_plugin_registry -from . import UID -from .fields import HoneypotField -from .forms import HoneypotInputForm +from .base import HoneypotInputPlugin __title__ = 'fobi.contrib.plugins.form_elements.security.' \ 'honeypot.fobi_form_elements' @@ -16,37 +11,5 @@ __copyright__ = '2014-2016 Artur Barseghyan' __license__ = 'GPL 2.0/LGPL 2.1' __all__ = ('HoneypotInputPlugin',) -theme = get_theme(request=None, as_instance=True) - - -class HoneypotInputPlugin(FormElementPlugin): - """Honeypot field plugin.""" - - uid = UID - name = _("Honeypot") - group = _("Security") - form = HoneypotInputForm - is_hidden = True - - def get_form_field_instances(self, request=None, form_entry=None, - form_element_entries=None, **kwargs): - """Get form field instances.""" - - field_kwargs = { - 'label': self.data.label, - 'initial': self.data.initial, - # 'help_text': self.data.help_text, - 'required': self.data.required, - 'widget': HiddenInput( - attrs={'class': theme.form_element_html_class} - ), - } - - if self.data.max_length: - field_kwargs['max_length'] = self.data.max_length - - # return [(self.data.name, (HoneypotField, TextInput), kwargs)] - return [(self.data.name, HoneypotField, field_kwargs)] - form_element_plugin_registry.register(HoneypotInputPlugin) diff --git a/src/fobi/contrib/plugins/form_elements/security/recaptcha/fobi_form_elements.py b/src/fobi/contrib/plugins/form_elements/security/recaptcha/fobi_form_elements.py index 4674f119..01964285 100644 --- a/src/fobi/contrib/plugins/form_elements/security/recaptcha/fobi_form_elements.py +++ b/src/fobi/contrib/plugins/form_elements/security/recaptcha/fobi_form_elements.py @@ -1,3 +1,5 @@ +from __future__ import absolute_import + import logging from django.utils.translation import ugettext_lazy as _ diff --git a/src/fobi/contrib/plugins/form_elements/test/dummy/base.py b/src/fobi/contrib/plugins/form_elements/test/dummy/base.py new file mode 100644 index 00000000..be4db2f4 --- /dev/null +++ b/src/fobi/contrib/plugins/form_elements/test/dummy/base.py @@ -0,0 +1,46 @@ +from __future__ import absolute_import + +from uuid import uuid4 + +from django.utils.translation import ugettext, ugettext_lazy as _ + +from nonefield.fields import NoneField + +from fobi.base import FormElementPlugin +from fobi.helpers import safe_text + +from . import UID + +__title__ = 'fobi.contrib.plugins.form_elements.test.dummy.base' +__author__ = 'Artur Barseghyan ' +__copyright__ = '2014-2016 Artur Barseghyan' +__license__ = 'GPL 2.0/LGPL 2.1' +__all__ = ('DummyPlugin',) + + +class DummyPlugin(FormElementPlugin): + """Dummy plugin.""" + + uid = UID + name = _("Dummy") + group = _("Testing") + + def post_processor(self): + """Post process data. + + Always the same. + """ + self.data.name = "{0}_{1}".format(self.uid, uuid4()) + + def get_form_field_instances(self, request=None, form_entry=None, + form_element_entries=None, **kwargs): + """Get form field instances.""" + field_kwargs = { + 'initial': "

{0}

".format( + safe_text(ugettext("Dummy content")) + ), + 'required': False, + 'label': '', + } + + return[(self.data.name, NoneField, field_kwargs)] diff --git a/src/fobi/contrib/plugins/form_elements/test/dummy/fobi_form_elements.py b/src/fobi/contrib/plugins/form_elements/test/dummy/fobi_form_elements.py index e33a3832..7e71a199 100644 --- a/src/fobi/contrib/plugins/form_elements/test/dummy/fobi_form_elements.py +++ b/src/fobi/contrib/plugins/form_elements/test/dummy/fobi_form_elements.py @@ -1,13 +1,8 @@ -from uuid import uuid4 +from __future__ import absolute_import -from django.utils.translation import ugettext, ugettext_lazy as _ +from fobi.base import form_element_plugin_registry -from nonefield.fields import NoneField - -from fobi.base import FormElementPlugin, form_element_plugin_registry -from fobi.helpers import safe_text - -from . import UID +from .base import DummyPlugin __title__ = 'fobi.contrib.plugins.form_elements.test.dummy.fobi_form_elements' __author__ = 'Artur Barseghyan ' @@ -16,32 +11,4 @@ __license__ = 'GPL 2.0/LGPL 2.1' __all__ = ('DummyPlugin',) -class DummyPlugin(FormElementPlugin): - """Dummy plugin.""" - - uid = UID - name = _("Dummy") - group = _("Testing") - - def post_processor(self): - """Post process data. - - Always the same. - """ - self.data.name = "{0}_{1}".format(self.uid, uuid4()) - - def get_form_field_instances(self, request=None, form_entry=None, - form_element_entries=None, **kwargs): - """Get form field instances.""" - field_kwargs = { - 'initial': "

{0}

".format( - safe_text(ugettext("Dummy content")) - ), - 'required': False, - 'label': '', - } - - return[(self.data.name, NoneField, field_kwargs)] - - form_element_plugin_registry.register(DummyPlugin) diff --git a/src/fobi/helpers.py b/src/fobi/helpers.py index 67a34d7e..06c36afd 100644 --- a/src/fobi/helpers.py +++ b/src/fobi/helpers.py @@ -666,6 +666,7 @@ class StrippedRequest(object): # ***************************************************************************** # ***************************************************************************** + class JSONDataExporter(object): """Exporting the data into JSON.""" diff --git a/src/fobi/models.py b/src/fobi/models.py index 2bc422c9..ff393e28 100644 --- a/src/fobi/models.py +++ b/src/fobi/models.py @@ -257,7 +257,7 @@ class FormWizardEntry(models.Model): user = models.ForeignKey(AUTH_USER_MODEL, verbose_name=_("User")) name = models.CharField(_("Name"), max_length=255) title = models.CharField(_("Title"), max_length=255, null=True, - blank=True, help_text=_("Shown in templates if" + blank=True, help_text=_("Shown in templates if " "available.")) slug = AutoSlugField(populate_from='name', verbose_name=_("Slug"), unique=True) @@ -338,7 +338,7 @@ class FormEntry(models.Model): user = models.ForeignKey(AUTH_USER_MODEL, verbose_name=_("User")) name = models.CharField(_("Name"), max_length=255) title = models.CharField(_("Title"), max_length=255, null=True, - blank=True, help_text=_("Shown in templates if" + blank=True, help_text=_("Shown in templates if " "available.")) slug = AutoSlugField( populate_from='name', verbose_name=_("Slug"), unique=True diff --git a/src/fobi/tests/data.py b/src/fobi/tests/data.py index 029bc025..d026deea 100644 --- a/src/fobi/tests/data.py +++ b/src/fobi/tests/data.py @@ -3,70 +3,72 @@ import datetime from django.utils.text import force_text -# from fobi.contrib.plugins.form_elements.content.content_image.fobi_form_elements \ -# import ContentImagePlugin -# from fobi.contrib.plugins.form_elements.content.content_text.fobi_form_elements \ -# import ContentTextPlugin -# from fobi.contrib.plugins.form_elements.content.content_video.fobi_form_elements \ -# import ContentVideoPlugin +# from fobi.contrib.plugins.form_elements.content \ +# .content_image.fobi_form_elements import ContentImagePlugin +# from fobi.contrib.plugins.form_elements.content \ +# .content_text.fobi_form_elements import ContentTextPlugin +# from fobi.contrib.plugins.form_elements.content \ +# .content_video.fobi_form_elements import ContentVideoPlugin -from fobi.contrib.plugins.form_elements.fields.boolean.fobi_form_elements \ - import BooleanSelectPlugin -# from fobi.contrib.plugins.form_elements.fields.checkbox_select_multiple.fobi_form_elements \ -# import CheckboxSelectMultipleInputPlugin -from fobi.contrib.plugins.form_elements.fields.date.fobi_form_elements \ - import DateInputPlugin -# from fobi.contrib.plugins.form_elements.fields.date_drop_down.fobi_form_elements \ -# import DateDropDownInputPlugin -from fobi.contrib.plugins.form_elements.fields.datetime.fobi_form_elements \ - import DateTimeInputPlugin -from fobi.contrib.plugins.form_elements.fields.decimal.fobi_form_elements \ - import DecimalInputPlugin -from fobi.contrib.plugins.form_elements.fields.email.fobi_form_elements \ - import EmailInputPlugin -# from fobi.contrib.plugins.form_elements.fields.file.fobi_form_elements \ -# import FileInputPlugin -from fobi.contrib.plugins.form_elements.fields.float.fobi_form_elements \ - import FloatInputPlugin -# from fobi.contrib.plugins.form_elements.fields.hidden.fobi_form_elements \ -# import HiddenInputPlugin -# from fobi.contrib.plugins.form_elements.fields.hidden_model_object.fobi_form_elements \ -# import HiddenModelObjectInputPlugin -from fobi.contrib.plugins.form_elements.fields.integer.fobi_form_elements \ - import IntegerInputPlugin -from fobi.contrib.plugins.form_elements.fields.ip_address.fobi_form_elements \ - import IPAddressInputPlugin -from fobi.contrib.plugins.form_elements.fields.null_boolean.fobi_form_elements \ - import NullBooleanSelectPlugin -from fobi.contrib.plugins.form_elements.fields.select.fobi_form_elements \ - import SelectInputPlugin -from fobi.contrib.plugins.form_elements.fields.select_model_object.fobi_form_elements \ - import SelectModelObjectInputPlugin -from fobi.contrib.plugins.form_elements.fields.select_multiple.fobi_form_elements \ - import SelectMultipleInputPlugin -from fobi.contrib.plugins.form_elements.fields.slug.fobi_form_elements \ - import SlugInputPlugin -from fobi.contrib.plugins.form_elements.fields.text.fobi_form_elements \ - import TextInputPlugin -from fobi.contrib.plugins.form_elements.fields.textarea.fobi_form_elements \ - import TextareaPlugin -from fobi.contrib.plugins.form_elements.fields.url.fobi_form_elements \ - import URLInputPlugin +from fobi.contrib.plugins.form_elements.fields \ + .boolean.fobi_form_elements import BooleanSelectPlugin +# from fobi.contrib.plugins.form_elements.fields.checkbox_select_multiple \ +# .fobi_form_elements import CheckboxSelectMultipleInputPlugin +from fobi.contrib.plugins.form_elements.fields \ + .date.fobi_form_elements import DateInputPlugin +# from fobi.contrib.plugins.form_elements.fields \ +# .date_drop_down.fobi_form_elements import DateDropDownInputPlugin +from fobi.contrib.plugins.form_elements.fields \ + .datetime.fobi_form_elements import DateTimeInputPlugin +from fobi.contrib.plugins.form_elements.fields \ + .decimal.fobi_form_elements import DecimalInputPlugin +from fobi.contrib.plugins.form_elements.fields \ + .email.fobi_form_elements import EmailInputPlugin +# from fobi.contrib.plugins.form_elements.fields \ +# .file.fobi_form_elements import FileInputPlugin +from fobi.contrib.plugins.form_elements.fields \ + .float.fobi_form_elements import FloatInputPlugin +# from fobi.contrib.plugins.form_elements.fields \ +# .hidden.fobi_form_elements import HiddenInputPlugin +# from fobi.contrib.plugins.form_elements.fields.hidden_model_object \ +# .fobi_form_elements import HiddenModelObjectInputPlugin +from fobi.contrib.plugins.form_elements.fields \ + .integer.fobi_form_elements import IntegerInputPlugin +from fobi.contrib.plugins.form_elements.fields \ + .ip_address.fobi_form_elements import IPAddressInputPlugin +from fobi.contrib.plugins.form_elements.fields \ + .null_boolean.fobi_form_elements import NullBooleanSelectPlugin +from fobi.contrib.plugins.form_elements.fields \ + .select.fobi_form_elements import SelectInputPlugin +from fobi.contrib.plugins.form_elements.fields.select_model_object \ + .fobi_form_elements import SelectModelObjectInputPlugin +from fobi.contrib.plugins.form_elements.fields \ + .select_multiple.fobi_form_elements import SelectMultipleInputPlugin +from fobi.contrib.plugins.form_elements.fields.slug \ + .fobi_form_elements import SlugInputPlugin +from fobi.contrib.plugins.form_elements.fields \ + .text.fobi_form_elements import TextInputPlugin +from fobi.contrib.plugins.form_elements.fields \ + .textarea.fobi_form_elements import TextareaPlugin +from fobi.contrib.plugins.form_elements.fields \ + .url.fobi_form_elements import URLInputPlugin -from fobi.contrib.plugins.form_handlers.db_store.fobi_form_handlers \ - import DBStoreHandlerPlugin -from fobi.contrib.plugins.form_handlers.mail.fobi_form_handlers \ - import MailHandlerPlugin -from fobi.contrib.plugins.form_handlers.http_repost.fobi_form_handlers \ - import HTTPRepostHandlerPlugin +from fobi.contrib.plugins.form_handlers \ + .db_store.fobi_form_handlers import DBStoreHandlerPlugin +from fobi.contrib.plugins.form_handlers \ + .mail.fobi_form_handlers import MailHandlerPlugin +from fobi.contrib.plugins.form_handlers \ + .http_repost.fobi_form_handlers import HTTPRepostHandlerPlugin __title__ = 'fobi.tests.data' __author__ = 'Artur Barseghyan ' __copyright__ = '2014-2016 Artur Barseghyan' __license__ = 'GPL 2.0/LGPL 2.1' __all__ = ( - 'TEST_FORM_ELEMENT_PLUGIN_DATA', 'TEST_FORM_FIELD_DATA', + 'TEST_FORM_ELEMENT_PLUGIN_DATA', + 'TEST_FORM_FIELD_DATA', 'TEST_FORM_HANDLER_PLUGIN_DATA', + 'TEST_MAILCHIMP_IMPORTER_FORM_DATA' ) TEST_FORM_ELEMENT_PLUGIN_DATA = { @@ -84,14 +86,14 @@ TEST_FORM_ELEMENT_PLUGIN_DATA = { # 'required': False, # }, - # Add a "Date" input form elelement + # Add a "Date" input form element force_text(DateInputPlugin.name): { 'label': "Test date input", 'help_text': "Lorem ipsum select multiple input", 'required': False, }, - # Add a "DateTime" input form elelement + # Add a "DateTime" input form element force_text(DateTimeInputPlugin.name): { 'label': "Test datetime input", 'help_text': "Lorem ipsum select multiple input", @@ -113,7 +115,7 @@ TEST_FORM_ELEMENT_PLUGIN_DATA = { }, # TODO: Add file test. - # Add a "File" (file) form elelement + # Add a "File" (file) form element # force_text(FileInputPlugin.name): { # 'label': "Test file input", # #'name': "test_file_input", @@ -129,7 +131,7 @@ TEST_FORM_ELEMENT_PLUGIN_DATA = { }, # TODO: Find out why selenium fails here! - # Add a "Hidden" (boolean) form elelement + # Add a "Hidden" (boolean) form element # force_text(HiddenInputPlugin.name): { # 'label': "Test hidden input", # #'name': "test_hidden_input", @@ -137,70 +139,70 @@ TEST_FORM_ELEMENT_PLUGIN_DATA = { # 'required': True, # }, - # Add a "Integer" (text input) form elelement + # Add a "Integer" (text input) form element force_text(IntegerInputPlugin.name): { 'label': "Test integer", 'help_text': "Lorem ipsum text input", 'required': True, }, - # Add a "IP address" (text input) form elelement + # Add a "IP address" (text input) form element force_text(IPAddressInputPlugin.name): { 'label': "Test IP address", 'help_text': "Lorem ipsum text input", 'required': True, }, - # Add a "null boolean" form elelement + # Add a "null boolean" form element force_text(NullBooleanSelectPlugin.name): { 'label': "Test null boolean", 'help_text': "Lorem ipsum text input", 'required': True, }, - # Add a "Select Input" (select input) form elelement + # Add a "Select Input" (select input) form element force_text(SelectInputPlugin.name): { 'label': "Test select", 'help_text': "Lorem ipsum text input", 'required': False, }, - # Add a "Select model object" (select input) form elelement + # Add a "Select model object" (select input) form element force_text(SelectModelObjectInputPlugin.name): { 'label': "Test select model object", 'help_text': "Lorem ipsum select model object input", 'required': False, }, - # Add a "Select multiple" (select multiple input) form elelement + # Add a "Select multiple" (select multiple input) form element force_text(SelectMultipleInputPlugin.name): { 'label': "Test select multiple input", 'help_text': "Lorem ipsum select multiple input", 'required': False, }, - # Add a "Select multiple" (select multiple input) form elelement + # Add a "Select multiple" (select multiple input) form element force_text(SlugInputPlugin.name): { 'label': "Test slug input", 'help_text': "Lorem ipsum select multiple input", 'required': False, }, - # Add a "Text" (text input) form elelement + # Add a "Text" (text input) form element force_text(TextInputPlugin.name): { 'label': "Test text", 'help_text': "Lorem ipsum text input", 'required': True, }, - # Add a "Textarea" (text area) form elelement + # Add a "Textarea" (text area) form element force_text(TextareaPlugin.name): { 'label': "Test text area", 'help_text': "Lorem ipsum text area", 'required': True, }, - # Add a "URL input" form elelement + # Add a "URL input" form element force_text(URLInputPlugin.name): { 'label': "Test URL input", 'help_text': "Lorem ipsum text area", @@ -246,3 +248,210 @@ TEST_FORM_HANDLER_PLUGIN_DATA = { 'endpoint_url': 'http://dev.example.com' } } + + +TEST_MAILCHIMP_IMPORTER_FORM_DATA = [ + { + u'default': u'', + u'field_type': u'email', + u'helptext': u'', + u'id': 0, + u'name': u'Email Address', + u'order': u'1', + u'public': True, + u'req': True, + u'show': True, + u'size': u'25', + u'tag': u'EMAIL' + }, + { + u'default': u'', + u'field_type': u'text', + u'helptext': u'', + u'id': 1, + u'name': u'First Name', + u'order': u'2', + u'public': True, + u'req': False, + u'show': True, + u'size': u'25', + u'tag': u'FNAME' + }, + { + u'default': u'', + u'field_type': u'text', + u'helptext': u'', + u'id': 2, + u'name': u'Last Name', + u'order': u'3', + u'public': True, + u'req': False, + u'show': True, + u'size': u'25', + u'tag': u'LNAME' + }, + { + u'default': u'', + u'field_type': u'text', + u'helptext': u'', + u'id': 3, + u'name': u'Organisation', + u'order': u'4', + u'public': True, + u'req': False, + u'show': True, + u'size': u'25', + u'tag': u'ORG' + }, + { + u'default': u'Type Text Default Value', + u'field_type': u'text', + u'helptext': u'Type Text Help Text', + u'id': 4, + u'name': u'type_text', + u'order': u'5', + u'public': True, + u'req': True, + u'show': True, + u'size': u'25', + u'tag': u'TYPE_TEXT' + }, + { + u'default': u'1', + u'field_type': u'number', + u'helptext': u'Type Number Help Text', + u'id': 5, + u'name': u'type_number', + u'order': u'6', + u'public': True, + u'req': False, + u'show': True, + u'size': u'25', + u'tag': u'TYPE_NUMBE' + }, + { + u'choices': [u'First Choice', u'Second Choice', u'Third Choice'], + u'default': u'Second Choice', + u'field_type': u'radio', + u'helptext': u'Type Radio Buttons Help Text', + u'id': 6, + u'name': u'type_radio_buttons', + u'order': u'7', + u'public': True, + u'req': True, + u'show': True, + u'size': u'25', + u'tag': u'TYPE_RADIO' + }, + { + u'choices': [u'First Choice', u'Second Choice', u'Third Choice'], + u'default': u'Third Choice', + u'field_type': u'dropdown', + u'helptext': u'Drop Down Help Text', + u'id': 7, + u'name': u'type_drop_down', + u'order': u'9', + u'public': True, + u'req': True, + u'show': True, + u'size': u'25', + u'tag': u'TYPE_DROPD' + }, + { + u'dateformat': u'MM/DD/YYYY', + u'default': u'', + u'field_type': u'date', + u'helptext': u'Type Date Help Text', + u'id': 8, + u'name': u'type_date', + u'order': u'10', + u'public': True, + u'req': True, + u'show': True, + u'size': u'25', + u'tag': u'TYPE_DATE' + }, + { + u'dateformat': u'MM/DD', + u'default': u'', + u'field_type': u'birthday', + u'helptext': u'Type Birthday Help Text', + u'id': 9, + u'name': u'type_birthday', + u'order': u'11', + u'public': True, + u'req': True, + u'show': True, + u'size': u'25', + u'tag': u'TYPE_BIRTH' + }, + { + u'default': u'', + u'defaultcountry': u'109', + u'defaultcountry_cc': u'NL', + u'defaultcountry_name': u'Netherlands', + u'field_type': u'address', + u'helptext': u'Type Address Help Text', + u'id': 10, + u'name': u'type_address', + u'order': u'12', + u'public': True, + u'req': False, + u'show': True, + u'size': u'25', + u'tag': u'TYPE_ADDRE' + }, + { + u'default': u'', + u'field_type': u'zip', + u'helptext': u'Type Zip Code Help Text', + u'id': 11, + u'name': u'type_zip_code', + u'order': u'13', + u'public': True, + u'req': False, + u'show': True, + u'size': u'25', + u'tag': u'TYPE_ZIP_C' + }, + { + u'default': u'', + u'field_type': u'phone', + u'helptext': u'Type Phone Help Text', + u'id': 12, + u'name': u'type_phone', + u'order': u'14', + u'phoneformat': u'none', + u'public': True, + u'req': False, + u'show': True, + u'size': u'25', + u'tag': u'TYPE_PHONE' + }, + { + u'default': u'', + u'field_type': u'url', + u'helptext': u'Type Website Help Text', + u'id': 13, + u'name': u'type_website', + u'order': u'15', + u'public': True, + u'req': True, + u'show': True, + u'size': u'25', + u'tag': u'TYPE_WEBSI' + }, + { + u'default': u'', + u'field_type': u'imageurl', + u'helptext': u'Type Image Help Text', + u'id': 14, + u'name': u'type_image', + u'order': u'16', + u'public': True, + u'req': False, + u'show': True, + u'size': u'25', + u'tag': u'TYPE_IMAGE' + } +] diff --git a/src/fobi/tests/helpers.py b/src/fobi/tests/helpers.py index 63606f31..9dcddb60 100644 --- a/src/fobi/tests/helpers.py +++ b/src/fobi/tests/helpers.py @@ -4,37 +4,37 @@ from django.core.exceptions import ObjectDoesNotExist from django.core.management import call_command from fobi.models import FormEntry, FormElementEntry, FormHandlerEntry -from \ - fobi.contrib.plugins.form_elements.content.content_text.fobi_form_elements \ - import ContentTextPlugin -from \ - fobi.contrib.plugins.form_elements.content.content_image.fobi_form_elements \ - import ContentImagePlugin +from fobi.contrib.plugins.form_elements.content \ + .content_text.fobi_form_elements import ContentTextPlugin +from fobi.contrib.plugins.form_elements.content \ + .content_image.fobi_form_elements import ContentImagePlugin -from fobi.contrib.plugins.form_elements.fields.boolean.fobi_form_elements \ - import BooleanSelectPlugin -from fobi.contrib.plugins.form_elements.fields.email.fobi_form_elements \ - import EmailInputPlugin -from fobi.contrib.plugins.form_elements.fields.hidden.fobi_form_elements \ - import HiddenInputPlugin -from fobi.contrib.plugins.form_elements.fields.integer.fobi_form_elements \ - import IntegerInputPlugin -from fobi.contrib.plugins.form_elements.fields.text.fobi_form_elements \ - import TextInputPlugin -from fobi.contrib.plugins.form_elements.fields.textarea.fobi_form_elements \ - import TextareaPlugin +from fobi.contrib.plugins.form_elements.fields \ + .boolean.fobi_form_elements import BooleanSelectPlugin +from fobi.contrib.plugins.form_elements.fields \ + .email.fobi_form_elements import EmailInputPlugin +from fobi.contrib.plugins.form_elements.fields \ + .hidden.fobi_form_elements import HiddenInputPlugin +from fobi.contrib.plugins.form_elements.fields \ + .integer.fobi_form_elements import IntegerInputPlugin +from fobi.contrib.plugins.form_elements.fields \ + .text.fobi_form_elements import TextInputPlugin +from fobi.contrib.plugins.form_elements.fields \ + .textarea.fobi_form_elements import TextareaPlugin -from fobi.contrib.plugins.form_handlers.db_store.fobi_form_handlers \ - import DBStoreHandlerPlugin -from fobi.contrib.plugins.form_handlers.mail.fobi_form_handlers \ - import MailHandlerPlugin +from fobi.contrib.plugins.form_handlers \ + .db_store.fobi_form_handlers import DBStoreHandlerPlugin +from fobi.contrib.plugins.form_handlers \ + .mail.fobi_form_handlers import MailHandlerPlugin -from fobi.tests.base import ( +from .base import ( is_fobi_setup_completed, mark_fobi_setup_as_completed ) -from fobi.tests.constants import ( - FOBI_TEST_USER_USERNAME, FOBI_TEST_USER_PASSWORD, - TEST_FORM_NAME, TEST_FORM_SLUG +from .constants import ( + FOBI_TEST_USER_USERNAME, + FOBI_TEST_USER_PASSWORD, + TEST_FORM_NAME, + TEST_FORM_SLUG ) __title__ = 'fobi.tests.helpers' @@ -42,8 +42,10 @@ __author__ = 'Artur Barseghyan ' __copyright__ = '2014-2016 Artur Barseghyan' __license__ = 'GPL 2.0/LGPL 2.1' __all__ = ( - 'get_or_create_admin_user', 'get_or_create_admin_user', - 'create_form_with_entries', 'db_clean_up', + 'get_or_create_admin_user', + 'get_or_create_admin_user', + 'create_form_with_entries', + 'db_clean_up', ) # **************************************************************************** @@ -126,9 +128,9 @@ def create_form_with_entries(user=None, create_entries_if_form_exist=True): ) form_entry.save() - # ************************************************************************* - # ******************************** Form elements ************************** - # ************************************************************************* + # ************************************************************************ + # ******************************** Form elements ************************* + # ************************************************************************ position = 1 # Text input form_element_entry = FormElementEntry( @@ -225,8 +227,8 @@ def create_form_with_entries(user=None, create_entries_if_form_exist=True): '{"text": "Suspendisse potenti. Etiam in nunc sodales, ' 'congue lectus ut, suscipit massa. In commodo fringilla ' 'orci, in varius eros gravida a! Aliquam erat volutpat. ' - 'Donec sodales orci nec massa aliquam bibendum. Aenean sed ' - 'condimentum velit. Mauris luctus bibendum nulla vel ' + 'Donec sodales orci nec massa aliquam bibendum. Aenean ' + 'sed condimentum velit. Mauris luctus bibendum nulla vel ' 'tempus. Integer tempor condimentum ligula sed feugiat. ' 'Aenean scelerisque ultricies vulputate. Donec semper ' 'lorem rhoncus sem cras amet."}', @@ -235,9 +237,9 @@ def create_form_with_entries(user=None, create_entries_if_form_exist=True): form_element_entry.save() position += 1 - # ************************************************************************* - # ******************************** Form handlers ************************** - # ************************************************************************* + # ************************************************************************ + # ******************************** Form handlers ************************* + # ************************************************************************ # DB save form_handler_entry = FormHandlerEntry( diff --git a/src/fobi/tests/test_browser_build_dynamic_forms.py b/src/fobi/tests/test_browser_build_dynamic_forms.py index a9d85371..ba85dfa3 100644 --- a/src/fobi/tests/test_browser_build_dynamic_forms.py +++ b/src/fobi/tests/test_browser_build_dynamic_forms.py @@ -17,15 +17,19 @@ from django.conf import settings from fobi.models import FormEntry -from fobi.tests.base import print_info, skip # , BaseBrowserTest -from fobi.tests.helpers import ( - setup_fobi, get_or_create_admin_user, db_clean_up -) -from fobi.tests import constants -from fobi.tests.data import ( - TEST_FORM_ELEMENT_PLUGIN_DATA, TEST_FORM_FIELD_DATA, +from . import constants +from .base import print_info, skip +from .data import ( + TEST_FORM_ELEMENT_PLUGIN_DATA, + TEST_FORM_FIELD_DATA, TEST_FORM_HANDLER_PLUGIN_DATA ) +from .helpers import ( + setup_fobi, + get_or_create_admin_user, + db_clean_up +) + __title__ = 'fobi.tests.test_browser_build_dynamic_forms' __author__ = 'Artur Barseghyan ' @@ -239,7 +243,8 @@ class BaseFobiBrowserBuldDynamicFormsTest(LiveServerTestCase): self.selenium.find_element_by_xpath('//button[@type="submit"]').click() logger.debug( - """//div[contains(text(), 'Form {0} was created successfully.') and contains(@class, "alert-info")]""".format( + """//div[contains(text(), 'Form {0} was created """ + """successfully.') and contains(@class, "alert-info")]""".format( constants.TEST_FORM_NAME ) ) @@ -247,7 +252,9 @@ class BaseFobiBrowserBuldDynamicFormsTest(LiveServerTestCase): # Wait until the fobi page opens with the form element in WebDriverWait(self.selenium, timeout=TIMEOUT).until( lambda driver: driver.find_element_by_xpath( - """//div[contains(text(), 'Form {0} was created successfully.') and contains(@class, "alert-info")]""".format( + """//div[contains(text(), 'Form {0} was created """ + """successfully.') """ + """and contains(@class, "alert-info")]""".format( constants.TEST_FORM_NAME ) ) @@ -272,7 +279,8 @@ class BaseFobiBrowserBuldDynamicFormsTest(LiveServerTestCase): # Click the add form element button to add a new form element to the # form. add_form_element_link = self.selenium.find_element_by_xpath( - """//a[contains(text(), 'Choose form element to add') and contains(@class, "dropdown-toggle")]""" + """//a[contains(text(), 'Choose form element to add') and """ + """contains(@class, "dropdown-toggle")]""" ) self._scroll_to(0, 0) @@ -290,7 +298,8 @@ class BaseFobiBrowserBuldDynamicFormsTest(LiveServerTestCase): # Click on the element we want form_element_to_add = \ - add_form_element_available_elements_container.find_element_by_xpath( + add_form_element_available_elements_container \ + .find_element_by_xpath( '//a[text()="{0}"]'.format(form_element_name) ) @@ -303,7 +312,8 @@ class BaseFobiBrowserBuldDynamicFormsTest(LiveServerTestCase): # Wait until the add widget view opens WebDriverWait(self.selenium, timeout=TIMEOUT).until( lambda driver: driver.find_element_by_xpath( - """//h1[contains(text(), 'Add "{0}" element to the form')]""".format( + """//h1[contains(text(), 'Add "{0}" element to """ + """the form')]""".format( form_element_name ) ) @@ -323,7 +333,9 @@ class BaseFobiBrowserBuldDynamicFormsTest(LiveServerTestCase): # Wait until the fobi page opens with the form element in. WebDriverWait(self.selenium, timeout=TIMEOUT).until( lambda driver: driver.find_element_by_xpath( - """//div[contains(text(), 'The form element plugin "{0}" was added successfully.') and contains(@class, "alert-info")]""".format( + """//div[contains(text(), 'The form element plugin "{0}" """ + """was added successfully.') """ + """and contains(@class, "alert-info")]""".format( form_element_name ) ) @@ -364,7 +376,8 @@ class BaseFobiBrowserBuldDynamicFormsTest(LiveServerTestCase): # Get the label of the given form element in order to delete it later # from the form. delete_form_element_label = self.selenium.find_element_by_xpath( - """//label[contains(text(), '({0})') and contains(@class, "control-label")]""".format( + """//label[contains(text(), '({0})') """ + """and contains(@class, "control-label")]""".format( form_element_name ) ) @@ -376,7 +389,8 @@ class BaseFobiBrowserBuldDynamicFormsTest(LiveServerTestCase): # Click the add form element button to add a new form element to the # form. delete_form_element_link = \ - delete_form_element_label_parent_container.find_element_by_partial_link_text( + delete_form_element_label_parent_container \ + .find_element_by_partial_link_text( 'Delete' ) delete_form_element_link.click() @@ -387,7 +401,9 @@ class BaseFobiBrowserBuldDynamicFormsTest(LiveServerTestCase): # Wait until the fobi page opens with the form element in. WebDriverWait(self.selenium, timeout=LONG_TIMEOUT).until( lambda driver: driver.find_element_by_xpath( - """//div[contains(text(), 'The form element plugin "{0}" was deleted successfully.') and contains(@class, "alert-info")]""".format( + """//div[contains(text(), 'The form element plugin "{0}" """ + """was deleted successfully.') """ + """and contains(@class, "alert-info")]""".format( form_element_name ) ) @@ -424,7 +440,8 @@ class BaseFobiBrowserBuldDynamicFormsTest(LiveServerTestCase): # Click the add form element button to add a new form element to the # form. add_form_handler_link = self.selenium.find_element_by_xpath( - """//a[contains(text(), 'Choose form handler to add') and contains(@class, "dropdown-toggle")]""" + """//a[contains(text(), 'Choose form handler to add') """ + """and contains(@class, "dropdown-toggle")]""" ) add_form_handler_link.click() @@ -440,7 +457,8 @@ class BaseFobiBrowserBuldDynamicFormsTest(LiveServerTestCase): # Click on the element we want form_handler_to_add = \ - add_form_handler_available_elements_container.find_element_by_xpath( + add_form_handler_available_elements_container \ + .find_element_by_xpath( '//a[text()="{0}"]'.format(form_handler_name) ) form_handler_to_add.click() @@ -450,7 +468,8 @@ class BaseFobiBrowserBuldDynamicFormsTest(LiveServerTestCase): # Wait until the add widget view opens WebDriverWait(self.selenium, timeout=TIMEOUT).until( lambda driver: driver.find_element_by_xpath( - """//h1[contains(text(), 'Add "{0}" handler to the form')]""".format( + """//h1[contains(text(), 'Add "{0}" handler to """ + """the form')]""".format( form_handler_name ) ) @@ -469,7 +488,9 @@ class BaseFobiBrowserBuldDynamicFormsTest(LiveServerTestCase): # Wait until the fobi page opens with the form element in. WebDriverWait(self.selenium, timeout=TIMEOUT).until( lambda driver: driver.find_element_by_xpath( - """//div[contains(text(), 'The form handler plugin "{0}" was added successfully.') and contains(@class, "alert-info")]""".format( + """//div[contains(text(), 'The form handler plugin "{0}" """ + """was added successfully.') """ + """and contains(@class, "alert-info")]""".format( form_handler_name ) ) @@ -529,7 +550,8 @@ class BaseFobiBrowserBuldDynamicFormsTest(LiveServerTestCase): # Click the add form element button to add a new form element to the # form. delete_form_handler_link = \ - delete_form_handler_label_parent_container.find_element_by_partial_link_text( + delete_form_handler_label_parent_container \ + .find_element_by_partial_link_text( 'Delete' ) delete_form_handler_link.click() @@ -539,7 +561,9 @@ class BaseFobiBrowserBuldDynamicFormsTest(LiveServerTestCase): # Wait until the fobi page opens with the form element in. WebDriverWait(self.selenium, timeout=TIMEOUT).until( lambda driver: driver.find_element_by_xpath( - """//div[contains(text(), 'The form handler plugin "{0}" was deleted successfully.') and contains(@class, "alert-info")]""".format( + """//div[contains(text(), 'The form handler plugin "{0}" """ + """was deleted successfully.') """ + """and contains(@class, "alert-info")]""".format( form_handler_name ) ) @@ -652,7 +676,9 @@ class BaseFobiBrowserBuldDynamicFormsTest(LiveServerTestCase): # Wait until the submit success page opens a clear success message. WebDriverWait(self.selenium, timeout=TIMEOUT).until( lambda driver: driver.find_element_by_xpath( - """//div[contains(text(), 'Form {0} was submitted successfully.') and contains(@class, "alert-info")]""".format( + """//div[contains(text(), 'Form {0} was submitted """ + """successfully.') """ + """and contains(@class, "alert-info")]""".format( constants.TEST_FORM_NAME ) ) diff --git a/src/fobi/tests/test_core.py b/src/fobi/tests/test_core.py index 416cdd1b..a0d1fd1c 100644 --- a/src/fobi/tests/test_core.py +++ b/src/fobi/tests/test_core.py @@ -3,14 +3,17 @@ import unittest from django.test import TestCase, RequestFactory from fobi.base import ( - get_registered_form_element_plugins, get_registered_form_handler_plugins, - get_registered_themes, get_registered_form_callbacks + get_registered_form_element_plugins, + get_registered_form_handler_plugins, + get_registered_themes, + get_registered_form_callbacks ) from fobi.models import FormEntry from fobi.forms import FormEntryForm -from fobi.tests.constants import TEST_FORM_NAME, TEST_FORM_SLUG -from fobi.tests.base import print_info -from fobi.tests.helpers import setup_fobi, get_or_create_admin_user + +from .base import print_info +from .constants import TEST_FORM_NAME, TEST_FORM_SLUG +from .helpers import setup_fobi, get_or_create_admin_user __title__ = 'fobi.tests.test_core' __author__ = 'Artur Barseghyan ' diff --git a/src/fobi/tests/test_dynamic_forms.py b/src/fobi/tests/test_dynamic_forms.py index aec68b32..1979177d 100644 --- a/src/fobi/tests/test_dynamic_forms.py +++ b/src/fobi/tests/test_dynamic_forms.py @@ -3,9 +3,12 @@ import unittest from django.test import TestCase from fobi.dynamic import assemble_form_class -from fobi.tests.base import print_info -from fobi.tests.helpers import ( - setup_fobi, get_or_create_admin_user, create_form_with_entries + +from .base import print_info +from .helpers import ( + setup_fobi, + get_or_create_admin_user, + create_form_with_entries ) __title__ = 'fobi.tests.test_dynamic_forms' diff --git a/src/fobi/tests/test_form_importers_mailchimp.py b/src/fobi/tests/test_form_importers_mailchimp.py index b160c544..7dc8c1c4 100644 --- a/src/fobi/tests/test_form_importers_mailchimp.py +++ b/src/fobi/tests/test_form_importers_mailchimp.py @@ -1,227 +1,54 @@ +import unittest + from django.contrib.auth import get_user_model +from django.test import TestCase -from \ - fobi.contrib.plugins.form_importers.mailchimp_importer.fobi_form_importers \ - import MailChimpImporter +from fobi.contrib.plugins.form_importers \ + .mailchimp_importer.fobi_form_importers import MailChimpImporter +from fobi.models import FormEntry, FormElementEntry -test_form_data = [ - { - u'default': u'', - u'field_type': u'email', - u'helptext': u'', - u'id': 0, - u'name': u'Email Address', - u'order': u'1', - u'public': True, - u'req': True, - u'show': True, - u'size': u'25', - u'tag': u'EMAIL' - }, - { - u'default': u'', - u'field_type': u'text', - u'helptext': u'', - u'id': 1, - u'name': u'First Name', - u'order': u'2', - u'public': True, - u'req': False, - u'show': True, - u'size': u'25', - u'tag': u'FNAME' - }, - { - u'default': u'', - u'field_type': u'text', - u'helptext': u'', - u'id': 2, - u'name': u'Last Name', - u'order': u'3', - u'public': True, - u'req': False, - u'show': True, - u'size': u'25', - u'tag': u'LNAME' - }, - { - u'default': u'', - u'field_type': u'text', - u'helptext': u'', - u'id': 3, - u'name': u'Organisation', - u'order': u'4', - u'public': True, - u'req': False, - u'show': True, - u'size': u'25', - u'tag': u'ORG' - }, - { - u'default': u'Type Text Default Value', - u'field_type': u'text', - u'helptext': u'Type Text Help Text', - u'id': 4, - u'name': u'type_text', - u'order': u'5', - u'public': True, - u'req': True, - u'show': True, - u'size': u'25', - u'tag': u'TYPE_TEXT' - }, - { - u'default': u'1', - u'field_type': u'number', - u'helptext': u'Type Number Help Text', - u'id': 5, - u'name': u'type_number', - u'order': u'6', - u'public': True, - u'req': False, - u'show': True, - u'size': u'25', - u'tag': u'TYPE_NUMBE' - }, - { - u'choices': [u'First Choice', u'Second Choice', u'Third Choice'], - u'default': u'Second Choice', - u'field_type': u'radio', - u'helptext': u'Type Radio Buttons Help Text', - u'id': 6, - u'name': u'type_radio_buttons', - u'order': u'7', - u'public': True, - u'req': True, - u'show': True, - u'size': u'25', - u'tag': u'TYPE_RADIO' - }, - { - u'choices': [u'First Choice', u'Second Choice', u'Third Choice'], - u'default': u'Third Choice', - u'field_type': u'dropdown', - u'helptext': u'Drop Down Help Text', - u'id': 7, - u'name': u'type_drop_down', - u'order': u'9', - u'public': True, - u'req': True, - u'show': True, - u'size': u'25', - u'tag': u'TYPE_DROPD' - }, - { - u'dateformat': u'MM/DD/YYYY', - u'default': u'', - u'field_type': u'date', - u'helptext': u'Type Date Help Text', - u'id': 8, - u'name': u'type_date', - u'order': u'10', - u'public': True, - u'req': True, - u'show': True, - u'size': u'25', - u'tag': u'TYPE_DATE' - }, - { - u'dateformat': u'MM/DD', - u'default': u'', - u'field_type': u'birthday', - u'helptext': u'Type Birthday Help Text', - u'id': 9, - u'name': u'type_birthday', - u'order': u'11', - u'public': True, - u'req': True, - u'show': True, - u'size': u'25', - u'tag': u'TYPE_BIRTH' - }, - { - u'default': u'', - u'defaultcountry': u'109', - u'defaultcountry_cc': u'NL', - u'defaultcountry_name': u'Netherlands', - u'field_type': u'address', - u'helptext': u'Type Address Help Text', - u'id': 10, - u'name': u'type_address', - u'order': u'12', - u'public': True, - u'req': False, - u'show': True, - u'size': u'25', - u'tag': u'TYPE_ADDRE' - }, - { - u'default': u'', - u'field_type': u'zip', - u'helptext': u'Type Zip Code Help Text', - u'id': 11, - u'name': u'type_zip_code', - u'order': u'13', - u'public': True, - u'req': False, - u'show': True, - u'size': u'25', - u'tag': u'TYPE_ZIP_C' - }, - { - u'default': u'', - u'field_type': u'phone', - u'helptext': u'Type Phone Help Text', - u'id': 12, - u'name': u'type_phone', - u'order': u'14', - u'phoneformat': u'none', - u'public': True, - u'req': False, - u'show': True, - u'size': u'25', - u'tag': u'TYPE_PHONE' - }, - { - u'default': u'', - u'field_type': u'url', - u'helptext': u'Type Website Help Text', - u'id': 13, - u'name': u'type_website', - u'order': u'15', - u'public': True, - u'req': True, - u'show': True, - u'size': u'25', - u'tag': u'TYPE_WEBSI' - }, - { - u'default': u'', - u'field_type': u'imageurl', - u'helptext': u'Type Image Help Text', - u'id': 14, - u'name': u'type_image', - u'order': u'16', - u'public': True, - u'req': False, - u'show': True, - u'size': u'25', - u'tag': u'TYPE_IMAGE' - } -] +from .base import print_info +from .data import TEST_MAILCHIMP_IMPORTER_FORM_DATA +from .helpers import setup_fobi, get_or_create_admin_user + +__title__ = 'fobi.tests.test_form_importers_mailchimp' +__author__ = 'Artur Barseghyan ' +__copyright__ = '2014-2016 Artur Barseghyan' +__license__ = 'GPL 2.0/LGPL 2.1' +__all__ = ('FormImpotersMailchimpTest',) -def do(): - """Do test. +class FormImpotersMailchimpTest(TestCase): + """Tests of form importers mailchimp functionality.""" - TODO: Make a normal test out of this. - """ - User = get_user_model() - kwargs = {User.USERNAME_FIELD: 'test_user'} - user = User.objects.get(**kwargs) + def setUp(self): + """Set up.""" + setup_fobi(fobi_sync_plugins=True) - form_properties = {'name': 'Test mailchimp form', 'user': user} + @print_info + def test_01_test_mailchimp_impoter(self): + """Test mailchimp impoter.""" + user = get_or_create_admin_user() - importer = MailChimpFormImporter() + form_properties = { + 'name': 'Test mailchimp form', + 'user': user + } - importer.import_data(form_properties, test_form_data) + importer = MailChimpImporter( + form_entry_cls=FormEntry, + form_element_entry_cls=FormElementEntry + ) + + importer.import_data( + form_properties=form_properties, + form_data=TEST_MAILCHIMP_IMPORTER_FORM_DATA + ) + + form_entry = FormEntry.objects.get(**form_properties) + + self.assertIsNotNone(form_entry.pk) + + +if __name__ == '__main__': + unittest.main() diff --git a/src/fobi/tests/test_sortable_dict.py b/src/fobi/tests/test_sortable_dict.py index 366b65da..8ed7b014 100644 --- a/src/fobi/tests/test_sortable_dict.py +++ b/src/fobi/tests/test_sortable_dict.py @@ -6,7 +6,7 @@ from django.test import TestCase from fobi.data_structures import SortableDict -from fobi.tests.base import print_info +from .base import print_info __title__ = 'fobi.tests.test_dynamic_forms' __author__ = 'Artur Barseghyan ' diff --git a/src/fobi/validators.py b/src/fobi/validators.py index e5b1e315..0d5b55dd 100644 --- a/src/fobi/validators.py +++ b/src/fobi/validators.py @@ -1,7 +1,11 @@ import requests from requests.exceptions import ( - ConnectionError, ConnectTimeout, ReadTimeout, SSLError, ProxyError, + ConnectionError, + ConnectTimeout, + ReadTimeout, + SSLError, + ProxyError, RetryError ) diff --git a/src/fobi/views.py b/src/fobi/views.py index f91a6694..f4fe0623 100644 --- a/src/fobi/views.py +++ b/src/fobi/views.py @@ -1445,6 +1445,7 @@ class FormWizardView(DynamicSessionWizardView): ] form_list = [] form_entry_mapping = {} + form_element_entry_mapping = {} wizard_form_element_entries = [] for creation_counter, form_entry in enumerate(form_entries): # Using frozen queryset to minimize query usage @@ -1463,6 +1464,7 @@ class FormWizardView(DynamicSessionWizardView): (form_entry.slug, form_cls) ) form_entry_mapping[form_entry.slug] = form_entry + form_element_entry_mapping[form_entry.slug] = form_element_entries if 0 == len(form_list): raise Http404( @@ -1478,6 +1480,7 @@ class FormWizardView(DynamicSessionWizardView): 'form_wizard_entry': form_wizard_entry, 'wizard_form_element_entries': wizard_form_element_entries, 'form_entry_mapping': form_entry_mapping, + 'form_element_entry_mapping': form_element_entry_mapping, 'fobi_theme': theme, } @@ -1518,12 +1521,16 @@ class FormWizardView(DynamicSessionWizardView): if form.is_valid(): # Get current form entry form_entry = self.form_entry_mapping[self.steps.current] + # Get form elements for the current form entry + form_element_entries = \ + self.form_element_entry_mapping[self.steps.current] # Fire plugin processors form = submit_plugin_form_data( form_entry=form_entry, request=self.request, form=form, - # **{'': ''} # TODO + form_element_entries=form_element_entries, + **{'form_wizard_entry': self.form_wizard_entry} ) # Form wizards make use of form.data instead of form.cleaned_data. # Therefore, we update the form.data with values from @@ -1590,12 +1597,18 @@ class FormWizardView(DynamicSessionWizardView): **kwargs) # Fire plugin processors + # Get current form entry form_entry = self.form_entry_mapping[form_key] + # Get form elements for the current form entry + form_element_entries = \ + self.form_element_entry_mapping[self.steps.current] + form_obj = submit_plugin_form_data( form_entry=form_entry, request=self.request, form=form_obj, - # **{'': ''} # TODO + form_element_entries=form_element_entries, + **{'form_wizard_entry': self.form_wizard_entry} ) final_forms[form_key] = form_obj