-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
Static category view #1135
Static category view #1135
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1135 +/- ##
==========================================
+ Coverage 68.89% 69.74% +0.84%
==========================================
Files 113 115 +2
Lines 6163 6524 +361
Branches 751 835 +84
==========================================
+ Hits 4246 4550 +304
- Misses 1746 1800 +54
- Partials 171 174 +3
Continue to review full report at Codecov.
|
Delete data-category from category template.
Add dynamically created filters for variant and product attributes.
Add filter for price. Add filters for product/variant attributes - not working properly. Add some template updates.
Refactor filters and views.
Change building product_attributes and variant_attributes to correct one.
Fix filters for product.attributtes and product.variants.
Change filters to be ordered by name. Use product_with_details in category_index view.
Add sort by to filters and template.
Fix category/index.html template. Add category/_items.html template to render product items in category/index.html. Add availability to product list.
Delete RequestFactory from tests/test_product.py. Use clients instead.
d3f9787
to
bd9b761
Compare
tests/test_product.py
Outdated
default_category): | ||
products = models.Product.objects.all() | ||
url = reverse('product:category', args=[default_category.slug, | ||
default_category.pk]) |
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.
For better readability we rather use kwargs
in reverse function (same below).
tests/test_product.py
Outdated
products = models.Product.objects.all() | ||
url = reverse('product:category', args=[default_category.slug, | ||
default_category.pk]) | ||
data = {u'price_0': [u'20'], u'price_1': [u'']} |
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.
I think you don't need to convert it to unicode, since you are using very basic data in tests (same above).
Refactor some code in product.filters.py, product.views.py, and in templates.
Refactor tests. Add Sort by links to category/index.html.
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.
Most if not all files (including the test suite) should import unicode_literals
. At least until we can drop support for Python 2 😄
saleor/core/templatetags/shop.py
Outdated
else: | ||
new_sort_by = field # ascending sort | ||
request_get['sort_by'] = new_sort_by | ||
return '%s?%s' % (request.path, urlencode(request_get)) |
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.
Missing from __future__ import unicode_literals
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.
Done
@@ -0,0 +1,55 @@ | |||
from collections import OrderedDict |
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.
Missing from __future__ import unicode_literals
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.
and done
Add missing imports for unicode_literals.
Its not done yet :) Missing part is a frontend magic in category/index.html |
Add toggle to filters in category/index.html. Add plain JS in template (so far).
- Refactor category_index in product.views. - Translat and refactored choices for _sort_by.html. - Delete unused class in _sort_by.html.
Products_with_availability now runs only for products on current page. Products_paginated added to context. Update template.
Delete some duplicated queries in product.filter.py. Products_with_availability now runs only for products on current page. Add products_paginated to context. Update template.
ef26b4a
to
534b31d
Compare
Fis sort_by to have translated labels.
Refactor sort_menu.py.
Add order_by('name') to products_with_detail to have initial ordering by name ascending. Just like on demo site.
Add DEFAULT_SORT to product.filters.py for easy change of default sorting on the category page.
saleor/product/filters.py
Outdated
self.category = kwargs.pop('category') | ||
super(ProductFilter, self).__init__(*args, **kwargs) | ||
self.product_attributes, self.variant_attributes = \ | ||
self._get_attributes(self.category) |
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's the point of passing the instance variable self.category
as an argument to a instance method? The _get_attributes
method shouldn't require this argument and use self.category
internally.
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.
old code remainings, done
saleor/product/filters.py
Outdated
def __init__(self, *args, **kwargs): | ||
self.category = kwargs.pop('category') | ||
super(ProductFilter, self).__init__(*args, **kwargs) | ||
self.product_attributes, self.variant_attributes = \ |
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.
I think we've already talked about this - we don't use backslashes to break lines in our code.
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.
Done
saleor/product/filters.py
Outdated
self._get_attributes(self.category) | ||
self._add_product_attributes_filters() | ||
self._add_product_variants_attributes_filters() | ||
self.filters = OrderedDict(sorted(self.filters.items())) |
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.
As a result of each of the three lines above the instance variable self.filters
is modified. I think that instance variables should represent state of the instance and here we have to call these three particular lines to have it initialized properly. Instead, the first two functions should return some structures, then join them together, sort and and the end the result should be assigned to self.filters
.
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.
functions now updates self.filters instead of modifing it
register = template.Library() | ||
|
||
|
||
@register.inclusion_tag('category/_sort_by.html', takes_context=True) |
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.
I think the idea of context was misunderstood here. The context that you get in first argument when using takes_context=True
is the template context as of when the tag was called. What a inclusion tag should return is the context for the snippet it is rendering, not the whole context of the template. I don't see any need for the context in this tag. Here you should simply return a dictionary with attributes data.
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.
done, but we need to pass request all the way through get_sort_by_url
context['sort_by_choices'] = attributes | ||
context['arrow_down'] = \ | ||
(context['request'].GET.get('sort_by', DEFAULT_SORT).startswith('-')) | ||
return context |
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.
Again, instead of returning whole context you received as first argument, you should construct your own dictionary with data required by _sort_menu.html
snippet.
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.
same as above
saleor/product/views.py
Outdated
'products': products_and_availability, | ||
'products_paginated': products_paginated, | ||
'sort_by_choices': SORT_BY_FIELDS, | ||
'show_pagination': len(products) > PAGINATE_BY} |
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.
len(products)
makes additional queries and evaluates the whole queryset of products. This makes the pagination pointless.
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.
Done
templates/category/index.html
Outdated
</div> | ||
<div class="row"> | ||
<div class="m-auto"> | ||
{% if show_pagination %} |
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.
{% if products_paginated.has_other_pages %}
is much better way of checking this and doesn't make any 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.
Done
Change everything from last review.
Combine sort_by and sort_menu to one template and templatetag. Move templatetags to shop.py. Delete sort_menu.py and _sort_menu.html. Update index.html with new templatetags.
Deleted _sort_by.html and sort_by templatetag from shop.py. Updated index.html and category_index view.
Closes #1132