Beispiel #1
0
    def populate_context(self, request, *args, **kwargs):
        super(PauStreamBaseView,
              self).populate_context(request, *args, **kwargs)
        self.populate_stream_context(request, *args, **kwargs)
        self.view_ctx['__js_page_load_hooks'] += [
            'init_stream', 'post_create.init_post_file_uploader'
        ]
        if request.user.is_authenticated():
            self.view_ctx['__js_viewer_username'] = request.user.username
        self.view_ctx['infinite_scroll'] = True
        post_create_pre_text = self.post_create_pre_text + ' ' if self.post_create_pre_text else ''
        if self.stream_marker_view:
            self.view_ctx['__js_stream_marker_name'] = self.stream_marker_name

        self.view_ctx['__js_permit_attachments'] = True
        self.view_ctx['show_new_post_box'] = self.show_new_post_box
        self.view_ctx['post_box_presenter'] = PostCreatePresenter.from_data(
            request, post_create_pre_text=post_create_pre_text)
        self.view_ctx[
            '__js_additional_stream_view_params'] = self.view_ctx.get(
                '__js_additional_stream_view_params', {})
        for arg in ('post_presenter', 'max_width', 'max_height'):
            arg_value = request.GET.get(arg)
            if arg_value:
                self.view_ctx['__js_additional_stream_view_params'][
                    arg] = arg_value
Beispiel #2
0
    def populate_context(self, request, *args, **kwargs):
        super(PauStreamBaseView, self).populate_context(request, *args, **kwargs)
        self.populate_stream_context(request, *args, **kwargs)
        self.view_ctx['__js_page_load_hooks'] += ['init_stream', 'post_create.init_post_file_uploader']
        if request.user.is_authenticated():
            self.view_ctx['__js_viewer_username'] = request.user.username
        self.view_ctx['infinite_scroll'] = True
        post_create_pre_text = self.post_create_pre_text + ' ' if self.post_create_pre_text else ''
        if self.stream_marker_view:
            self.view_ctx['__js_stream_marker_name'] = self.stream_marker_name

        self.view_ctx['__js_permit_attachments'] = True
        self.view_ctx['show_new_post_box'] = self.show_new_post_box
        self.view_ctx['post_box_presenter'] = PostCreatePresenter.from_data(request, post_create_pre_text=post_create_pre_text)
        self.view_ctx['__js_additional_stream_view_params'] = self.view_ctx.get('__js_additional_stream_view_params', {})
        for arg in ('post_presenter', 'max_width', 'max_height'):
            arg_value = request.GET.get(arg)
            if arg_value:
                self.view_ctx['__js_additional_stream_view_params'][arg] = arg_value
Beispiel #3
0
    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)
Beispiel #4
0
    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)