Use metadata model's related name to address a document's metadata instances
This commit is contained in:
@@ -30,7 +30,7 @@ def update_indexes(document):
|
|||||||
warnings = []
|
warnings = []
|
||||||
|
|
||||||
eval_dict = {}
|
eval_dict = {}
|
||||||
document_metadata_dict = dict([(metadata.metadata_type.name, metadata.value) for metadata in document.documentmetadata_set.all() if metadata.value])
|
document_metadata_dict = dict([(metadata.metadata_type.name, metadata.value) for metadata in document.metadata.all() if metadata.value])
|
||||||
eval_dict['document'] = document
|
eval_dict['document'] = document
|
||||||
eval_dict['metadata'] = MetadataClass(document_metadata_dict)
|
eval_dict['metadata'] = MetadataClass(document_metadata_dict)
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ class SmartLinkManager(models.Manager):
|
|||||||
errors = []
|
errors = []
|
||||||
result = {}
|
result = {}
|
||||||
metadata_dict = {}
|
metadata_dict = {}
|
||||||
for document_metadata in document.documentmetadata_set.all():
|
for document_metadata in document.metadata.all():
|
||||||
metadata_dict[document_metadata.metadata_type.name] = document_metadata.value
|
metadata_dict[document_metadata.metadata_type.name] = document_metadata.value
|
||||||
eval_dict = {}
|
eval_dict = {}
|
||||||
eval_dict['document'] = document
|
eval_dict['document'] = document
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ class DocumentMetadata(models.Model):
|
|||||||
Link a document to a specific instance of a metadata type with it's
|
Link a document to a specific instance of a metadata type with it's
|
||||||
current value
|
current value
|
||||||
"""
|
"""
|
||||||
document = models.ForeignKey(Document, verbose_name=_(u'document'))
|
document = models.ForeignKey(Document, verbose_name=_(u'document'), related_name='metadata')
|
||||||
metadata_type = models.ForeignKey(MetadataType, verbose_name=_(u'type'))
|
metadata_type = models.ForeignKey(MetadataType, verbose_name=_(u'type'))
|
||||||
value = models.CharField(max_length=255, blank=True, verbose_name=_(u'value'), db_index=True)
|
value = models.CharField(max_length=255, blank=True, verbose_name=_(u'value'), db_index=True)
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ from .permissions import (PERMISSION_METADATA_DOCUMENT_EDIT,
|
|||||||
def metadata_edit(request, document_id=None, document_id_list=None):
|
def metadata_edit(request, document_id=None, document_id_list=None):
|
||||||
if document_id:
|
if document_id:
|
||||||
documents = [get_object_or_404(Document, pk=document_id)]
|
documents = [get_object_or_404(Document, pk=document_id)]
|
||||||
if documents[0].documentmetadata_set.count() == 0:
|
if documents[0].metadata.count() == 0:
|
||||||
messages.warning(request, _(u'The selected document doesn\'t have any metadata.'))
|
messages.warning(request, _(u'The selected document doesn\'t have any metadata.'))
|
||||||
return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))
|
return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))
|
||||||
elif document_id_list:
|
elif document_id_list:
|
||||||
@@ -58,7 +58,7 @@ def metadata_edit(request, document_id=None, document_id_list=None):
|
|||||||
for document in documents:
|
for document in documents:
|
||||||
RecentDocument.objects.add_document_for_user(request.user, document)
|
RecentDocument.objects.add_document_for_user(request.user, document)
|
||||||
|
|
||||||
for item in document.documentmetadata_set.all():
|
for item in document.metadata.all():
|
||||||
value = item.value
|
value = item.value
|
||||||
if item.metadata_type in metadata:
|
if item.metadata_type in metadata:
|
||||||
if value not in metadata[item.metadata_type]:
|
if value not in metadata[item.metadata_type]:
|
||||||
@@ -186,7 +186,7 @@ def metadata_multiple_add(request):
|
|||||||
def metadata_remove(request, document_id=None, document_id_list=None):
|
def metadata_remove(request, document_id=None, document_id_list=None):
|
||||||
if document_id:
|
if document_id:
|
||||||
documents = [get_object_or_404(Document, pk=document_id)]
|
documents = [get_object_or_404(Document, pk=document_id)]
|
||||||
if documents[0].documentmetadata_set.count() == 0:
|
if documents[0].metadata.count() == 0:
|
||||||
messages.warning(request, _(u'The selected document doesn\'t have any metadata.'))
|
messages.warning(request, _(u'The selected document doesn\'t have any metadata.'))
|
||||||
return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))
|
return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))
|
||||||
|
|
||||||
@@ -210,7 +210,7 @@ def metadata_remove(request, document_id=None, document_id_list=None):
|
|||||||
for document in documents:
|
for document in documents:
|
||||||
RecentDocument.objects.add_document_for_user(request.user, document)
|
RecentDocument.objects.add_document_for_user(request.user, document)
|
||||||
|
|
||||||
for item in document.documentmetadata_set.all():
|
for item in document.metadata.all():
|
||||||
value = item.value
|
value = item.value
|
||||||
if item.metadata_type in metadata:
|
if item.metadata_type in metadata:
|
||||||
if value not in metadata[item.metadata_type]:
|
if value not in metadata[item.metadata_type]:
|
||||||
@@ -274,7 +274,7 @@ def metadata_view(request, document_id):
|
|||||||
|
|
||||||
return render_to_response('generic_list.html', {
|
return render_to_response('generic_list.html', {
|
||||||
'title': _(u'metadata for: %s') % document,
|
'title': _(u'metadata for: %s') % document,
|
||||||
'object_list': document.documentmetadata_set.all(),
|
'object_list': document.metadata.all(),
|
||||||
'extra_columns': [{'name': _(u'value'), 'attribute': 'value'}],
|
'extra_columns': [{'name': _(u'value'), 'attribute': 'value'}],
|
||||||
'hide_link': True,
|
'hide_link': True,
|
||||||
'object': document,
|
'object': document,
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ def document_create_siblings(request, document_id):
|
|||||||
|
|
||||||
document = get_object_or_404(Document, pk=document_id)
|
document = get_object_or_404(Document, pk=document_id)
|
||||||
query_dict = {}
|
query_dict = {}
|
||||||
for pk, metadata in enumerate(document.documentmetadata_set.all()):
|
for pk, metadata in enumerate(document.metadata.all()):
|
||||||
query_dict['metadata%s_id' % pk] = metadata.metadata_type_id
|
query_dict['metadata%s_id' % pk] = metadata.metadata_type_id
|
||||||
query_dict['metadata%s_value' % pk] = metadata.value
|
query_dict['metadata%s_value' % pk] = metadata.value
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user