def delete(self, survey_id, action = 'self'): if current_user.is_authenticated(): try: s_id = HashId.decode(survey_id) svey = Survey.objects(id = s_id).first() if svey is None: raise TypeError if svey.hidden: raise APIException("This Survey has already been deleted", 404) except TypeError: raise APIException("Invalid Survey ID", 404) if action == 'self': svey.hidden = True svey.save() ret = { 'id': str(svey), 'field': action, 'saved': True, } return ret, 200 elif action == 'img': args = self.post_args() dat = args['swag'] try: im_id = HashId.decode(dat) img = AttachmentImage.objects(id = im_id).first() if img is None: raise TypeError if img.hidden: raise APIException("This Image has already been deleted", 404) img.hidden = True svey.attachments.remove(img) img.save() svey.save() ret = { 'id': str(svey), 'img_id': str(img), 'field': action, 'saved': True, } return ret, 200 except (TypeError, ValueError): raise APIException("Invalid Image ID", 404) else: raise APIException("Login Required", 401)