@task(rate_limit='120/m')
def tidy_revision_content(pk, refresh=True):
 try:
  revision = Revision.objects.get(pk=pk)
 except Revision.DoesNotExist as exc:
  log.error('Tidy was unable to get revision id: %d. Retrying.', pk)
  tidy_revision_content.retry(countdown=(60 * 2), max_retries=5, exc=exc)
 else:
  if (revision.tidied_content and (not refresh)):
   return
  (tidied_content, errors) = tidy_content(revision.content)
  if (tidied_content != revision.tidied_content):
   Revision.objects.filter(pk=pk).update(tidied_content=tidied_content)
  return errors

@ task ( rate_limit = '120/m' ) def tidy_revision_content ( pk , refresh = True ) : try : revision = Revision . objects . get ( pk = pk ) except Revision . DoesNotExist as exc : log . error ( 'Tidy was unable to get revision id: %d. Retrying.' , pk ) tidy_revision_content . retry ( countdown = ( 60 * 2 ) , max_retries = 5 , exc = exc ) else : if ( revision . tidied_content and ( not refresh ) ) : return ( tidied_content , errors ) = tidy_content ( revision . content ) if ( tidied_content != revision . tidied_content ) : Revision . objects . filter ( pk = pk ) . update ( tidied_content = tidied_content ) return errors
run tidy over the given revisions content and save it to the tidy_content field if the content is not equal to the current value .