- try:
- assert request.user.is_staff
- assert 'choose_cite' in request.GET
- cite = Cite.objects.get(pk=request.GET['choose_cite'])
- except (AssertionError, Cite.DoesNotExist):
- if book_id is not None:
- cites = Cite.objects.filter(Q(book=book_id) | Q(book__ancestor=book_id))
- elif tag_ids is not None:
- tags = Tag.objects.filter(pk__in=tag_ids)
- cites = cites_for_tags(tags)
- else:
- cites = Cite.objects.all()
- stickies = cites.filter(sticky=True)
- count = stickies.count()
+ if book_id is not None:
+ cites = Cite.objects.filter(Q(book=book_id) | Q(book__ancestor=book_id))
+ elif tag_ids is not None:
+ tags = Tag.objects.filter(pk__in=tag_ids)
+ cites = cites_for_tags(tags)
+ else:
+ cites = Cite.objects.all()
+ stickies = cites.filter(sticky=True)
+ count = stickies.count()
+ if count:
+ cite = stickies[randint(0, count - 1)]
+ else:
+ count = cites.count()