def handle(self, **options): if int(options.get('verbosity')) > 0: verbose = True counter = 0 buffer = set() for vote in models.Vote.objects.all(): content = (vote.content_type, vote.object_id, vote.key) if content not in buffer: if verbose: counter += 1 print(u'#%d - model %s id %s key %s' % ((counter,) + content)) models.upsert_score(content[:2], content[2], options['weight']) buffer.add(content)
def delete(self, request, vote): """ Delete the vote from the database. By default this method just do *vote.delete()* and recalculates the related score (average, total, number of votes). """ # thread safe delete try: vote.delete() except AssertionError: # maybe the object was already deleted pass else: models.upsert_score(vote.content_object, vote.key, weight=self.weight)
def handle(self, **options): if int(options.get('verbosity')) > 0: verbose = True counter = 0 buffer = set() for vote in models.Vote.objects.all(): content = (vote.content_type, vote.object_id, vote.key) if content not in buffer: if verbose: counter += 1 print u'#%d - model %s id %s key %s' % ( (counter, ) + content) models.upsert_score(content[:2], content[2], options['weight']) buffer.add(content)
def vote(self, request, vote): """ Save the vote to the database. Must return True if the *vote* was created, False otherwise. By default this method just does *vote.save()* and recalculates the related score (average, total, number of votes). """ created = not vote.id try: vote.save() except IntegrityError: # assume another thread created the vote created = False else: models.upsert_score(vote.content_object, vote.key, weight=self.weight) return created