Merge branch issue1676.
diff --git a/app/soc/logic/delete_account.py b/app/soc/logic/delete_account.py
index 789b015..0edf00c 100644
--- a/app/soc/logic/delete_account.py
+++ b/app/soc/logic/delete_account.py
@@ -27,8 +27,9 @@
from soc.models import user
from soc.modules.gci.logic import profile as profile_logic
-from soc.modules.gci.models import comment
-from soc.modules.gci.models import task
+from soc.modules.gci.models import comment as comment_model
+from soc.modules.gci.models import task as task_model
+
ADMIN_REQUEST_EMAIL_SUBJEST = """
@@ -88,16 +89,31 @@
user_delete = not (profile_logic.hasOtherGCIProfiles(profile) or
profile_logic.hasOtherGCIProfiles(profile))
- task_sub_q = task.GCITask.all().filter('subscribers', profile)
+ task_sub_q = task_model.GCITask.all().filter('subscribers', profile)
+ task_sub_remove_list = []
+ for task in task_sub_q.run():
+ task_sub_remove_list.append(task)
- tasks_created_by_q = task.GCITask.all().filter('created_by', profile)
+ tasks_created_by_q = task_model.GCITask.all().filter('created_by', profile)
+ task_created_list = []
+ for task in tasks_created_by_q.run():
+ task_created_list.append(task)
- tasks_modified_by_q = task.GCITask.all().filter('modified_by', profile)
+ tasks_modified_by_q = task_model.GCITask.all().filter('modified_by', profile)
+ task_modified_list = []
+ for task in tasks_modified_by_q.run():
+ task_modified_list.append(task)
- tasks_student_q = task.GCITask.all().filter('student', profile)
+ tasks_student_q = task_model.GCITask.all().filter('student', profile)
+ task_student_list = []
+ for task in tasks_student_q.run():
+ task_student_list.append(task)
- comments_created_by_q = comment.GCIComment.all().filter(
+ comments_created_by_q = comment_model.GCIComment.all().filter(
'created_by', profile.user)
+ comments_created_by_list = []
+ for comment in comments_created_by_q.run():
+ comments_created_by_list.append(comment)
dummy_user = user_logic.getOrCreateDummyMelangeDeletedUser()
dummy_profile = profile_logic.getOrCreateDummyMelangeDeletedProfile(
@@ -112,24 +128,28 @@
# The batch size for query.run() is 20, in most of the cases we have
# seen so far the user had a few tasks with subscriptions, created_by,
# modified_by etc., so this should still be single datastore hits per
- # loop.
- for task in task_sub_q.run():
+ # loop. Also, by running the query outside the transaction we may run
+ # into situations of user subscribing to the task or creating or modifying
+ # tasks or performing another activity after this batch fetch. However,
+ # the chances of that happening is very low and can be traded-off for
+ # the bigger problem of half run transactions.
+ for task in task_sub_remove_list:
task.subscribers.remove(profile_key)
entities_to_save.add(task)
- for task in tasks_created_by_q.run():
+ for task in task_created_list:
task.created_by = dummy_profile
entities_to_save.add(task)
- for task in tasks_modified_by_q.run():
+ for task in task_modified_list:
task.modified_by = dummy_profile
entities_to_save.add(task)
- for task in tasks_student_q.run():
+ for task in task_student_list:
task.student = dummy_profile
entities_to_save.add(task)
- for comment in comments_created_by_q.run():
+ for comment in comments_created_by_list:
comment.created_by = dummy_user
entities_to_save.add(comment)
diff --git a/app/soc/modules/gci/logic/profile.py b/app/soc/modules/gci/logic/profile.py
index bd779bc..5da9f6b 100644
--- a/app/soc/modules/gci/logic/profile.py
+++ b/app/soc/modules/gci/logic/profile.py
@@ -49,7 +49,7 @@
MELANGE_DELETED_USER_PHONE = '0000000000'
-MELANGE_DELETED_USER_BIRTH_DATE = datetime.datetime(1, 1, 1)
+MELANGE_DELETED_USER_BIRTH_DATE = datetime.date(1, 1, 1)
def hasStudentFormsUploaded(student):
diff --git a/app/soc/modules/gci/views/moderate_delete_account.py b/app/soc/modules/gci/views/moderate_delete_account.py
index c8932ab..0f5da88 100644
--- a/app/soc/modules/gci/views/moderate_delete_account.py
+++ b/app/soc/modules/gci/views/moderate_delete_account.py
@@ -56,5 +56,7 @@
}
def post(self):
+ link_id = self.data.url_profile.link_id
delete_account.confirm_delete(self.data.url_profile)
- self.redirect.program().to('gci_moderate_delete_account', validated=True)
+ self.redirect.profile(link_id).to(
+ 'gci_moderate_delete_account', validated=True)