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

#213 paginated products #238

Merged
merged 6 commits into from
Dec 31, 2018
Merged

#213 paginated products #238

merged 6 commits into from
Dec 31, 2018

Conversation

ArtemijRodionov
Copy link
Contributor

Closes #213

@ArtemijRodionov ArtemijRodionov self-assigned this Dec 30, 2018
Copy link
Collaborator

@duker33 duker33 left a comment

Choose a reason for hiding this comment

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

few minor fixes

@@ -17,9 +17,9 @@ def context(self):

class ParsedTags(Tags):

def __init__(self, tags: Tags, req_kwargs):
def __init__(self, tags: Tags, raw_tags: str=''):
Copy link
Collaborator

Choose a reason for hiding this comment

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

with default value '' we can miss type annotation. That's what we are usually doing now.
But we has no convention for it, it's up to you


def test_paginated_qs(self):
with override_settings(CATEGORY_STEP_MULTIPLIERS=[30]):
products = self.products_ctx()
Copy link
Collaborator

Choose a reason for hiding this comment

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

we can call products_ctx as just the context. We are already in ProductsContext 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.

It will raise name conflicts with module context, so i'd prefer to leave it as it is. Should i create a todo for it?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@artemiy312 , it'll not lead to conflict, because it's method but not a function.
Create todo plz, y

)

def test_paginated_qs(self):
with override_settings(CATEGORY_STEP_MULTIPLIERS=[30]):
Copy link
Collaborator

Choose a reason for hiding this comment

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

we have const 30 below as per_page var.
Define the var before with block or move value 30 to class level const

def qs(self):
return self._pagination_context()['page'].object_list

def context(self):
Copy link
Collaborator

Choose a reason for hiding this comment

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

annotate it's returning value with dict plz

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is implementation of base class' abstract method, that already have the annotation and it won't be changed. Should we duplicate this information?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@artemiy312 , i think we should. Because when we read code, we don't walk throw ancestors of class we are reading

def _pagination_context(self):
return self._pagination.context()

def qs(self):
Copy link
Collaborator

Choose a reason for hiding this comment

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

annotate it's with QuerySet plz


def context(self):
return {
**self._products.context(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe we should remove this string?
It seems to me, that every context class ancestor should return only it's part of context.
But maybe i don't fully understand how context instances should chain in a view finally.
So, it's up to you

Copy link
Contributor Author

@ArtemijRodionov ArtemijRodionov Dec 31, 2018

Choose a reason for hiding this comment

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

It just helps to avoid key conflicts, that would be occurred. For example we already have a copy of page instance in final context, but pagination has page too

Copy link
Collaborator

Choose a reason for hiding this comment

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

@artemiy312 , so similar keys should be merged. Python dict already has such strategy and it looks clear:

In [1]: {**{1: 'one', 2: 'two'}, **{1: 'uno'}}
Out[1]: {1: 'uno', 2: 'two'}

raise http.Http404('Page does not exist.')

self._products = products
self._url = url
Copy link
Collaborator

Choose a reason for hiding this comment

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

seems we don't use url at this class

context.products.PaginatedProducts(None, '', page_number, per_page-1)

with self.assertRaises(Http404):
# page_number < 1
Copy link
Collaborator

Choose a reason for hiding this comment

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

not existing page number might be more clear

@@ -55,13 +83,13 @@ class TagsContext(TestCase):

def test_parsed_tags(self):
tags_ctx = mocked_ctx()
context.tags.ParsedTags(tags_ctx, {'tags': 'test'}).qs()
context.tags.ParsedTags(tags_ctx, 'test').qs()
Copy link
Collaborator

Choose a reason for hiding this comment

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

let's use named arg for 'test' it might be more clear

Copy link
Collaborator

@duker33 duker33 left a comment

Choose a reason for hiding this comment

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

ask for a few minor fixes

@ArtemijRodionov ArtemijRodionov merged commit 11231f5 into master Dec 31, 2018
@ArtemijRodionov ArtemijRodionov deleted the 213-paginated-products branch December 31, 2018 18:32
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