Skip to content

Commit

Permalink
codeclimate
Browse files Browse the repository at this point in the history
  • Loading branch information
fopina committed Dec 7, 2018
1 parent e380107 commit 61e0072
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions simple_history/management/commands/clean_duplicate_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ def handle(self, *args, **options):
except NotHistoricalModelError:
continue
to_process.add((model, history_model))
if not to_process and self.verbosity >= 1:
self.stdout.write(self.NO_REGISTERED_MODELS)
if not to_process:
self.log(self.NO_REGISTERED_MODELS)

elif self.verbosity >= 1:
self.stdout.write(self.COMMAND_HINT)
else:
self.log(self.COMMAND_HINT)

self._process(to_process, date_back=options["minutes"], dry_run=options["dry"])

Expand All @@ -68,8 +68,7 @@ def _process(self, to_process, date_back=None, dry_run=True):
if stop_date:
m_qs = m_qs.filter(history_date__gte=stop_date)
found = m_qs.count()
if self.verbosity >= 2:
self.stdout.write("{0} has {1} historical entries".format(model, found))
self.log("{0} has {1} historical entries".format(model, found), 2)
if not found:
continue

Expand Down Expand Up @@ -100,10 +99,14 @@ def _process_instance(self, instance, model, stop_date=None, dry_run=True):
f1 = f2
if extra_one:
entries_deleted += self._check_and_delete(f1, extra_one, dry_run)
if self.verbosity >= 1:
self.stdout.write(
self.DONE_CLEANING_FOR_MODEL.format(model=model, count=entries_deleted)
)

self.log(
self.DONE_CLEANING_FOR_MODEL.format(model=model, count=entries_deleted)
)

def log(self, message, verbosity_level=1):
if self.verbosity >= verbosity_level:
self.stdout.write(message)

def _check_and_delete(self, entry1, entry2, dry_run=True):
delta = entry1.diff_against(entry2)
Expand Down

0 comments on commit 61e0072

Please sign in to comment.