Show current metadata in document upload view

This commit is contained in:
Roberto Rosario
2011-03-09 15:27:08 -04:00
parent 1148cae5e5
commit fa073237b2
5 changed files with 109 additions and 13 deletions

View File

@@ -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 %}
<div class="generic_subform">
{% include subtemplate %}
</div><!--end subform-->
{% 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 %}
<div class="container_12">
{% if form %}

View File

@@ -0,0 +1,19 @@
{% if side_bar %}
<div class="block">
<h3>{{ title }}</h3>
<div class="content">
{% else %}
<div class="content">
<h2 class="title">{{ title }}</h2>
<div class="inner">
{% endif %}
{% if content %}
<p>{{ content }}</p>
{% endif %}
{% for paragraph in paragraphs %}
<p>{{ paragraph }}</p>
{% endfor %}
</div></div>

View File

@@ -1,15 +1,6 @@
{% extends "base.html" %}
{% block title %}{{ title }}{% endblock %}
{% block title %} :: {{ title }}{% endblock %}
{% block content %}
<div class="content">
<h2 class="title">{{ title }}</h2>
<div class="inner">
<p>{{ content }}</p>
{% for paragraph in paragraphs %}
<p>{{ paragraph }}</p>
{% endfor %}
</div>
</div>
{% include "generic_subtemplate.html" %}
{% endblock %}

View File

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

View File

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