@cronjobs.register
def fix_current_revisions():
 try:
  pin_this_thread()
  docs = Document.objects.all()
  for d in docs:
   revs = Revision.objects.filter(document=d, is_approved=True)
   revs = list(revs.order_by('-reviewed')[:1])
   if len(revs):
    rev = revs[0]
    if (d.current_revision != rev):
     d.current_revision = rev
     d.save()
     print d.get_absolute_url()
     statsd.incr('wiki.cron.fix-current-revision')
 finally:
  unpin_this_thread()

@ cronjobs . register def fix_current_revisions ( ) : try : pin_this_thread ( ) docs = Document . objects . all ( ) for d in docs : revs = Revision . objects . filter ( document = d , is_approved = True ) revs = list ( revs . order_by ( '-reviewed' ) [ : 1 ] ) if len ( revs ) : rev = revs [ 0 ] if ( d . current_revision != rev ) : d . current_revision = rev d . save ( ) print d . get_absolute_url ( ) statsd . incr ( 'wiki.cron.fix-current-revision' ) finally : unpin_this_thread ( )
fixes documents that have the current_revision set incorrectly .