Mercurial > public > sg101
diff core/management/commands/ssl_images.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 | 65b2bc9cb3cc |
children |
line wrap: on
line diff
--- a/core/management/commands/ssl_images.py Fri Nov 27 15:45:05 2015 -0600 +++ b/core/management/commands/ssl_images.py Fri Nov 27 16:56:33 2015 -0600 @@ -25,6 +25,7 @@ from PIL import Image import requests +from bio.models import UserProfile from comments.models import Comment from forums.models import Post from core.download import download_file @@ -43,7 +44,7 @@ SG101_HOSTS = set(['www.surfguitar101.com', 'surfguitar101.com']) WHITELIST_HOSTS = set(settings.USER_IMAGES_SOURCES) -MODEL_CHOICES = ['comments', 'posts', 'news'] +MODEL_CHOICES = ['comments', 'posts', 'news', 'profiles'] PHOTO_MAX_SIZE = (660, 720) PHOTO_BASE_URL = settings.HOT_LINK_PHOTOS_BASE_URL @@ -328,6 +329,7 @@ if options['model'] not in MODEL_CHOICES: raise CommandError('Please choose a --model option') + save_kwargs = {} if options['model'] == 'comments': qs = Comment.objects.all() text_attrs = ['comment'] @@ -336,6 +338,11 @@ qs = Post.objects.all() text_attrs = ['body'] model_name = 'Post' + elif options['model'] == 'profiles': + qs = UserProfile.objects.all() + text_attrs = ['profile_text', 'signature'] + model_name = 'UserProfile' + save_kwargs = {'content_update': True} else: qs = Story.objects.all() text_attrs = ['short_text', 'long_text'] @@ -403,7 +410,7 @@ logger.debug(u"changed: %s", new_txt) setattr(model, text_attr, new_txt) save_flag = True - elif not html_based and html_check(model.html): + elif not html_based and hasattr(model, 'html') and html_check(model.html): # Check for content generated with older smiley code that used # absolute URLs for the smiley images. If True, then just save # the model again to force updated HTML to be created. @@ -411,7 +418,7 @@ save_flag = True if save_flag: - model.save() + model.save(**save_kwargs) count += 1 time_finished = datetime.datetime.now()