##// END OF EJS Templates
Don't show the Hide/Show option if it won't work
Don't show the Hide/Show option if it won't work

File last commit:

r1846:3bc31272 default
r2114:1012c538 opera_mini_fix
Show More
sync.py
83 lines | 2.1 KiB | text/x-python | PythonLexer
neko259
Added ability to filter posts in the LIST request
r1834 import logging
neko259
Added GET request handler, command for key generation. Changed KeyPair format for ecdsa (use to_string instead of to_pem because it's shorter)
r836 import xml.etree.ElementTree as et
neko259
Download attached filed to the post during sync
r1511
neko259
Added signatures to the GET response. Added a view to get a full post response for one post. Don't show post key as it is present in the XML post view. Changed key display format
r837 from django.http import HttpResponse, Http404
neko259
Added ability to filter posts in the LIST request
r1834
neko259
Allow filtering sync by tags
r1844 from boards.abstracts.sync_filters import ThreadFilter, TagsFilter,\
neko259
Allow syncing posts from timestamp
r1846 TimestampFromFilter,\
TAG_THREAD, TAG_TAGS, TAG_TIME_FROM
neko259
Added GET request handler, command for key generation. Changed KeyPair format for ecdsa (use to_string instead of to_pem because it's shorter)
r836 from boards.models import GlobalId, Post
neko259
Updated sync method for requesting and getting a post
r1177 from boards.models.post.sync import SyncManager
neko259
Added GET request handler, command for key generation. Changed KeyPair format for ecdsa (use to_string instead of to_pem because it's shorter)
r836
neko259
Added ability to filter posts in the LIST request
r1834 logger = logging.getLogger('boards.sync')
FILTERS = {
TAG_THREAD: ThreadFilter,
neko259
Allow filtering sync by tags
r1844 TAG_TAGS: TagsFilter,
neko259
Allow syncing posts from timestamp
r1846 TAG_TIME_FROM: TimestampFromFilter,
neko259
Added ability to filter posts in the LIST request
r1834 }
neko259
Rename "pull" request to "list"
r1566 def response_list(request):
neko259
Added PULL protocol method implementation without any filters
r1321 request_xml = request.body
neko259
Added ability to filter posts in the LIST request
r1834 filters = []
neko259
Rename "pull" request to "list"
r1566 if request_xml is None or len(request_xml) == 0:
neko259
Added PULL protocol method implementation without any filters
r1321 return HttpResponse(content='Use the API')
neko259
Added ability to filter posts in the LIST request
r1834 else:
root_tag = et.fromstring(request_xml)
model_tag = root_tag[0]
neko259
Added PULL protocol method implementation without any filters
r1321
neko259
Added ability to filter posts in the LIST request
r1834 for tag_filter in model_tag:
filter_name = tag_filter.tag
neko259
Allow filtering sync by tags
r1844 model_filter = FILTERS.get(filter_name)
neko259
Added ability to filter posts in the LIST request
r1834 if not model_filter:
logger.warning('Unavailable filter: {}'.format(filter_name))
neko259
Allow filtering sync by tags
r1844 filters.append(model_filter(tag_filter))
neko259
Added ability to filter posts in the LIST request
r1834
response_xml = SyncManager.generate_response_list(filters)
neko259
Added PULL protocol method implementation without any filters
r1321
return HttpResponse(content=response_xml)
neko259
Added a generator for the 'get' request for sync
r810
neko259
Updated sync method for requesting and getting a post
r1177 def response_get(request):
neko259
Added GET request handler, command for key generation. Changed KeyPair format for ecdsa (use to_string instead of to_pem because it's shorter)
r836 """
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.
"""
neko259
Updated sync method for requesting and getting a post
r1177 request_xml = request.body
neko259
Rename "pull" request to "list"
r1566 if request_xml is None or len(request_xml) == 0:
neko259
Updated sync method for requesting and getting a post
r1177 return HttpResponse(content='Use the API')
neko259
Added GET request handler, command for key generation. Changed KeyPair format for ecdsa (use to_string instead of to_pem because it's shorter)
r836
posts = []
root_tag = et.fromstring(request_xml)
model_tag = root_tag[0]
for id_tag in model_tag:
neko259
Refactored code for getting existing and new global ids
r1233 global_id, exists = GlobalId.from_xml_element(id_tag)
if exists:
neko259
Updated sync method for requesting and getting a post
r1177 posts.append(Post.objects.get(global_id=global_id))
neko259
Added GET request handler, command for key generation. Changed KeyPair format for ecdsa (use to_string instead of to_pem because it's shorter)
r836
neko259
Made SyncManager's methods static
r1236 response_xml = SyncManager.generate_response_get(posts)
neko259
Added GET request handler, command for key generation. Changed KeyPair format for ecdsa (use to_string instead of to_pem because it's shorter)
r836
neko259
Added signatures to the GET response. Added a view to get a full post response for one post. Don't show post key as it is present in the XML post view. Changed key display format
r837 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()
neko259
Download attached filed to the post during sync
r1511 xml_str = SyncManager.generate_response_get([post])
neko259
Added signatures to the GET response. Added a view to get a full post response for one post. Don't show post key as it is present in the XML post view. Changed key display format
r837
return HttpResponse(
neko259
Show only XML in raw post preview, browsers let user navigate it better
r1574 content_type='text/xml; charset=utf-8',
content=xml_str,
)