updatethreadranking.py 754 B

1234567891011121314151617
  1. from django.core.management.base import BaseCommand
  2. from django.db.models import F
  3. from misago.conf import settings
  4. from misago.models import Thread
  5. class Command(BaseCommand):
  6. """
  7. This command is intended to work as CRON job fired every few days to update thread popularity ranking
  8. """
  9. help = 'Updates Popular Threads ranking'
  10. def handle(self, *args, **options):
  11. if settings.thread_ranking_inflation > 0:
  12. inflation = float(100 - settings.thread_ranking_inflation) / 100
  13. Thread.objects.all().update(score=F('score') * inflation)
  14. self.stdout.write('Thread ranking has been updated.\n')
  15. else:
  16. self.stdout.write('Thread ranking inflation is disabled.\n')