diff options
author | Étienne Loks <etienne.loks@peacefrogs.net> | 2013-10-24 17:49:36 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@peacefrogs.net> | 2013-10-24 17:49:36 +0200 |
commit | fe1f68b1bff3908f87436d36532499677de07bcc (patch) | |
tree | 9c39d88874ecfe33792081ebecf01341c27b2ba8 /misc | |
parent | d7c0dc768721cb5174b3f62acdc960ad85b333a9 (diff) | |
download | Ishtar-fe1f68b1bff3908f87436d36532499677de07bcc.tar.bz2 Ishtar-fe1f68b1bff3908f87436d36532499677de07bcc.zip |
Scrip to fix duplicate in history
Diffstat (limited to 'misc')
-rw-r--r-- | misc/history_duplicate_clean.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/misc/history_duplicate_clean.py b/misc/history_duplicate_clean.py new file mode 100644 index 000000000..61d358720 --- /dev/null +++ b/misc/history_duplicate_clean.py @@ -0,0 +1,31 @@ +""" +Clean duplicate in history. +This should be unecessary now. +""" + +import datetime +from archaeological_operations.models import Operation, AdministrativeAct +from archaeological_files.models import File +from archaeological_context_records.models import ContextRecord +from archaeological_finds.models import Find, BaseFind, Treatment + +nb_deleted = {} +to_delete = [] +for model in [Operation, File, ContextRecord, AdministrativeAct, Find, + BaseFind, Treatment]: + nb_deleted[model.__name__] = 0 + for item in model.objects.all()[0:]: + c_user, c_date = None, None + for h in item.history.order_by('-history_modifier_id', '-history_date', + '-history_id').all(): + if c_user and c_date and h.history_modifier_id == c_user and \ + c_date - h.history_date < datetime.timedelta(seconds=5): + to_delete.append(h) + c_user = h.history_modifier_id + c_date = h.history_date + nb_deleted[model.__name__] += len(to_delete) + +for item in to_delete: + item.delete() +for m in nb_deleted: + print "* %d deleted for %s" % (nb_deleted[m], m) |