##// END OF EJS Templates
Moved signatures block to the model block. All the signed content is in the 'content' block now. Removed edit time, previous and next posts links from the XML sync output because they can be computed from the post itself and can be changed locally for foreign posts (which breaks the signature)
Moved signatures block to the model block. All the signed content is in the 'content' block now. Removed edit time, previous and next posts links from the XML sync output because they can be computed from the post itself and can be changed locally for foreign posts (which breaks the signature)

File last commit:

r837:fbeaaa16 decentral
r838:2b96b9e7 decentral
Show More
sync.py
48 lines | 1.3 KiB | text/x-python | PythonLexer
import xml.etree.ElementTree as et
from django.http import HttpResponse, Http404
from boards.models import GlobalId, Post
def respond_pull(request):
pass
def respond_get(request):
"""
Processes a GET request with post ID list and returns the posts XML list.
Request should contain an 'xml' post attribute with the actual request XML.
"""
request_xml = request.POST['xml']
posts = []
root_tag = et.fromstring(request_xml)
model_tag = root_tag[0]
for id_tag in model_tag:
try:
global_id = GlobalId.from_xml_element(id_tag, existing=True)
posts += Post.objects.filter(global_id=global_id)
except GlobalId.DoesNotExist:
# This is normal. If we don't have such GlobalId in the system,
# just ignore this ID and proceed to the next one.
pass
response_xml = Post.objects.generate_response_get(posts)
return HttpResponse(content=response_xml)
def get_post_sync_data(request, post_id):
try:
post = Post.objects.get(id=post_id)
except Post.DoesNotExist:
raise Http404()
content = 'Global ID: %s\n\nXML: %s' \
% (post.global_id, Post.objects.generate_response_get([post]))
return HttpResponse(
content_type='text/plain',
content=content,
)