예제 #1
0
파일: models.py 프로젝트: eiritana/canvas
 def get_by_short_id(cls, short_id):
     try:
         mapping_id = get_mapping_id_from_short_id(short_id)
     except ValueError:
         raise Http404
     comment = get_object_or_404(Comment.published, id=mapping_id)
     return cls.get_from_comment(comment)
예제 #2
0
 def get_by_short_id(cls, short_id):
     try:
         mapping_id = get_mapping_id_from_short_id(short_id)
     except ValueError:
         raise Http404
     quest = get_object_or_404(Quest.published, id=mapping_id)
     return cls.get_from_quest(quest)
예제 #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)
예제 #4
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)
예제 #5
0
 def get_by_short_id(cls, short_id):
     try:
         mapping_id = get_mapping_id_from_short_id(short_id)
     except ValueError:
         raise Http404
     quest = get_object_or_404(Quest.published, id=mapping_id)
     return cls.get_from_quest(quest)
예제 #6
0
 def get_by_short_id(cls, short_id):
     try:
         mapping_id = get_mapping_id_from_short_id(short_id)
     except ValueError:
         raise Http404
     comment = get_object_or_404(Comment.published, id=mapping_id)
     return cls.get_from_comment(comment)
예제 #7
0
파일: views.py 프로젝트: eiritana/canvas
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)
예제 #8
0
def playback(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 = comment.quest.details()

    playback_data = get_playback_data(comment)

    ctx = {
        'comment': comment_details,
        'quest': quest_details,
        'playback_data': playback_data,
    }

    return r2r_jinja('playback/playback.html', ctx, request)
    def __init__(self, request, short_id, page=None, gotoreply=None):
        try:
            mapping_id = get_mapping_id_from_short_id(short_id)
        except ValueError:
            raise Http404

        self.request = request
        self.short_id = short_id
        self.page = page
        try:
            self.gotoreply = int(gotoreply)
        except TypeError:
            self.gotoreply = None

        _op_comment = get_object_or_404(Comment.published, id=mapping_id)

        # Get relevant OP data.
        _op_content = _op_comment.reply_content
        op_content = _op_content.details() if _op_content else None

        op_comment = _op_comment.details
        op_category = _op_comment.category.details() if _op_comment.category else Category.ALL.details()

        linked_comment = op_comment
        _linked_comment = _op_comment

        reply_ids = list(_op_comment.get_replies().values_list('id', flat=True))

        # Remove user-hidden comments.
        reply_ids = remove_hidden_comment_ids(request.user, reply_ids)

        # Pagination.
        explicit_page_view = bool(page)
        num_replies = len(reply_ids)
        if gotoreply is not None:
            gotoreply = int(gotoreply)
            try:
                page = page_divide(reply_ids.index(gotoreply)+1, knobs.COMMENTS_PER_PAGE)
                # If going to a reply on the last page, show 'current'.
                if reply_ids.index(gotoreply) + 1 >= num_replies - knobs.COMMENTS_PER_PAGE:
                    page = 'current'
            except ValueError:
                page = '1'

            # Grab the gotoreply's content for metadata
            _linked_comment = Comment.objects.get_or_none(id=gotoreply)
            if _linked_comment:
                linked_comment = _linked_comment.details
        elif page is None:
            page = '1'

        self.page_reply_ids, self.page_current, self.page_next, self.page_last = paginate(
                reply_ids, page=page, per_page=knobs.COMMENTS_PER_PAGE)
        self.page_penultimate = self.page_last - 1
        # Make it easy for Django to do a for loop on the page numbers.
        pages = xrange(1, self.page_last + 1)

        self.op_comment     = op_comment
        self._op_comment    = _op_comment
        self.op_content     = op_content
        self._op_content    = _op_content
        self.op_category    = op_category
        self.linked_comment = linked_comment
        self._linked_comment = _linked_comment
        self.page           = page
        self.pages          = pages
        self.per_page       = knobs.COMMENTS_PER_PAGE
        self.num_replies    = num_replies
        self.reply_ids      = reply_ids
        self.explicit_page_view = explicit_page_view
        self.is_author = request.user == _op_comment.author