Exemplo n.º 1
0
    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']
        })
Exemplo n.º 2
0
def attachment(request, username, post_id, attachment_id):
    try:
        post_id = int(post_id)
        attachment_id = int(attachment_id)
    except:
        raise Http404()

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

    # get list of net.app.core.file_lists, flatten them
    attachments_lists = get_attachment_annotations(post.get('annotations'))
    attachments = [item for al in attachments_lists for item in al['value']['net.app.core.file_list']]
    if attachment_id < 1 or attachment_id > len(attachments):
        raise Http404()

    url = attachments[attachment_id - 1]['url']

    return HttpResponseRedirect(url)
Exemplo n.º 3
0
def attachment(request, username, post_id, attachment_id):
    try:
        post_id = int(post_id)
        attachment_id = int(attachment_id)
    except:
        raise Http404()

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

    # get list of net.app.core.file_lists, flatten them
    attachments_lists = get_attachment_annotations(post.get('annotations'))
    attachments = [
        item for al in attachments_lists
        for item in al['value']['net.app.core.file_list']
    ]
    if attachment_id < 1 or attachment_id > len(attachments):
        raise Http404()

    url = attachments[attachment_id - 1]['url']

    return HttpResponseRedirect(url)
Exemplo n.º 4
0
    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']
        })