diff --git a/apps/common/templates/generic_detail.html b/apps/common/templates/generic_detail.html index e201229699..6b2f05faf9 100644 --- a/apps/common/templates/generic_detail.html +++ b/apps/common/templates/generic_detail.html @@ -10,28 +10,26 @@ {% include subtemplate %} {% endfor %} - - {% for subtemplate in sidebar_subtemplates_dict %} - {% with subtemplate.title as title %} - {% with subtemplate.object_list as object_list %} - {% with subtemplate.extra_columns as extra_columns %} - {% with subtemplate.hide_object as hide_object %} - {% with subtemplate.main_object as main_object %} - {% with subtemplate.hide_link as hide_link %} - {% with subtemplate.hide_header as hide_header %} - {% with subtemplate.hide_columns as hide_columns %} - {% with "true" as side_bar %} - {% include subtemplate.name %} - {% endwith %} - {% endwith %} - {% endwith %} - {% endwith %} - {% endwith %} - {% endwith %} - {% endwith %} - {% endwith %} - {% endwith %} - {% endfor %} + + {% for subtemplate in sidebar_subtemplates_list %} + {% with "true" as side_bar %} + {% if subtemplate.form %} + {% render_subtemplate subtemplate.name subtemplate.context as rendered_subtemplate %} + {% with "true" as read_only %} +
+ {{ rendered_subtemplate }} +
+ {% endwith %} + {% else %} + {% render_subtemplate subtemplate.name subtemplate.context as rendered_subtemplate %} + {{ rendered_subtemplate }} + {% endif %} + + {% if subtemplate.grid_clear or not subtemplate.grid %} +
+ {% endif %} + {% endwith %} + {% endfor %} {% endblock %} {% block stylesheets %} @@ -45,83 +43,38 @@ {% endblock %} {% block content %} -
+
{% if form %} {% with "true" as read_only %} -
+
{% include "generic_form_subtemplate.html" %}
{% if grid_clear or not grid %} -
+
{% endif %} {% endwith %} {% endif %} - {% for subtemplate in subtemplates %} - {% include subtemplate %} - {% endfor %} - - {% for form in form_list %} - {% with form.submit_method as submit_method %} - {% with form.striptags as striptags %} - {% with form.title as title %} - {% with form.object as object %} - {% with form.object_name as object_name %} - {% with form.form_action as form_action %} - {% with "true" as read_only %} -
- {% with form.form as form %} -
- {% include "generic_form_subtemplate.html" %} -
- {% endwith %} -
- {% if form.grid_clear or not form.grid %} -
- {% endif %} - - {% endwith %} - {% endwith %} - {% endwith %} - {% endwith %} - {% endwith %} - {% endwith %} - {% endwith %} - {% endfor %} - {% for subtemplate in subtemplates_list %} - -
- - {% if subtemplate.form %} - {% with subtemplate.submit_method as submit_method %} - {% with subtemplate.striptags as striptags %} - {% with subtemplate.object as object %} - {% with subtemplate.object_name as object_name %} - {% with subtemplate.form_action as form_action %} - {% with "true" as read_only %} - {% with subtemplate.form as form %} -
- {% include subtemplate.name %} -
- {% endwith %} - {% endwith %} - {% endwith %} - {% endwith %} - {% endwith %} - {% endwith %} - {% endwith %} - {% else %} - {% render_subtemplate subtemplate.name subtemplate.context as rendered_subtemplate %} - {{ rendered_subtemplate }} - {% endif %} -
- {% if subtemplate.grid_clear or not subtemplate.grid %} -
+
+ {% if subtemplate.form %} + {% render_subtemplate subtemplate.name subtemplate.context as rendered_subtemplate %} + {% with "true" as read_only %} +
+ {{ rendered_subtemplate }} +
+ {% endwith %} + {% else %} + {% render_subtemplate subtemplate.name subtemplate.context as rendered_subtemplate %} + {{ rendered_subtemplate }} {% endif %} +
+ {% if subtemplate.grid_clear or not subtemplate.grid %} +
+ {% endif %} {% endfor %}
{% endblock %} diff --git a/apps/common/templates/generic_detail_subtemplate.html b/apps/common/templates/generic_detail_subtemplate.html index aae27f1983..7d8129f0bc 100644 --- a/apps/common/templates/generic_detail_subtemplate.html +++ b/apps/common/templates/generic_detail_subtemplate.html @@ -19,49 +19,5 @@
{% endwith %} {% endif %} - - {% for subtemplate in subtemplates %} - {% include subtemplate %} - {% endfor %} - - {% for form in form_list %} - {% with form.submit_method as submit_method %} - {% with form.striptags as striptags %} - {% with form.title as title %} - {% with form.object as object %} - {% with form.object_name as object_name %} - {% with form.form_action as form_action %} - {% with "true" as read_only %} - {% with form.form as form %} - {% include "generic_form_subtemplate.html" %} - {% endwith %} - - {% endwith %} - {% endwith %} - {% endwith %} - {% endwith %} - {% endwith %} - {% endwith %} - {% endwith %} - {% endfor %} - - - {% for subtemplate in subtemplates_dict %} - {% with subtemplate.title as title %} - {% with subtemplate.object_list as object_list %} - {% with subtemplate.extra_columns as extra_columns %} - {% with subtemplate.hide_object as hide_object %} - {% with subtemplate.main_object as main_object %} - {% with subtemplate.hide_link as hide_link %} - {% with subtemplate.hide_header as hide_header %} - {% include subtemplate.name %} - {% endwith %} - {% endwith %} - {% endwith %} - {% endwith %} - {% endwith %} - {% endwith %} - {% endwith %} - {% endfor %} {% endblock %} diff --git a/apps/common/templates/generic_form.html b/apps/common/templates/generic_form.html index ba6afd3efb..29eb58ce16 100644 --- a/apps/common/templates/generic_form.html +++ b/apps/common/templates/generic_form.html @@ -1,116 +1,51 @@ {% extends "base.html" %} +{% load subtemplates_tags %} + {% block title %} :: {% with "true" as striptags %}{% include "calculate_form_title.html" %}{% endwith %}{% endblock %} {% block sidebar %} - {% for subtemplate in sidebar_subtemplates %} -
- {% include subtemplate %} -
- {% endfor %} - {% for subtemplate in sidebar_subtemplates_list %} - {% with subtemplate.title as title %} - {% with subtemplate.object_list as object_list %} - {% with subtemplate.extra_columns as extra_columns %} - {% with subtemplate.hide_object as hide_object %} - {% with subtemplate.main_object as main_object %} - {% with subtemplate.hide_link as hide_link %} - {% with subtemplate.hide_header as hide_header %} - {% with subtemplate.hide_columns as hide_columns %} - {% with "true" as side_bar %} - - {% with subtemplate.submit_method as submit_method %} - {% with subtemplate.striptags as striptags %} - {% with subtemplate.title as title %} - {% with subtemplate.object as object %} - {% with subtemplate.object_name as object_name %} - {% with subtemplate.form_action as form_action %} - {% with subtemplate.submit_label as submit_label %} - {% with subtemplate.form as form %} - - {% with subtemplate.content as content %} - {% with subtemplate.paragraphs as paragraphs %} - - {% include subtemplate.name %} - - {% endwith %} - {% endwith %} - - {% endwith %} - {% endwith %} - {% endwith %} - {% endwith %} - {% endwith %} - {% endwith %} - {% endwith %} - {% endwith %} - - - {% endwith %} - {% endwith %} - {% endwith %} - {% endwith %} - {% endwith %} - {% endwith %} - {% endwith %} - {% endwith %} - {% endwith %} - {% endfor %} + {% if subtemplate.form %} + {% render_subtemplate subtemplate.name subtemplate.context as rendered_subtemplate %} +
+ {{ rendered_subtemplate }} +
+ {% else %} + {% render_subtemplate subtemplate.name subtemplate.context as rendered_subtemplate %} + {{ rendered_subtemplate }} + {% endif %} + {% if subtemplate.grid_clear or not subtemplate.grid %} + {% endif %} + {% endfor %} {% endblock %} {% block content %} -
- {% if form %} -
- {% include "generic_form_subtemplate.html" %} -
- {% if form.grid_clear or not form.grid %} -
- {% endif %} - {% endif %} - - {% for form in form_list %} - {% with form.submit_method as submit_method %} - {% with form.striptags as striptags %} - {% with form.title as title %} - {% with form.object as object %} - {% with form.object_name as object_name %} - {% with form.submit_label as submit_label %} - {% with form.form_action as form_action %} -
- {% with form.form as form %} - {% include "generic_form_subtemplate.html" %} - {% endwith %} +
+ {% if form %} +
+ {% include "generic_form_subtemplate.html" %}
{% if form.grid_clear or not form.grid %} -
+
{% endif %} - {% endwith %} - {% endwith %} - {% endwith %} - {% endwith %} - {% endwith %} - {% endwith %} - {% endwith %} - {% endfor %} -
+ {% endif %} - {% for subtemplate in subtemplates_dict %} - {% with subtemplate.title as title %} - {% with subtemplate.object_list as object_list %} - {% with subtemplate.extra_columns as extra_columns %} - {% with subtemplate.hide_object as hide_object %} - {% with subtemplate.main_object as main_object %} - {% with subtemplate.hide_link as hide_link %} - {% with subtemplate.hide_header as hide_header %} - {% include subtemplate.name %} - {% endwith %} - {% endwith %} - {% endwith %} - {% endwith %} - {% endwith %} - {% endwith %} - {% endwith %} - {% endfor %} + {% for subtemplate in subtemplates_list %} +
+ {% if subtemplate.form %} + {% render_subtemplate subtemplate.name subtemplate.context as rendered_subtemplate %} +
+ {{ rendered_subtemplate }} +
+ {% else %} + {% render_subtemplate subtemplate.name subtemplate.context as rendered_subtemplate %} + {{ rendered_subtemplate }} + {% endif %} +
+ {% if subtemplate.grid_clear or not subtemplate.grid %} +
+ {% endif %} + {% endfor %} +
{% endblock %} diff --git a/apps/common/templates/generic_list.html b/apps/common/templates/generic_list.html index 8f0c35f702..f0a72cfb02 100644 --- a/apps/common/templates/generic_list.html +++ b/apps/common/templates/generic_list.html @@ -4,84 +4,16 @@ {% block title %} :: {% blocktrans %}List of {{ title }}{% endblocktrans %}{% endblock %} {#{% block secondary_links %}{{ secondary_links|safe }}{% endblock %}#} - {% block sidebar %} {% for subtemplate in sidebar_subtemplates %}
{% include subtemplate %}
{% endfor %} - - {% for subtemplate in sidebar_subtemplates_list %} - {% with subtemplate.title as title %} - {% with subtemplate.object_list as object_list %} - {% with subtemplate.extra_columns as extra_columns %} - {% with subtemplate.hide_object as hide_object %} - {% with subtemplate.main_object as main_object %} - {% with subtemplate.hide_link as hide_link %} - {% with subtemplate.hide_header as hide_header %} - {% with subtemplate.hide_columns as hide_columns %} - {% with "true" as side_bar %} - - {% with subtemplate.submit_method as submit_method %} - {% with subtemplate.striptags as striptags %} - {% with subtemplate.title as title %} - {% with subtemplate.object as object %} - {% with subtemplate.object_name as object_name %} - {% with subtemplate.form_action as form_action %} - {% with subtemplate.form as form %} - - {% with subtemplate.content as content %} - {% with subtemplate.paragraphs as paragraphs %} - - {% include subtemplate.name %} - - {% endwith %} - {% endwith %} - - {% endwith %} - {% endwith %} - {% endwith %} - {% endwith %} - {% endwith %} - {% endwith %} - {% endwith %} - - - {% endwith %} - {% endwith %} - {% endwith %} - {% endwith %} - {% endwith %} - {% endwith %} - {% endwith %} - {% endwith %} - {% endwith %} - {% endfor %} {% endblock %} {% block content %} {% include "generic_list_subtemplate.html" %} - {% for subtemplate in subtemplates_dict %} - {% with subtemplate.title as title %} - {% with subtemplate.object_list as object_list %} - {% with subtemplate.extra_columns as extra_columns %} - {% with subtemplate.hide_object as hide_object %} - {% with subtemplate.main_object as main_object %} - {% with subtemplate.hide_link as hide_link %} - {% with subtemplate.hide_header as hide_header %} - {% with subtemplate.multi_select as multi_select %} - {% include subtemplate.name %} - {% endwith %} - {% endwith %} - {% endwith %} - {% endwith %} - {% endwith %} - {% endwith %} - {% endwith %} - {% endwith %} - {% endfor %} - {% endblock %} diff --git a/apps/documents/__init__.py b/apps/documents/__init__.py index 3515837b0b..67f0cfe77b 100644 --- a/apps/documents/__init__.py +++ b/apps/documents/__init__.py @@ -37,8 +37,8 @@ document_list_recent = {'text': _(u'recent documents list'), 'view': 'document_l document_create = {'text': _(u'upload a new document'), 'view': 'document_create', 'famfam': 'page_add', 'permissions': {'namespace': 'documents', 'permissions': [PERMISSION_DOCUMENT_CREATE]}} document_create_multiple = {'text': _(u'upload multiple new documents'), 'view': 'document_create_multiple', 'famfam': 'page_add', 'permissions': {'namespace': 'documents', 'permissions': [PERMISSION_DOCUMENT_CREATE]}} document_create_sibling = {'text': _(u'upload new document using same metadata'), 'view': 'document_create_sibling', 'args': 'object.id', 'famfam': 'page_copy', 'permissions': {'namespace': 'documents', 'permissions': [PERMISSION_DOCUMENT_CREATE]}} -document_view = {'text': _(u'details (advanced)'), 'view': 'document_view', 'args': 'object.id', 'famfam': 'page', 'permissions': {'namespace': 'documents', 'permissions': [PERMISSION_DOCUMENT_VIEW]}} document_view_simple = {'text': _(u'details (simple)'), 'view': 'document_view_simple', 'args': 'object.id', 'famfam': 'page', 'permissions': {'namespace': 'documents', 'permissions': [PERMISSION_DOCUMENT_VIEW]}} +document_view_advanced = {'text': _(u'details (advanced)'), 'view': 'document_view_advanced', 'args': 'object.id', 'famfam': 'page', 'permissions': {'namespace': 'documents', 'permissions': [PERMISSION_DOCUMENT_VIEW]}} document_delete = {'text': _(u'delete'), 'view': 'document_delete', 'args': 'object.id', 'famfam': 'page_delete', 'permissions': {'namespace': 'documents', 'permissions': [PERMISSION_DOCUMENT_DELETE]}} document_multiple_delete = {'text': _(u'delete'), 'view': 'document_multiple_delete', 'famfam': 'page_delete', 'permissions': {'namespace': 'documents', 'permissions': [PERMISSION_DOCUMENT_DELETE]}} document_edit = {'text': _(u'edit'), 'view': 'document_edit', 'args': 'object.id', 'famfam': 'page_edit', 'permissions': {'namespace': 'documents', 'permissions': [PERMISSION_DOCUMENT_PROPERTIES_EDIT]}} @@ -79,7 +79,7 @@ metadata_group_create_sibling = {'text': _(u'upload new document using same meta staging_file_preview = {'text': _(u'preview'), 'class': 'fancybox-noscaling', 'view': 'staging_file_preview', 'args': 'object.id', 'famfam': 'drive_magnify'} staging_file_delete = {'text': _(u'delete'), 'view': 'staging_file_delete', 'args': 'object.id', 'famfam': 'drive_delete'} -register_links(Document, [document_view_simple, document_view, document_edit, document_print, document_delete, document_download, document_find_duplicates, document_clear_transformations]) +register_links(Document, [document_view_simple, document_view_advanced, document_edit, document_print, document_delete, document_download, document_find_duplicates, document_clear_transformations]) register_links(Document, [document_create_sibling], menu_name='sidebar') register_multi_item_links(['metadatagroup_view', 'document_list', 'document_list_recent'], [document_multiple_clear_transformations, document_multiple_delete]) diff --git a/apps/documents/urls.py b/apps/documents/urls.py index 22308c3982..e843201ee6 100644 --- a/apps/documents/urls.py +++ b/apps/documents/urls.py @@ -16,7 +16,7 @@ urlpatterns = patterns('documents.views', url(r'^document/create/from/local/multiple/$', 'document_create', {'multiple': True}, 'document_create_multiple'), url(r'^document/type/upload/single/$', 'upload_document_with_type', {'multiple': False}, 'upload_document'), url(r'^document/type/upload/multiple/$', 'upload_document_with_type', {'multiple': True}, 'upload_document_multiple'), - url(r'^document/(?P\d+)/$', 'document_view', (), 'document_view'), + url(r'^document/(?P\d+)/$', 'document_view_advanced', (), 'document_view_advanced'), url(r'^document/(?P\d+)/simple/$', 'document_view_simple', (), 'document_view_simple'), url(r'^document/(?P\d+)/delete/$', 'document_delete', (), 'document_delete'), url(r'^document/multiple/delete/$', 'document_multiple_delete', (), 'document_multiple_delete'), diff --git a/apps/documents/views.py b/apps/documents/views.py index c74381b2fa..9fc2c31cef 100644 --- a/apps/documents/views.py +++ b/apps/documents/views.py @@ -205,16 +205,15 @@ def upload_document_with_type(request, multiple=True): else: return HttpResponseRedirect(reverse('document_list')) - context = { - 'document_type_id': document_type_id, - 'form_list': [ - { - 'form': local_form, - 'title': _(u'upload a local document'), - 'grid': 6, - 'grid_clear': False if USE_STAGING_DIRECTORY else True, - }, - ], + subtemplates_list = [] + local_upload_form = { + 'name': 'generic_form_subtemplate.html', + 'context': { + 'form': local_form, + 'title': _(u'upload a local document'), + 'grid': 6, + 'grid_clear': False if USE_STAGING_DIRECTORY else True, + } } if USE_STAGING_DIRECTORY: @@ -224,45 +223,146 @@ def upload_document_with_type(request, multiple=True): messages.error(request, e) filelist = [] finally: - context.update({ - 'subtemplates_dict': [ - { - 'name': 'generic_list_subtemplate.html', + subtemplates_list.append(local_upload_form) + subtemplates_list.append( + { + 'name': 'generic_form_subtemplate.html', + 'context': { + 'form': staging_form, + 'title': _(u'upload a document from staging'), + 'grid': 6, + 'grid_clear': True, + } + }, + ) + subtemplates_list.append( + { + 'name': 'generic_list_subtemplate.html', + 'context': { 'title': _(u'files in staging'), 'object_list': filelist, 'hide_link': True, - }, - ], - }) - context['form_list'].append( - { - 'form': staging_form, - 'title': _(u'upload a document from staging'), - 'grid': 6, - 'grid_clear': True, + } }, - ) + ) + else: + subtemplates_list.append(local_upload_form) + + + context = { + 'document_type_id': document_type_id, + 'subtemplates_list': subtemplates_list, + } context.update({ 'sidebar_subtemplates_list': [ { - 'title': _(u'Current metadata'), 'name': 'generic_subtemplate.html', - #'content': metadata_repr(decode_metadata_from_url(request.GET)), - 'paragraphs': metadata_repr_as_list(decode_metadata_from_url(request.GET)) + 'context': { + 'title': _(u'Current metadata'), + #'content': metadata_repr(decode_metadata_from_url(request.GET)), + 'paragraphs': metadata_repr_as_list(decode_metadata_from_url(request.GET)) + } }] - }) + }) return render_to_response('generic_form.html', context, context_instance=RequestContext(request)) -def document_view(request, document_id): +def document_view_simple(request, document_id): check_permissions(request.user, 'documents', [PERMISSION_DOCUMENT_VIEW]) document = get_object_or_404(Document.objects.select_related(), pk=document_id) RecentDocument.objects.add_document_for_user(request.user, document) + subtemplates_list = [] + + content_form = DocumentContentForm(document=document) + + preview_form = DocumentPreviewForm(document=document) + subtemplates_list.append( + { + 'name': 'generic_form_subtemplate.html', + 'context': { + 'form': preview_form, + 'object': document, + } + }, + ) + subtemplates_list.append( + { + 'name': 'generic_form_subtemplate.html', + 'context': { + 'title':_(u'document properties'), + 'form': content_form, + 'object': document, + }, + } + ) + + if document.tags.count(): + subtemplates_list.append(get_tags_subtemplate(document)) + + if Comment.objects.for_model(document).count(): + subtemplates_list.append(get_comments_subtemplate(document)) + + subtemplates_list.append( + { + 'name': 'generic_list_subtemplate.html', + 'context': { + 'title': _(u'metadata'), + 'object_list': document.documentmetadata_set.all(), + 'extra_columns': [{'name': _(u'value'), 'attribute': 'value'}], + 'hide_link': True, + } + }, + ) + + metadata_groups, errors = document.get_metadata_groups() + if (request.user.is_staff or request.user.is_superuser) and errors: + for error in errors: + messages.warning(request, _(u'Document group query error: %s' % error)) + + if not GROUP_SHOW_EMPTY: + #If GROUP_SHOW_EMPTY is False, remove empty groups from + #dictionary + metadata_groups = dict([(group, data) for group, data in metadata_groups.items() if data]) + + if metadata_groups: + subtemplates_list.append( + { + 'name': 'generic_form_subtemplate.html', + 'context': { + 'title': _(u'document groups (%s)') % len(metadata_groups.keys()), + 'form': MetaDataGroupForm( + groups=metadata_groups, current_document=document, + links=[ + metadata_group_link + ] + ), + 'form_action': reverse('metadatagroup_action'), + 'submit_method': 'GET', + } + } + ) + + return render_to_response('generic_detail.html', { + 'object': document, + 'document': document, + 'subtemplates_list': subtemplates_list, + }, context_instance=RequestContext(request)) + + +def document_view_advanced(request, document_id): + check_permissions(request.user, 'documents', [PERMISSION_DOCUMENT_VIEW]) + + document = get_object_or_404(Document.objects.select_related(), pk=document_id) + + RecentDocument.objects.add_document_for_user(request.user, document) + + subtemplates_list = [] + form = DocumentForm_view(instance=document, extra_fields=[ {'label': _(u'Filename'), 'field': 'file_filename'}, {'label': _(u'File extension'), 'field': 'file_extension'}, @@ -279,19 +379,27 @@ def document_view(request, document_id): ]) preview_form = DocumentPreviewForm(document=document) - form_list = [ - { - 'form': preview_form, - 'object': document, - }, - { - 'title': _(u'document properties'), - 'form': form, - 'object': document, - }, - ] - subtemplates_list = [] + subtemplates_list.append( + { + 'name': 'generic_form_subtemplate.html', + 'context': { + 'form': preview_form, + 'object': document, + } + }, + ) + subtemplates_list.append( + { + 'name': 'generic_form_subtemplate.html', + 'context': { + 'form': form, + 'title': _(u'document properties'), + 'object': document, + } + }, + ) + if document.tags.count(): subtemplates_list.append(get_tags_subtemplate(document)) @@ -346,7 +454,6 @@ def document_view(request, document_id): }) return render_to_response('generic_detail.html', { - 'form_list': form_list, 'object': document, 'document': document, 'subtemplates_list': subtemplates_list, @@ -723,13 +830,13 @@ def document_clear_transformations(request, document_id=None, document_id_list=N if document_id: documents = [get_object_or_404(Document.objects, pk=document_id)] - post_redirect = reverse('document_view', args=[documents[0].pk]) + post_redirect = reverse('document_view_simple', args=[documents[0].pk]) elif document_id_list: documents = [get_object_or_404(Document, pk=document_id) for document_id in document_id_list.split(',')] post_redirect = None else: messages.error(request, _(u'Must provide at least one document.')) - return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/')) + return HttpResponseRedirect(request.META.get('HTTP_REFERER', u'/')) previous = request.POST.get('previous', request.GET.get('previous', request.META.get('HTTP_REFERER', post_redirect or reverse('document_list')))) next = request.POST.get('next', request.GET.get('next', request.META.get('HTTP_REFERER', post_redirect or reverse('document_list')))) @@ -768,83 +875,6 @@ def document_multiple_clear_transformations(request): return document_clear_transformations(request, document_id_list=request.GET.get('id_list', [])) -def document_view_simple(request, document_id): - check_permissions(request.user, 'documents', [PERMISSION_DOCUMENT_VIEW]) - - document = get_object_or_404(Document.objects.select_related(), pk=document_id) - - RecentDocument.objects.add_document_for_user(request.user, document) - - content_form = DocumentContentForm(document=document) - - preview_form = DocumentPreviewForm(document=document) - form_list = [ - { - 'form': preview_form, - 'object': document, - }, - { - 'title':_(u'document properties'), - 'form': content_form, - 'object': document, - }, - ] - - subtemplates_list = [] - if document.tags.count(): - subtemplates_list.append(get_tags_subtemplate(document)) - - if Comment.objects.for_model(document).count(): - subtemplates_list.append(get_comments_subtemplate(document)) - - subtemplates_list.append( - { - 'name': 'generic_list_subtemplate.html', - 'context': { - 'title': _(u'metadata'), - 'object_list': document.documentmetadata_set.all(), - 'extra_columns': [{'name': _(u'value'), 'attribute': 'value'}], - 'hide_link': True, - } - }, - ) - - metadata_groups, errors = document.get_metadata_groups() - if (request.user.is_staff or request.user.is_superuser) and errors: - for error in errors: - messages.warning(request, _(u'Document group query error: %s' % error)) - - if not GROUP_SHOW_EMPTY: - #If GROUP_SHOW_EMPTY is False, remove empty groups from - #dictionary - metadata_groups = dict([(group, data) for group, data in metadata_groups.items() if data]) - - if metadata_groups: - subtemplates_list.append( - { - 'name': 'generic_form_subtemplate.html', - 'context': { - 'title': _(u'document groups (%s)') % len(metadata_groups.keys()), - 'form': MetaDataGroupForm( - groups=metadata_groups, current_document=document, - links=[ - metadata_group_link - ] - ), - 'form_action': reverse('metadatagroup_action'), - 'submit_method': 'GET', - } - } - ) - - return render_to_response('generic_detail.html', { - 'form_list': form_list, - 'object': document, - 'document': document, - 'subtemplates_list': subtemplates_list, - }, context_instance=RequestContext(request)) - - def document_missing_list(request): check_permissions(request.user, 'documents', [PERMISSION_DOCUMENT_VIEW]) @@ -876,16 +906,11 @@ def document_page_view(request, document_page_id): rotation = int(request.GET.get('rotation', 0)) document_page_form = DocumentPageForm(instance=document_page, zoom=zoom, rotation=rotation) - form_list = [ - { - 'form': document_page_form, - 'title': _(u'details for: %s') % document_page, - }, - ] return render_to_response('generic_detail.html', { - 'form_list': form_list, 'object': document_page, 'web_theme_hide_menus': True, + 'form': document_page_form, + 'title': _(u'details for: %s') % document_page, }, context_instance=RequestContext(request)) @@ -895,16 +920,11 @@ def document_page_text(request, document_page_id): document_page = get_object_or_404(DocumentPage, pk=document_page_id) document_page_form = DocumentPageForm_text(instance=document_page) - form_list = [ - { - 'form': document_page_form, - 'title': _(u'details for: %s') % document_page, - }, - ] return render_to_response('generic_detail.html', { - 'form_list': form_list, 'object': document_page, 'web_theme_hide_menus': True, + 'form': document_page_form, + 'title': _(u'details for: %s') % document_page, }, context_instance=RequestContext(request)) @@ -934,12 +954,12 @@ def document_page_edit(request, document_page_id): def document_page_navigation_next(request, document_page_id): check_permissions(request.user, 'documents', [PERMISSION_DOCUMENT_VIEW]) - view = resolve_to_name(urlparse.urlparse(request.META.get('HTTP_REFERER', '/')).path) + view = resolve_to_name(urlparse.urlparse(request.META.get('HTTP_REFERER', u'/')).path) document_page = get_object_or_404(DocumentPage, pk=document_page_id) if document_page.page_number >= document_page.document.documentpage_set.count(): messages.warning(request, _(u'There are no more pages in this document')) - return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/')) + return HttpResponseRedirect(request.META.get('HTTP_REFERER', u'/')) else: document_page = get_object_or_404(DocumentPage, document=document_page.document, page_number=document_page.page_number + 1) return HttpResponseRedirect(reverse(view, args=[document_page.pk])) @@ -947,12 +967,12 @@ def document_page_navigation_next(request, document_page_id): def document_page_navigation_previous(request, document_page_id): check_permissions(request.user, 'documents', [PERMISSION_DOCUMENT_VIEW]) - view = resolve_to_name(urlparse.urlparse(request.META.get('HTTP_REFERER', '/')).path) + view = resolve_to_name(urlparse.urlparse(request.META.get('HTTP_REFERER', u'/')).path) document_page = get_object_or_404(DocumentPage, pk=document_page_id) if document_page.page_number <= 1: messages.warning(request, _(u'You are already at the first page of this document')) - return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/')) + return HttpResponseRedirect(request.META.get('HTTP_REFERER', u'/')) else: document_page = get_object_or_404(DocumentPage, document=document_page.document, page_number=document_page.page_number - 1) return HttpResponseRedirect(reverse(view, args=[document_page.pk])) @@ -960,7 +980,7 @@ def document_page_navigation_previous(request, document_page_id): def document_page_navigation_first(request, document_page_id): check_permissions(request.user, 'documents', [PERMISSION_DOCUMENT_VIEW]) - view = resolve_to_name(urlparse.urlparse(request.META.get('HTTP_REFERER', '/')).path) + view = resolve_to_name(urlparse.urlparse(request.META.get('HTTP_REFERER', u'/')).path) document_page = get_object_or_404(DocumentPage, pk=document_page_id) document_page = get_object_or_404(DocumentPage, document=document_page.document, page_number=1) @@ -969,7 +989,7 @@ def document_page_navigation_first(request, document_page_id): def document_page_navigation_last(request, document_page_id): check_permissions(request.user, 'documents', [PERMISSION_DOCUMENT_VIEW]) - view = resolve_to_name(urlparse.urlparse(request.META.get('HTTP_REFERER', '/')).path) + view = resolve_to_name(urlparse.urlparse(request.META.get('HTTP_REFERER', u'/')).path) document_page = get_object_or_404(DocumentPage, pk=document_page_id) document_page = get_object_or_404(DocumentPage, document=document_page.document, page_number=document_page.document.documentpage_set.count()) @@ -986,11 +1006,11 @@ def document_list_recent(request): def transform_page(request, document_page_id, zoom_function=None, rotation_function=None): check_permissions(request.user, 'documents', [PERMISSION_DOCUMENT_VIEW]) - view = resolve_to_name(urlparse.urlparse(request.META.get('HTTP_REFERER', '/')).path) + view = resolve_to_name(urlparse.urlparse(request.META.get('HTTP_REFERER', u'/')).path) document_page = get_object_or_404(DocumentPage, pk=document_page_id) # Get the query string from the referer url - query = urlparse.urlparse(request.META.get('HTTP_REFERER', '/')).query + query = urlparse.urlparse(request.META.get('HTTP_REFERER', u'/')).query # Parse the query string and get the zoom value # parse_qs return a dictionary whose values are lists zoom = int(urlparse.parse_qs(query).get('zoom', ['100'])[0]) @@ -1047,7 +1067,7 @@ def metadatagroup_action(request): if not action: messages.error(request, _(u'No action selected.')) - return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/')) + return HttpResponseRedirect(request.META.get('HTTP_REFERER', u'/')) return HttpResponseRedirect(action) diff --git a/apps/main/templates/base.html b/apps/main/templates/base.html index 28c13164ca..16bbd160ba 100644 --- a/apps/main/templates/base.html +++ b/apps/main/templates/base.html @@ -30,7 +30,7 @@ {##} - + {##}