Mercurial > public > sg101
comparison bio/management/commands/bio_image_check.py @ 1012:fc528d4509b0
Prevent mixed content in UserProfiles.
Modified sslimages to update UserProfiles.
Added another command to check/re-save UserProfiles.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Fri, 27 Nov 2015 16:56:33 -0600 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1011:164a39d985ef | 1012:fc528d4509b0 |
---|---|
1 """bio_image_check | |
2 | |
3 A management command to check profiles for non-secure images. | |
4 """ | |
5 from optparse import make_option | |
6 | |
7 from django.core.management.base import NoArgsCommand | |
8 | |
9 from bio.models import UserProfile | |
10 from core.html import image_check | |
11 from core.html import ImageCheckError | |
12 | |
13 | |
14 def _image_check(html): | |
15 try: | |
16 image_check(html) | |
17 except ImageCheckError: | |
18 return False | |
19 return True | |
20 | |
21 | |
22 class Command(NoArgsCommand): | |
23 help = "Checks user profiles for non-secure images" | |
24 option_list = NoArgsCommand.option_list + ( | |
25 make_option('--resave', | |
26 action='store_true', | |
27 dest='resave', | |
28 default=False, | |
29 help='Re-save profile if issue found'), | |
30 ) | |
31 | |
32 def handle_noargs(self, **options): | |
33 | |
34 resave = options.get('resave', False) | |
35 | |
36 count = 0 | |
37 for p in UserProfile.objects.iterator(): | |
38 issue_found = False | |
39 if p.profile_html and not _image_check(p.profile_html): | |
40 self.stdout.write("%s: profile_text\n" % p.user.username) | |
41 count += 1 | |
42 issue_found = True | |
43 if p.signature_html and not _image_check(p.signature_html): | |
44 self.stdout.write("%s: signature\n" % p.user.username) | |
45 count += 1 | |
46 issue_found = True | |
47 | |
48 if issue_found and resave: | |
49 p.save(content_update=True) | |
50 | |
51 self.stdout.write("%d problem field(s) found\n" % count) |