diff --git a/markupwiki/management/__init__.py b/markupwiki/management/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/markupwiki/management/commands/__init__.py b/markupwiki/management/commands/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/markupwiki/management/commands/autolockarticles.py b/markupwiki/management/commands/autolockarticles.py new file mode 100644 index 0000000..c17a352 --- /dev/null +++ b/markupwiki/management/commands/autolockarticles.py @@ -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)