Repository: shuup/shuup

Issue:
Admin: categories list view wrong queryset
Currently, all categories except deleted are listed in CategoryListView, although we have Deleted status filter option in the picotable which when selected, never shows anything.

Perhaps we should:
- list all categories and set the filter as Visible by default
- remove the deleted filter option


Discussion:

Resolving patch:
diff --git a/shuup/admin/modules/categories/views/list.py b/shuup/admin/modules/categories/views/list.py
--- a/shuup/admin/modules/categories/views/list.py
+++ b/shuup/admin/modules/categories/views/list.py
@@ -17,6 +17,7 @@
 
 class CategoryListView(PicotableListView):
     model = Category
+    category_status_choices = [(status.value, status) for status in CategoryStatus if status != CategoryStatus.DELETED]
     default_columns = [
         Column("image", _("Image"), sortable=False, linked=True, raw=True),
         Column(
@@ -29,7 +30,7 @@ class CategoryListView(PicotableListView):
         Column(
             "status", _(u"Status"),
             filter_config=ChoicesFilter(
-                choices=CategoryStatus.choices,
+                choices=category_status_choices,
                 default=CategoryStatus.VISIBLE.value
             )
         ),
diff --git a/shuup/simple_cms/migrations/0012_available_from_default.py b/shuup/simple_cms/migrations/0012_available_from_default.py
new file mode 100644
--- /dev/null
+++ b/shuup/simple_cms/migrations/0012_available_from_default.py
@@ -0,0 +1,23 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.17 on 2018-12-17 10:20
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+import django.db.models.deletion
+import django.utils.timezone
+import parler.fields
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('shuup_simple_cms', '0011_open_graph'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='page',
+            name='available_from',
+            field=models.DateTimeField(blank=True, db_index=True, default=django.utils.timezone.now, help_text='Set an available from date to restrict the page to be available only after a certain date and time. This is useful for pages describing sales campaigns or other time-sensitive pages.', null=True, verbose_name='available from'),
+        ),
+    ]
diff --git a/shuup/simple_cms/models.py b/shuup/simple_cms/models.py
--- a/shuup/simple_cms/models.py
+++ b/shuup/simple_cms/models.py
@@ -64,7 +64,7 @@ def for_shop(self, shop):
 class Page(MPTTModel, TranslatableModel):
     shop = models.ForeignKey("shuup.Shop", verbose_name=_('shop'))
     available_from = models.DateTimeField(
-        null=True, blank=True, db_index=True,
+        default=now, null=True, blank=True, db_index=True,
         verbose_name=_('available from'), help_text=_(
             "Set an available from date to restrict the page to be available only after a certain date and time. "
             "This is useful for pages describing sales campaigns or other time-sensitive pages."


Test patch:
diff --git a/shuup_tests/gdpr/test_consent_requirements.py b/shuup_tests/gdpr/test_consent_requirements.py
--- a/shuup_tests/gdpr/test_consent_requirements.py
+++ b/shuup_tests/gdpr/test_consent_requirements.py
@@ -43,7 +43,7 @@ def test_consent_required(rf):
     assert not is_documents_consent_in_sync(shop, user)
 
     # create revisioned page
-    hidden_page = Page.objects.create(shop=shop, )
+    hidden_page = Page.objects.create(shop=shop, available_from=None)
     assert hidden_page not in Page.objects.visible(shop=shop)
     assert gdpr_settings.privacy_policy_page == get_privacy_policy_page(shop)
     assert hidden_page in get_possible_consent_pages(shop)
diff --git a/shuup_tests/simple_cms/test_children.py b/shuup_tests/simple_cms/test_children.py
--- a/shuup_tests/simple_cms/test_children.py
+++ b/shuup_tests/simple_cms/test_children.py
@@ -74,7 +74,7 @@ def test_invisible_children(rf):
     parent_content = "Parent content"
     page = create_page(available_from=datetime.date(1988, 1, 1), content=parent_content, shop=shop)
     children_content = "Children content"
-    create_page(content=children_content, parent=page, shop=shop)  # Create invisible children
+    create_page(content=children_content, parent=page, shop=shop, available_from=None)  # Create invisible children
 
     assert page.list_children_on_page == False
     check_children_content(request, page, children_content, False)
diff --git a/shuup_tests/simple_cms/test_date_logic.py b/shuup_tests/simple_cms/test_date_logic.py
--- a/shuup_tests/simple_cms/test_date_logic.py
+++ b/shuup_tests/simple_cms/test_date_logic.py
@@ -17,7 +17,7 @@
 @pytest.mark.django_db
 def test_none_dates_page_not_visible():
     # create page that is not anymore visible
-    page = create_page(shop=get_default_shop())
+    page = create_page(shop=get_default_shop(), available_from=None)
 
     assert not Page.objects.visible(get_default_shop()).filter(pk=page.pk).exists()
     assert not page.is_visible()
diff --git a/shuup_tests/simple_cms/test_page_view.py b/shuup_tests/simple_cms/test_page_view.py
--- a/shuup_tests/simple_cms/test_page_view.py
+++ b/shuup_tests/simple_cms/test_page_view.py
@@ -23,7 +23,7 @@
 
 @pytest.mark.django_db
 def test_anon_cant_see_invisible_page(rf):
-    page = create_page(shop=get_default_shop())
+    page = create_page(shop=get_default_shop(), available_from=None)
     get_default_shop()
     view_func = PageView.as_view()
     request = apply_request_middleware(rf.get("/"))