Permalink
Browse files

Added duplicate detection/deletion to clean_occurrences command.

  • Loading branch information...
1 parent aaa4cd8 commit 6de88481b1ea2bbee79d0d3b4d060178840cfcb3 @Aramgutang Aramgutang committed Mar 6, 2012
Showing with 24 additions and 0 deletions.
  1. +24 −0 eventtools/management/commands/clean_occurrences.py
@@ -68,3 +68,27 @@ def handle_label(self, arg, **options):
occurrence.end = occurrence.end.replace(
*occurrence.start.timetuple()[:3])
Model.save(occurrence)
+ # Check for duplicates
+ deleted_pks = []
+ duplicates = 0
+ for occurrence in generator.occurrences.all():
+ if not generator.exceptions \
+ or not generator.exceptions.has_key(
+ occurrence.start.isoformat()) \
+ and not occurrence.pk in deleted_pks:
+ possible_duplicates = generator.occurrences.filter(
+ start=occurrence.start, end=occurrence.end).exclude(
+ pk=occurrence.pk)
+ if possible_duplicates:
+ for duplicate in possible_duplicates:
+ if not generator.exceptions \
+ or not generator.exceptions.has_key(
+ duplicate.start.isoformat()):
+ duplicates += 1
+ deleted_pks += [duplicate.pk]
+ if not dry_run:
+ duplicate.generator = None
+ duplicate.delete()
+ if verbosity and duplicates:
+ print 'Generator "%s" has %s duplicate occurrences.' % (
+ generator, duplicates)

0 comments on commit 6de8848

Please sign in to comment.