Skip to content

Commit

Permalink
Revert "Create CatalogBlock model"
Browse files Browse the repository at this point in the history
This reverts commit 95b6771.
  • Loading branch information
ArtemijRodionov committed Jul 2, 2019
1 parent ad066f0 commit c2ac5ce
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 112 deletions.
28 changes: 0 additions & 28 deletions shopelectro/migrations/0036_catalogblock.py

This file was deleted.

54 changes: 0 additions & 54 deletions shopelectro/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
31 changes: 1 addition & 30 deletions shopelectro/tests/tests_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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()))

1 comment on commit c2ac5ce

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on c2ac5ce Jul 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 880-520a1edd disappeared from shopelectro/models.py, that's why I closed #924. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.

Please sign in to comment.