Skip to content

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

Logic of collection templates, formatting

k-brk5906c4c56c5c
diff --git a/saleor/dashboard/collection/forms.py b/saleor/dashboard/collection/forms.py
index cd5d1f430a..fba945286a 100644
--- a/saleor/dashboard/collection/forms.py
+++ b/saleor/dashboard/collection/forms.py
@@ -29,7 +29,8 @@ class CollectionForm(forms.ModelForm):
'Collection published toggle',
'Published'),
'published_date': pgettext_lazy(
- 'The publication date field, can be a posterior date for a planned publication.',
+ 'The publication date field, can be a posterior date for '
+ 'a planned publication.',
'Published date'),
'description': pgettext_lazy(
'Description field of a collection',
diff --git a/saleor/product/migrations/0080_collection_published_at.py b/saleor/product/migrations/0080_collection_published_date.py
similarity index 80%
rename from saleor/product/migrations/0080_collection_published_at.py
rename to saleor/product/migrations/0080_collection_published_date.py
index 0e57d501bc..1150b788de 100644
--- a/saleor/product/migrations/0080_collection_published_at.py
+++ b/saleor/product/migrations/0080_collection_published_date.py
@@ -1,4 +1,4 @@
-# Generated by Django 2.1.3 on 2018-11-30 21:40
+# Generated by Django 2.1.3 on 2018-12-03 20:52
from django.db import migrations, models
@@ -12,7 +12,7 @@ class Migration(migrations.Migration):
operations = [
migrations.AddField(
model_name='collection',
- name='published_at',
+ name='published_date',
field=models.DateField(blank=True, null=True),
),
]
diff --git a/saleor/product/migrations/0081_auto_20181202_1337.py b/saleor/product/migrations/0081_auto_20181202_1337.py
deleted file mode 100644
index 8d5d220beb..0000000000
--- a/saleor/product/migrations/0081_auto_20181202_1337.py
+++ /dev/null
@@ -1,18 +0,0 @@
-# Generated by Django 2.1.3 on 2018-12-02 19:37
-
-from django.db import migrations
-
-
-class Migration(migrations.Migration):
-
- dependencies = [
- ('product', '0080_collection_published_at'),
- ]
-
- operations = [
- migrations.RenameField(
- model_name='collection',
- old_name='published_at',
- new_name='published_date',
- ),
- ]
diff --git a/saleor/product/models.py b/saleor/product/models.py
index dad1a3bbeb..aa19fafe19 100644
--- a/saleor/product/models.py
+++ b/saleor/product/models.py
@@ -437,7 +437,8 @@ class CollectionQuerySet(models.QuerySet):
def public(self):
return self.filter(
Q(is_published=True),
- Q(published_date__lte=datetime.date.today()) | Q(published_date__isnull=True))
+ Q(published_date__isnull=True)
+ | Q(published_date__lte=datetime.date.today()))
def visible_to_user(self, user):
has_access_to_all = (
@@ -474,7 +475,8 @@ class Collection(SeoModel):
@property
def is_visible(self):
return self.is_published and (
- self.published_date is None or self.published_date <= datetime.date.today())
+ self.published_date is None or
+ self.published_date <= datetime.date.today())
class CollectionTranslation(SeoModelTranslation):
diff --git a/templates/collection/index.html b/templates/collection/index.html
index deff267d79..1d86734460 100644
--- a/templates/collection/index.html
+++ b/templates/collection/index.html
@@ -17,7 +17,7 @@
You are previewing a collection that is not published.
{% endblocktrans %}
</div>
- {% elif object.is_published and object.published_date is not None %}
+ {% elif object.published_date is not None %}
<div class="alert alert-warning" role="alert">
{% blocktrans trimmed with date=object.published_date|date context "Unpublished collection details text" %}
<strong>Warning!</strong>
diff --git a/templates/dashboard/includes/_collection_availability.html b/templates/dashboard/includes/_collection_availability.html
index ae453d82fb..7cd9a2ad70 100644
--- a/templates/dashboard/includes/_collection_availability.html
+++ b/templates/dashboard/includes/_collection_availability.html
@@ -1,16 +1,17 @@
{% load i18n %}
- <div class="label label-{{ label_cls }}">
- {% if is_visible %}
- {% trans "Published" context "Collection availability status" %}
- {% elif not collection.is_published %}
- <div class="label">
- {% trans "Hidden" context "Collection availability status" %}
- </div>
- {% elif collection.is_published and collection.published_date is not None %}
+<div class="label label-{{ label_cls }}">
+ {% if is_visible %}
+ {% trans "Published" context "Collection availability status" %}
+ {% elif not collection.is_published %}
+ {% trans "Hidden" context "Collection availability status" %}
+ {% elif collection.published_date is not None %}
<div class="label">
{% blocktrans with date=collection.published_date context "Collection availability status" %}
Hidden (will become visible on {{ date }})
{% endblocktrans %}
</div>
-{% endif %}
+ {% else %}
+ {% trans "Hidden" context "Collection availability status" %}
+ {% endif %}
+</div>
diff --git a/tests/test_collection.py b/tests/test_collection.py
index 5b2b5f6fa9..5327ffbd4f 100644
--- a/tests/test_collection.py
+++ b/tests/test_collection.py
@@ -33,12 +33,15 @@ def test_collection_not_exists(client):
assert response.status_code == 404
-def test_collection_not_published_404(admin_client, client, draft_collection):
+def test_collection_not_yet_published_returns_404(
+ admin_client, client, draft_collection):
url_kwargs = {'pk': draft_collection.pk, 'slug': draft_collection.slug}
url = reverse('product:collection', kwargs=url_kwargs)
response = client.get(url)
assert response.status_code == 404
+ # A non staff user should not have access to collections yet to be published
+ # A staff user should have access to collections yet to be published
draft_collection.is_published = True
draft_collection.published_date = date.today() + timedelta(days=1)
draft_collection.save()