Mercurial > public > sg101
comparison gpp/forums/views/main.py @ 235:d302c498560e
Fix problem when deleting multiple topics from a forum in bulk. We getting a list of topics from the database, then deleting each topic. But after you delete a topic, the forum.last_post on the remaining non-deleted topics can be stale. This was causing a weird DoesNotExist. Now just get the topics one at a time from the database.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Thu, 26 Aug 2010 04:01:58 +0000 |
parents | a46788862737 |
children | 307a74e28112 |
comparison
equal
deleted
inserted
replaced
234:f53eb0aae7a9 | 235:d302c498560e |
---|---|
876 | 876 |
877 def _bulk_delete(forum, topic_ids): | 877 def _bulk_delete(forum, topic_ids): |
878 """ | 878 """ |
879 Deletes the list of topics. | 879 Deletes the list of topics. |
880 """ | 880 """ |
881 topics = Topic.objects.filter(pk__in=topic_ids).select_related() | 881 # Because we are deleting stuff, retrieve each topic one at a |
882 for topic in topics: | 882 # time since we are going to be adjusting de-normalized fields |
883 if topic.forum == forum: | 883 # during deletes. In particular, we can't do this: |
884 _delete_topic(topic) | 884 # topics = Topic.objects.filter(pk__in=topic_ids).select_related() |
885 # for topic in topics: | |
886 # since topic.forum.last_post can go stale after a delete. | |
887 | |
888 for id in topic_ids: | |
889 try: | |
890 topic = Topic.objects.select_related().get(pk=id) | |
891 except Topic.DoesNotExist: | |
892 continue | |
893 _delete_topic(topic) | |
885 | 894 |
886 | 895 |
887 def _bulk_move(topic_ids, old_forum, new_forum): | 896 def _bulk_move(topic_ids, old_forum, new_forum): |
888 """ | 897 """ |
889 Moves the list of topics to a new forum. | 898 Moves the list of topics to a new forum. |