# HG changeset patch # User cavaliet # Date 1326295178 -3600 # Node ID 63f729155d8156d81c2fa714d78946cd8c2ccbf8 # Parent d211a78da3953a9f9baa9a5a0123d0e8ed45be23 Enhance search and front template : add begin and duration to searched segments. diff -r d211a78da395 -r 63f729155d81 src/ldt/ldt/indexation/__init__.py --- a/src/ldt/ldt/indexation/__init__.py Wed Jan 11 12:38:06 2012 +0100 +++ b/src/ldt/ldt/indexation/__init__.py Wed Jan 11 16:19:38 2012 +0100 @@ -23,12 +23,16 @@ title = doc.getField('title').stringValue() desc = doc.getField('abstract').stringValue() tags = doc.getField('tags').stringValue() + begin = doc.getField('begin').stringValue() + duration = doc.getField('duration').stringValue() ids['context'] = desc ids['title'] = title ids['tags'] = tags ids['score'] = score ids['lucene_id'] = i.doc + ids['begin'] = begin + ids['duration'] = duration contexts.append(ids) searcher.close() diff -r d211a78da395 -r 63f729155d81 src/ldt/ldt/ldt_utils/contentindexer.py --- a/src/ldt/ldt/ldt_utils/contentindexer.py Wed Jan 11 12:38:06 2012 +0100 +++ b/src/ldt/ldt/ldt_utils/contentindexer.py Wed Jan 11 16:19:38 2012 +0100 @@ -101,7 +101,9 @@ doc.add(lucene.Field("tags", tags, lucene.Field.Store.YES, lucene.Field.Index.ANALYZED)) doc.add(lucene.Field("title", title, lucene.Field.Store.YES, lucene.Field.Index.ANALYZED)) doc.add(lucene.Field("abstract", abstract, lucene.Field.Store.YES, lucene.Field.Index.ANALYZED)) - doc.add(lucene.Field("all", " ".join([tags, title, abstract]), lucene.Field.Store.YES, lucene.Field.Index.ANALYZED)) + doc.add(lucene.Field("all", " ".join([tags, title, abstract]), lucene.Field.Store.YES, lucene.Field.Index.ANALYZED)) + doc.add(lucene.Field("begin", str(start_ts), lucene.Field.Store.YES, lucene.Field.Index.NOT_ANALYZED)) + doc.add(lucene.Field("duration", str(duration), lucene.Field.Store.YES, lucene.Field.Index.NOT_ANALYZED)) seg = Segment(content=content, iri_id=content.iri_id, diff -r d211a78da395 -r 63f729155d81 src/ldt/ldt/ldt_utils/models.py --- a/src/ldt/ldt/ldt_utils/models.py Wed Jan 11 12:38:06 2012 +0100 +++ b/src/ldt/ldt/ldt_utils/models.py Wed Jan 11 16:19:38 2012 +0100 @@ -158,20 +158,6 @@ self.save() return self.duration - def duration_str(self): - if self.duration is None: - return "?" - # We take off the milliseconds - sec = self.duration//1000 - if sec < 60 : - return str(dur) + "s" - hours = sec//3600 - min = (sec - (hours * 3600))//60 - if min<10: - min_str = "0" + str(min) - else: - min_str = str(min) - return str(hours) + "h" + min_str def mimetype(): #@NoSelf def fget(self): @@ -460,7 +446,7 @@ self.save() def unpublish(self): - if not self.pk(): + if not self.pk: self.save() self.state = 1 everyone = Group.objects.get(name=settings.PUBLIC_GROUP_NAME) diff -r d211a78da395 -r 63f729155d81 src/ldt/ldt/ldt_utils/templates/front/front_group.html --- a/src/ldt/ldt/ldt_utils/templates/front/front_group.html Wed Jan 11 12:38:06 2012 +0100 +++ b/src/ldt/ldt/ldt_utils/templates/front/front_group.html Wed Jan 11 16:19:38 2012 +0100 @@ -1,6 +1,7 @@ {% extends "front/front_base.html" %} {% load i18n %} {% load thumbnail %} +{% load str_duration %} {% block title %}Lignes de temps : groupe "{{group.name}}"{% endblock %} @@ -21,7 +22,7 @@ {% thumbnail content.image "134x75" format="PNG" crop="center" as im %}{% endthumbnail %}
120

{% if content.title|length > 69 %}{{content.title|slice:":69"}}...{% else %}{{content.title}}{% endif %}

-

{% trans 'by' %} IRI | {{content.duration_str}}

+

{% trans 'by' %} IRI | {{content.duration|str_duration:"h"}}

{% endfor %} diff -r d211a78da395 -r 63f729155d81 src/ldt/ldt/ldt_utils/templates/front/front_home.html --- a/src/ldt/ldt/ldt_utils/templates/front/front_home.html Wed Jan 11 12:38:06 2012 +0100 +++ b/src/ldt/ldt/ldt_utils/templates/front/front_home.html Wed Jan 11 16:19:38 2012 +0100 @@ -1,6 +1,8 @@ {% extends "front/front_base.html" %} {% load i18n %} {% load thumbnail %} +{% load str_duration %} + {% block title %}Lignes de temps : Home{% endblock %} @@ -21,7 +23,7 @@ {% thumbnail content.image "294x165" format="PNG" crop="center" as im %}{% endthumbnail %}
{{ content.nb_annotation }}

{{content.title}}

-

{% trans 'by' %} IRI | {{content.duration_str}}

+

{% trans 'by' %} IRI | {{content.duration|str_duration:"h"}}

{% endfor %} @@ -35,7 +37,7 @@ {% thumbnail content.image "134x75" format="PNG" crop="center" as im %}{% endthumbnail %}
{{ content.nb_annotation }}

{% if content.title|length > 69 %}{{content.title|slice:":69"}}...{% else %}{{content.title}}{% endif %}

-

{% trans 'by' %} IRI | {{content.duration_str}}

+

{% trans 'by' %} IRI | {{content.duration|str_duration:"h"}}

{% endfor %} diff -r d211a78da395 -r 63f729155d81 src/ldt/ldt/ldt_utils/templates/front/front_search_results.html --- a/src/ldt/ldt/ldt_utils/templates/front/front_search_results.html Wed Jan 11 12:38:06 2012 +0100 +++ b/src/ldt/ldt/ldt_utils/templates/front/front_search_results.html Wed Jan 11 16:19:38 2012 +0100 @@ -1,6 +1,7 @@ {% extends "front/front_base.html" %} {% load i18n %} {% load thumbnail %} +{% load str_duration %} {% block title %}Lignes de temps : {% trans 'search' %} ""{% endblock %} @@ -65,7 +66,7 @@

{% if segment.title %}{{ segment.title }}{% else %}{% trans "No title" %}{% endif %}

-

{% if segment.context %}{{ segment.context }}{% endif %} +

{% if segment.context %}{{ segment.context }}{% endif %}
begin : {{ segment.begin|str_duration:"::" }} - dur : {{ segment.duration|str_duration:"::" }} diff -r d211a78da395 -r 63f729155d81 src/ldt/ldt/ldt_utils/views/workspace.py --- a/src/ldt/ldt/ldt_utils/views/workspace.py Wed Jan 11 12:38:06 2012 +0100 +++ b/src/ldt/ldt/ldt_utils/views/workspace.py Wed Jan 11 16:19:38 2012 +0100 @@ -167,7 +167,8 @@ else: results = get_results_with_context(field, search) complete_results = [] - proj_list = Project.safe_objects.all() + # the search is made only on the published project + proj_list = Project.safe_objects.filter(state=2) results.sort(key=lambda k: k['iri_id']) for iri_id, item in groupby(results, itemgetter('iri_id')): try: diff -r d211a78da395 -r 63f729155d81 src/ldt/ldt/templatetags/str_duration.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ldt/ldt/templatetags/str_duration.py Wed Jan 11 16:19:38 2012 +0100 @@ -0,0 +1,46 @@ +from django.template import Library, TemplateSyntaxError + +register = Library() + +@register.filter +def str_duration(value, arg=None): + """Takes an integer value of milliseconds and write a human readable duration like 1h23, 01:23 (hours:minutes), 01:23:45 (hours:minutes:seconds), or number of seconds """ + # Error management + if value is None : + return "" + if not isinstance(value, (int,long,float,str,unicode)) : + raise TemplateSyntaxError('str_duration value error : value must be integer or long or float or string. type = ' + str(type(value))) + if isinstance(value, (str,unicode)) : + try: + value = int(value) + except : + raise TemplateSyntaxError('str_duration value error : can not convert value "' + value + '" into integer') + # We take off the milliseconds + ms = abs(value) + sec = ms//1000 + if arg is None : + arg = "::" + if arg=="::" or arg=="h" or arg==":" : + hours = sec//3600 + min = (sec - (hours * 3600))//60 + if min<10: + min_str = "0" + str(min) + else: + min_str = str(min) + if (arg=="::" or arg==":") and hours<10 : + hours_str = "0" + str(hours) + else : + hours_str = str(hours) + if arg=="h" or arg==":" : + return hours_str + arg + min_str + sec = (sec - (hours * 3600) - (min*60)) + if sec<10: + sec_str = "0" + str(sec) + else: + sec_str = str(sec) + return hours_str + ":" + min_str + ":" + sec_str + elif arg=="s" : + return sec + else : + raise TemplateSyntaxError('str_duration filter error : filters argument must be None, "::", ":", "h" or "s"') +str_duration.is_safe = True