mirror of
https://github.com/Hopiu/django-fobi.git
synced 2026-05-05 20:04:42 +00:00
make it possible to order by plugin name
This commit is contained in:
parent
3a5c4fdffc
commit
af2ff1bca8
6 changed files with 61 additions and 19 deletions
|
|
@ -5,3 +5,4 @@ LOCALE_PATHS = [
|
|||
os.path.abspath(os.path.join(BASE_DIR, 'fobi_locale')),
|
||||
os.path.abspath(os.path.join(BASE_DIR, 'locale')),
|
||||
]
|
||||
FOBI_SORT_PLUGINS_BY_VALUE = True
|
||||
|
|
|
|||
|
|
@ -58,6 +58,7 @@ from .settings import (
|
|||
FAIL_ON_MISSING_INTEGRATION_FORM_HANDLER_PLUGINS,
|
||||
FORM_HANDLER_PLUGINS_EXECUTION_ORDER,
|
||||
FORM_WIZARD_HANDLER_PLUGINS_EXECUTION_ORDER,
|
||||
SORT_PLUGINS_BY_VALUE,
|
||||
THEME_FOOTER_TEXT,
|
||||
# FAIL_ON_ERRORS_IN_FORM_ELEMENT_PLUGINS,
|
||||
)
|
||||
|
|
@ -2793,7 +2794,9 @@ def get_registered_plugins(registry, as_instances=False, sort_items=True):
|
|||
return registered_plugins
|
||||
|
||||
|
||||
def get_registered_plugins_grouped(registry, sort_items=True):
|
||||
def get_registered_plugins_grouped(registry,
|
||||
sort_items=True,
|
||||
sort_by_value=SORT_PLUGINS_BY_VALUE):
|
||||
"""Get registered plugins grouped.
|
||||
|
||||
Gets a list of registered plugins in a form of tuple (plugin name, plugin
|
||||
|
|
@ -2818,7 +2821,10 @@ def get_registered_plugins_grouped(registry, sort_items=True):
|
|||
|
||||
ordered_registered_plugins = OrderedDict()
|
||||
for key, prop in sorted(registered_plugins.items()):
|
||||
ordered_registered_plugins[key] = sorted(prop)
|
||||
if sort_by_value:
|
||||
ordered_registered_plugins[key] = sorted(prop, key=lambda t: t[1])
|
||||
else:
|
||||
ordered_registered_plugins[key] = sorted(prop)
|
||||
|
||||
return ordered_registered_plugins
|
||||
|
||||
|
|
@ -2871,7 +2877,9 @@ def get_registered_form_element_plugins():
|
|||
return get_registered_plugins(form_element_plugin_registry)
|
||||
|
||||
|
||||
def get_registered_form_element_plugins_grouped():
|
||||
def get_registered_form_element_plugins_grouped(
|
||||
sort_by_value=SORT_PLUGINS_BY_VALUE
|
||||
):
|
||||
"""Get registered form element plugins grouped.
|
||||
|
||||
Gets a list of registered plugins in a form of tuple (plugin name, plugin
|
||||
|
|
@ -2879,7 +2887,10 @@ def get_registered_form_element_plugins_grouped():
|
|||
|
||||
:return dict:
|
||||
"""
|
||||
return get_registered_plugins_grouped(form_element_plugin_registry)
|
||||
return get_registered_plugins_grouped(
|
||||
form_element_plugin_registry,
|
||||
sort_by_value=sort_by_value
|
||||
)
|
||||
|
||||
|
||||
def get_registered_form_element_plugin_uids(flattern=True):
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ __all__ = (
|
|||
'FORM_IMPORTER_PLUGINS_MODULE_NAME',
|
||||
'FORM_WIZARD_HANDLER_PLUGINS_EXECUTION_ORDER',
|
||||
'GET_PARAM_INITIAL_DATA',
|
||||
'SORT_PLUGINS_BY_VALUE',
|
||||
'INTEGRATION_FORM_ELEMENT_PLUGINS_MODULE_NAME',
|
||||
'INTEGRATION_FORM_HANDLER_PLUGINS_MODULE_NAME',
|
||||
'RESTRICT_PLUGIN_ACCESS',
|
||||
|
|
@ -110,6 +111,8 @@ FORM_WIZARD_HANDLER_PLUGINS_EXECUTION_ORDER = (
|
|||
# be the last plugin to be executed.
|
||||
)
|
||||
|
||||
SORT_PLUGINS_BY_VALUE = False
|
||||
|
||||
FAIL_ON_MISSING_FORM_ELEMENT_PLUGINS = True
|
||||
FAIL_ON_MISSING_FORM_HANDLER_PLUGINS = True
|
||||
FAIL_ON_MISSING_INTEGRATION_FORM_ELEMENT_PLUGINS = False
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ __all__ = (
|
|||
'FORM_ELEMENT_PLUGINS_MODULE_NAME',
|
||||
'FORM_HANDLER_PLUGINS_EXECUTION_ORDER',
|
||||
'FORM_HANDLER_PLUGINS_MODULE_NAME',
|
||||
'SORT_PLUGINS_BY_VALUE',
|
||||
'FORM_IMPORTER_PLUGINS_MODULE_NAME',
|
||||
'FORM_WIZARD_HANDLER_PLUGINS_EXECUTION_ORDER',
|
||||
'GET_PARAM_INITIAL_DATA',
|
||||
|
|
@ -110,6 +111,7 @@ THEME_FOOTER_TEXT = get_setting('THEME_FOOTER_TEXT')
|
|||
|
||||
DEFAULT_MIN_LENGTH = get_setting('DEFAULT_MIN_LENGTH')
|
||||
DEFAULT_MAX_LENGTH = get_setting('DEFAULT_MAX_LENGTH')
|
||||
SORT_PLUGINS_BY_VALUE = get_setting('SORT_PLUGINS_BY_VALUE')
|
||||
|
||||
FORM_HANDLER_PLUGINS_EXECUTION_ORDER = \
|
||||
get_setting('FORM_HANDLER_PLUGINS_EXECUTION_ORDER')
|
||||
|
|
|
|||
|
|
@ -46,7 +46,12 @@ from .models import (
|
|||
FormHandlerEntry,
|
||||
FormWizardHandler
|
||||
)
|
||||
from .settings import RESTRICT_PLUGIN_ACCESS, DEBUG, WIZARD_FILES_UPLOAD_DIR
|
||||
from .settings import (
|
||||
RESTRICT_PLUGIN_ACCESS,
|
||||
DEBUG,
|
||||
WIZARD_FILES_UPLOAD_DIR,
|
||||
SORT_PLUGINS_BY_VALUE,
|
||||
)
|
||||
|
||||
if DJANGO_GTE_1_10:
|
||||
from django.urls import reverse
|
||||
|
|
@ -204,15 +209,22 @@ def get_user_plugins_grouped(get_allowed_plugin_uids_func,
|
|||
get_registered_plugins_grouped_func,
|
||||
registry,
|
||||
user,
|
||||
sort_items=True):
|
||||
sort_items=True,
|
||||
sort_by_value=False):
|
||||
"""Get user plugins grouped.
|
||||
|
||||
:param callable get_allowed_plugin_uids_func:
|
||||
:param callable get_registered_plugins_grouped_func:
|
||||
:param fobi.base.BaseRegistry registry: Subclass of
|
||||
``fobi.base.BaseRegistry`` instance.
|
||||
:param django.contrib.auth.models.User user:
|
||||
:param bool sort_items:
|
||||
:param get_allowed_plugin_uids_func:
|
||||
:param get_registered_plugins_grouped_func:
|
||||
:param registry: Subclass of ``fobi.base.BaseRegistry`` instance.
|
||||
:param user:
|
||||
:param sort_items:
|
||||
:param sort_by_value:
|
||||
:type get_allowed_plugin_uids_func: callable
|
||||
:type get_registered_plugins_grouped_func: callable
|
||||
:type registry: fobi.base.BaseRegistry
|
||||
:type user: django.contrib.auth.models.User
|
||||
:type sort_items: bool
|
||||
:type sort_by_value: bool
|
||||
:return dict:
|
||||
"""
|
||||
ensure_autodiscover()
|
||||
|
|
@ -246,7 +258,11 @@ def get_user_plugins_grouped(get_allowed_plugin_uids_func,
|
|||
|
||||
ordered_registered_plugins = OrderedDict()
|
||||
for key, prop in sorted(registered_plugins.items()):
|
||||
ordered_registered_plugins[key] = sorted(prop)
|
||||
import ipdb; ipdb.set_trace()
|
||||
if sort_by_value:
|
||||
ordered_registered_plugins[key] = sorted(prop, key=lambda t: t[1])
|
||||
else:
|
||||
ordered_registered_plugins[key] = sorted(prop)
|
||||
|
||||
return ordered_registered_plugins
|
||||
|
||||
|
|
@ -354,13 +370,15 @@ def get_user_form_element_plugins(user):
|
|||
)
|
||||
|
||||
|
||||
def get_user_form_element_plugins_grouped(user):
|
||||
def get_user_form_element_plugins_grouped(user,
|
||||
sort_by_value=SORT_PLUGINS_BY_VALUE):
|
||||
"""Get user form element plugins grouped."""
|
||||
return get_user_plugins_grouped(
|
||||
get_allowed_form_element_plugin_uids,
|
||||
get_registered_form_element_plugins_grouped,
|
||||
form_element_plugin_registry,
|
||||
user
|
||||
user,
|
||||
sort_by_value=sort_by_value
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -455,13 +473,15 @@ def get_user_form_handler_plugins(user,
|
|||
# return user_form_handler_plugins
|
||||
|
||||
|
||||
def get_user_form_handler_plugins_grouped(user):
|
||||
def get_user_form_handler_plugins_grouped(user,
|
||||
sort_by_value=SORT_PLUGINS_BY_VALUE):
|
||||
"""Get user form handler plugins grouped."""
|
||||
return get_user_plugins_grouped(
|
||||
get_allowed_form_handler_plugin_uids,
|
||||
get_registered_form_handler_plugins,
|
||||
form_handler_plugin_registry,
|
||||
user
|
||||
user,
|
||||
sort_by_value=sort_by_value
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -67,7 +67,11 @@ from .models import (
|
|||
FormWizardFormEntry,
|
||||
FormWizardHandlerEntry
|
||||
)
|
||||
from .settings import GET_PARAM_INITIAL_DATA, DEBUG
|
||||
from .settings import (
|
||||
GET_PARAM_INITIAL_DATA,
|
||||
DEBUG,
|
||||
SORT_PLUGINS_BY_VALUE,
|
||||
)
|
||||
from .utils import (
|
||||
append_edit_and_delete_links_to_field,
|
||||
get_user_form_element_plugins_grouped,
|
||||
|
|
@ -530,7 +534,8 @@ def edit_form_entry(request, form_entry_id, theme=None, template_name=None):
|
|||
|
||||
# List of form element plugins allowed to user
|
||||
user_form_element_plugins = get_user_form_element_plugins_grouped(
|
||||
request.user
|
||||
request.user,
|
||||
sort_by_value=SORT_PLUGINS_BY_VALUE
|
||||
)
|
||||
# List of form handler plugins allowed to user
|
||||
user_form_handler_plugins = get_user_form_handler_plugins(
|
||||
|
|
|
|||
Loading…
Reference in a new issue