def quest_history(user): """ Returns quest details. """ from drawquest.apps.quests.details_models import QuestDetails if not user.is_authenticated(): return [] completed_quests = completed_quest_ids_with_timestamps(user) completed_quests = sorted(completed_quests, key=lambda q: -q['timestamp']) completed_quests = completed_quests[:knobs.QUEST_HISTORY_SIZE] ugq = Quest.objects.filter(author=user).order_by('-id').values('id', 'timestamp') ugq = list(ugq[:knobs.QUEST_HISTORY_SIZE]) dismissed_quests = user.redis.dismissed_quests.zrevrange(0, knobs.QUEST_HISTORY_SIZE, withscores=True) dismissed_quests = [{'id': int(item[0]), 'timestamp': item[1]} for item in dismissed_quests] history = completed_quests + ugq + dismissed_quests history = _dedupe_quests(history) history = sorted(history, key=lambda quest: -quest['timestamp']) history = history[:knobs.QUEST_HISTORY_SIZE] history = [quest['id'] for quest in history] return QuestDetails.from_ids(history)
def quest_inbox(user): """ Returns quest details in a tuple: current_quest, quests. current_quest may be None. """ from drawquest.apps.quests.details_models import QuestDetails if not user.is_authenticated(): return (current_quest_details(), []) current_quest = _current_quest_for_inbox(user) user_completed_quest_ids = completed_quest_ids(user) followee_quest_ids = _followee_quest_ids(user) followee_quest_ids = [id_ for id_ in followee_quest_ids if id_ not in user_completed_quest_ids] followee_quests = QuestDetails.from_ids(followee_quest_ids[:knobs.QUEST_INBOX_SIZE]) followee_quests = [(quest, quest.timestamp) for quest in followee_quests] invited_quests = user.redis.quest_invites.uncompleted_invites() invited_quests = [ (quest, ts) for quest, ts in invited_quests if ((current_quest is None or quest.id != current_quest.id) and quest.id not in followee_quest_ids) ] quests = followee_quests + invited_quests quests = [(quest, ts) for quest, ts in quests if int(quest.id) not in user_completed_quest_ids] quests = [quest for quest, ts in sorted(quests, key=lambda q: -q[1])] quests = user.redis.dismissed_quests.filter_quests(quests) quests = quests[:knobs.QUEST_INBOX_SIZE] if (current_quest is not None and (current_quest.id in user_completed_quest_ids or str(current_quest.id) in user.redis.dismissed_quests)): current_quest = None return current_quest, quests
def top_quest_details(viewer=None): return QuestDetails.from_ids(_top_quest_ids(viewer=viewer))
def top_quest_details(viewer=None): return QuestDetails.from_ids(_top_quest_ids(viewer=viewer))
def _invites(self, invited_quests): if not invited_quests: return [] ids, timestamps = zip(*invited_quests) return zip(QuestDetails.from_ids(ids), timestamps)
def _invites(self, invited_quests): if not invited_quests: return [] ids, timestamps = zip(*invited_quests) return zip(QuestDetails.from_ids(ids), timestamps)