prepare 0.6.2; make it simple to render list of fobi forms on any page

This commit is contained in:
Artur Barseghyan 2015-12-22 00:15:51 +01:00
parent d9b09bc7b6
commit 91a880c2cf
20 changed files with 323 additions and 24 deletions

View file

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

View file

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

View file

@ -0,0 +1,5 @@
<html>
<body>
{% include theme.forms_list_template %}
</body>
</html>

View file

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

View file

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

View file

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

View file

@ -1,6 +1,6 @@
__title__ = 'django-fobi'
__version__ = '0.6.1'
__build__ = 0x00004a
__version__ = '0.6.2'
__build__ = 0x00004b
__author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>'
__copyright__ = '2014-2015 Artur Barseghyan'
__license__ = 'GPL 2.0/LGPL 2.1'

View file

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

View file

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

View file

@ -0,0 +1 @@
{% extends "fobi/generic/forms_list.html" %}

View file

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

View file

@ -0,0 +1,56 @@
{% load i18n %}
<table id="result_list">
<thead>
<tr>
<th>
<div class="text">
<span>{% trans "Name" %}</span>
</div>
<div class="clear"></div>
</th>
{% if show_custom_actions %}
<th>
<div class="text">
<span>{% trans "Actions" %}</span>
</div>
<div class="clear"></div>
</th>
{% endif %}
</tr>
</thead>
<tbody>
{% for form_entry in form_entries %}
<tr class="{% if forloop.counter|divisibleby:2 %}row2{% else %}row1{% endif %}">
<th><a href="{% url 'fobi.view_form_entry' form_entry.slug %}">{{ form_entry.name }}</a></th>
{% if show_custom_actions %}
<td>
<ul class="list-inline">
{% if show_edit_link %}
<li>
<a href="{% url 'fobi.edit_form_entry' form_entry.pk %}" class="edit" title="{% trans 'Edit' %}">
<span></span>
</a>
</li>
{% endif %}
{% if show_delete_link %}
<li>
<a href="{% url 'fobi.delete_form_entry' form_entry.pk %}" class="deletelink" title="{% trans 'Delete' %}">
<span></span>
</a>
</li>
{% endif %}
{% if show_export_link %}
<li>
<a href="{% url 'fobi.export_form_entry' form_entry.pk %}" class="exportlink" title="{% trans 'Export' %}">
<span class="custom-icon custom-icon-export"></span>
</a>
</li>
{% endif %}
</ul>
</td>
{% endif %}
</tr>
{% endfor %}
</tbody>
</table>

View file

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

View file

@ -0,0 +1,32 @@
{% load i18n %}
<table class="table table-striped large-12">
<thead>
<tr>
<th>{% trans "Form" %}</th>
{% if show_custom_actions %}<th>{% trans "Actions" %}</th>{% endif %}
</tr>
</thead>
<tbody>
{% for form_entry in form_entries %}
<tr>
<td><a href="{% url 'fobi.view_form_entry' form_entry.slug %}">{{ form_entry.name }}</a></td>
{% if show_custom_actions %}
<td>
<ul class="inline-list">
{% if show_edit_link %}
<li><a href="{% url 'fobi.edit_form_entry' form_entry.pk %}"><span class="fi-page-edit"></span> {% trans "Edit" %}</a></li>
{% endif %}
{% if show_delete_link %}
<li><a href="{% url 'fobi.delete_form_entry' form_entry.pk %}"><span class="fi-page-delete"></span> {% trans "Delete" %}</a></li>
{% endif %}
{% if show_export_link %}
<li><a href="{% url 'fobi.export_form_entry' form_entry.pk %}"><span class="fi-download"></span> {% trans "Export" %}</a></li>
{% endif %}
</ul>
</td>
{% endif %}
</tr>
{% endfor %}
</tbody>
</table>

View file

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

View file

@ -0,0 +1,56 @@
{% load i18n %}
<table id="result_list">
<thead>
<tr>
<th>
<div class="text">
<span>{% trans "Name" %}</span>
</div>
<div class="clear"></div>
</th>
{% if show_custom_actions %}
<th>
<div class="text">
<span>{% trans "Actions" %}</span>
</div>
<div class="clear"></div>
</th>
{% endif %}
</tr>
</thead>
<tbody>
{% for form_entry in form_entries %}
<tr class="{% if forloop.counter|divisibleby:2 %}row2{% else %}row1{% endif %}">
<th><a href="{% url 'fobi.view_form_entry' form_entry.slug %}">{{ form_entry.name }}</a></th>
{% if show_custom_actions %}
<td>
<ul class="list-inline">
{% if show_edit_link %}
<li>
<a href="{% url 'fobi.edit_form_entry' form_entry.pk %}">
<span class="glyphicon glyphicon-edit"></span> {% trans "Edit" %}
</a>
</li>
{% endif %}
{% if show_delete_link %}
<li>
<a href="{% url 'fobi.delete_form_entry' form_entry.pk %}">
<span class="glyphicon glyphicon-remove"></span> {% trans "Delete" %}
</a>
</li>
{% endif %}
{% if show_export_link %}
<li>
<a href="{% url 'fobi.export_form_entry' form_entry.pk %}">
<span class="glyphicon glyphicon-export"></span> {% trans "Export" %}
</a>
</li>
{% endif %}
</ul>
</td>
{% endif %}
</tr>
{% endfor %}
</tbody>
</table>

View file

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

View file

@ -0,0 +1,44 @@
{% load i18n %}
<table class="table table-striped">
<thead>
<tr>
<th class="col-sm-3">{% trans "Form" %}</th>
{% if show_custom_actions %}<th class="col-sm-3">{% trans "Actions" %}</th>{% endif %}
</tr>
</thead>
<tbody>
{% for form_entry in form_entries %}
<tr>
<td><a href="{% url 'fobi.view_form_entry' form_entry.slug %}">{{ form_entry.name }}</a></td>
{% if show_custom_actions %}
<td>
<ul class="list-inline">
{% if show_edit_link %}
<li>
<a href="{% url 'fobi.edit_form_entry' form_entry.pk %}">
<span class="glyphicon glyphicon-edit"></span> {% trans "Edit" %}
</a>
</li>
{% endif %}
{% if show_delete_link %}
<li>
<a href="{% url 'fobi.delete_form_entry' form_entry.pk %}">
<span class="glyphicon glyphicon-remove"></span> {% trans "Delete" %}
</a>
</li>
{% endif %}
{% if show_export_link %}
<li>
<a href="{% url 'fobi.export_form_entry' form_entry.pk %}">
<span class="glyphicon glyphicon-export"></span> {% trans "Export" %}
</a>
</li>
{% endif %}
</ul>
</td>
{% endif %}
</tr>
{% endfor %}
</tbody>
</table>

View file

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

View file

@ -147,7 +147,7 @@ def dashboard(request, theme=None, template_name=None):
return render_to_response(
template_name, context, context_instance=RequestContext(request)
)
)
# *****************************************************************************
# *****************************************************************************