示例#1
0
def content_fetch_view(request, objtype, guid):
    """Diaspora content fetch view.

    Returns the signed payload for the public content. Non-public content will return 404.

    If the content is not local, redirect to content author server.

    Args:
        objtype (str) - Diaspora content type. Currently if it is `status_message`, `post` or `reshare`,
            we try to find `Content`.
        guid (str) - The object guid to look for.
    """
    if objtype not in ["status_message", "post", "reshare", "comment"]:
        raise Http404()
    content = get_object_or_404(Content,
                                guid=guid,
                                visibility=Visibility.PUBLIC)
    if not content.local:
        url = "https://%s/fetch/%s/%s" % (content.author.handle.split("@")[1],
                                          objtype, guid)
        return HttpResponseRedirect(url)
    entity = make_federable_content(content)
    message = get_full_xml_representation(entity, content.author.private_key)
    document = MagicEnvelope(message=message,
                             private_key=content.author.private_key,
                             author_handle=content.author.handle)
    return HttpResponse(document.render(),
                        content_type="application/magic-envelope+xml")
示例#2
0
 def test_returns_xml_document(self):
     entity = Post()
     document = get_full_xml_representation(entity, "")
     document = re.sub(r"<created_at>.*</created_at>", "", document)  # Dates are annoying to compare
     assert document == "<XML><post><status_message><text></text><guid></guid>" \
                        "<author></author><public>false</public>" \
                        "<provider_display_name></provider_display_name></status_message></post></XML>"
示例#3
0
 def test_returns_xml_document(self):
     entity = Post()
     document = get_full_xml_representation(entity)
     document = re.sub(r"<created_at>.*</created_at>", "", document)  # Dates are annoying to compare
     assert document == "<XML><post><status_message><raw_message></raw_message><guid></guid>" \
                        "<diaspora_handle></diaspora_handle><public>false</public>" \
                        "<provider_display_name></provider_display_name></status_message></post></XML>"
示例#4
0
def content_xml_view(request, uuid):
    """Diaspora single post view XML representation.

    Fetched by remote servers in certain situations.
    """
    content = get_object_or_404(Content, uuid=uuid, visibility=Visibility.PUBLIC, local=True)
    entity = make_federable_content(content)
    xml = get_full_xml_representation(entity, content.author.private_key)
    return HttpResponse(xml, content_type="application/xml")