Example #1
0
def share_page(request, short_id):
    try:
        comment_id = get_mapping_id_from_short_id(short_id)
    except ValueError:
        raise Http404

    comment = get_object_or_404(QuestComment, id=comment_id)
    comment_details = comment.details()

    quest_details = QuestDetails.from_id(comment_details.quest_id)

    author_details = UserDetails.from_id(comment.author_id)

    ctx = {
        "quest": quest_details,
        "quest_template_url": "",
        "comment": comment_details,
        "author": author_details,
        "private_profile": bool(UserKV(comment.author_id).web_profile_privacy.get()),
    }

    if quest_details.content:
        ctx.update(
            {
                "quest_template_url": quest_details.content.get_absolute_url_for_image_type("gallery"),
                "original_quest_template_url": quest_details.content.get_absolute_url_for_image_type("original"),
            }
        )

    return r2r_jinja("quest_comments/share_comment_page.html", ctx, request)
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)
Example #3
0
def share_page(request, short_id):
    try:
        comment_id = get_mapping_id_from_short_id(short_id)
    except ValueError:
        raise Http404

    comment = get_object_or_404(QuestComment, id=comment_id)
    comment_details = comment.details()

    quest_details = QuestDetails.from_id(comment_details.quest_id)

    author_details = UserDetails.from_id(comment.author_id)

    ctx = {
        'quest':
        quest_details,
        'quest_template_url':
        '',
        'comment':
        comment_details,
        'author':
        author_details,
        'private_profile':
        bool(UserKV(comment.author_id).web_profile_privacy.get()),
    }

    if quest_details.content:
        ctx.update({
            'quest_template_url':
            quest_details.content.get_absolute_url_for_image_type('gallery'),
            'original_quest_template_url':
            quest_details.content.get_absolute_url_for_image_type('original'),
        })

    return r2r_jinja('quest_comments/share_comment_page.html', ctx, request)
Example #4
0
def quest_comment(request, comment_id):
    comment = QuestCommentDetails.from_id(comment_id)
    quest = QuestDetails.from_id(comment.quest_id)

    if request.user.is_authenticated():
        comment.user.viewer_is_following = comment.user.id in request.user.following_ids()

    add_viewer_has_starred_field([comment], viewer=request.user)

    return {
        'comment': comment,
        'quest': quest,
    }
def share_comment_by_email(comment, sender, recipients):
    from drawquest.apps.quests.details_models import QuestDetails

    quest_details = QuestDetails.from_id(comment.parent_comment_id)
    template_url = ""

    if quest_details.content:
        template_url = quest_details.content.gallery["url"]

    return _share_by_email(
        sender,
        recipients,
        _("Someone shared a drawing with you on DrawQuest!"),
        "comment_share",
        {"comment": comment.details(), "quest": quest_details, "quest_template_url": template_url},
    )
def share_comment_by_email(comment, sender, recipients):
    from drawquest.apps.quests.details_models import QuestDetails

    quest_details = QuestDetails.from_id(comment.parent_comment_id)
    template_url = ''

    if quest_details.content:
        template_url = quest_details.content.gallery['url']

    return _share_by_email(
        sender, recipients,
        _('Someone shared a drawing with you on DrawQuest!'), 'comment_share',
        {
            'comment': comment.details(),
            'quest': quest_details,
            'quest_template_url': template_url,
        })
Example #7
0
def share_page(request, short_id):
    try:
        comment_id = get_mapping_id_from_short_id(short_id)
    except ValueError:
        raise Http404

    comment = get_object_or_404(QuestComment, id=comment_id)
    comment_details = comment.details()

    quest_details = QuestDetails.from_id(comment_details.quest_id)

    author_details = UserDetails.from_id(comment.author_id)

    return r2r_jinja('quest_comments/share_page.html', {
        'quest': quest_details,
        'comment': comment_details,
        'author': author_details,
    }, request)
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
Example #9
0
def top_quest_details(viewer=None):
    return QuestDetails.from_ids(_top_quest_ids(viewer=viewer))
Example #10
0
def top_quest_details(viewer=None):
    return QuestDetails.from_ids(_top_quest_ids(viewer=viewer))
Example #11
0
    def _invites(self, invited_quests):
        if not invited_quests:
            return []

        ids, timestamps = zip(*invited_quests)
        return zip(QuestDetails.from_ids(ids), timestamps)
def get_share_page_url(comment_details):
    if getattr(comment_details, 'ugq', False) or isinstance(comment_details, QuestDetails):
        obj = QuestDetails.from_id(comment_details.id)
    else:
        obj = QuestCommentDetails.from_id(comment_details.id)
    return obj.share_page_url
Example #13
0
    def _invites(self, invited_quests):
        if not invited_quests:
            return []

        ids, timestamps = zip(*invited_quests)
        return zip(QuestDetails.from_ids(ids), timestamps)