Example #1
0
 def put(self, request, *args, **kwargs):
     """PUTing to this view is used to create
     a specific annotation which is attached
     to the scamp at this URL.
     """
     # Due to Django's handling of PUT requests
     # we have to coerce our PUT variables via
     # the POST handling stuff first.
     coerce_put_post(request)
     self.object = self.get_object()
     form = AnnotationForm(self.object, request.PUT)
     if self.object.is_editable(request.user,
                                request.session.get('scamp_key')):
         if form.is_valid():
             annotation = form.save()
             response = {'id': annotation.id,
                         'text_raw': annotation.text.raw,
                         'text_rendered': annotation.text.rendered,
                         'edit_url': reverse('annotation_detail',
                                             args=[self.object.slug,
                                                   annotation.id])}
             return json_response(200, **response)
         else:
             return json_response(400, message=form.errors.as_ul())
     else:
         return json_response(403, message="Permission denied.")
Example #2
0
 def post(self, request, *args, **kwargs):
     """POSTing here updates a specific existing annotation.
     """
     self.object = self.get_object()
     form = AnnotationForm(self.object.scamp, request.POST,
                               instance=self.object)
     if self.object.scamp.is_editable(request.user,
                                      request.session.get('scamp_key')):
         if form.is_valid():
             annotation = form.save()
             response = {'id': annotation.id,
                         'text_rendered': annotation.text.rendered}
             return json_response(200, **response)
         else:
             return json_response(400, message=form.errors.as_ul())
     else:
         return json_response(403, message="Permission denied.")