Skip to content

Commit

Permalink
Merge c8fa33b into 453bc30
Browse files Browse the repository at this point in the history
  • Loading branch information
chessbr committed Feb 17, 2021
2 parents 453bc30 + c8fa33b commit c75ff3a
Show file tree
Hide file tree
Showing 15 changed files with 37 additions and 21 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

List all changes after the last release here (newer on top). Each change on a separate bullet point line

### Fixed

- Do not rely on STATIC_URL and MEDIA_URL while formatting static and media urls

## [2.3.14] - 2021-02-04

- Front: add template cache to basket partial
Expand Down
3 changes: 2 additions & 1 deletion shuup/admin/browser_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# This source code is licensed under the OSL-3.0 license found in the
# LICENSE file in the root directory of this source tree.
from django.conf import settings
from django.templatetags.static import static

from shuup.admin.utils.permissions import has_permission
from shuup.utils.i18n import get_current_babel_locale
Expand Down Expand Up @@ -49,5 +50,5 @@ def get_gettings(cls, request, **kwargs):
"timeInputFormat": settings.SHUUP_ADMIN_TIME_INPUT_FORMAT,
"datetimeInputStep": settings.SHUUP_ADMIN_DATETIME_INPUT_STEP,
"dateInputLocale": get_current_babel_locale().language,
"staticPrefix": settings.STATIC_URL,
"staticPrefix": static(""),
}
2 changes: 1 addition & 1 deletion shuup/admin/modules/products/views/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def get_primary_image(self, instance):
if instance.product.primary_image:
thumbnail = instance.product.primary_image.get_thumbnail()
if thumbnail:
return "<img src='{}{}'>".format(settings.MEDIA_URL, thumbnail)
return "<img src='{}'>".format(thumbnail.url)
return "<img src='%s'>" % static("shuup_admin/img/no_image_thumbnail.png")

def get_queryset(self):
Expand Down
2 changes: 1 addition & 1 deletion shuup/admin/utils/picotable.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ def get_display_value(self, context, object):

def check_different_types(self, value):
if isinstance(value, ProductMedia):
return "<img src='/media/%s'>" % value.get_thumbnail()
return "<img src='%s'>" % value.get_thumbnail().url

if isinstance(value, Image):
thumbnailer = get_thumbnailer(value)
Expand Down
13 changes: 8 additions & 5 deletions shuup/front/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class ShuupFrontMiddleware(MiddlewareMixin):
"""

def process_request(self, request):
if (
if settings.DEBUG and (
request.path.startswith(settings.MEDIA_URL) or
request.path.startswith(settings.STATIC_URL)
):
Expand Down Expand Up @@ -192,10 +192,13 @@ def _set_language(self, request):
request.LANGUAGE_CODE = translation.get_language()

def _get_maintenance_response(self, request, view_func):
if settings.DEBUG:
# Allow media and static accesses in debug mode
if request.path.startswith("/media") or request.path.startswith("/static"):
return None
# Allow media and static accesses in debug mode
if settings.DEBUG and (
request.path.startswith(settings.MEDIA_URL) or
request.path.startswith(settings.STATIC_URL)
):
return None

if getattr(view_func, "maintenance_mode_exempt", False):
return None
if "login" in view_func.__name__:
Expand Down
Binary file modified shuup/front/static/shuup/front/img/favicon.ico
100644 → 100755
Binary file not shown.
4 changes: 2 additions & 2 deletions shuup/front/templates/shuup/front/errors/404.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="{{ STATIC_URL }}shuup/front/img/favicon.ico">
<link rel="stylesheet" href="{{ shuup_static("shuup/front/css/style.css") }}">
<link rel="icon" type="image/x-icon" href="{{ static('shuup/front/img/favicon.ico') }}">
<link rel="stylesheet" href="{{ shuup_static('shuup/front/css/style.css') }}">
<title>{{ _("Page Not Found") }} (404)</title>
<style>
body {
Expand Down
4 changes: 2 additions & 2 deletions shuup/front/templates/shuup/front/errors/500.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="{{ STATIC_URL }}shuup/front/img/favicon.ico">
<link rel="stylesheet" href="{{ shuup_static("shuup/front/css/style.css") }}">
<link rel="icon" type="image/x-icon" href="{{ static('shuup/front/img/favicon.ico') }}">
<link rel="stylesheet" href="{{ shuup_static('shuup/front/css/style.css') }}">
<title>{% trans %}Internal Server Error{% endtrans %} (500)</title>
<style>
body {
Expand Down
2 changes: 1 addition & 1 deletion shuup/front/templates/shuup/front/macros/basket.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<a class="product-name"
href="{{ shuup.urls.model_url(product) }}">
<img class="img-responsive"
src="{{ STATIC_URL }}shuup/front/img/no_image_thumbnail.png">
src="{{ static('shuup/front/img/no_image_thumbnail.png') }}">
</a>
{% endif %}
</div>
Expand Down
2 changes: 1 addition & 1 deletion shuup/front/templates/shuup/front/macros/order.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
width="70" height="70">
{% else %}
<img class="img-responsive"
src="{{ STATIC_URL }}shuup/front/img/no_image_thumbnail.png"
src="{{ static('shuup/front/img/no_image_thumbnail.png') }}"
width="70" height="70">
{% endif %}
{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion shuup/front/templates/shuup/front/macros/product.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Inheritance order for product macors:
{% if product_image and primary_image_thumb %}
{% set image_url = primary_image_thumb %}
{% else %}
{% set image_url = STATIC_URL ~ "shuup/front/img/no_image.png" %}
{% set image_url = static('shuup/front/img/no_image.png') %}
{% endif %}
<div class="image" style="background-image:url('{{ image_url }}')"></div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<div class="thumbnail" rel="{{ rel }}1">
<img class="img-responsive no-image"
alt="{{ product.name }}"
src="{{ STATIC_URL }}shuup/front/img/no_image.png">
src="{{ static('shuup/front/img/no_image.png') }}">
</div>
</div>
{% endfor %}
Expand Down
4 changes: 2 additions & 2 deletions shuup/xtheme/templates/shuup/xtheme/admin/config_detail.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
{% set active = " active" if style_definition.stylesheet == active_stylesheet else "" %}
<div class="col-md-4 theme-screenshot{{ active }}" data-identifier="{{ style_definition.identifier }}">
<div class="theme-name">{{ style_definition.name }}</div>
<a class="theme-image lightbox" href="{{ STATIC_URL }}{{ image }}">
<img src="{{ STATIC_URL }}{{ image }}">
<a class="theme-image lightbox" href="{{ static(image) }}">
<img src="{{ static(image) }}">
</a>
<div class="tools">
<button
Expand Down
4 changes: 2 additions & 2 deletions shuup/xtheme/templates/shuup/xtheme/admin/wizard.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
{% set active = " active" if style_definition.stylesheet == active_stylesheet else "" %}
<div class="col-md-3 theme-screenshot{{ active }}" data-identifier="{{ style_definition.identifier }}">
<div class="theme-name">{{ style_definition.name }}</div>
<a class="theme-image lightbox" href="{{ STATIC_URL }}{{ image }}">
<img src="{{ STATIC_URL }}{{ image }}">
<a class="theme-image lightbox" href="{{ static(image) }}">
<img src="{{ static(image) }}">
</a>
<div class="tools">
<button
Expand Down
10 changes: 9 additions & 1 deletion shuup_tests/front/test_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from django.conf import settings
from django.contrib.auth import logout
from django.contrib.auth.models import AnonymousUser
from django.test import override_settings
from django.utils import timezone

import shuup.core.models
Expand Down Expand Up @@ -201,7 +202,14 @@ def test_with_statics(rf):
shop = get_default_shop() # Create a shop

request = apply_request_middleware(rf.get("/static/test.png"))
assert not hasattr(request, "customer")
assert hasattr(request, "customer") # Since debug is False

request = apply_request_middleware(rf.get("/"))
assert hasattr(request, "customer")

with override_settings(DEBUG=True):
request = apply_request_middleware(rf.get("/static/test.png"))
assert not hasattr(request, "customer") # Since debug is True

request = apply_request_middleware(rf.get("/"))
assert hasattr(request, "customer")

0 comments on commit c75ff3a

Please sign in to comment.