add autolockarticles management command

This commit is contained in:
Jeremy Carbaugh 2011-04-13 14:00:49 -04:00
parent a255c92198
commit aff4f04d5e
3 changed files with 22 additions and 0 deletions

View File

View File

@ -0,0 +1,22 @@
from django.conf import settings
from django.core.management.base import BaseCommand, CommandError
from django.db.models import Min
from markupwiki.models import Article, PUBLIC, LOCKED, DELETED
import datetime
class Command(BaseCommand):
help = 'Auto-locks articles based on time and other factors'
def handle(self, *args, **options):
''' Lock any public article that was created earlier than
MARKUPWIKI_AUTOLOCK_TIMEDELTA ago.
'''
timedelta = getattr(settings, 'MARKUPWIKI_AUTOLOCK_TIMEDELTA', None)
if timedelta is not None:
ts = datetime.datetime.now() - timedelta
qs = Article.objects.filter(status=PUBLIC).annotate(
timestamp=Min('versions__timestamp')).filter(timestamp__lte=ts)
qs.update(status=LOCKED)