-
Notifications
You must be signed in to change notification settings - Fork 5
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
Conversation
shopelectro/views/catalog.py
Outdated
def get_sorting_index(self): | ||
return int(self.kwargs.get('sorting', 0)) | ||
|
||
def get_tags(self) -> typing.Union[models.TagQuerySet, None]: |
There was a problem hiding this comment.
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
shopelectro/views/catalog.py
Outdated
# See details at parent task. | ||
class TaggedCategoryPage(CategoryPage): | ||
|
||
def get_sorting_index(self): |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
shopelectro/views/catalog.py
Outdated
page = context['page'] | ||
page.get_template_render_context = partial( | ||
template_context, page, tag_titles, tags) | ||
tags = self.get_tags() |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
shopelectro/views/catalog.py
Outdated
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), |
There was a problem hiding this comment.
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
541168e
to
67ccf88
Compare
@artemiy312 , review plz again |
There was a problem hiding this 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
shopelectro/context.py
Outdated
models.ProductPage.objects.filter(shopelectro_product__in=products) | ||
) | ||
|
||
# @todo #550:30m Create Product.get_brand method |
There was a problem hiding this comment.
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
shopelectro/views/catalog.py
Outdated
@@ -158,11 +159,14 @@ def get_context_data(self, **kwargs): | |||
} | |||
|
|||
|
|||
# TODO - split to ProductImagesContext and ProductBrandContext |
There was a problem hiding this comment.
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
shopelectro/views/catalog.py
Outdated
"""Add sorting options and view_types in context.""" | ||
context_ = ( | ||
context.Category(self.kwargs, self.request) | ||
| context.TaggedCategory() |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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()
shopelectro/context.py
Outdated
return self.direction + self.field | ||
|
||
|
||
# @todo #539:60m Move PaginatorLinks to refarm-site. |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
shopelectro/context.py
Outdated
# Depends on updating to python3.7 | ||
view_type = self.request.session.get('view_type', 'tile') | ||
|
||
# @todo #550:60m Create `Product.get_brand` |
There was a problem hiding this comment.
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
cba1d81
to
b0d5151
Compare
shopelectro/context.py
Outdated
def get_sorting_index(self): | ||
return int(self.url_kwargs.get('sorting', 0)) | ||
|
||
# @todo #550:30m Test if context.TaggedCategory.get_tags cached. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
@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
b0d5151
to
dd55ab6
Compare
Contains view context classes. | ||
|
||
Context is our own concept. | ||
It's part of the View abstract layer in MTV paradigm. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MTV -> MVT
There was a problem hiding this comment.
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.
It's the start of splitting CatalogPage's monolith code
Closes #550
Closes #548