コード例 #1
0
ファイル: alpha.py プロジェクト: jvimedia/alpha
    def populate_context(self, request, username=None, post_id=None, photo_id=None, *args, **kwargs):
        super(PauPhotoView, self).populate_context(request, *args, **kwargs)

        try:
            post_id = int(post_id)
            photo_id = int(photo_id)
        except:
            raise Http404()

        post_api_obj = bridge.get_post(request, post_id)
        if not verify_post(username, post_api_obj):
            raise Http404()

        photo_annotations = get_photo_annotations(post_api_obj.get('annotations', []))
        num_photos = len(photo_annotations)
        # N.B. photo_id is 1-based
        if photo_id < 1 or photo_id > num_photos:
            raise Http404()

        photo_annotation = photo_annotations[photo_id - 1]
        value = photo_annotation['value']
        width = value['width']
        height = value['height']
        url = value.get('url_secure', value['url'])

        next_photo_url = None
        prev_photo_url = None
        if photo_id > 1:
            prev_photo_url = smart_reverse(request, 'photo', args=[username, post_id, photo_id - 1])
        if photo_id < num_photos:
            next_photo_url = smart_reverse(request, 'photo', args=[username, post_id, photo_id + 1])

        post_presenter = PhotoPostPresenter.from_item(request, post_api_obj)
        self.view_ctx['page_title'] = u'App.net | %s photo: %s' % (post_api_obj.user.username, truncate(post_api_obj.get('text', ''), 50))
        self.view_ctx['page_description'] = truncate(post_api_obj.get('text', self.view_ctx['page_title']), 100)

        self.view_ctx.update_ctx({
            'image_url': url,
            'image_width': width,
            'image_height': height,
            'next_photo_url': next_photo_url,
            'prev_photo_url': prev_photo_url,
            'post_presenter': post_presenter,
            'post_url': smart_reverse(request, 'post_detail_view', args=[username, post_id]),
            'post_api_obj': post_api_obj,
            'oembed_url': oembed_url(request.build_absolute_uri()),
            '__js_page_load_hooks': ['photo.init']
        })
コード例 #2
0
ファイル: alpha.py プロジェクト: AYCHUB/AYCHBlogging.micro
    def populate_context(self,
                         request,
                         username=None,
                         post_id=None,
                         photo_id=None,
                         *args,
                         **kwargs):
        super(PauPhotoView, self).populate_context(request, *args, **kwargs)

        try:
            post_id = int(post_id)
            photo_id = int(photo_id)
        except:
            raise Http404()

        post_api_obj = bridge.get_post(request, post_id)
        if not verify_post(username, post_api_obj):
            raise Http404()

        photo_annotations = get_photo_annotations(
            post_api_obj.get('annotations', []))
        num_photos = len(photo_annotations)
        # N.B. photo_id is 1-based
        if photo_id < 1 or photo_id > num_photos:
            raise Http404()

        photo_annotation = photo_annotations[photo_id - 1]
        value = photo_annotation['value']
        width = value['width']
        height = value['height']
        url = value.get('url_secure', value['url'])

        next_photo_url = None
        prev_photo_url = None
        if photo_id > 1:
            prev_photo_url = smart_reverse(
                request, 'photo', args=[username, post_id, photo_id - 1])
        if photo_id < num_photos:
            next_photo_url = smart_reverse(
                request, 'photo', args=[username, post_id, photo_id + 1])

        post_presenter = PhotoPostPresenter.from_item(request, post_api_obj)
        self.view_ctx['page_title'] = u'App.net | %s photo: %s' % (
            post_api_obj.user.username,
            truncate(post_api_obj.get('text', ''), 50))
        self.view_ctx['page_description'] = truncate(
            post_api_obj.get('text', self.view_ctx['page_title']), 100)

        self.view_ctx.update_ctx({
            'image_url':
            url,
            'image_width':
            width,
            'image_height':
            height,
            'next_photo_url':
            next_photo_url,
            'prev_photo_url':
            prev_photo_url,
            'post_presenter':
            post_presenter,
            'post_url':
            smart_reverse(request,
                          'post_detail_view',
                          args=[username, post_id]),
            'post_api_obj':
            post_api_obj,
            'oembed_url':
            oembed_url(request.build_absolute_uri()),
            '__js_page_load_hooks': ['photo.init']
        })
コード例 #3
0
ファイル: alpha.py プロジェクト: jvimedia/alpha
    def populate_context(self, request, *args, **kwargs):
        super(PauPostDetailView, self).populate_context(request, *args, **kwargs)
        post_id = kwargs.get('post_id')
        before_post_objs, target_post_api_obj, after_post_objs = bridge.get_conversation(request, post_id)

        if target_post_api_obj.user and kwargs.get('username') != target_post_api_obj.user.username:
            new_url = smart_reverse(request, 'post_detail_view', kwargs={'username': target_post_api_obj.user.username,
                                    'post_id': str(target_post_api_obj.id)})
            self.view_ctx.response = HttpResponsePermanentRedirect(new_url)
            return

        if target_post_api_obj.get('is_deleted') and target_post_api_obj.get('repost_of'):
            # Deleted reposts should actually go away, so this can 404. If a user got deleted, their reposts may be ghosts
            # instead of being deleted correctly
            raise Http404()

        if all((target_post_api_obj.get('is_deleted'), (target_post_api_obj.get('reply_to') is None),
                (target_post_api_obj.get('num_replies') == 0))):
            # render normally but 404 status code
            self.view_ctx.status_code = 404

        original_post = target_post_api_obj.get('repost_of')
        if original_post:
            # This is the post detail of a repost post, all activity should be redirected to the
            # original post.
            new_url = smart_reverse(request, 'post_detail_view', kwargs={'username': original_post.user.username,
                                    'post_id': str(original_post.id)})
            self.view_ctx.response = HttpResponsePermanentRedirect(new_url)
            return

        owner = target_post_api_obj.user
        owner_id = owner['id'] if owner else None
        viewer_is_author = request.user.is_authenticated() and owner_id == request.user.adn_user.id

        if owner:
            name = target_post_api_obj.user.get('name') or target_post_api_obj.user.username
            self.view_ctx['page_title'] = u'%s: %s on App.net' % (name, truncate(target_post_api_obj.get('text', ''), 50))
            self.view_ctx['post_create_pre_text'] = u'@%s ' % (target_post_api_obj['user']['username']) if not viewer_is_author else ''
            self.view_ctx['page_description'] = u'%s' % (truncate(target_post_api_obj.get('text', ''), 100))
        else:
            # user of root post was deleted
            self.view_ctx['page_title'] = u'App.net'
            self.view_ctx['post_create_pre_text'] = ''
            self.view_ctx['page_description'] = u'This App.net post has been deleted'

        self.view_ctx['oembed_url'] = oembed_url(request.build_absolute_uri())
        self.view_ctx['post_a'] = target_post_api_obj
        self.view_ctx['main_post_inner'] = ChooseFeedPostPresenter.from_item(request, target_post_api_obj, show_deleted=True, single_post=True, in_conversation=True)
        self.view_ctx['before_post_presenters'] = [
            ChooseFeedPostPresenter.from_item(request, post_api_obj, show_deleted=True, in_conversation=True) for post_api_obj in before_post_objs
        ]
        self.view_ctx['after_post_presenters'] = [
            ChooseFeedPostPresenter.from_item(request, post_api_obj, show_deleted=True, in_conversation=True) for post_api_obj in after_post_objs
        ]
        self.view_ctx['num_stars'] = target_post_api_obj.num_stars
        self.view_ctx['num_reposts'] = target_post_api_obj.num_reposts
        self.view_ctx['star_facepile_presenter'] = StarFacepilePresenter.from_data(request, target_post_api_obj)
        self.view_ctx['owner'] = owner
        self.view_ctx['num_replies'] = target_post_api_obj['num_replies']
        self.view_ctx['__js_refresh_on_post_create'] = '1'
        self.view_ctx['__js_permit_attachments'] = True
        if before_post_objs:
            self.view_ctx['__js_post_id'] = post_id
        self.view_ctx['__js_page_load_hooks'] += ['init_follow', 'zoom_to_post', 'post_create.init_post_file_uploader']
        if request.user.is_authenticated():
            self.view_ctx['__js_page_load_hooks'] += ['post_create.init', ]
            self.view_ctx['__js_viewer_username'] = request.user.username

        self.view_ctx['post_box_presenter'] = PostCreatePresenter.from_data(request, btn_action='Reply', reply_to=target_post_api_obj)
コード例 #4
0
ファイル: alpha.py プロジェクト: AYCHUB/AYCHBlogging.micro
    def populate_context(self, request, *args, **kwargs):
        super(PauPostDetailView,
              self).populate_context(request, *args, **kwargs)
        post_id = kwargs.get('post_id')
        before_post_objs, target_post_api_obj, after_post_objs = bridge.get_conversation(
            request, post_id)

        if target_post_api_obj.user and kwargs.get(
                'username') != target_post_api_obj.user.username:
            new_url = smart_reverse(request,
                                    'post_detail_view',
                                    kwargs={
                                        'username':
                                        target_post_api_obj.user.username,
                                        'post_id': str(target_post_api_obj.id)
                                    })
            self.view_ctx.response = HttpResponsePermanentRedirect(new_url)
            return

        if target_post_api_obj.get('is_deleted') and target_post_api_obj.get(
                'repost_of'):
            # Deleted reposts should actually go away, so this can 404. If a user got deleted, their reposts may be ghosts
            # instead of being deleted correctly
            raise Http404()

        if all((target_post_api_obj.get('is_deleted'),
                (target_post_api_obj.get('reply_to') is None),
                (target_post_api_obj.get('num_replies') == 0))):
            # render normally but 404 status code
            self.view_ctx.status_code = 404

        original_post = target_post_api_obj.get('repost_of')
        if original_post:
            # This is the post detail of a repost post, all activity should be redirected to the
            # original post.
            new_url = smart_reverse(request,
                                    'post_detail_view',
                                    kwargs={
                                        'username':
                                        original_post.user.username,
                                        'post_id': str(original_post.id)
                                    })
            self.view_ctx.response = HttpResponsePermanentRedirect(new_url)
            return

        owner = target_post_api_obj.user
        owner_id = owner['id'] if owner else None
        viewer_is_author = request.user.is_authenticated(
        ) and owner_id == request.user.adn_user.id

        if owner:
            name = target_post_api_obj.user.get(
                'name') or target_post_api_obj.user.username
            self.view_ctx['page_title'] = u'%s: %s on App.net' % (
                name, truncate(target_post_api_obj.get('text', ''), 50))
            self.view_ctx['post_create_pre_text'] = u'@%s ' % (
                target_post_api_obj['user']['username']
            ) if not viewer_is_author else ''
            self.view_ctx['page_description'] = u'%s' % (truncate(
                target_post_api_obj.get('text', ''), 100))
        else:
            # user of root post was deleted
            self.view_ctx['page_title'] = u'App.net'
            self.view_ctx['post_create_pre_text'] = ''
            self.view_ctx[
                'page_description'] = u'This App.net post has been deleted'

        self.view_ctx['oembed_url'] = oembed_url(request.build_absolute_uri())
        self.view_ctx['post_a'] = target_post_api_obj
        self.view_ctx['main_post_inner'] = ChooseFeedPostPresenter.from_item(
            request,
            target_post_api_obj,
            show_deleted=True,
            single_post=True,
            in_conversation=True)
        self.view_ctx['before_post_presenters'] = [
            ChooseFeedPostPresenter.from_item(request,
                                              post_api_obj,
                                              show_deleted=True,
                                              in_conversation=True)
            for post_api_obj in before_post_objs
        ]
        self.view_ctx['after_post_presenters'] = [
            ChooseFeedPostPresenter.from_item(request,
                                              post_api_obj,
                                              show_deleted=True,
                                              in_conversation=True)
            for post_api_obj in after_post_objs
        ]
        self.view_ctx['num_stars'] = target_post_api_obj.num_stars
        self.view_ctx['num_reposts'] = target_post_api_obj.num_reposts
        self.view_ctx[
            'star_facepile_presenter'] = StarFacepilePresenter.from_data(
                request, target_post_api_obj)
        self.view_ctx['owner'] = owner
        self.view_ctx['num_replies'] = target_post_api_obj['num_replies']
        self.view_ctx['__js_refresh_on_post_create'] = '1'
        self.view_ctx['__js_permit_attachments'] = True
        if before_post_objs:
            self.view_ctx['__js_post_id'] = post_id
        self.view_ctx['__js_page_load_hooks'] += [
            'init_follow', 'zoom_to_post',
            'post_create.init_post_file_uploader'
        ]
        if request.user.is_authenticated():
            self.view_ctx['__js_page_load_hooks'] += [
                'post_create.init',
            ]
            self.view_ctx['__js_viewer_username'] = request.user.username

        self.view_ctx['post_box_presenter'] = PostCreatePresenter.from_data(
            request, btn_action='Reply', reply_to=target_post_api_obj)