--- a/src/ldt/ldt/ldt_utils/admin.py Mon Feb 06 16:03:30 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/admin.py Mon Feb 06 16:03:56 2012 +0100
@@ -6,6 +6,7 @@
from ldt.ldt_utils.fileimport import FileImport, FileImportError
from ldt.ldt_utils.forms import LdtImportForm, ReindexForm, StatAnnotationForm
from ldt.ldt_utils.models import Content, Project, Media, Author
+from ldt.ldt_utils.stat import update_stat_content
import ldt.indexation
from guardian.admin import GuardedModelAdmin
@@ -89,13 +90,13 @@
if form.is_valid():
if form.cleaned_data['choose_all']:
- projects = Content.objects.all()
+ contents = Content.objects.all()
else:
- projects = form.cleaned_data['projects']
+ contents = form.cleaned_data['contents']
-# for content in contents:
-# compute_stats_for(content)
- message = "Stats computed for :" + repr(projects)
+ for content in contents:
+ update_stat_content(content)
+ message = "Stats computed for :" + repr(contents)
else:
form = StatAnnotationForm()
--- a/src/ldt/ldt/ldt_utils/forms.py Mon Feb 06 16:03:30 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/forms.py Mon Feb 06 16:03:56 2012 +0100
@@ -25,7 +25,7 @@
index_projects = forms.BooleanField(required=False, initial=False)
class StatAnnotationForm(forms.Form):
- projects = forms.ModelMultipleChoiceField(Project.objects.all())
+ contents = forms.ModelMultipleChoiceField(Content.objects.all(), required=False)
choose_all = forms.BooleanField(required=False, initial=False)
class SearchForm(forms.Form):
@@ -68,8 +68,9 @@
if not iriurl_data:
iriurl_data = "%s/%s.iri" % (iri_id_data, iri_id_data)
cleaned_data['iriurl'] = iriurl_data
- # we add a comma to the tag list, to force comma separated list and enable tags with spaces.
- cleaned_data['tags'] = cleaned_data['tags'] + ','
+ # if needed, we add a comma to the tag list, to force comma separated list and enable tags with spaces.
+ if ',' not in cleaned_data['tags'] and cleaned_data['tags']!="" :
+ cleaned_data['tags'] = cleaned_data['tags'] + ','
return cleaned_data
class Meta:
--- a/src/ldt/ldt/ldt_utils/projectserializer.py Mon Feb 06 16:03:30 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/projectserializer.py Mon Feb 06 16:03:56 2012 +0100
@@ -69,26 +69,30 @@
if ensemble_id not in self.display_ensemble_list:
self.display_ensemble_list.append(ensemble_id)
+
# sets cutting to display in first position for the metadataplayer
if self.first_cutting:
annotation_types = new_display['annotation_types']
- if len(annotation_types) > 1:
- index = -1
- for i, s in enumerate(annotation_types):
- if s == self.first_cutting:
- index = i
- break
- if index >= 0:
- annotation_types[0], annotation_types[index] = annotation_types[index], annotation_types[0]
+
+ if self.first_cutting not in annotation_types:
+ annotation_types.append(self.first_cutting)
+
+ index = -1
+ for i, s in enumerate(annotation_types):
+ if s == self.first_cutting:
+ index = i
+ break
+
+ annotation_types[0], annotation_types[index] = annotation_types[index], annotation_types[0]
if self.only_one_cutting:
new_display['annotation_types'] = [new_display['annotation_types'][0]]
-
+
self.views_dict[display_id] = new_display
- def __parse_ensemble(self, ensemble_node, content):
+ def __parse_ensemble(self, ensemble_node, content, cutting_only=None):
ensemble_id = ensemble_node.attrib[u"id"]
ensemble_author = ensemble_node.attrib[u"author"]
@@ -113,13 +117,17 @@
}
}
-
- for decoupage_node in ensemble_node:
+ if cutting_only:
+ cuttings_list = cutting_only
+ else:
+ cuttings_list = ensemble_node
+
+ for decoupage_node in cuttings_list:
if decoupage_node.tag != "decoupage" :
continue
decoupage_id = decoupage_node.attrib[ u"id"]
- if self.from_display and decoupage_id not in self.display_cuttings_list:
+ if not cutting_only and self.from_display and decoupage_id not in self.display_cuttings_list:
continue
decoupage_creator = decoupage_node.attrib[u"author"]
if not decoupage_creator:
@@ -134,6 +142,7 @@
break
except Exception:
decoupage_created = None
+
if decoupage_created is None:
decoupage_created = datetime.utcnow().isoformat()
decoupage_modified = decoupage_created
@@ -146,9 +155,8 @@
for txtRes in decoupage_node.xpath("abstract/text()", smart_strings=False):
decoupage_description += txtRes
-
list_items.append({"id-ref":decoupage_id})
-
+
new_annotation_types = {
"id":decoupage_id,
"dc:creator":decoupage_creator,
@@ -159,9 +167,9 @@
"dc:description":decoupage_description
}
- self.annotation_types_dict[decoupage_id] = new_annotation_types
+ self.annotation_types_dict[decoupage_id] = new_annotation_types
self.annotations_by_annotation_types[decoupage_id] = []
-
+
res = decoupage_node.xpath("elements/element")
for element_node in res:
@@ -262,7 +270,7 @@
"dc:modified": decoupage_modified,
}
}
-
+
if element_source:
new_annotation['meta']['dc:source'] = element_source
@@ -295,7 +303,8 @@
res = self.ldt_doc.xpath("/iri/annotations/content")
for content_node in res:
- content_id = content_node.attrib[u"id"]
+ content_id = content_node.attrib[u"id"]
+
if self.from_display and content_id not in self.display_contents_list:
continue
content = Content.objects.get(iri_id=content_id) #@UndefinedVariable
@@ -305,13 +314,25 @@
ensemble_id = ensemble_node.get("id")
if self.from_display and ensemble_id not in self.display_ensemble_list:
continue
- self.__parse_ensemble(ensemble_node, content)
+ self.__parse_ensemble(ensemble_node, content)
+
+ if self.first_cutting and self.first_cutting not in self.display_cuttings_list:
+
+ cutting_node= self.ldt_doc.xpath('/iri/annotations/content/ensemble/decoupage[@id=\'%s\']' % self.first_cutting)[0]
+ ensemble_node = cutting_node.xpath('..')[0]
+ content_node = ensemble_node.xpath('..')[0]
+
+ iri_id = content_node.get("id")
+ content = Content.objects.get(iri_id=iri_id)
+
+ self.__parse_ensemble(ensemble_node, content, cutting_only=[cutting_node])
+
#reorder annotations and annotation type from view
if self.from_display and len(self.views_dict) > 0:
new_annotation_types_dict = SortedDict()
new_annotations_dict = SortedDict()
- for annotation_type in self.display_cuttings_list:
+ for annotation_type in self.display_cuttings_list + [self.first_cutting]:
if annotation_type in self.annotation_types_dict:
new_annotation_types_dict[annotation_type] = self.annotation_types_dict[annotation_type]
for annot in self.annotations_by_annotation_types[annotation_type]:
@@ -319,7 +340,7 @@
self.annotations_dict = new_annotations_dict
self.annotation_types_dict = new_annotation_types_dict
-
+
self.parsed = True
def __parse_content(self, content):
--- a/src/ldt/ldt/ldt_utils/segmentserializer.py Mon Feb 06 16:03:30 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/segmentserializer.py Mon Feb 06 16:03:56 2012 +0100
@@ -32,7 +32,10 @@
def __get_cutting_title(self, project_id, content_id, ensemble_id, cutting_id):
if not self.xml_docs.has_key(project_id):
- project = Project.objects.get(ldt_id=project_id)
+ project = Project.objects.filter(ldt_id=project_id)
+ if not project:
+ return None
+ project = project[0]
doc = lxml.etree.fromstring(project.ldt)
self.xml_docs[project_id] = doc
else: