From c2ac5ce267c0281996c90054a39957ab7c0a2c4d Mon Sep 17 00:00:00 2001 From: Artemiy Rodionov Date: Tue, 2 Jul 2019 12:24:17 +0300 Subject: [PATCH] Revert "Create CatalogBlock model" This reverts commit 95b6771ce7dc71d5c854fdddb18443ed06963d0c. --- shopelectro/migrations/0036_catalogblock.py | 28 ----------- shopelectro/models.py | 54 --------------------- shopelectro/tests/tests_models.py | 31 +----------- 3 files changed, 1 insertion(+), 112 deletions(-) delete mode 100644 shopelectro/migrations/0036_catalogblock.py diff --git a/shopelectro/migrations/0036_catalogblock.py b/shopelectro/migrations/0036_catalogblock.py deleted file mode 100644 index 77185bb4..00000000 --- a/shopelectro/migrations/0036_catalogblock.py +++ /dev/null @@ -1,28 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.20 on 2019-07-02 08:11 -from __future__ import unicode_literals - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('shopelectro', '0035_product_in_pack'), - ] - - operations = [ - migrations.CreateModel( - name='CatalogBlock', - fields=[ - ('category', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, primary_key=True, related_name='catalog_block', serialize=False, to='shopelectro.Category', verbose_name='category')), - ('block_size', models.PositiveSmallIntegerField(null=True, verbose_name='block size')), - ], - options={ - 'verbose_name': 'Catalog block', - 'verbose_name_plural': 'Catalog blocks', - 'ordering': ['category__page__position', 'category__name'], - }, - ), - ] diff --git a/shopelectro/models.py b/shopelectro/models.py index cbd2f427..1667d670 100644 --- a/shopelectro/models.py +++ b/shopelectro/models.py @@ -56,60 +56,6 @@ def get_absolute_url(self): return reverse('category', args=(self.page.slug,)) -class CatalogBlockManager(models.Manager): - - def blocks(self): - return ( - super() - .get_queryset() - .select_related('category', 'category__page') - .prefetch_related('category__children') - .filter(category__level=0, category__page__is_active=True) - ) - - -class CatalogBlock(models.Model): - """Catalog block is an element of catalog matrix UI element.""" - - # @todo #880:60m Add it to the admin panel, use it in the matrix view. - # Get the block_size data from the matrix view and fill out the model from admin. - - class Meta: - verbose_name = _('Catalog block') - verbose_name_plural = _('Catalog blocks') - ordering = ['category__page__position', 'category__name'] - - objects = CatalogBlockManager() - - category = models.OneToOneField( - Category, - on_delete=models.CASCADE, - primary_key=True, - verbose_name=_('category'), - related_name=_('catalog_block'), - limit_choices_to={'level': 0}, - ) - - block_size = models.PositiveSmallIntegerField( - null=True, - verbose_name=_('block size'), - ) - - @property - def name(self): - self.category.name - - @property - def url(self): - self.category.url - - def rows(self): - rows = self.category.children.active() - if self.block_size: - return rows[:self.block_size] - return rows - - class Product( catalog_models.AbstractProduct, catalog_models.AbstractPosition, diff --git a/shopelectro/tests/tests_models.py b/shopelectro/tests/tests_models.py index fcdd7d99..0be22810 100644 --- a/shopelectro/tests/tests_models.py +++ b/shopelectro/tests/tests_models.py @@ -5,7 +5,7 @@ from django.forms.models import model_to_dict from django.test import TestCase, TransactionTestCase, tag -from shopelectro.models import Category, CatalogBlock, Product, Tag, TagGroup +from shopelectro.models import Product, Tag, TagGroup @tag('fast') @@ -86,32 +86,3 @@ def test_get_brands_from_products(self): p: p.tags.filter(group__name=settings.BRAND_TAG_GROUP_NAME).first() for p in products } - - def test_get_catalog_blocks(self): - """Perform four queries to fetch in batch blocks, categories, pages and category's children.""" - roots = Category.objects.filter(level=0) - roots_count = roots.count() - for category in roots: - CatalogBlock.objects.create(category=category) - - with self.assertNumQueries(4): - blocks = list(CatalogBlock.objects.blocks()) - self.assertEquals(roots_count, len(blocks)) - for block in blocks: - self.assertTrue(block.category) - self.assertTrue(block.category.page) - self.assertTrue(block.rows()) - - -@tag('fast') -class CatalogBlockModel(TestCase): - - fixtures = ['dump.json'] - - def test_rows_count(self): - first, second, *_ = Category.objects.all() - block = CatalogBlock.objects.create(category=first) - sized_block = CatalogBlock.objects.create(category=second, block_size=2) - - self.assertNotEquals(first.children.active(), len(sized_block.rows())) - self.assertEquals(sized_block.block_size, len(sized_block.rows()))