Skip to content

Commit cbe6544

Browse files
authored
Merge pull request #19 from farridav/hotfix/image_uploads_cdn_assets
Hotfix/image uploads cdn assets
2 parents 10793b7 + ab4a471 commit cbe6544

File tree

4 files changed

+14
-21
lines changed

4 files changed

+14
-21
lines changed

adminlteui/admin.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from django.contrib import admin
55
from django.contrib import messages
66
from django.contrib.admin import widgets
7+
from django.core.files.storage import default_storage
78
from django.urls import path, reverse
89
from django.template.response import TemplateResponse
910
from django.utils import timezone
@@ -29,9 +30,7 @@ def get_option(option_name):
2930

3031
def handle_uploaded_file(f, file_name):
3132
# save site_logo
32-
with open(settings.MEDIA_ROOT + '/' + file_name, 'wb+') as destination:
33-
for chunk in f.chunks():
34-
destination.write(chunk)
33+
return default_storage.save(file_name, f)
3534

3635

3736
class ImageBox:
@@ -109,11 +108,8 @@ def save(self):
109108
if not self.files.get(data_item) or self.data.get(
110109
data_item) == '':
111110
continue
112-
handle_uploaded_file(self.files.get(data_item),
113-
self.files.get(data_item).name)
114-
obj.option_value = settings.MEDIA_URL.lstrip(
115-
'/') + self.files.get(
116-
data_item).name
111+
filename = handle_uploaded_file(self.files.get(data_item), self.files.get(data_item).name)
112+
obj.option_value = settings.MEDIA_URL + filename
117113
else:
118114
if obj.option_value == self.data.get(data_item):
119115
continue
@@ -124,13 +120,10 @@ def save(self):
124120
self.errors[data_item] = _(
125121
'site_logo depends on setting.MEDIA_URL and setting.MEDIA_ROOT.')
126122
return False
127-
handle_uploaded_file(self.files.get(data_item),
128-
self.files.get(data_item).name)
123+
filename = handle_uploaded_file(self.files.get(data_item), self.files.get(data_item).name)
129124
obj = Options.objects.create(
130125
option_name=data_item,
131-
option_value=settings.MEDIA_URL.lstrip(
132-
'/') + self.files.get(
133-
data_item).name,
126+
option_value=settings.MEDIA_URL + filename,
134127
create_time=timezone.now())
135128
else:
136129
obj = Options.objects.create(

adminlteui/templates/admin/base.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
<!-- Tell the browser to be responsive to screen width -->
1313
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
1414
<!-- Bootstrap 3.3.6 -->
15-
<link rel="stylesheet" href={% static "admin/bootstrap/css/bootstrap.min.css" %}>
15+
<link rel="stylesheet" href="//stackpath.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
1616
<!-- Font Awesome -->
1717
<!--<link rel="stylesheet" href="//cdn.bootcss.com/font-awesome/4.5.0/css/font-awesome.min.css">-->
18-
<link rel="stylesheet" href={% static "admin/font-awesome/css/font-awesome.min.css" %}>
18+
<link rel="stylesheet" href="//stackpath.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
1919
<!-- Ionicons -->
2020
<link rel="stylesheet" href={% static "admin/ionicons/ionicons.min.css" %}>
2121

@@ -34,8 +34,8 @@
3434

3535
<link rel="stylesheet" href={% static "admin/dist/css/django.css" %}>
3636
{% if adminlte_site_logo.valid %}
37-
<link rel="apple-touch-icon" href="/{{ adminlte_site_logo.site_logo }}">
38-
<link rel="icon" href="/{{ adminlte_site_logo.site_logo }}">
37+
<link rel="apple-touch-icon" href="{{ adminlte_site_logo.site_logo }}">
38+
<link rel="icon" href="{{ adminlte_site_logo.site_logo }}">
3939
{% else %}
4040
<link rel="apple-touch-icon" href="{% static "admin/dist/img/default-log.svg" %}">
4141
<link rel="icon" href="{% static "admin/dist/img/default-log.svg" %}">
@@ -58,15 +58,15 @@
5858
<!-- mini logo for sidebar mini 50x50 pixels -->
5959
<span class="logo-mini">
6060
{% if adminlte_site_logo.valid %}
61-
<img src="/{{ adminlte_site_logo.site_logo }}" class="user-image" alt="User Image" style="width:45px;height:45px;padding:5px;">
61+
<img src="{{ adminlte_site_logo.site_logo }}" class="user-image" alt="User Image" style="width:45px;height:45px;padding:5px;">
6262
{% else %}
6363
<img src={% static "admin/dist/img/default-log.svg" %} class="user-image" alt="User Image" style="width:45px;height:45px;padding:5px;">
6464
{% endif %}
6565
</span>
6666
<!-- logo for regular state and mobile devices -->
6767
<span class="logo-lg">
6868
{% if adminlte_site_logo.valid %}
69-
<img src="/{{ adminlte_site_logo.site_logo }}" class="user-image" alt="User Image" style="width:45px;height:45px;padding:5px;">
69+
<img src="{{ adminlte_site_logo.site_logo }}" class="user-image" alt="User Image" style="width:45px;height:45px;padding:5px;">
7070
{% else %}
7171
<img src={% static "admin/dist/img/default-log.svg" %} class="user-image" alt="User Image" style="width:45px;height:45px;padding:5px;">
7272
{% endif %}

adminlteui/templates/admin/login.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<!-- Tell the browser to be responsive to screen width -->
1818
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
1919
<!-- Bootstrap 3.3.6 -->
20-
<link rel="stylesheet" href={% static "admin/bootstrap/css/bootstrap.min.css" %}>
20+
<link rel="stylesheet" href="//stackpath.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
2121
<!-- Font Awesome -->
2222
<link rel="stylesheet" href="//cdn.bootcss.com/font-awesome/4.5.0/css/font-awesome.min.css">
2323
<!-- Ionicons -->

adminlteui/templates/registration/logged_out.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<!-- Tell the browser to be responsive to screen width -->
1818
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
1919
<!-- Bootstrap 3.3.6 -->
20-
<link rel="stylesheet" href={% static "admin/bootstrap/css/bootstrap.min.css" %}>
20+
<link rel="stylesheet" href="//stackpath.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
2121
<!-- Font Awesome -->
2222
<link rel="stylesheet" href="//cdn.bootcss.com/font-awesome/4.5.0/css/font-awesome.min.css">
2323
<!-- Ionicons -->

0 commit comments

Comments
 (0)