upload_file_url

Brightcells 8 jaren geleden
bovenliggende
commit
c98fa4a4ed
2 gewijzigde bestanden met toevoegingen van 10 en 5 verwijderingen
  1. 4 3
      operation/models.py
  2. 6 2
      utils/url_utils.py

+ 4 - 3
operation/models.py

@@ -8,6 +8,7 @@ from django.utils.translation import ugettext_lazy as _
8 8
 from TimeConvert import TimeConvert as tc
9 9
 
10 10
 from pai2.basemodels import CreateUpdateMixin, PlatformMixin, VersionMixin
11
+from utils.url_utils import upload_file_url
11 12
 
12 13
 
13 14
 def upload_path(instance, old_filename):
@@ -49,7 +50,7 @@ class LatestAppInfo(CreateUpdateMixin):
49 50
 
50 51
     @property
51 52
     def final_latest_adr_url(self):
52
-        return self.latest_adr_url or u'{}{}'.format(settings.DOMAIN, self.latest_adr_app and self.latest_adr_app.url)
53
+        return self.latest_adr_url or upload_file_url(self.latest_adr_app)
53 54
 
54 55
     @property
55 56
     def data(self):
@@ -88,7 +89,7 @@ class PatchInfo(CreateUpdateMixin, PlatformMixin):
88 89
 
89 90
     @property
90 91
     def patch_url(self):
91
-        return u'{}{}'.format(settings.DOMAIN, self.patch and self.patch.url)
92
+        return upload_file_url(self.patch)
92 93
 
93 94
     @property
94 95
     def data(self):
@@ -142,7 +143,7 @@ class SplashInfo(CreateUpdateMixin):
142 143
 
143 144
     @property
144 145
     def splash_image_url(self):
145
-        return self.splash_image and (settings.DOMAIN + self.splash_image.url)
146
+        return upload_file_url(self.splash_image)
146 147
 
147 148
     @property
148 149
     def data(self):

+ 6 - 2
utils/url_utils.py

@@ -4,8 +4,12 @@ from django.conf import settings
4 4
 
5 5
 
6 6
 def img_url(img_path):
7
-    return u'{}/{}'.format(settings.IMG_DOMAIN, img_path) if img_path else ''
7
+    return '{}/{}'.format(settings.IMG_DOMAIN, img_path) if img_path else ''
8 8
 
9 9
 
10 10
 def share_url(photo_id):
11
-    return u'{}/gp/{}'.format(settings.DOMAIN, photo_id) if photo_id else ''
11
+    return '{}/gp/{}'.format(settings.DOMAIN, photo_id) if photo_id else ''
12
+
13
+
14
+def upload_file_url(file_path):
15
+    return file_path and ('{}{}'.format(settings.DOMAIN, file_path))