def delete_joke(request, pk): user = request.user.groups.filter(name='Moderator') if user: joke = Joke.objects.get(pk=pk) joke.hidden = timezone.now() joke.save() logger.info('Joke %s removed.', joke.key) api_remove_joke(joke.key) return HttpResponse(status=200) else: return HttpResponse('User not authorised to remove joke', status=401)
def duplicate_joke(request, pk, key): user = request.user.groups.filter(name='Moderator') if user: joke = Joke.objects.get(pk=pk) original = Joke.objects.get(key=key) joke.duplicate = original joke.save() logger.info('Joke %s marked as duplicate of %s.', joke.key, original.key) api_remove_joke(joke.key) return HttpResponse(status=200) else: return HttpResponse('User not authorised to mark joke as duplicated', status=401)