Skip to content

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

Rename published_date to publication_date on collection model

Michał Jelonekf31400e59eb7
diff --git a/saleor/core/sitemaps.py b/saleor/core/sitemaps.py
index af923cfa82..d1d0fd422c 100644
--- a/saleor/core/sitemaps.py
+++ b/saleor/core/sitemaps.py
@@ -26,7 +26,7 @@ class CategorySitemap(I18nSitemap):
class CollectionSitemap(I18nSitemap):
def items(self):
- collections = Collection.objects.public().order_by('id')
+ collections = Collection.objects.available().order_by('id')
return collections.only('id', 'name', 'slug')
diff --git a/saleor/dashboard/collection/forms.py b/saleor/dashboard/collection/forms.py
index e752ad54db..634a1fe28a 100644
--- a/saleor/dashboard/collection/forms.py
+++ b/saleor/dashboard/collection/forms.py
@@ -30,10 +30,10 @@ class CollectionForm(forms.ModelForm):
'is_published': pgettext_lazy(
'Collection published toggle',
'Published'),
- 'published_date': pgettext_lazy(
+ 'publication_date': pgettext_lazy(
'The publication date field, can be a posterior date for '
'a planned publication.',
- 'Published date'),
+ 'Publication date'),
'description': pgettext_lazy(
'Description field of a collection',
'Description')}
diff --git a/saleor/dashboard/order/forms.py b/saleor/dashboard/order/forms.py
index 62b13288ac..a5578b24d1 100644
--- a/saleor/dashboard/order/forms.py
+++ b/saleor/dashboard/order/forms.py
@@ -539,7 +539,7 @@ class AddVariantToOrderForm(forms.Form):
variant = AjaxSelect2ChoiceField(
queryset=ProductVariant.objects.filter(
- product__in=Product.objects.available_products()),
+ product__in=Product.objects.available()),
fetch_data_url=reverse_lazy('dashboard:ajax-available-variants'),
label=pgettext_lazy(
'Order form: subform to add variant to order form: variant field',
diff --git a/saleor/dashboard/product/views.py b/saleor/dashboard/product/views.py
index 33336a4ec5..8eaf63071c 100644
--- a/saleor/dashboard/product/views.py
+++ b/saleor/dashboard/product/views.py
@@ -206,7 +206,7 @@ def ajax_products_list(request):
queryset = (
Product.objects.all()
if request.user.has_perm('product.manage_products')
- else Product.objects.available_products())
+ else Product.objects.available())
search_query = request.GET.get('q', '')
if search_query:
queryset = queryset.filter(Q(name__icontains=search_query))
@@ -405,7 +405,7 @@ def ajax_available_variants_list(request):
Response format is that of a Select2 JS widget.
"""
- available_products = Product.objects.available_products().prefetch_related(
+ available_products = Product.objects.available().prefetch_related(
'category',
'product_type__product_attributes')
queryset = ProductVariant.objects.filter(
diff --git a/saleor/graphql/product/mutations/products.py b/saleor/graphql/product/mutations/products.py
index 7ce943203a..d1be645695 100644
--- a/saleor/graphql/product/mutations/products.py
+++ b/saleor/graphql/product/mutations/products.py
@@ -119,7 +119,7 @@ class CollectionInput(graphene.InputObjectType):
background_image_alt = graphene.String(
description='Alt text for an image.')
seo = SeoInput(description='Search engine optimization fields.')
- published_date = graphene.Date(
+ publication_date = graphene.Date(
description='Publication date. ISO 8601 standard.')
diff --git a/saleor/graphql/product/types.py b/saleor/graphql/product/types.py
index e95da9407e..e7c6cd3006 100644
--- a/saleor/graphql/product/types.py
+++ b/saleor/graphql/product/types.py
@@ -402,6 +402,9 @@ class Collection(CountableDjangoObjectType):
prefetch_related=prefetch_products)
background_image = graphene.Field(
Image, size=graphene.Int(description='Size of the image'))
+ published_date = graphene.Date(
+ deprecation_reason=(
+ 'publishedDate is deprecated, use publicationDate instead'))
class Meta:
description = "Represents a collection of products."
@@ -422,6 +425,9 @@ class Collection(CountableDjangoObjectType):
qs = self.products.visible_to_user(info.context.user)
return gql_optimizer.query(qs, info)
+ def resolve_published_date(self, info):
+ return self.publication_date
+
class Category(CountableDjangoObjectType):
ancestors = PrefetchingConnectionField(
@@ -475,7 +481,7 @@ class Category(CountableDjangoObjectType):
# Otherwise we want to include products from child categories which
# requires performing additional logic.
tree = self.get_descendants(include_self=True)
- qs = models.Product.objects.available_products()
+ qs = models.Product.objects.available()
qs = qs.filter(category__in=tree)
return gql_optimizer.query(qs, info)
diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphql
index 1195496ccd..529d7a0fbf 100644
--- a/saleor/graphql/schema.graphql
+++ b/saleor/graphql/schema.graphql
@@ -417,7 +417,8 @@ type Collection implements Node {
backgroundImage(size: Int): Image
isPublished: Boolean!
description: String!
- publishedDate: Date
+ publicationDate: Date
+ publishedDate: Date @deprecated(reason: "publishedDate is deprecated, use publicationDate instead")
}
type CollectionAddProducts {
@@ -449,7 +450,7 @@ input CollectionCreateInput {
backgroundImage: Upload
backgroundImageAlt: String
seo: SeoInput
- publishedDate: Date
+ publicationDate: Date
products: [ID]
}
@@ -466,7 +467,7 @@ input CollectionInput {
backgroundImage: Upload
backgroundImageAlt: String
seo: SeoInput
- publishedDate: Date
+ publicationDate: Date
}
type CollectionRemoveProducts {
diff --git a/saleor/product/migrations/0087_auto_20190208_0326.py b/saleor/product/migrations/0087_auto_20190208_0326.py
new file mode 100644
index 0000000000..4341600657
--- /dev/null
+++ b/saleor/product/migrations/0087_auto_20190208_0326.py
@@ -0,0 +1,18 @@
+# Generated by Django 2.1.5 on 2019-02-08 09:26
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('product', '0086_product_publication_date'),
+ ]
+
+ operations = [
+ migrations.RenameField(
+ model_name='collection',
+ old_name='published_date',
+ new_name='publication_date',
+ ),
+ ]
diff --git a/saleor/product/models.py b/saleor/product/models.py
index 3eaed70c24..0338be7458 100644
--- a/saleor/product/models.py
+++ b/saleor/product/models.py
@@ -447,7 +447,7 @@ class Collection(SeoModel):
background_image_alt = models.CharField(max_length=128, blank=True)
is_published = models.BooleanField(default=False)
description = models.TextField(blank=True)
- published_date = models.DateField(blank=True, null=True)
+ publication_date = models.DateField(blank=True, null=True)
objects = PublishedQuerySet.as_manager()
translated = TranslationProxy()
@@ -466,8 +466,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.publication_date is None
+ or self.publication_date <= datetime.date.today())
class CollectionTranslation(SeoModelTranslation):
diff --git a/saleor/product/utils/__init__.py b/saleor/product/utils/__init__.py
index e9b255b990..e09d6d4885 100644
--- a/saleor/product/utils/__init__.py
+++ b/saleor/product/utils/__init__.py
@@ -17,7 +17,7 @@ def products_visible_to_user(user):
from ..models import Product
if user.is_authenticated and user.is_active and user.is_staff:
return Product.objects.all()
- return Product.objects.available_products()
+ return Product.objects.available()
def products_with_details(user):
@@ -138,7 +138,7 @@ def collections_visible_to_user(user):
from ..models import Collection
if user.is_authenticated and user.is_active and user.is_staff:
return Collection.objects.all()
- return Collection.objects.public()
+ return Collection.objects.available()
def calculate_revenue_for_variant(variant, start_date):
diff --git a/saleor/static/dashboard-next/types/globalTypes.ts b/saleor/static/dashboard-next/types/globalTypes.ts
index 2c86092ba2..457e4f75da 100644
--- a/saleor/static/dashboard-next/types/globalTypes.ts
+++ b/saleor/static/dashboard-next/types/globalTypes.ts
@@ -183,7 +183,7 @@ export interface CollectionCreateInput {
backgroundImage?: any | null;
backgroundImageAlt?: string | null;
seo?: SeoInput | null;
- publishedDate?: any | null;
+ publicationDate?: any | null;
products?: (string | null)[] | null;
}
@@ -195,7 +195,7 @@ export interface CollectionInput {
backgroundImage?: any | null;
backgroundImageAlt?: string | null;
seo?: SeoInput | null;
- publishedDate?: any | null;
+ publicationDate?: any | null;
}
export interface CustomerInput {
diff --git a/templates/collection/index.html b/templates/collection/index.html
index 55266374a6..dfb22e16e1 100644
--- a/templates/collection/index.html
+++ b/templates/collection/index.html
@@ -12,8 +12,8 @@
{% block collection_published_warning %}
{% if not object.is_visible %}
<div class="alert alert-warning" role="alert">
- {% if object.published_date %}
- {% blocktrans trimmed with date=object.published_date|date context "Unpublished collection details text" %}
+ {% if object.publication_date %}
+ {% blocktrans trimmed with date=object.publication_date|date context "Unpublished collection details text" %}
<strong>Warning!</strong>
You are previewing a collection that will become visible on <strong>{{ date }}</strong>.
{% endblocktrans %}
diff --git a/templates/dashboard/collection/detail.html b/templates/dashboard/collection/detail.html
index 5d5f6a30a6..446fc092f9 100644
--- a/templates/dashboard/collection/detail.html
+++ b/templates/dashboard/collection/detail.html
@@ -68,7 +68,7 @@
{{ form.is_published|materializecss }}
</div>
<div class="row">
- {{ form.published_date|materializecss }}
+ {{ form.publication_date|materializecss }}
</div>
{% include "dashboard/includes/_google_preview.html" with object=collection form=form %}
</div>
diff --git a/templates/dashboard/includes/_collection_availability.html b/templates/dashboard/includes/_collection_availability.html
index fdffa53018..49b0290fbf 100644
--- a/templates/dashboard/includes/_collection_availability.html
+++ b/templates/dashboard/includes/_collection_availability.html
@@ -3,9 +3,9 @@
<div class="label label-{{ label_cls }}">
{% if is_visible %}
{% trans "Published" context "Collection availability status" %}
- {% elif collection.published_date is not None %}
+ {% elif collection.publication_date is not None %}
<div class="label">
- {% blocktrans with date=collection.published_date context "Collection availability status" %}
+ {% blocktrans with date=collection.publication_date context "Collection availability status" %}
Hidden (will become visible on {{ date }})
{% endblocktrans %}
</div>
diff --git a/tests/api/test_collection.py b/tests/api/test_collection.py
index 2b9b310821..0b8613d3c4 100644
--- a/tests/api/test_collection.py
+++ b/tests/api/test_collection.py
@@ -57,9 +57,9 @@ def test_create_collection(
monkeypatch, staff_api_client, product_list, permission_manage_products):
query = """
mutation createCollection(
- $name: String!, $slug: String!, $description: String, $products: [ID], $backgroundImage: Upload!, $backgroundImageAlt: String, $isPublished: Boolean!, $publishedDate: Date) {
+ $name: String!, $slug: String!, $description: String, $products: [ID], $backgroundImage: Upload!, $backgroundImageAlt: String, $isPublished: Boolean!, $publicationDate: Date) {
collectionCreate(
- input: {name: $name, slug: $slug, description: $description, products: $products, backgroundImage: $backgroundImage, backgroundImageAlt: $backgroundImageAlt, isPublished: $isPublished, publishedDate: $publishedDate}) {
+ input: {name: $name, slug: $slug, description: $description, products: $products, backgroundImage: $backgroundImage, backgroundImageAlt: $backgroundImageAlt, isPublished: $isPublished, publicationDate: $publicationDate}) {
collection {
name
slug
@@ -67,7 +67,7 @@ def test_create_collection(
products {
totalCount
}
- publishedDate
+ publicationDate
backgroundImage{
alt
}
@@ -89,12 +89,12 @@ def test_create_collection(
name = 'test-name'
slug = 'test-slug'
description = 'test-description'
- published_date = date.today()
+ publication_date = date.today()
variables = {
'name': name, 'slug': slug, 'description': description,
'products': product_ids, 'backgroundImage': image_name,
'backgroundImageAlt': image_alt, 'isPublished': True,
- 'publishedDate': published_date}
+ 'publicationDate': publication_date}
body = get_multipart_request_body(query, variables, image_file, image_name)
response = staff_api_client.post_multipart(
body, permissions=[permission_manage_products])
@@ -103,7 +103,7 @@ def test_create_collection(
assert data['name'] == name
assert data['slug'] == slug
assert data['description'] == description
- assert data['publishedDate'] == published_date.isoformat()
+ assert data['publicationDate'] == publication_date.isoformat()
assert data['products']['totalCount'] == len(product_ids)
collection = Collection.objects.get(slug=slug)
assert collection.background_image.file
@@ -144,14 +144,14 @@ def test_update_collection(
monkeypatch, staff_api_client, collection, permission_manage_products):
query = """
mutation updateCollection(
- $name: String!, $slug: String!, $description: String, $id: ID!, $isPublished: Boolean!, $publishedDate: Date) {
+ $name: String!, $slug: String!, $description: String, $id: ID!, $isPublished: Boolean!, $publicationDate: Date) {
collectionUpdate(
- id: $id, input: {name: $name, slug: $slug, description: $description, isPublished: $isPublished, publishedDate: $publishedDate}) {
+ id: $id, input: {name: $name, slug: $slug, description: $description, isPublished: $isPublished, publicationDate: $publicationDate}) {
collection {
name
slug
description
- publishedDate
+ publicationDate
}
}
}
@@ -166,17 +166,17 @@ def test_update_collection(
name = 'new-name'
slug = 'new-slug'
description = 'new-description'
- published_date = date.today()
+ publication_date = date.today()
variables = {
'name': name, 'slug': slug, 'description': description,
- 'id': to_global_id('Collection', collection.id), 'isPublished': True, 'publishedDate': published_date}
+ 'id': to_global_id('Collection', collection.id), 'isPublished': True, 'publicationDate': publication_date}
response = staff_api_client.post_graphql(
query, variables, permissions=[permission_manage_products])
content = get_graphql_content(response)
data = content['data']['collectionUpdate']['collection']
assert data['name'] == name
assert data['slug'] == slug
- assert data['publishedDate'] == published_date.isoformat()
+ assert data['publicationDate'] == publication_date.isoformat()
assert mock_create_thumbnails.call_count == 0
diff --git a/tests/test_collection.py b/tests/test_collection.py
index f1febec871..5680f7f4ad 100644
--- a/tests/test_collection.py
+++ b/tests/test_collection.py
@@ -41,7 +41,7 @@ def test_collection_not_yet_published_returns_404(
assert response.status_code == 404
draft_collection.is_published = True
- draft_collection.published_date = date.today() + timedelta(days=1)
+ draft_collection.publication_date = date.today() + timedelta(days=1)
draft_collection.save()
# A non staff user should not have access to collections yet to be published
diff --git a/tests/test_product_availability.py b/tests/test_product_availability.py
index 6e209ccdea..ab34e0f46d 100644
--- a/tests/test_product_availability.py
+++ b/tests/test_product_availability.py
@@ -92,7 +92,7 @@ def test_availability(product, monkeypatch, settings, taxes):
def test_available_products_only_published(product_list):
- available_products = models.Product.objects.available_products()
+ available_products = models.Product.objects.available()
assert available_products.count() == 2
assert all([product.is_published for product in available_products])
@@ -102,6 +102,6 @@ def test_available_products_only_available(product_list):
date_tomorrow = datetime.date.today() + datetime.timedelta(days=1)
product.publication_date = date_tomorrow
product.save()
- available_products = models.Product.objects.available_products()
+ available_products = models.Product.objects.available()
assert available_products.count() == 1
assert all([product.is_available() for product in available_products])