예제 #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.")
예제 #2
0
 def delete(self, request, *args, **kwargs):
     """DELETEing here deletes a specific existing annotation.
     """
     self.object = self.get_object()
     if self.object.scamp.is_editable(request.user,
                                      request.session.get('scamp_key')):
         self.object.delete()
         return json_response(200)
     else:
         return json_response(403, message="Permission denied.")
예제 #3
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.")
예제 #4
0
 def post(self, request, *args, **kwargs):
     """POSTing to this view is used to update attributes
     on the scamp such as the title and description.
     """
     self.object = self.get_object()
     form = ScampForm(request.POST, instance=self.object)
     if self.object.is_editable(request.user,
                                request.session.get('scamp_key')):
         if form.is_valid():
             scamp = form.save()
             response = {'title': scamp.title,
                         'description': scamp.description.rendered,
                         'description_raw': scamp.description.raw,
             }
             return json_response(200, **response)
         else:
             return json_response(400, message=form.errors.as_ul())
     else:
         return json_response(403, message="Permission denied.")
예제 #5
0
 def post(self, request, *args, **kwargs):
     """Post a list of ordered annotation IDs to
     this view to get them reordered on the scamp.
     """
     self.object = self.get_object()
     if self.object.is_editable(request.user,
                                request.session.get('scamp_key')):
         new_order = request.POST.getlist('order')
         new_order = [int(x) for x in new_order]
         old_order = self.object.annotations.all().values_list('id',
                                                               flat=True)
         # Check we have the same IDs before and
         # after before we start reordering.
         if set(new_order) == set(old_order):
             for i, pk in enumerate(new_order):
                 Annotation.objects.filter(pk=pk).update(order=i+1)
             return json_response(200)
         else:
             return json_response(400,
                                  message="IDs sent for reordering do"
                                     " not match those already saved.")
     else:
         return json_response(403, message="Permission denied.")