Exemplo n.º 1
0
 def delete(self, request, *args, **kwargs):
     """Deletes post."""
     try:
         post = self.model.objects.get(id=kwargs["id"])
     except self.model.DoesNotExist:
         raise ErrorResponse(status.NOT_FOUND)
     key = get_key(request.GET["password"])
     if post.password == key:
         post.remove()
     elif is_mod(request, post.section_slug()):
         mod_delete_post(request, post)
         post.remove()
     else:
         raise ErrorResponse(status.FORBIDDEN, content={
             "detail": u"{0}{1}. {2}".format(
                 _("Error on deleting post #"), post.pid,
                 _("Password mismatch")
             )
         })
     return Response(status.NO_CONTENT)
Exemplo n.º 2
0
    def delete(self, request, *args, **kwargs):
        """Deletes attachment."""
        try:
            file = self.model.objects.get(**kwargs)
        except self.model.DoesNotExist:
            raise ErrorResponse(status.NOT_FOUND)

        key = get_key(request.GET["password"])
        if file.post.password == key:
            file.remove()
        elif is_mod(request, file.post.section_slug()):
            mod_delete_post(request, file.post)
            file.remove()
        else:
            raise ErrorResponse(status.FORBIDDEN, content={
                "detail": u"{}{}. {}".format(
                    _("Error on deleting file #"), file.post.pid,
                    _("Password mismatch")
                )
            })
        return Response(status.NO_CONTENT)