##// END OF EJS Templates
Added GET request handler, command for key generation. Changed KeyPair format for ecdsa (use to_string instead of to_pem because it's shorter)
Added GET request handler, command for key generation. Changed KeyPair format for ecdsa (use to_string instead of to_pem because it's shorter)

File last commit:

r836:9ee107b9 decentral
r836:9ee107b9 decentral
Show More
sync.py
32 lines | 958 B | text/x-python | PythonLexer
import xml.etree.ElementTree as et
from django.http import HttpResponse
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)