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

Static category view #1135

Merged
merged 63 commits into from
Oct 6, 2017
Merged

Static category view #1135

merged 63 commits into from
Oct 6, 2017

Conversation

koradon
Copy link
Contributor

@koradon koradon commented Sep 21, 2017

Closes #1132

@codecov-io
Copy link

codecov-io commented Sep 22, 2017

Codecov Report

Merging #1135 into master will increase coverage by 0.84%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
saleor/settings.py 88.63% <ø> (+1.56%) ⬆️
saleor/core/templatetags/shop.py 90% <100%> (+10%) ⬆️
saleor/product/filters.py 100% <100%> (ø)
saleor/core/permissions.py 100% <100%> (ø) ⬆️
saleor/core/utils/random_data.py 80.82% <0%> (-1.13%) ⬇️
saleor/dashboard/product/urls.py 100% <0%> (ø) ⬆️
saleor/dashboard/customer/views.py 100% <0%> (ø) ⬆️
saleor/dashboard/product/api.py 58.13% <0%> (ø)
... and 7 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ef4c648...ff20509. Read the comment docs.

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.
Add tests for product/filters.py.
Delete RequestFactory from tests/test_product.py. Use clients instead.
default_category):
products = models.Product.objects.all()
url = reverse('product:category', args=[default_category.slug,
default_category.pk])
Copy link
Contributor

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).

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'']}
Copy link
Contributor

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.
Copy link
Member

@patrys patrys left a 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 😄

else:
new_sort_by = field # ascending sort
request_get['sort_by'] = new_sort_by
return '%s?%s' % (request.path, urlencode(request_get))
Copy link
Member

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

Copy link
Contributor Author

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
Copy link
Member

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

Copy link
Contributor Author

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.
@koradon
Copy link
Contributor Author

koradon commented Sep 28, 2017

Its not done yet :)
But thx for trust.

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).
Add some js
- Refactor category_index in product.views.
- Translat and refactored choices for _sort_by.html.
- Delete unused class in _sort_by.html.
@koradon koradon removed the request for review from dominik-zeglen October 4, 2017 09:35
dominik-zeglen and others added 6 commits October 4, 2017 16:29
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.
koradon and others added 10 commits October 5, 2017 14:51
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.
self.category = kwargs.pop('category')
super(ProductFilter, self).__init__(*args, **kwargs)
self.product_attributes, self.variant_attributes = \
self._get_attributes(self.category)
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

old code remainings, done

def __init__(self, *args, **kwargs):
self.category = kwargs.pop('category')
super(ProductFilter, self).__init__(*args, **kwargs)
self.product_attributes, self.variant_attributes = \
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

self._get_attributes(self.category)
self._add_product_attributes_filters()
self._add_product_variants_attributes_filters()
self.filters = OrderedDict(sorted(self.filters.items()))
Copy link
Member

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.

Copy link
Contributor Author

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)
Copy link
Member

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.

Copy link
Contributor Author

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
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same as above

'products': products_and_availability,
'products_paginated': products_paginated,
'sort_by_choices': SORT_BY_FIELDS,
'show_pagination': len(products) > PAGINATE_BY}
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

</div>
<div class="row">
<div class="m-auto">
{% if show_pagination %}
Copy link
Member

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.

Copy link
Contributor Author

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.
@maarcingebala maarcingebala merged commit d65b80f into master Oct 6, 2017
@maarcingebala maarcingebala deleted the static_category_view branch October 6, 2017 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants