def load_timeline(request, name, select_id, microblogging_load_type): """ Use this function to get the timeline for the given user. Referenced posts will show up in the timeline as the originals do. Hiding of the original posts for a tidy timeline should be done in the frontend due to performance resons. """ try: named_user = User.objects.filter(username=name).all()[0] except ObjectDoesNotExist: return json_error_response('Unknown user','The user "'+name+'" does not exist.') if named_user == request.user: followed = Q(author__profile__followers=request.user) else: followed = Q(author = named_user) own = Q(author = named_user) if not select_id: # Get latest posts feed = Post.objects.filter(followed | own).\ order_by('-time').prefetch_related('author', 'is_reference_to')[:20] return json_response({'loadMicrobloggingResponse':convert_response_list(feed)}) else: if microblogging_load_type == "newer": startpoint = Q(id__gt=select_id) else: # older startpoint = Q(id__lt=select_id) feed = Post.objects.filter(followed | own).\ filter(startpoint).order_by('time').prefetch_related('author', 'is_reference_to')[:20] return json_response({'loadMicrobloggingResponse':convert_response_list(reversed(feed))})
def store_microblog_post(request, path): if request.method == 'POST': if request.user.is_authenticated: create_post(request.POST['microBlogText'], request.user) return json_response({}) else: return json_error_response('Authentification reqired',"You need to be authenticated to store microblogging.") else: return json_error_response('Wrong method',"You must send a POST request to store microblogging.")
def load_microblogging(request, path, select_id, microblogging_load_type): try: node = backend.get_node_for_path(path) except backend.IllegalPath: return json_error_response('Illegal path','Illegal path: '+path) if microblogging_load_type == "newer": startpoint = Q(id__gt=select_id) else: # older startpoint = Q(id__lt=select_id) posts = node.microblogging_references.filter(startpoint).prefetch_related('author', 'is_reference_to')[:20] return json_response({'loadMicrobloggingResponse':convert_response_list(reversed(posts))})