Skip to content

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

Improve page visibility rendering

akjanik7756b4ed4ce0
diff --git a/saleor/core/templatetags/status.py b/saleor/core/templatetags/status.py
index 2c15ce59bd..f1fda5fd69 100644
--- a/saleor/core/templatetags/status.py
+++ b/saleor/core/templatetags/status.py
@@ -1,3 +1,5 @@
+import datetime
+
from django.template import Library
from payments import PaymentStatus
@@ -48,3 +50,13 @@ def render_variant_availability_status(variant):
else:
label_cls = LABEL_DANGER
return {'status': display, 'label_cls': label_cls}
+
+
[email protected]_tag('dashboard/includes/_page_availability.html')
+def render_page_availability(page):
+ today = datetime.date.today()
+ is_published = (
+ page.is_visible and (
+ page.available_on is None or page.available_on <= today))
+ return {
+ 'is_published': is_published, 'page': page}
diff --git a/saleor/dashboard/templatetags/utils.py b/saleor/dashboard/templatetags/utils.py
index 71dfe76972..46464c571b 100644
--- a/saleor/dashboard/templatetags/utils.py
+++ b/saleor/dashboard/templatetags/utils.py
@@ -1,6 +1,5 @@
from __future__ import unicode_literals
-import datetime
from json import dumps
from urllib.parse import urlencode
@@ -149,11 +148,3 @@ def sorting_header(context, field, label, is_wide=False):
'url': '%s?%s' % (request.path, request_get.urlencode()),
'is_active': is_active, 'sorting_icon': sorting_icon, 'label': label,
'is_wide': is_wide}
-
-
-def page_published(page):
- today = datetime.date.today()
- return (
- page.is_visible
- and (page.available_on is None or page.available_on <= today))
diff --git a/templates/dashboard/includes/_page_availability.html b/templates/dashboard/includes/_page_availability.html
new file mode 100644
index 0000000000..0db01ab3cf
--- /dev/null
+++ b/templates/dashboard/includes/_page_availability.html
@@ -0,0 +1,17 @@
+{% load i18n %}
+
+{% if is_published %}
+ <div class="label">
+ {% trans "Published" context "Page availability status" %}
+ </div>
+{% elif page.available_on %}
+ <div class="label">
+ {% blocktrans with date=page.available_on context "Page availability status" %}
+ Hidden (will become visible on {{ date }})
+ {% endblocktrans %}
+ </div>
+{% else %}
+ <div class="label">
+ {% trans "Hidden" context "Page availability status" %}
+ </div>
+{% endif %}
diff --git a/templates/dashboard/page/detail.html b/templates/dashboard/page/detail.html
index 2ff2f745bc..165fa17c47 100644
--- a/templates/dashboard/page/detail.html
+++ b/templates/dashboard/page/detail.html
@@ -3,6 +3,7 @@
{% load mptt_tags %}
{% load materializecss %}
{% load staticfiles %}
+{% load status %}
{% load utils %}
{% block title %}{% trans "Pages" context "Pages list page title" %} -
@@ -37,15 +38,7 @@
<div class="col s12 l9">
<div class="card">
<div class="card-content">
- {% page_published page=page as is_published %}
- {% if is_published %}
- <span class="right label label-success">PUBLISHED</span>
- {% else %}
- <div class="right align label">
- HIDDEN<br>
- WILL BE AVAILABLE AT {{ page.available_on }}
- </div>
- {% endif %}
+ <span class="right">{% render_page_availability page %}</span>
<span class="card-title">{{ page }}<br></span>
<h4>
{% trans "Page URL" context "Page field" %}
@@ -54,7 +47,7 @@
</div>
<div class="card-action">
{% if perms.page.edit_page %}
- <a href="{% url "dashboard:page-update" page.pk %}" class="btn-flat waves-effect">
+ <a href="{% url 'dashboard:page-update' page.pk %}" class="btn-flat waves-effect">
{% trans "Edit page" context "Page action" %}
</a>
<a href="#base-modal" data-href="{% url 'dashboard:page-delete' pk=page.pk %}" class="modal-trigger-custom btn-flat waves-effect">
diff --git a/templates/dashboard/page/list.html b/templates/dashboard/page/list.html
index aeb1ee68e3..353eb79642 100644
--- a/templates/dashboard/page/list.html
+++ b/templates/dashboard/page/list.html
@@ -1,6 +1,7 @@
{% extends "dashboard/base.html" %}
{% load i18n %}
{% load staticfiles %}
+{% load status %}
{% load utils %}
{% block title %}
@@ -41,7 +42,7 @@
{% trans "URL" context "Static pages table header url" as label %}
{% sorting_header 'url' label is_wide=True %}
<th>
- {% trans "Status" context "Pages table header" %}
+ {% trans "Visibility" context "Pages table header" %}
</th>
</tr>
</thead>
@@ -55,16 +56,7 @@
{{ page.get_absolute_url }}
</td>
<td>
- {% page_published page=page as is_published %}
- {% if is_published %}
- <div>
- PUBLISHED
- </div>
- {% else %}
- <div>
- HIDDEN
- </div>
- {% endif %}
+ {% render_page_availability page %}
</td>
</tr>
{% endfor %}