+
+
+ def refresh_tag_counter(self):
+ tags = {}
+ for child in self.children.all().order_by():
+ for tag_pk, value in child.tag_counter.iteritems():
+ tags[tag_pk] = tags.get(tag_pk, 0) + value
+ for tag in self.tags.exclude(category__in=('book', 'theme', 'set')).order_by():
+ tags[tag.pk] = 1
+ self.set__tag_counter_value(tags)
+ self.save(reset_short_html=False, refresh_mp3=False)
+ return tags
+
+ @property
+ def tag_counter(self):
+ if self._tag_counter == '':
+ return self.refresh_tag_counter()
+ return dict((int(k), v) for k, v in self.get__tag_counter_value().iteritems())
+ #return self.get__tag_counter_value()
+
+ def refresh_theme_counter(self):
+ tags = {}
+ for fragment in Fragment.tagged.with_any([self.book_tag()]).order_by():
+ for tag in fragment.tags.filter(category='theme').order_by():
+ tags[tag.pk] = tags.get(tag.pk, 0) + 1
+ self.set__theme_counter_value(tags)
+ self.save(reset_short_html=False, refresh_mp3=False)
+ return tags
+
+ @property
+ def theme_counter(self):
+ if self._theme_counter == '':
+ return self.refresh_theme_counter()
+ return dict((int(k), v) for k, v in self.get__theme_counter_value().iteritems())
+ return self.get__theme_counter_value()
+