def get_interviewees(self, user): " Get interviews that the current user can answer in behalf of. " if not user.is_authenticated() or not self.can_reply(): interviewees = [] else: if user.has_perm('interviews.add_answer'): interviewees = get_cached_list(Interviewee, interview__pk=self.pk) else: interviewees = get_cached_list(Interviewee, interview__pk=self.pk, user=user) return interviewees
def render(self, context): from django.utils.safestring import mark_safe from ella.core.cache import get_cached_list from ella.core.models import HitCount, Placement try: tct = template.Variable(self.target_ct).resolve(context) oid = template.Variable(self.target_id).resolve(context) # TODO: this improve speed but it's dirty #if not tct in [16,28,29,55,32]: # return '' hl = get_cached_list( Placement, target_ct=tct, target_id=oid ) l = '' for h in hl: hit_count = HitCount.objects.get(placement=h) if not hit_count: continue l += '<li><a href="../../../core/hitcount/%d/" class="viewsitelink">Hits: %d</a></li>' \ % (hit_count._get_pk_val(), hit_count.hits) return mark_safe(l) except (HitCount.DoesNotExist, template.VariableDoesNotExist): return ''
def content(self): """Returns first item from ArticleContents linked to current article""" if not hasattr(self, '_contents'): self._contents = get_cached_list(ArticleContents, article=self) if self._contents: return self._contents[0] else: return None
def main_placement(self): " Return object's main placement, that is the object's placement in its primary category " if hasattr(self, '_main_placement'): return self._main_placement current_site = Site.objects.get_current() # TODO: what if have got multiple listings on one site? placements = get_cached_list( Placement, publishable=self.pk, category__site=current_site, ) if placements: if len(placements) == 1: self._main_placement = placements[0] else: # with multiple listings, one with first publish_from # primary first_published = None for placement in placements: if first_published is None or placement.publish_from < first_published.publish_from: first_published = placement assert first_published is not None self._main_placement = first_published else: try: # TODO - check and if we don't have category, take the only placement that exists in current site self._main_placement = get_cached_object( Placement, publishable=self.pk, category=self.category_id ) except Placement.DoesNotExist: self._main_placement = None if self._main_placement: # preserve memory and SQL queries by using the same object self._main_placement.publishable = self return self._main_placement
def main_placement(self): " Return object's main placement, that is the object's placement in its primary category " if hasattr(self, '_main_placement'): return self._main_placement current_site = Site.objects.get_current() # TODO: what if have got multiple listings on one site? placements = get_cached_list( Placement, publishable=self.pk, category__site=current_site, ) if placements: if len(placements) == 1: self._main_placement = placements[0] else: # with multiple listings, one with first publish_from # primary first_published = None for placement in placements: if first_published is None or placement.publish_from < first_published.publish_from: first_published = placement assert first_published is not None self._main_placement = first_published else: try: # TODO - check and if we don't have category, take the only placement that exists in current site self._main_placement = get_cached_object( Placement, publishable=self.pk, category=self.category_id) except Placement.DoesNotExist: self._main_placement = None if self._main_placement: # preserve memory and SQL queries by using the same object self._main_placement.publishable = self return self._main_placement
def render(self, context): from django.utils.safestring import mark_safe from ella.core.cache import get_cached_list from ella.core.models import HitCount, Placement try: oid = template.Variable(self.target_id).resolve(context) # TODO: this improve speed but it's dirty #if not tct in [16,28,29,55,32]: # return '' hl = get_cached_list(Placement, publishable=oid) l = '' for h in hl: hit_count = HitCount.objects.get(placement=h) if not hit_count: continue l += '<li><a href="../../../core/hitcount/%d/" class="viewsitelink">Hits: %d</a></li>' \ % (hit_count._get_pk_val(), hit_count.hits) # return mark_safe(l) return mark_safe(u'<!-- here is hidden hitcount button: %s -->' % l) except (HitCount.DoesNotExist, template.VariableDoesNotExist): return ''
def total(self): """ Returns count of displayed quiz results """ res = get_cached_list(Result, quiz=self.quiz) return sum(r.count for r in res)
def questions(self): return get_cached_list(Question, quiz=self)
def questions(self): return get_cached_list(Question, contest=self)
def answers(self): return get_cached_list(Answer, question__pk=self.pk)