Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add publication date to collections #3369

Merged
merged 12 commits into from
Dec 20, 2018
3 changes: 2 additions & 1 deletion saleor/dashboard/collection/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class Meta:
'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',
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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),
),
]
18 changes: 0 additions & 18 deletions saleor/product/migrations/0081_auto_20181202_1337.py

This file was deleted.

6 changes: 4 additions & 2 deletions saleor/product/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down Expand Up @@ -474,7 +475,8 @@ def get_absolute_url(self):
@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):
Expand Down
2 changes: 1 addition & 1 deletion templates/collection/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
k-brk marked this conversation as resolved.
Show resolved Hide resolved
<div class="alert alert-warning" role="alert">
{% blocktrans trimmed with date=object.published_date|date context "Unpublished collection details text" %}
<strong>Warning!</strong>
Expand Down
19 changes: 10 additions & 9 deletions templates/dashboard/includes/_collection_availability.html
Original file line number Diff line number Diff line change
@@ -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 %}
k-brk marked this conversation as resolved.
Show resolved Hide resolved
{% trans "Hidden" context "Collection availability status" %}
{% elif collection.published_date is not None %}
<div class="label">
k-brk marked this conversation as resolved.
Show resolved Hide resolved
{% blocktrans with date=collection.published_date context "Collection availability status" %}
Hidden (will become visible on {{ date }})
k-brk marked this conversation as resolved.
Show resolved Hide resolved
{% endblocktrans %}
</div>
{% endif %}
{% else %}
{% trans "Hidden" context "Collection availability status" %}
{% endif %}
</div>
5 changes: 4 additions & 1 deletion tests/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
k-brk marked this conversation as resolved.
Show resolved Hide resolved
draft_collection.is_published = True
draft_collection.published_date = date.today() + timedelta(days=1)
draft_collection.save()
k-brk marked this conversation as resolved.
Show resolved Hide resolved
Expand Down