updatethreadranking.py 801 B

123456789101112131415161718
  1. from django.core.management.base import BaseCommand
  2. from django.db.models import F
  3. from misago.dbsettings import DBSettings
  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. settings = DBSettings()
  12. if settings['thread_ranking_inflation'] > 0:
  13. inflation = float(100 - settings['thread_ranking_inflation']) / 100
  14. Thread.objects.all().update(score=F('score') * inflation)
  15. self.stdout.write('Thread ranking has been updated.\n')
  16. else:
  17. self.stdout.write('Thread ranking inflation is disabled.\n')