Permalink
Browse files

Using theirs

  • Loading branch information...
samluescher committed Jul 19, 2011
1 parent f7d7abc commit 30589c66626e9c0aebea7503ff36d27b35a177ea
Showing with 2,164 additions and 509 deletions.
  1. +5 −0 .gitignore
  2. +0 −3 .gitmodules
  3. +2 −0 AUTHORS
  4. +15 −0 MANIFEST.in
  5. +6 −10 README.md
  6. +7 −0 form_designer/__init__.py
  7. +135 −50 form_designer/admin.py
  8. +0 −7 form_designer/admin_urls.py
  9. +0 −62 form_designer/admin_views.py
  10. +0 −8 form_designer/app_settings.py
  11. +7 −6 form_designer/cms_plugins.py
  12. +0 −55 form_designer/defaults.py
  13. +33 −1 form_designer/{model_name_field.py → fields.py}
  14. +58 −0 form_designer/forms.py
  15. BIN form_designer/locale/de/LC_MESSAGES/django.mo
  16. +189 −149 form_designer/locale/de/LC_MESSAGES/django.po
  17. +404 −0 form_designer/locale/en/LC_MESSAGES/django.po
  18. BIN form_designer/locale/nl/LC_MESSAGES/django.mo
  19. +309 −0 form_designer/locale/nl/LC_MESSAGES/django.po
  20. +50 −0 form_designer/media/form_designer/js/jquery-inline-collapsible.js
  21. +5 −0 form_designer/media/form_designer/js/jquery-inline-fieldset-collapsible.js
  22. +45 −0 form_designer/media/form_designer/js/jquery-inline-positioning.js
  23. +29 −0 form_designer/media/form_designer/js/jquery-inline-prepopulate-label.js
  24. +44 −0 form_designer/media/form_designer/js/jquery-inline-rename.js
  25. 0 form_designer/media/form_designer/js/{lib → }/jquery-ui.js
  26. +17 −0 form_designer/media/form_designer/js/jquery-url-param.js
  27. 0 form_designer/media/form_designer/js/{lib → }/jquery.js
  28. +0 −1 form_designer/media/form_designer/js/lib/django-admin-tweaks-js-lib
  29. +4 −0 form_designer/media/form_designer/js/lib/django-admin-tweaks-js-lib/README.md
  30. +50 −0 form_designer/media/form_designer/js/lib/django-admin-tweaks-js-lib/js/jquery-inline-collapsible.js
  31. +5 −0 ...er/media/form_designer/js/lib/django-admin-tweaks-js-lib/js/jquery-inline-fieldset-collapsible.js
  32. +45 −0 form_designer/media/form_designer/js/lib/django-admin-tweaks-js-lib/js/jquery-inline-positioning.js
  33. +29 −0 ...igner/media/form_designer/js/lib/django-admin-tweaks-js-lib/js/jquery-inline-prepopulate-label.js
  34. +44 −0 form_designer/media/form_designer/js/lib/django-admin-tweaks-js-lib/js/jquery-inline-rename.js
  35. +17 −0 form_designer/media/form_designer/js/lib/django-admin-tweaks-js-lib/js/jquery-url-param.js
  36. +175 −0 form_designer/migrations/0001_initial.py
  37. +104 −0 form_designer/migrations/0002_auto__chg_field_formdefinitionfield_initial.py
  38. 0 form_designer/migrations/__init__.py
  39. +65 −35 form_designer/models.py
  40. +0 −25 form_designer/pickled_object_field.py
  41. +65 −0 form_designer/settings.py
  42. +0 −34 form_designer/template_field.py
  43. +7 −0 form_designer/templates/admin/form_designer/formlog/change_list.html
  44. +12 −0 form_designer/templates/html/formdefinition/forms/as_p.html
  45. +12 −0 form_designer/templates/html/formdefinition/forms/as_table.html
  46. +12 −0 form_designer/templates/html/formdefinition/forms/as_u.html
  47. +12 −0 form_designer/templates/html/formdefinition/forms/as_ul.html
  48. +42 −0 form_designer/templates/html/formdefinition/forms/custom.html
  49. +2 −1 form_designer/templates/txt/formdefinition/data_message.txt
  50. +3 −2 form_designer/templatetags/friendly.py
  51. +6 −0 form_designer/templatetags/widget_type.py
  52. +0 −23 form_designer/tests.py
  53. +1 −1 form_designer/urls.py
  54. +48 −36 form_designer/views.py
  55. +44 −0 setup.py
View
@@ -0,0 +1,5 @@
+*.pyc
+.*
+dist
+MANIFEST
+
View
@@ -1,3 +0,0 @@
-[submodule "form_designer/media/form_designer/js/lib/django-admin-tweaks-js-lib"]
- path = form_designer/media/form_designer/js/lib/django-admin-tweaks-js-lib
- url = git://github.com/philomat/django-admin-tweaks-js-lib.git
View
@@ -0,0 +1,2 @@
+Samuel Lüscher (philomat)
+Jannis Leidel (jezdez)
View
@@ -0,0 +1,15 @@
+<<<<<<< HEAD
+include LICENSE
+include README.md
+
+recursive-include form_designer/locale *
+recursive-include form_designer/media *
+recursive-include form_designer/templates *
+=======
+include AUTHORS
+include README.md
+include LICENSE
+recursive-include form_designer/templates *.html *.txt
+recursive-include form_designer/media *.js
+recursive-include form_designer/locale *.po *.mo
+>>>>>>> 29a8207f09ef53dba714edf377d444702106ad5c
View
@@ -29,18 +29,19 @@ This document assumes that you are familiar with Python and Django.
2. Make sure `form_designer` is on your `PYTHONPATH`.
3. Make the directory `form_designer/media/form_designer` available under your `MEDIA_ROOT`.
-4. Set up the database tables using
-
- $ manage.py syncdb
-5. Add `form_designer` to your `INSTALLED_APPS` setting.
+4. Add `form_designer` to your `INSTALLED_APPS` setting.
INSTALLED_APPS = (
...
'form_designer',
)
-6. Add the form_designer URLs to your URL conf. For instance, in order to make a form named `example-form` available under `http://domain.com/forms/example-form`, add the following line to `urls.py`. Note: __If you are using the form_designer plugin for Django CMS, step 5 is not necessary__:
+5. Set up the database tables using
+
+ $ manage.py syncdb
+
+6. Add the form_designer URLs to your URL conf. For instance, in order to make a form named `example-form` available under `http://domain.com/forms/example-form`, add the following line to `urls.py`. Note: __If you are using the form_designer plugin for Django CMS, this step is not necessary__:
urlpatterns = patterns('',
(r'^forms/', include('form_designer.urls')),
@@ -62,8 +63,3 @@ Optional requirements
* The form_designer admin interface requires jQuery and the jQuery UI Sortable plugin to make building forms a lot more user-friendly. The two Javascript files are bundled with form_designer. Optionally, if Django CMS is installed, the files bundled with that app will be used. If you want to use you own jquery.js instead because you're already including it anyway, define JQUERY_JS in your settings file. For instance:
JQUERY_JS = 'jquery/jquery-latest.js'
-
-Missing features
-----------------
-
-* File upload fields should be implemented
@@ -0,0 +1,7 @@
+from south.modelsinspector import add_introspection_rules
+
+
+add_introspection_rules([], ['^form_designer\.pickled_object_field\.PickledObjectField'])
+add_introspection_rules([], ['^form_designer\.model_name_field\.ModelNameField'])
+add_introspection_rules([], ['^form_designer\.template_field\.TemplateCharField'])
+add_introspection_rules([], ['^form_designer\.template_field\.TemplateTextField'])
View
@@ -1,21 +1,23 @@
+import csv
from django.contrib import admin
+from django.utils.translation import ugettext as _, ugettext_lazy
+from django.conf.urls.defaults import patterns, url
+from django.contrib.admin.views.main import ChangeList
+from django.db.models import Count
+from django.http import HttpResponse
+from django.utils.encoding import smart_unicode, smart_str
+
+try:
+ import xlwt
+except ImportError:
+ xlwt_installed = False
+else:
+ xlwt_installed = True
+
+from form_designer.forms import FormDefinitionForm, FormDefinitionFieldInlineForm
from form_designer.models import FormDefinition, FormDefinitionField, FormLog
-from django import forms
-from django.utils.translation import ugettext as _
-from django.db import models
-from django.conf import settings
-import os
-
-MEDIA_SUBDIR = 'form_designer'
-
-class FormDefinitionFieldInlineForm(forms.ModelForm):
- class Meta:
- model = FormDefinitionField
-
- def clean_choice_model(self):
- if not self.cleaned_data['choice_model'] and self.cleaned_data.has_key('field_class') and self.cleaned_data['field_class'] in ('forms.ModelChoiceField', 'forms.ModelMultipleChoiceField'):
- raise forms.ValidationError(_('This field class requires a model.'))
- return self.cleaned_data['choice_model']
+from form_designer import settings
+from form_designer.templatetags.friendly import friendly
class FormDefinitionFieldInline(admin.StackedInline):
form = FormDefinitionFieldInlineForm
@@ -31,34 +33,6 @@ class FormDefinitionFieldInline(admin.StackedInline):
(_('Model Choices'), {'fields': ['choice_model', 'choice_model_empty_label']}),
]
-class FormDefinitionForm(forms.ModelForm):
- class Meta:
- model = FormDefinition
- class Media:
- js = ([
- # Use central jQuery
- settings.JQUERY_JS,
- # and use jQuery UI bundled with this app
- os.path.join(MEDIA_SUBDIR, 'lib/jquery/ui.core.js'),
- os.path.join(MEDIA_SUBDIR, 'lib/jquery/ui.sortable.js'),
- ] if hasattr(settings, 'JQUERY_JS') else [
- # Use jQuery bundled with CMS
- os.path.join(settings.CMS_MEDIA_URL, 'js/lib/jquery.js'),
- os.path.join(settings.CMS_MEDIA_URL, 'js/lib/ui.core.js'),
- os.path.join(settings.CMS_MEDIA_URL, 'js/lib/ui.sortable.js'),
- ] if hasattr(settings, 'CMS_MEDIA_URL') else [
- # or use jQuery bundled with this app
- os.path.join(MEDIA_SUBDIR, 'lib/jquery/jquery.js'),
- os.path.join(MEDIA_SUBDIR, 'lib/jquery/ui.core.js'),
- os.path.join(MEDIA_SUBDIR, 'lib/jquery/ui.sortable.js'),
- ])+[os.path.join(MEDIA_SUBDIR, 'js/lib/django-admin-tweaks-js-lib/js', basename) for basename in (
- 'jquery-inline-positioning.js',
- 'jquery-inline-rename.js',
- 'jquery-inline-collapsible.js',
- 'jquery-inline-fieldset-collapsible.js',
- 'jquery-inline-prepopulate-label.js',
- )]
-
class FormDefinitionAdmin(admin.ModelAdmin):
fieldsets = [
(_('Basic'), {'fields': ['name', 'method', 'action', 'title', 'allow_get_initial', 'log_data', 'success_redirect', 'success_clear']}),
@@ -76,33 +50,144 @@ class FormLogAdmin(admin.ModelAdmin):
list_display = ('form_no_link', 'created', 'id', 'data_html')
list_filter = ('form_definition',)
list_display_links = ()
-
+ actions = ['export_csv']
+ if xlwt_installed:
+ actions.append('export_xls')
+
# Disabling all edit links: Hack as found at http://stackoverflow.com/questions/1618728/disable-link-to-edit-object-in-djangos-admin-display-list-only
def form_no_link(self, obj):
return '<a>'+obj.form_definition.__unicode__()+'</a>'
form_no_link.admin_order_field = 'form_definition'
form_no_link.allow_tags = True
form_no_link.short_description = _('Form')
+ def get_urls(self):
+ urls = patterns('',
+ url(r'^export/csv/$', self.admin_site.admin_view(self.export_csv), name='form_designer_export_csv'),
+ )
+ if xlwt_installed:
+ urls += patterns('',
+ url(r'^export/xls/$', self.admin_site.admin_view(self.export_xls), name='form_designer_export_xls'),
+ )
+ return urls + super(FormLogAdmin, self).get_urls()
+
def data_html(self, obj):
return obj.form_definition.compile_message(obj.data, 'html/formdefinition/data_message.html')
data_html.allow_tags = True
data_html.short_description = _('Data')
+ def get_change_list_query_set(self, request):
+ cl = ChangeList(request, self.model, self.list_display, self.list_display_links, self.list_filter,
+ self.date_hierarchy, self.search_fields, self.list_select_related, self.list_per_page, self.list_editable, self)
+ return cl.get_query_set()
+
+ def export_csv(self, request, queryset=None):
+ response = HttpResponse(mimetype='text/csv')
+ response['Content-Disposition'] = 'attachment; filename=' + settings.CSV_EXPORT_FILENAME
+ writer = csv.writer(response, delimiter=settings.CSV_EXPORT_DELIMITER)
+ if queryset is None:
+ queryset = self.get_change_list_query_set(request)
+
+ distinct_forms = queryset.aggregate(Count('form_definition', distinct=True))['form_definition__count']
+
+ include_created = settings.CSV_EXPORT_INCLUDE_CREATED
+ include_pk = settings.CSV_EXPORT_INCLUDE_PK
+ include_header = settings.CSV_EXPORT_INCLUDE_HEADER and distinct_forms == 1
+ include_form = settings.CSV_EXPORT_INCLUDE_FORM and distinct_forms > 1
+
+ if include_header:
+ header = []
+ if include_form:
+ header.append(_('Form'))
+ if include_created:
+ header.append(_('Created'))
+ if include_pk:
+ header.append(_('ID'))
+ for field in queryset[0].data:
+ header.append(field['label'] if field['label'] else field['key'])
+ writer.writerow([smart_str(cell, encoding=settings.CSV_EXPORT_ENCODING) for cell in header])
+
+ for entry in queryset:
+ row = []
+ if include_form:
+ row.append(entry.form_definition)
+ if include_created:
+ row.append(entry.created)
+ if include_pk:
+ row.append(entry.pk)
+ for field in entry.data:
+ value = friendly(field['value'])
+ row.append(smart_str(
+ value, encoding=settings.CSV_EXPORT_ENCODING))
+ writer.writerow(row)
+ return response
+ export_csv.short_description = ugettext_lazy("Export selected %(verbose_name_plural)s as CSV")
+
+ def export_xls(self, request, queryset=None):
+ import xlwt
+
+ response = HttpResponse(mimetype='application/ms-excel')
+ response['Content-Disposition'] = 'attachment; filename=%s.xls' % unicode(self.model._meta.verbose_name_plural)
+ wb = xlwt.Workbook()
+ ws = wb.add_sheet(unicode(self.model._meta.verbose_name_plural))
+ if queryset is None:
+ queryset = self.get_change_list_query_set(request)
+
+ distinct_forms = queryset.aggregate(Count('form_definition', distinct=True))['form_definition__count']
+
+ include_created = settings.CSV_EXPORT_INCLUDE_CREATED
+ include_pk = settings.CSV_EXPORT_INCLUDE_PK
+ include_header = settings.CSV_EXPORT_INCLUDE_HEADER and distinct_forms == 1
+ include_form = settings.CSV_EXPORT_INCLUDE_FORM and distinct_forms > 1
+
+ if include_header:
+ header = []
+ if include_form:
+ header.append(_('Form'))
+ if include_created:
+ header.append(_('Created'))
+ if include_pk:
+ header.append(_('ID'))
+ for field in queryset[0].data:
+ header.append(field['label'] if field['label'] else field['key'])
+ for i, f in enumerate(header):
+ ws.write(0, i, smart_unicode(f, encoding=settings.CSV_EXPORT_ENCODING))
+
+ for i, entry in enumerate(queryset):
+ row = []
+ if include_form:
+ row.append(entry.form_definition)
+ if include_created:
+ row.append(entry.created)
+ if include_pk:
+ row.append(entry.pk)
+ for field in entry.data:
+ value = friendly(field['value'])
+ row.append(smart_unicode(
+ value, encoding=settings.CSV_EXPORT_ENCODING))
+ for j, cell in enumerate(row):
+ ws.write(i+1, j, smart_unicode(cell))
+ wb.save(response)
+ return response
+ export_xls.short_description = ugettext_lazy("Export selected %(verbose_name_plural)s as XLS")
+
def changelist_view(self, request, extra_context=None):
- from django.core.urlresolvers import reverse, NoReverseMatch
+ from django.core.urlresolvers import reverse, NoReverseMatch
extra_context = extra_context or {}
try:
query_string = '?'+request.META['QUERY_STRING']
- except TypeError, KeyError:
+ except (TypeError, KeyError):
query_string = ''
try:
- extra_context['export_csv_url'] = reverse('form_designer_export_csv')+query_string
+ extra_context['export_csv_url'] = reverse('admin:form_designer_export_csv')+query_string
except NoReverseMatch:
request.user.message_set.create(message=_('CSV export is not enabled.'))
-
+ if xlwt_installed:
+ try:
+ extra_context['export_xls_url'] = reverse('admin:form_designer_export_xls')+query_string
+ except NoReverseMatch:
+ request.user.message_set.create(message=_('XLS export is not enabled.'))
return super(FormLogAdmin, self).changelist_view(request, extra_context)
admin.site.register(FormDefinition, FormDefinitionAdmin)
admin.site.register(FormLog, FormLogAdmin)
-
@@ -1,7 +0,0 @@
-from django.conf.urls.defaults import *
-
-urlpatterns = patterns('',
-
- url(r'^formlog/export_csv/$', 'form_designer.admin_views.export_csv', name='form_designer_export_csv'),
-
-)
@@ -1,62 +0,0 @@
-# encoding=utf-8
-from django.http import HttpResponse
-from form_designer.models import FormLog
-from form_designer.admin import FormLogAdmin
-from form_designer import app_settings
-from django.utils.translation import ugettext as _
-from form_designer.templatetags.friendly import friendly
-from django.conf import settings
-import csv
-
-# Returns a QuerySet with the same ordering and filtering like the one that would be visible in Django admin
-def get_change_list_query_set(model_admin, model, request):
- from django.contrib import admin
- from django.contrib.admin.views.main import ChangeList
- a = model_admin(model, admin.site)
- cl = ChangeList(request, a.model, a.list_display, a.list_display_links, a.list_filter,
- a.date_hierarchy, a.search_fields, a.list_select_related, a.list_per_page, a.list_editable, a)
- return cl.get_query_set()
-
-def export_csv(request):
- response = HttpResponse(mimetype='text/csv')
- response['Content-Disposition'] = 'attachment; filename='+app_settings.get('FORM_DESIGNER_CSV_EXPORT_FILENAME')
- writer = csv.writer(response, delimiter=app_settings.get('FORM_DESIGNER_CSV_EXPORT_DELIMITER'))
- qs = get_change_list_query_set(FormLogAdmin, FormLog, request)
-
- from django.db.models import Count
- distinct_forms = qs.aggregate(Count('form_definition', distinct=True))['form_definition__count']
-
- include_created = app_settings.get('FORM_DESIGNER_CSV_EXPORT_INCLUDE_CREATED')
- include_pk = app_settings.get('FORM_DESIGNER_CSV_EXPORT_INCLUDE_PK')
- include_header = app_settings.get('FORM_DESIGNER_CSV_EXPORT_INCLUDE_HEADER') and distinct_forms == 1
- include_form = app_settings.get('FORM_DESIGNER_CSV_EXPORT_INCLUDE_FORM') and distinct_forms > 1
-
- if include_header:
- header = []
- if include_form:
- header.append(_('Form'))
- if include_created:
- header.append(_('Created'))
- if include_pk:
- header.append(_('ID'))
- for field in qs.all()[0].data:
- header.append(field['label'] if field['label'] else field['key'])
- writer.writerow(header)
-
- for entry in qs:
- row = []
- if include_form:
- row.append(entry.form_definition)
- if include_created:
- row.append(entry.created)
- if include_pk:
- row.append(entry.pk)
- for field in entry.data:
- value = friendly(field['value'])
- if not isinstance(value, basestring):
- value = unicode(value)
- value = value.encode(settings.DEFAULT_CHARSET)
- row.append(value)
- writer.writerow(row)
-
- return response
@@ -1,8 +0,0 @@
-from django.conf import settings
-from form_designer import defaults
-
-def get(key):
- if hasattr(settings, key):
- return getattr(settings, key)
- else:
- return getattr(defaults, key)
Oops, something went wrong.

0 comments on commit 30589c6

Please sign in to comment.