add autolockarticles management command
This commit is contained in:
parent
a255c92198
commit
aff4f04d5e
0
markupwiki/management/__init__.py
Normal file
0
markupwiki/management/__init__.py
Normal file
0
markupwiki/management/commands/__init__.py
Normal file
0
markupwiki/management/commands/__init__.py
Normal file
22
markupwiki/management/commands/autolockarticles.py
Normal file
22
markupwiki/management/commands/autolockarticles.py
Normal 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)
|
Loading…
Reference in New Issue
Block a user