changeset 1196:e3a7e876aca7

More changes for local upload path.
author Brian Neal <bgneal@gmail.com>
date Sun, 07 May 2023 19:16:03 -0500 (19 months ago)
parents 7fc6c42b2f5b
children ba23e79438f4
files core/images/upload.py sg101/settings/base.py
diffstat 2 files changed, 16 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/core/images/upload.py	Sun May 07 16:22:13 2023 -0500
+++ b/core/images/upload.py	Sun May 07 19:16:03 2023 -0500
@@ -7,6 +7,7 @@
 import datetime
 import logging
 from io import BytesIO
+import os
 import os.path
 import shutil
 import uuid
@@ -155,29 +156,30 @@
     thumb_name = '%st%s' % (unique_name, ext)
     image_path = os.path.join(upload_dir, image_name)
     thumb_path = os.path.join(upload_dir, thumb_name)
+    perms = 0644
 
     shutil.copy(filename, image_path)
+    os.chmod(image_path, perms)
+
     if thumb:
+        thumb.seek(0)
         shutil.copyfileobj(thumb, thumb_path)
+        os.chmod(thumb_path, perms)
 
     # Generate URLs for the image and thumb.
+    image_url = _user_photo_url(image_name)
+    thumb_url = _user_photo_url(thumb_name)
+
+    return (image_url, thumb_url)
+
+
+def _user_photo_url(filename):
+    url_pattern = '%s://%s%s%s/%s'
     site = Site.objects.get_current()
 
-    url_pattern = '%s://%s%s%s/%s'
-
     image_url = url_pattern % (
             settings.SITE_SCHEME,
             site.domain,
             settings.MEDIA_URL,
             settings.USER_PHOTOS_LOCAL_UPLOAD_DIR,
-            image_name)
-
-    thumb_url = url_pattern % (
-            settings.SITE_SCHEME,
-            site.domain,
-            settings.MEDIA_URL,
-            settings.USER_PHOTOS_LOCAL_UPLOAD_DIR,
-            thumb_name)
-
-    return (image_url, thumb_url)
-
+            filename)
--- a/sg101/settings/base.py	Sun May 07 16:22:13 2023 -0500
+++ b/sg101/settings/base.py	Sun May 07 19:16:03 2023 -0500
@@ -305,6 +305,7 @@
     's3-us-west-1.amazonaws.com',
     'scontent-ord1-1.xx.fbcdn.net',
     'lh3.googleusercontent.com',
+    'surfguitar101.com',
 ]
 
 USER_PHOTOS_LOCAL_UPLOAD = False