Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Use data from site settings

Krzysztof Wolski17f073fd4dc9
diff --git a/saleor/core/context_processors.py b/saleor/core/context_processors.py
index 0ad06852a9..178411e105 100644
--- a/saleor/core/context_processors.py
+++ b/saleor/core/context_processors.py
@@ -5,6 +5,8 @@ import json
from django.conf import settings
from django.urls import reverse
+from ..core.utils import build_absolute_uri
+from ..site.utils import get_site_settings_from_request
from ..product.models import Category
@@ -33,18 +35,18 @@ def search_enabled(request):
def webpage_schema(request):
- # Todo: add editing this data in dashboard
+ site_settings = get_site_settings_from_request(request)
+ url = build_absolute_uri(location='/', site_settings=site_settings)
data = {
'@context': 'http://schema.org',
'@type': 'WebSite',
- 'url': settings.SITE_ADDRESS,
- 'name': settings.SITE_NAME,
+ 'url': url,
+ 'name': site_settings.name,
'description': settings.SITE_DESCRIPTION,
}
if bool(settings.SEARCH_BACKENDS):
data['potentialAction'] = {
'@type': 'SearchAction',
- 'target': '%s%s?q={search_term}' % (settings.SITE_ADDRESS,
- reverse('search:search')),
+ 'target': '%s%s?q={search_term}' % (url, reverse('search:search')),
'query-input': 'required name=search_term'}
return {'webpage_schema': json.dumps(data)}
diff --git a/saleor/core/utils/__init__.py b/saleor/core/utils/__init__.py
index 940c3313be..a025fa8b00 100644
--- a/saleor/core/utils/__init__.py
+++ b/saleor/core/utils/__init__.py
@@ -40,9 +40,11 @@ class CategoryChoiceField(forms.ModelChoiceField):
return '%s%s' % (indent, smart_text(obj))
-def build_absolute_uri(location, is_secure=False):
- site = get_site_settings()
- host = site.domain
+def build_absolute_uri(location, is_secure=False, site_settings=None):
+ # type: (str, bool, saleor.site.models.SiteSettings) -> str
+ if site_settings is None:
+ site_settings = get_site_settings()
+ host = site_settings.domain
current_uri = '%s://%s' % ('https' if is_secure else 'http', host)
location = urljoin(current_uri, location)
return iri_to_uri(location)
diff --git a/saleor/settings.py b/saleor/settings.py
index 4a9f1f96af..d1ee6384f0 100644
--- a/saleor/settings.py
+++ b/saleor/settings.py
@@ -375,6 +375,4 @@ GRAPHENE = {
SITE_SETTINGS_ID = 1
-SITE_ADDRESS = os.environ.get('SITE_ADDRESS', 'localhost:8000')
-SITE_NAME = os.environ.get('SITE_NAME', 'Saleor')
SITE_DESCRIPTION = 'Shop with unique products and great prices.'