def to_form_data(self): return to_json(self, ( ('blog', 'blog__form'), 'title', 'text', 'type', 'addition', 'raw_tags', ))
def change_action(request, post_id): post = get_object_or_404(Post, id=post_id) try: obj = model.objects.get( user=request.user, post=post, ) obj.delete() except model.DoesNotExist: model.objects.create( user=request.user, post=post, ) return to_json(post)
def rate_fnc(request, id, value): """Rate function""" value = +1 if value else -1 obj = get_object_or_404(cls, id=id) if request.get_profile.check_access(permission): if action(obj, request.user, value): return to_json(obj) else: return { 'error': _(u'Rating allowed once a time') } else: return { 'error': _(u'Permission denied'), }
def post_options(request, post_id, disable_rate, disable_reply, pinch): """Change post options""" post = get_object_or_404(Post, id=post_id) form = PostOptions({ 'disable_rate': disable_rate, 'disable_reply': disable_reply, 'pinch': pinch, }, instance=post) if form.is_valid(): post = form.save() return to_json(post) else: return { 'error': form.errors, }
def user__json(self): return to_json(self.user)
def author__json(self): return to_json(self.authr)
def post__json(self): return to_json(self.post)
def blog__json(self): return to_json(self.blog)