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

This commit is contained in:
Artur Barseghyan 2016-11-17 00:07:06 +01:00
parent d3232ff071
commit 4cf22a9cee
131 changed files with 3592 additions and 2885 deletions

View file

@ -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

View file

@ -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 <https://raw.githubusercontent.com/barseghyanartur/django-fobi/master/TODOS.rst>`_
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)

View file

@ -1,6 +1,6 @@
Roadmap of upcoming releases
============================
0.10
0.11
----
yyyy-mm-ddd (upcoming).

View file

@ -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
-------

View file

@ -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 <https://raw.githubusercontent.com/barseghyanartur/django-fobi/master/TODOS.rst>`_
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)

View file

@ -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)

View file

@ -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

View file

@ -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."""

View file

@ -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

View file

@ -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}

View file

@ -1 +1 @@
from customauth.models import MyUser
from .models import MyUser

View file

@ -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',)

View file

@ -13,7 +13,7 @@ from fobi.constants import (
logger = logging.getLogger('fobi')
__all__= (
__all__ = (
'SaveAsFooItem',
'DummyInvalidCallback',
)

View file

@ -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

View file

@ -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

View file

@ -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 = \

View file

@ -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('&copy; 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

View file

@ -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'

View file

@ -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

View file

@ -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

View file

@ -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',
#}
# }

View file

@ -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

View file

@ -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

View file

@ -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',
#}
# }

View file

@ -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',
#}
# }

View file

@ -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 = {

View file

@ -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

View file

@ -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')

View file

@ -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'

View file

@ -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 = (

View file

@ -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'
)

View file

@ -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'
)

View file

@ -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'
)

View file

@ -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'
)

View file

@ -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 = {

View file

@ -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,

View file

@ -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')

View file

@ -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 = {}

View file

@ -2,5 +2,5 @@
{% block theme-javascripts %}
{{ block.super }}
{% include "google_analytics.html" %}
{% endblock theme-javascripts %}
{% if not testing %}{% include "google_analytics.html" %}{% endif %}
{% endblock theme-javascripts %}

2
scripts/pycodestyle.sh Executable file
View file

@ -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/

2
scripts/pycodestyle_example.sh Executable file
View file

@ -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

View file

@ -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 *********************************

View file

@ -1,6 +1,6 @@
__title__ = 'django-fobi'
__version__ = '0.9.17'
__build__ = 0x000072
__version__ = '0.10'
__build__ = 0x000073
__author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>'
__copyright__ = '2014-2016 Artur Barseghyan'
__license__ = 'GPL 2.0/LGPL 2.1'

View file

@ -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

View file

@ -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 <artur.barseghyan@gmail.com>'
__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)]

View file

@ -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)

View file

@ -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 <artur.barseghyan@gmail.com>'
__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': "<p>{0}</p>".format(smart_str(self.data.text)),
'required': False,
'label': '',
}
return [(self.data.name, NoneField, field_kwargs)]

View file

@ -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': "<p>{0}</p>".format(smart_str(self.data.text)),
'required': False,
'label': '',
}
return [(self.data.name, NoneField, field_kwargs)]
form_element_plugin_registry.register(ContentTextPlugin)

View file

@ -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 <artur.barseghyan@gmail.com>'
__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': '<div class="video-wrapper">{0}</div>'.format(
render_video(self.data.url, width, height)
),
'required': False,
'label': '',
}
return [(self.data.name, NoneField, field_kwargs)]

View file

@ -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': '<div class="video-wrapper">{0}</div>'.format(
render_video(self.data.url, width, height)
),
'required': False,
'label': '',
}
return [(self.data.name, NoneField, field_kwargs)]
form_element_plugin_registry.register(ContentVideoPlugin)

View file

@ -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 <artur.barseghyan@gmail.com>'
__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)]

View file

@ -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)

View file

@ -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 <artur.barseghyan@gmail.com>'
__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

View file

@ -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)

View file

@ -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 <artur.barseghyan@gmail.com>'
__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

View file

@ -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 <artur.barseghyan@gmail.com>'
@ -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)

View file

@ -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 <artur.barseghyan@gmail.com>'
__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)]

View file

@ -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)

View file

@ -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 <artur.barseghyan@gmail.com>'
__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

View file

@ -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)

View file

@ -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 <artur.barseghyan@gmail.com>'
__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)]

View file

@ -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)

View file

@ -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 <artur.barseghyan@gmail.com>'
__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

View file

@ -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)

View file

@ -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 <artur.barseghyan@gmail.com>'
__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

View file

@ -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 <artur.barseghyan@gmail.com>'
@ -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)

View file

@ -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 <artur.barseghyan@gmail.com>'
__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)]

View file

@ -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)

View file

@ -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 <artur.barseghyan@gmail.com>'
__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)]

View file

@ -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)

View file

@ -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 <artur.barseghyan@gmail.com>'
__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)]

View file

@ -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)

View file

@ -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 <artur.barseghyan@gmail.com>'
__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)]

View file

@ -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)

View file

@ -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 <artur.barseghyan@gmail.com>'
__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)]

View file

@ -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)

View file

@ -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 <artur.barseghyan@gmail.com>'
__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)]

View file

@ -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)

View file

@ -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 <artur.barseghyan@gmail.com>'
__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)]

View file

@ -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)

View file

@ -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 <artur.barseghyan@gmail.com>'
__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

View file

@ -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)

View file

@ -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 <artur.barseghyan@gmail.com>'
__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)]

View file

@ -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)

View file

@ -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 <artur.barseghyan@gmail.com>'
__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)]

View file

@ -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)

View file

@ -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))
)
)

View file

@ -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 <artur.barseghyan@gmail.com>'
__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

View file

@ -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)

View file

@ -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 <artur.barseghyan@gmail.com>'
__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

View file

@ -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)

View file

@ -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 <artur.barseghyan@gmail.com>'
__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

View file

@ -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)

View file

@ -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 <artur.barseghyan@gmail.com>'
__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

View file

@ -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)

View file

@ -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 <artur.barseghyan@gmail.com>'
__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

View file

@ -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)

View file

@ -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 <artur.barseghyan@gmail.com>'
__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

View file

@ -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

View file

@ -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 <artur.barseghyan@gmail.com>'
__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

Some files were not shown because too many files have changed in this diff Show more