From fa073237b2ee2e6fa5936597b45f84d792722561 Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Wed, 9 Mar 2011 15:27:08 -0400 Subject: [PATCH] Show current metadata in document upload view --- apps/common/templates/generic_form.html | 56 +++++++++++++++++++ .../common/templates/generic_subtemplate.html | 19 +++++++ apps/common/templates/generic_template.html | 13 +---- apps/documents/metadata.py | 20 +++++++ apps/documents/views.py | 14 ++++- 5 files changed, 109 insertions(+), 13 deletions(-) create mode 100644 apps/common/templates/generic_subtemplate.html diff --git a/apps/common/templates/generic_form.html b/apps/common/templates/generic_form.html index 644efe59bf..365901bbfe 100644 --- a/apps/common/templates/generic_form.html +++ b/apps/common/templates/generic_form.html @@ -1,5 +1,61 @@ {% extends "base.html" %} {% 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.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 %}
{% if form %} diff --git a/apps/common/templates/generic_subtemplate.html b/apps/common/templates/generic_subtemplate.html new file mode 100644 index 0000000000..0372611fc3 --- /dev/null +++ b/apps/common/templates/generic_subtemplate.html @@ -0,0 +1,19 @@ +{% if side_bar %} +
+

{{ title }}

+
+{% else %} +
+

{{ title }}

+
+{% endif %} + +{% if content %} +

{{ content }}

+{% endif %} + +{% for paragraph in paragraphs %} +

{{ paragraph }}

+{% endfor %} + +
diff --git a/apps/common/templates/generic_template.html b/apps/common/templates/generic_template.html index 7a68388c99..b11e5b2da3 100644 --- a/apps/common/templates/generic_template.html +++ b/apps/common/templates/generic_template.html @@ -1,15 +1,6 @@ {% extends "base.html" %} -{% block title %}{{ title }}{% endblock %} +{% block title %} :: {{ title }}{% endblock %} {% block content %} -
-

{{ title }}

-
-

{{ content }}

- - {% for paragraph in paragraphs %} -

{{ paragraph }}

- {% endfor %} -
-
+ {% include "generic_subtemplate.html" %} {% endblock %} diff --git a/apps/documents/metadata.py b/apps/documents/metadata.py index 08f63008aa..f9a6e0a4da 100644 --- a/apps/documents/metadata.py +++ b/apps/documents/metadata.py @@ -31,6 +31,8 @@ def save_metadata_list(metadata_list, document): if item['value']: save_metadata(item, document) else: + #If there is no metadata value, delete the metadata entry + #completely from the document try: metadata_type = MetadataType.objects.get(id=item['id']) document_metadata = DocumentMetadata.objects.get(document=document, @@ -52,3 +54,21 @@ def save_metadata(metadata_dict, document): #http://stackoverflow.com/questions/4382875/handling-iri-in-django document_metadata.value=unquote_plus(metadata_dict['value'])#.decode('utf-8') document_metadata.save() + + +def metadata_repr(metadata_list): + return ', '.join(metadata_repr_as_list(metadata_list)) + + +def metadata_repr_as_list(metadata_list): + output = [] + for metadata_dict in metadata_list: + try: + output.append('%s - %s' % (MetadataType.objects.get(pk=metadata_dict['id']), metadata_dict.get('value', ''))) + except: + pass + + return output + + + diff --git a/apps/documents/views.py b/apps/documents/views.py index 4185442777..2ec91ea873 100644 --- a/apps/documents/views.py +++ b/apps/documents/views.py @@ -50,7 +50,8 @@ from forms import DocumentTypeSelectForm, DocumentCreateWizard, \ StagingDocumentForm, DocumentTypeMetadataType, DocumentPreviewForm, \ MetadataFormSet, DocumentPageForm, DocumentPageTransformationForm -from metadata import save_metadata, save_metadata_list, decode_metadata_from_url +from metadata import save_metadata, save_metadata_list, \ + decode_metadata_from_url, metadata_repr_as_list from models import Document, DocumentMetadata, DocumentType, MetadataType, \ DocumentPage, DocumentPageTransformation from staging import StagingFile @@ -227,7 +228,16 @@ def upload_document_with_type(request, document_type_id, multiple=True): 'grid_clear':True, }, ) - + + 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)) + }] + }) return render_to_response('generic_form.html', context, context_instance=RequestContext(request))