def delete(self, request, pk=None): profile = self.get_user(request, pk) allow_delete_user(request.user, profile) if request.method == 'POST': with transaction.atomic(): profile.lock() if request.data.get('with_content'): profile.delete_content() else: categories_to_sync = set() threads = profile.thread_set.select_related('category', 'first_post') for thread in threads.filter(is_hidden=False).iterator(): categories_to_sync.add(thread.category_id) hide_thread(request, thread) posts = profile.post_set.select_related( 'category', 'thread', 'thread__category' ) for post in posts.filter(is_hidden=False).iterator(): categories_to_sync.add(post.category_id) hide_post(request.user, post) post.thread.synchronize() post.thread.save() categories = Category.objects.filter(id__in=categories_to_sync) for category in categories.iterator(): category.synchronize() category.save() profile.delete() return Response({'detail': 'ok'})
def delete(self, request, pk=None): profile = self.get_user(request, pk) allow_delete_user(request.user, profile) if request.method == 'POST': with transaction.atomic(): profile.lock() if request.data.get('with_content'): profile.delete_content() else: categories_to_sync = set() threads = profile.thread_set.select_related('category', 'first_post') for thread in threads.filter(is_hidden=False).iterator(): categories_to_sync.add(thread.category_id) hide_thread(request, thread) posts = profile.post_set.select_related( 'category', 'thread', 'thread__category' ) for post in posts.filter(is_hidden=False).iterator(): categories_to_sync.add(post.category_id) hide_post(request.user, post) post.thread.synchronize() post.thread.save() categories = Category.objects.filter(id__in=categories_to_sync) for category in categories.iterator(): category.synchronize() category.save() profile.delete() return Response({})