From 91a880c2cf2c4fd69e994ffdaa22639194441cef Mon Sep 17 00:00:00 2001 From: Artur Barseghyan Date: Tue, 22 Dec 2015 00:15:51 +0100 Subject: [PATCH] prepare 0.6.2; make it simple to render list of fobi forms on any page --- CHANGELOG.rst | 7 +++ examples/requirements_docs.txt | 29 ++++++++++ .../simple/foo/templates/foo/forms_list.html | 5 ++ examples/simple/foo/urls.py | 5 +- examples/simple/foo/views.py | 28 +++++++++- setup.py | 2 +- src/fobi/__init__.py | 4 +- src/fobi/base.py | 1 + .../contrib/themes/bootstrap3/fobi_themes.py | 1 + .../templates/bootstrap3/forms_list.html | 1 + .../fobi_themes.py | 1 + .../forms_list.html | 56 +++++++++++++++++++ .../contrib/themes/foundation5/fobi_themes.py | 1 + .../templates/foundation5/forms_list.html | 32 +++++++++++ src/fobi/contrib/themes/simple/fobi_themes.py | 1 + .../simple/templates/simple/forms_list.html | 56 +++++++++++++++++++ src/fobi/models.py | 36 ++++++------ .../templates/fobi/generic/forms_list.html | 44 +++++++++++++++ src/fobi/templatetags/fobi_tags.py | 35 ++++++++++++ src/fobi/views.py | 2 +- 20 files changed, 323 insertions(+), 24 deletions(-) create mode 100644 examples/requirements_docs.txt create mode 100644 examples/simple/foo/templates/foo/forms_list.html create mode 100644 src/fobi/contrib/themes/bootstrap3/templates/bootstrap3/forms_list.html create mode 100644 src/fobi/contrib/themes/djangocms_admin_style_theme/templates/djangocms_admin_style_theme/forms_list.html create mode 100644 src/fobi/contrib/themes/foundation5/templates/foundation5/forms_list.html create mode 100644 src/fobi/contrib/themes/simple/templates/simple/forms_list.html create mode 100644 src/fobi/templates/fobi/generic/forms_list.html diff --git a/CHANGELOG.rst b/CHANGELOG.rst index e16f164c..5bad90b7 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -15,6 +15,13 @@ are used for versioning (schema follows below): 0.3.4 to 0.4). - All backwards incompatible changes are mentioned in this document. +0.6.2 +----- +2015-12-22 + +- Make it possible to render a list of forms using custom template tag (not + only on the dashboard page). + 0.6.1 ----- 2015-12-21 diff --git a/examples/requirements_docs.txt b/examples/requirements_docs.txt new file mode 100644 index 00000000..8a60b80d --- /dev/null +++ b/examples/requirements_docs.txt @@ -0,0 +1,29 @@ +Django +Jinja2 +MarkupSafe +MySQL-python +mailchimp +Sphinx +django-admin-tools>=0.5.2 +django-autoslug>=1.7.1 +django-debug-toolbar>=0.11.0 +django-localeurl>=2.0.2 +Pillow>=2.0.0 +requests>=1.0.0 +django-autoslug>=1.3.0 +django-nonefield>=0.1 +ordereddict>=1.1 +six>=1.4.1 +easy-thumbnails>=1.4 +vishap>=0.1.3,<2.0 +Unidecode>=0.04.1 +django-nine>=0.1.6 +django-registration-redux>=1.1 +docutils +ipdb +ipython +ordereddict>=1.1 +# Selenium shall always be upgraded +selenium +simple-timer>=0.2 +tox diff --git a/examples/simple/foo/templates/foo/forms_list.html b/examples/simple/foo/templates/foo/forms_list.html new file mode 100644 index 00000000..8235a136 --- /dev/null +++ b/examples/simple/foo/templates/foo/forms_list.html @@ -0,0 +1,5 @@ + + +{% include theme.forms_list_template %} + + diff --git a/examples/simple/foo/urls.py b/examples/simple/foo/urls.py index 366fda06..475883d4 100644 --- a/examples/simple/foo/urls.py +++ b/examples/simple/foo/urls.py @@ -1,7 +1,10 @@ from django.conf.urls import url -from foo.views import endpoint as foo_views_endpoint +from foo.views import ( + endpoint as foo_views_endpoint, forms_list as foo_forms_list, +) urlpatterns = [ url(r'^endpoint/$', view=foo_views_endpoint, name='foo.endpoint'), + url(r'^forms-list/$', view=foo_forms_list, name='foo.forms_list'), ] diff --git a/examples/simple/foo/views.py b/examples/simple/foo/views.py index 8171064a..671b5c34 100644 --- a/examples/simple/foo/views.py +++ b/examples/simple/foo/views.py @@ -3,8 +3,12 @@ import logging from django.http import HttpResponse from django.views.decorators.csrf import csrf_exempt +from django.template import RequestContext +from django.shortcuts import render_to_response +from fobi.models import FormEntry from fobi.helpers import handle_uploaded_file +from fobi.base import get_theme logger = logging.getLogger('fobi') @@ -22,4 +26,26 @@ def endpoint(request): for field_name, imf in request.FILES.items(): handle_uploaded_file('foo', "{0}".format(uuid.uuid4())) - return HttpResponse("POST: {0}\nFILES: {1}".format(request.POST, request.FILES)) + return HttpResponse( + "POST: {0}\nFILES: {1}".format(request.POST, request.FILES) + ) + + +def forms_list(request, template_name='foo/forms_list.html'): + """ + Fobi forms list. + """ + form_entries = FormEntry._default_manager.filter(is_public=True) \ + .select_related('user') + theme = get_theme(request=request, as_instance=True) + context = { + 'form_entries': form_entries, + 'theme': theme, + 'show_custom_actions': False, + 'show_edit_link': False, + 'show_delete_link': False, + 'show_export_link': False, + } + return render_to_response( + template_name, context, context_instance=RequestContext(request) + ) diff --git a/setup.py b/setup.py index fb3cb2ed..5253fd82 100644 --- a/setup.py +++ b/setup.py @@ -69,7 +69,7 @@ for static_dir in static_dirs: for locale_dir in locale_dirs: locale_files += [os.path.join(locale_dir, f) for f in os.listdir(locale_dir)] -version = '0.6.1' +version = '0.6.2' install_requires = [ 'Pillow>=2.0.0', diff --git a/src/fobi/__init__.py b/src/fobi/__init__.py index 5f78854c..0a159bc6 100644 --- a/src/fobi/__init__.py +++ b/src/fobi/__init__.py @@ -1,6 +1,6 @@ __title__ = 'django-fobi' -__version__ = '0.6.1' -__build__ = 0x00004a +__version__ = '0.6.2' +__build__ = 0x00004b __author__ = 'Artur Barseghyan ' __copyright__ = '2014-2015 Artur Barseghyan' __license__ = 'GPL 2.0/LGPL 2.1' diff --git a/src/fobi/base.py b/src/fobi/base.py index b7c8f88f..71f66131 100644 --- a/src/fobi/base.py +++ b/src/fobi/base.py @@ -169,6 +169,7 @@ class BaseTheme(object): create_form_entry_template = 'fobi/generic/create_form_entry.html' create_form_entry_ajax_template = 'fobi/generic/create_form_entry_ajax.html' dashboard_template = 'fobi/generic/dashboard.html' + forms_list_template = 'fobi/generic/forms_list.html' edit_form_element_entry_template = \ 'fobi/generic/edit_form_element_entry.html' edit_form_element_entry_ajax_template = \ diff --git a/src/fobi/contrib/themes/bootstrap3/fobi_themes.py b/src/fobi/contrib/themes/bootstrap3/fobi_themes.py index 05221156..fffd1de5 100644 --- a/src/fobi/contrib/themes/bootstrap3/fobi_themes.py +++ b/src/fobi/contrib/themes/bootstrap3/fobi_themes.py @@ -76,6 +76,7 @@ class Bootstrap3Theme(BaseTheme): create_form_entry_ajax_template = 'bootstrap3/create_form_entry_ajax.html' dashboard_template = 'bootstrap3/dashboard.html' + forms_list_template = 'bootstrap3/forms_list.html' edit_form_element_entry_template = 'bootstrap3/edit_form_element_entry.html' edit_form_element_entry_ajax_template = \ diff --git a/src/fobi/contrib/themes/bootstrap3/templates/bootstrap3/forms_list.html b/src/fobi/contrib/themes/bootstrap3/templates/bootstrap3/forms_list.html new file mode 100644 index 00000000..37406bc9 --- /dev/null +++ b/src/fobi/contrib/themes/bootstrap3/templates/bootstrap3/forms_list.html @@ -0,0 +1 @@ +{% extends "fobi/generic/forms_list.html" %} \ No newline at end of file diff --git a/src/fobi/contrib/themes/djangocms_admin_style_theme/fobi_themes.py b/src/fobi/contrib/themes/djangocms_admin_style_theme/fobi_themes.py index 4b387015..e3f40166 100644 --- a/src/fobi/contrib/themes/djangocms_admin_style_theme/fobi_themes.py +++ b/src/fobi/contrib/themes/djangocms_admin_style_theme/fobi_themes.py @@ -78,6 +78,7 @@ class DjangoCMSAdminStyleTheme(BaseTheme): create_form_entry_ajax_template = 'djangocms_admin_style_theme/create_form_entry_ajax.html' dashboard_template = 'djangocms_admin_style_theme/dashboard.html' + forms_list_template = 'djangocms_admin_style_theme/forms_list.html' edit_form_element_entry_template = 'djangocms_admin_style_theme/edit_form_element_entry.html' edit_form_element_entry_ajax_template = 'djangocms_admin_style_theme/edit_form_element_entry_ajax.html' diff --git a/src/fobi/contrib/themes/djangocms_admin_style_theme/templates/djangocms_admin_style_theme/forms_list.html b/src/fobi/contrib/themes/djangocms_admin_style_theme/templates/djangocms_admin_style_theme/forms_list.html new file mode 100644 index 00000000..77f5500c --- /dev/null +++ b/src/fobi/contrib/themes/djangocms_admin_style_theme/templates/djangocms_admin_style_theme/forms_list.html @@ -0,0 +1,56 @@ +{% load i18n %} + + + + + + {% if show_custom_actions %} + + {% endif %} + + + + {% for form_entry in form_entries %} + + + {% if show_custom_actions %} + + {% endif %} + + {% endfor %} + +
+
+ {% trans "Name" %} +
+
+
+
+ {% trans "Actions" %} +
+
+
{{ form_entry.name }} +
    + {% if show_edit_link %} +
  • + + + +
  • + {% endif %} + {% if show_delete_link %} +
  • + + + +
  • + {% endif %} + {% if show_export_link %} +
  • + + + +
  • + {% endif %} +
+
diff --git a/src/fobi/contrib/themes/foundation5/fobi_themes.py b/src/fobi/contrib/themes/foundation5/fobi_themes.py index 79d6e508..0c224b11 100644 --- a/src/fobi/contrib/themes/foundation5/fobi_themes.py +++ b/src/fobi/contrib/themes/foundation5/fobi_themes.py @@ -86,6 +86,7 @@ class Foundation5Theme(BaseTheme): create_form_entry_ajax_template = 'foundation5/create_form_entry_ajax.html' dashboard_template = 'foundation5/dashboard.html' + forms_list_template = 'foundation5/forms_list.html' edit_form_element_entry_template = 'foundation5/edit_form_element_entry.html' edit_form_element_entry_ajax_template = \ diff --git a/src/fobi/contrib/themes/foundation5/templates/foundation5/forms_list.html b/src/fobi/contrib/themes/foundation5/templates/foundation5/forms_list.html new file mode 100644 index 00000000..7c427aa1 --- /dev/null +++ b/src/fobi/contrib/themes/foundation5/templates/foundation5/forms_list.html @@ -0,0 +1,32 @@ +{% load i18n %} + + + + + + {% if show_custom_actions %}{% endif %} + + + + {% for form_entry in form_entries %} + + + {% if show_custom_actions %} + + {% endif %} + + {% endfor %} + +
{% trans "Form" %}{% trans "Actions" %}
{{ form_entry.name }} + +
diff --git a/src/fobi/contrib/themes/simple/fobi_themes.py b/src/fobi/contrib/themes/simple/fobi_themes.py index 41444f54..aeb904ec 100644 --- a/src/fobi/contrib/themes/simple/fobi_themes.py +++ b/src/fobi/contrib/themes/simple/fobi_themes.py @@ -77,6 +77,7 @@ class SimpleTheme(BaseTheme): create_form_entry_ajax_template = 'simple/create_form_entry_ajax.html' dashboard_template = 'simple/dashboard.html' + forms_list_template = 'simple/forms_list.html' edit_form_element_entry_template = 'simple/edit_form_element_entry.html' edit_form_element_entry_ajax_template = 'simple/edit_form_element_entry_ajax.html' diff --git a/src/fobi/contrib/themes/simple/templates/simple/forms_list.html b/src/fobi/contrib/themes/simple/templates/simple/forms_list.html new file mode 100644 index 00000000..b09cd8b2 --- /dev/null +++ b/src/fobi/contrib/themes/simple/templates/simple/forms_list.html @@ -0,0 +1,56 @@ +{% load i18n %} + + + + + + {% if show_custom_actions %} + + {% endif %} + + + + {% for form_entry in form_entries %} + + + {% if show_custom_actions %} + + {% endif %} + + {% endfor %} + +
+
+ {% trans "Name" %} +
+
+
+
+ {% trans "Actions" %} +
+
+
{{ form_entry.name }} + +
diff --git a/src/fobi/models.py b/src/fobi/models.py index 02bccc61..41b02acd 100644 --- a/src/fobi/models.py +++ b/src/fobi/models.py @@ -27,7 +27,7 @@ from autoslug import AutoSlugField from fobi.base import ( get_registered_form_element_plugins, get_registered_form_handler_plugins, form_element_plugin_registry, form_handler_plugin_registry - ) +) # **************************************************************************** # **************** Safe User import for Django > 1.5, < 1.8 ****************** @@ -95,7 +95,7 @@ class AbstractPluginModel(models.Model): """ raise NotImplemented( "You should implement ``get_registered_plugins`` method!" - ) + ) def __unicode__(self): return "{0} ({1})".format( @@ -158,7 +158,7 @@ class FormElement(AbstractPluginModel): plugin_uid = models.CharField( _("Plugin UID"), max_length=255, unique=True, editable=False, choices=get_registered_form_element_plugins() - ) + ) #objects = FormFieldPluginModelManager() class Meta: @@ -189,7 +189,7 @@ class FormHandler(AbstractPluginModel): plugin_uid = models.CharField( _("Plugin UID"), max_length=255, unique=True, editable=False, choices=get_registered_form_handler_plugins() - ) + ) #objects = FormHandlerPluginModelManager() class Meta: @@ -219,11 +219,11 @@ class FormWizardEntry(models.Model): is_public = models.BooleanField( _("Is public?"), default=False, help_text=_("Makes your form wizard visible to the public.") - ) + ) is_cloneable = models.BooleanField( _("Is cloneable?"), default=False, help_text=_("Makes your form wizard cloneable by other users.") - ) + ) class Meta: verbose_name = _("Form wizard entry") @@ -259,38 +259,38 @@ class FormEntry(models.Model): """ form_wizard_entry = models.ForeignKey( FormWizardEntry, verbose_name=_("Form wizard"), null=True, blank=True - ) + ) user = models.ForeignKey(AUTH_USER_MODEL, verbose_name=_("User")) name = models.CharField(_("Name"), max_length=255) slug = AutoSlugField( populate_from='name', verbose_name=_("Slug"), unique=True - ) + ) is_public = models.BooleanField( _("Public?"), default=False, help_text=_("Makes your form visible to the public.") - ) + ) is_cloneable = models.BooleanField( _("Cloneable?"), default=False, help_text=_("Makes your form cloneable by other users.") - ) + ) position = models.PositiveIntegerField( _("Position"), null=True, blank=True - ) + ) success_page_title = models.CharField( _("Success page title"), max_length=255, null=True, blank=True, help_text=_("Custom message title to display after valid form is " "submitted") - ) + ) success_page_message = models.TextField( _("Success page body"), null=True, blank=True, help_text=_("Custom message text to display after valid form is " "submitted") - ) + ) action = models.CharField( _("Action"), max_length=255, null=True, blank=True, help_text=_("Custom form action; don't fill this field, unless really " "necessary.") - ) + ) created = models.DateTimeField(_("Created"), null=True, blank=True, auto_now_add=True) updated = models.DateTimeField(_("Updated"), null=True, blank=True, @@ -323,7 +323,7 @@ class FormFieldsetEntry(models.Model): is_repeatable = models.BooleanField( _("Is repeatable?"), default=False, help_text=_("Makes your form fieldset repeatable.") - ) + ) class Meta: verbose_name = _("Form fieldset entry") @@ -363,7 +363,7 @@ class AbstractPluginEntry(models.Model): def __unicode__(self): return "{0} plugin for user {1}".format( self.plugin_uid, self.form_entry.user - ) + ) def get_registered_plugins(self): """ @@ -395,7 +395,7 @@ class AbstractPluginEntry(models.Model): if registry.fail_on_missing_plugin: err_msg = registry.plugin_not_found_error_message.format( self.plugin_uid, registry.__class__ - ) + ) raise registry.plugin_not_found_exception_cls(err_msg) return None @@ -407,7 +407,7 @@ class AbstractPluginEntry(models.Model): return plugin.process( self.plugin_data, fetch_related_data=fetch_related_data - ) + ) def plugin_uid_code(self): """ diff --git a/src/fobi/templates/fobi/generic/forms_list.html b/src/fobi/templates/fobi/generic/forms_list.html new file mode 100644 index 00000000..30069715 --- /dev/null +++ b/src/fobi/templates/fobi/generic/forms_list.html @@ -0,0 +1,44 @@ +{% load i18n %} + + + + + + {% if show_custom_actions %}{% endif %} + + + + {% for form_entry in form_entries %} + + + {% if show_custom_actions %} + + {% endif %} + + {% endfor %} + +
{% trans "Form" %}{% trans "Actions" %}
{{ form_entry.name }} + +
diff --git a/src/fobi/templatetags/fobi_tags.py b/src/fobi/templatetags/fobi_tags.py index 54e4742d..57e31baa 100644 --- a/src/fobi/templatetags/fobi_tags.py +++ b/src/fobi/templatetags/fobi_tags.py @@ -6,6 +6,7 @@ __all__ = ( 'get_fobi_plugin', 'get_fobi_form_handler_plugin_custom_actions', 'get_form_field_type', 'get_form_hidden_fields_errors', 'has_edit_form_entry_permissions', 'render_auth_link', + 'render_fobi_forms_list', ) from django.template import Library, TemplateSyntaxError, Node @@ -21,6 +22,8 @@ else: from django.forms.util import ErrorDict from fobi.settings import DISPLAY_AUTH_LINK +from fobi.base import get_theme +theme = get_theme(request=None, as_instance=True) register = Library() @@ -186,6 +189,38 @@ register.inclusion_tag( 'fobi/snippets/render_auth_link.html', takes_context=True )(render_auth_link) + +@register.inclusion_tag(theme.forms_list_template, takes_context=True) +def render_fobi_forms_list(context, queryset, *args, **kwargs): + """ + Render the list of fobi forms. + + :syntax: + + {% render_fobi_forms_list [queryset] [show_edit_link] \ + [show_delete_link] \ + [show_export_link] %} + + :example: + + {% render_fobi_forms_list queryset show_edit_link=True \ + show_delete_link=False \ + show_export_link=False %} + """ + request = context.get('request', None) + show_edit_link = kwargs.get('edit_link', False) + show_delete_link = kwargs.get('delete_link', False) + show_export_link = kwargs.get('export_link', False) + return { + 'show_custom_actions': ( + show_edit_link or show_delete_link or show_export_link + ), + 'show_edit_link': show_edit_link, + 'show_delete_link': show_delete_link, + 'show_export_link': show_export_link, + } + + # ***************************************************************************** # ***************************************************************************** # ***************************************************************************** diff --git a/src/fobi/views.py b/src/fobi/views.py index 608912f0..5323b687 100644 --- a/src/fobi/views.py +++ b/src/fobi/views.py @@ -147,7 +147,7 @@ def dashboard(request, theme=None, template_name=None): return render_to_response( template_name, context, context_instance=RequestContext(request) - ) + ) # ***************************************************************************** # *****************************************************************************