# HG changeset patch # User verrierj # Date 1328267394 -3600 # Node ID 20e7bb9d2d14c0863df288f52f18fa2c1e144c1b # Parent 10284a1810fecc7f538126cd3789a7688484d18d Fix bug when adding first annotation diff -r 10284a1810fe -r 20e7bb9d2d14 src/ldt/ldt/ldt_utils/models.py --- a/src/ldt/ldt/ldt_utils/models.py Fri Feb 03 11:50:52 2012 +0100 +++ b/src/ldt/ldt/ldt_utils/models.py Fri Feb 03 12:09:54 2012 +0100 @@ -226,7 +226,7 @@ if not self.nb_annotation: self.nb_annotation = 0 if not self.stat_annotation: - self.stat_annotation = self.__list2str([0] * (settings.DIVISIONS_FOR_STAT_ANNOTATION + len(settings.SYNTAX.keys()))) + self.__get_empty_stat() super(Content, self).save(*args, **kwargs) @@ -405,7 +405,7 @@ def __make_getter(self, i): def inner_getter(self): if not self.stat_annotation: - self.stat_annotation = self.__list2str([0] * (settings.DIVISIONS_FOR_STAT_ANNOTATION + len(settings.SYNTAX.keys()))) + self.__get_empty_stat() l = self.__str2list(self.stat_annotation) return l[Content.__pol_indices[i]] return inner_getter @@ -413,7 +413,7 @@ def __make_setter(self, i): def inner_setter(self, value): if not self.stat_annotation: - self.stat_annotation = self.__list2str([0] * (settings.DIVISIONS_FOR_STAT_ANNOTATION + len(settings.SYNTAX.keys()))) + self.__get_empty_stat() l = self.__str2list(self.stat_annotation) l[Content.__pol_indices[i]] = value self.stat_annotation = self.__list2str(l) @@ -431,14 +431,21 @@ def __str2list(self, s): return [int(x) for x in s.split(',')] + + def __get_empty_stat(self): + self.stat_annotation = self.__list2str([0] * (settings.DIVISIONS_FOR_STAT_ANNOTATION + len(settings.SYNTAX.keys()))) def annotation_volume(): #@NoSelf def fget(self): + if not self.stat_annotation: + self.__get_empty_stat() l = self.__str2list(self.stat_annotation) return l[Content.__pol_indices['annotation_volume_begin']:Content.__pol_indices['annotation_volume_end']] def fset(self, value): # value is a list + if not self.stat_annotation: + self.__get_empty_stat() l = self.__str2list(self.stat_annotation) l[Content.__pol_indices['annotation_volume_begin']:Content.__pol_indices['annotation_volume_end']] = value self.stat_annotation = self.__list2str(l) diff -r 10284a1810fe -r 20e7bb9d2d14 src/ldt/ldt/ldt_utils/stat.py --- a/src/ldt/ldt/ldt_utils/stat.py Fri Feb 03 11:50:52 2012 +0100 +++ b/src/ldt/ldt/ldt_utils/stat.py Fri Feb 03 12:09:54 2012 +0100 @@ -52,13 +52,12 @@ return True - def add_annotation_to_stat(content, begin, end): nb_division = settings.DIVISIONS_FOR_STAT_ANNOTATION if not content.nb_annotation or not content.stat_annotation: content.nb_annotation = 1 - content.stat_annotation = get_empty_stat_vector() + content.stat_annotation = get_empty_stat_field() size_division = content.duration / nb_division limits = [x * size_division for x in range(nb_division+1)]