annotate bio/management/commands/bio_image_check.py @ 1127:829d3b7fc0f7

Convert search page to V3 design.
author Brian Neal <bgneal@gmail.com>
date Tue, 13 Sep 2016 21:49:22 -0500
parents fc528d4509b0
children
rev   line source
bgneal@1012 1 """bio_image_check
bgneal@1012 2
bgneal@1012 3 A management command to check profiles for non-secure images.
bgneal@1012 4 """
bgneal@1012 5 from optparse import make_option
bgneal@1012 6
bgneal@1012 7 from django.core.management.base import NoArgsCommand
bgneal@1012 8
bgneal@1012 9 from bio.models import UserProfile
bgneal@1012 10 from core.html import image_check
bgneal@1012 11 from core.html import ImageCheckError
bgneal@1012 12
bgneal@1012 13
bgneal@1012 14 def _image_check(html):
bgneal@1012 15 try:
bgneal@1012 16 image_check(html)
bgneal@1012 17 except ImageCheckError:
bgneal@1012 18 return False
bgneal@1012 19 return True
bgneal@1012 20
bgneal@1012 21
bgneal@1012 22 class Command(NoArgsCommand):
bgneal@1012 23 help = "Checks user profiles for non-secure images"
bgneal@1012 24 option_list = NoArgsCommand.option_list + (
bgneal@1012 25 make_option('--resave',
bgneal@1012 26 action='store_true',
bgneal@1012 27 dest='resave',
bgneal@1012 28 default=False,
bgneal@1012 29 help='Re-save profile if issue found'),
bgneal@1012 30 )
bgneal@1012 31
bgneal@1012 32 def handle_noargs(self, **options):
bgneal@1012 33
bgneal@1012 34 resave = options.get('resave', False)
bgneal@1012 35
bgneal@1012 36 count = 0
bgneal@1012 37 for p in UserProfile.objects.iterator():
bgneal@1012 38 issue_found = False
bgneal@1012 39 if p.profile_html and not _image_check(p.profile_html):
bgneal@1012 40 self.stdout.write("%s: profile_text\n" % p.user.username)
bgneal@1012 41 count += 1
bgneal@1012 42 issue_found = True
bgneal@1012 43 if p.signature_html and not _image_check(p.signature_html):
bgneal@1012 44 self.stdout.write("%s: signature\n" % p.user.username)
bgneal@1012 45 count += 1
bgneal@1012 46 issue_found = True
bgneal@1012 47
bgneal@1012 48 if issue_found and resave:
bgneal@1012 49 p.save(content_update=True)
bgneal@1012 50
bgneal@1012 51 self.stdout.write("%d problem field(s) found\n" % count)