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

#550 Split TaggedCategoryPage class #551

Merged
merged 4 commits into from
Sep 7, 2018
Merged

Conversation

duker33
Copy link
Contributor

@duker33 duker33 commented Aug 27, 2018

It's the start of splitting CatalogPage's monolith code

Closes #550
Closes #548

@duker33 duker33 self-assigned this Aug 27, 2018
@duker33 duker33 changed the title #550 Split catalog page #550 Split TaggedCategoryPage class Aug 27, 2018
def get_sorting_index(self):
return int(self.kwargs.get('sorting', 0))

def get_tags(self) -> typing.Union[models.TagQuerySet, None]:
Copy link
Contributor

Choose a reason for hiding this comment

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

typing.Optional[models.TagQuerySet] will be better

# See details at parent task.
class TaggedCategoryPage(CategoryPage):

def get_sorting_index(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems the better place for it in CategoryPage class

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@artemiy312 , the best place is SortedCategoryPage.
I moved all instead of CategoryPage's logic to TaggedCategoryPage.
Then i'll fork another class from TaggedCategoryPage and so on

page = context['page']
page.get_template_render_context = partial(
template_context, page, tag_titles, tags)
tags = self.get_tags()
Copy link
Contributor

Choose a reason for hiding this comment

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

You are calling it two times: here and in get_products(...). It will increase quantity of queries to db.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@artemiy312 , i thought, ORM caches such queries. I'll fix it

paginated_page = get_paginated_page_or_404(all_products, products_on_page, page_number)
total_products = all_products.count()
paginated_page = get_paginated_page_or_404(products, products_on_page, page_number)
total_products = products.count()
products = paginated_page.object_list
if not products:
raise http.Http404('Page without products does not exist.')

return {
**context,
'products_data': merge_products_context(products),
Copy link
Contributor

Choose a reason for hiding this comment

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

It will increase quantity of queries too, because you are already doing it in CategoryPage class

@duker33 duker33 force-pushed the 550_split_catalog_page branch from 541168e to 67ccf88 Compare September 3, 2018 15:13
@duker33
Copy link
Contributor Author

duker33 commented Sep 3, 2018

@artemiy312 , review plz again

Copy link
Contributor

@ArtemijRodionov ArtemijRodionov left a comment

Choose a reason for hiding this comment

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

One moment with object composition

models.ProductPage.objects.filter(shopelectro_product__in=products)
)

# @todo #550:30m Create Product.get_brand method
Copy link
Contributor

Choose a reason for hiding this comment

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

We already have such issue

@@ -158,11 +159,14 @@ def get_context_data(self, **kwargs):
}


# TODO - split to ProductImagesContext and ProductBrandContext
Copy link
Contributor

@ArtemijRodionov ArtemijRodionov Sep 6, 2018

Choose a reason for hiding this comment

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

Let's remove it or create well-formatted todoS

"""Add sorting options and view_types in context."""
context_ = (
context.Category(self.kwargs, self.request)
| context.TaggedCategory()
Copy link
Contributor

@ArtemijRodionov ArtemijRodionov Sep 6, 2018

Choose a reason for hiding this comment

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

Currently I do not understand why we need to use such syntax: context_obj | context_obj | ....
It has some critical cons:

  • We can not explicitly work with dependencies
  • We have to note, how some context depends on another one

I propose to use classic object composition, that has no any of these cons

Copy link
Contributor

Choose a reason for hiding this comment

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

e.g. of object composition:

category = context.SortedCategory(context.TaggedCategory(context.Category(self.kwargs, self.request)))
pagination = context.PaginationContext(category)
rendered_fields = context.RenderedFields(category)

Contexts(category, pagination, rendered_fields).get_context()

return self.direction + self.field


# @todo #539:60m Move PaginatorLinks to refarm-site.
Copy link
Contributor

Choose a reason for hiding this comment

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

This is no longer relevant todo, i am going to integrate implemented refarm_pagination after fidals/refarm-site#175

from django.core.paginator import Paginator, InvalidPage
from django_user_agents.utils import get_user_agent

from images.models import Image
Copy link
Contributor

Choose a reason for hiding this comment

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

We should place RF related packages to single group, as i remember

# Depends on updating to python3.7
view_type = self.request.session.get('view_type', 'tile')

# @todo #550:60m Create `Product.get_brand`
Copy link
Contributor

Choose a reason for hiding this comment

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

We already have the issue for it

@duker33 duker33 force-pushed the 550_split_catalog_page branch from cba1d81 to b0d5151 Compare September 7, 2018 02:04
def get_sorting_index(self):
return int(self.url_kwargs.get('sorting', 0))

# @todo #550:30m Test if context.TaggedCategory.get_tags cached.
Copy link
Contributor

@ArtemijRodionov ArtemijRodionov Sep 7, 2018

Choose a reason for hiding this comment

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

What exactly should be cached here? DB queries?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@artemiy312 , y, i supposed them. But django ORM caches them by default.
So, i rm both lru_cache and task

@ArtemijRodionov
Copy link
Contributor

@duker33 I left some comments

#550  Resolve branch inner conflicts

#550  Apply linter rules

#550  Review#2 fixes. Rm redundant pdd issue, fix imports

#550  Rm redundant pdd issue

#550  Pdd issue about context module improving

#550  Merge fixes after hell

#550  Minor self-review fixes

#550  Add code example for creating context

#550  Make context names shorten

#550  Fork AbstractPageContext

#550  Cleanup code

#550  Fork PaginationCategoryContext class

#550  Fork SortingCategoryContext class

#550  Fork DBTemplateContext class. Improve pipe mech

#550  Fork TaggedCategoryContext class

#550  Implement CatalogContext

#550  Fork SortingCategoryPage class

#550  Fork PaginatedCatalogPage class

#550  Fork DBContextCatalogPage class

#548  Apply E305 linter rule

#550  Review#1 fixes. Cache in memory db queries

#548  Rm E305 pycodestyle rule

#550  Add pdd issue for continue splitting

#550  Create TaggedCategoryPage class
@duker33 duker33 force-pushed the 550_split_catalog_page branch from b0d5151 to dd55ab6 Compare September 7, 2018 05:22
Contains view context classes.

Context is our own concept.
It's part of the View abstract layer in MTV paradigm.
Copy link
Contributor

Choose a reason for hiding this comment

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

MTV -> MVT

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@artemiy312 , seems it's called MTV. Like one popular TV-channel

If you’re hungry for acronyms, you might say that Django is a “MTV” framework – that is, “model”, “template”, and “view.” That breakdown makes much more sense.

https://docs.djangoproject.com/en/2.1/faq/general/#django-appears-to-be-a-mvc-framework-but-you-call-the-controller-the-view-and-the-view-the-template-how-come-you-don-t-use-the-standard-names

@duker33 duker33 closed this Sep 7, 2018
@duker33 duker33 reopened this Sep 7, 2018
@duker33 duker33 merged commit 9399dd6 into master Sep 7, 2018
@duker33 duker33 deleted the 550_split_catalog_page branch September 7, 2018 23:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants