Commit 1ca6886d by Clinton Blackburn

Updated dashboard orders list view

Removing the display and querying of address values drastically improves query speed.

ECOM-2501
parent 2e748dfd
...@@ -10,6 +10,7 @@ from selenium.common.exceptions import NoSuchElementException ...@@ -10,6 +10,7 @@ from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.firefox.webdriver import WebDriver from selenium.webdriver.firefox.webdriver import WebDriver
from selenium.webdriver.support.wait import WebDriverWait from selenium.webdriver.support.wait import WebDriverWait
from ecommerce.extensions.dashboard.orders.views import queryset_orders_for_user
from ecommerce.extensions.dashboard.tests import DashboardViewTestMixin from ecommerce.extensions.dashboard.tests import DashboardViewTestMixin
from ecommerce.extensions.fulfillment.signals import SHIPPING_EVENT_NAME from ecommerce.extensions.fulfillment.signals import SHIPPING_EVENT_NAME
from ecommerce.extensions.fulfillment.status import ORDER, LINE from ecommerce.extensions.fulfillment.status import ORDER, LINE
...@@ -153,6 +154,14 @@ class OrderListViewTests(OrderViewTestsMixin, RefundTestMixin, LiveServerTestCas ...@@ -153,6 +154,14 @@ class OrderListViewTests(OrderViewTestsMixin, RefundTestMixin, LiveServerTestCas
)) ))
self.assert_successful_response(response, [new_order]) self.assert_successful_response(response, [new_order])
def test_address_not_displayed(self):
""" Verify no address data is displayed when the view is rendered. """
self.client.login(username=self.user.username, password=self.password)
response = self.client.get(self.path)
self.assertEqual(response.status_code, 200)
self.assertNotIn('address', response.content)
class OrderDetailViewTests(DashboardViewTestMixin, OrderViewTestsMixin, RefundTestMixin, TestCase): class OrderDetailViewTests(DashboardViewTestMixin, OrderViewTestsMixin, RefundTestMixin, TestCase):
def _request_refund(self, order): def _request_refund(self, order):
...@@ -216,3 +225,11 @@ class OrderDetailViewTests(DashboardViewTestMixin, OrderViewTestsMixin, RefundTe ...@@ -216,3 +225,11 @@ class OrderDetailViewTests(DashboardViewTestMixin, OrderViewTestsMixin, RefundTe
self.assert_message_equals(response, self.assert_message_equals(response,
'A refund cannot be created for these lines. They may have already been refunded.', 'A refund cannot be created for these lines. They may have already been refunded.',
MSG.ERROR) MSG.ERROR)
class HelperMethodTests(UserMixin, TestCase):
def test_queryset_orders_for_user_select_related(self):
""" Verify the method only selects the related user. """
user = self.create_user(is_staff=True)
queryset = queryset_orders_for_user(user)
self.assertDictEqual(queryset.query.select_related, {'user': {}})
...@@ -7,11 +7,35 @@ from oscar.apps.dashboard.orders.views import ( ...@@ -7,11 +7,35 @@ from oscar.apps.dashboard.orders.views import (
) )
from oscar.core.loading import get_model from oscar.core.loading import get_model
Order = get_model('order', 'Order')
Partner = get_model('partner', 'Partner')
Refund = get_model('refund', 'Refund') Refund = get_model('refund', 'Refund')
def queryset_orders_for_user(user): # pylint: disable=unused-argument
"""
Returns a queryset of all orders that a user is allowed to access.
A staff user may access all orders.
To allow access to an order for a non-staff user, at least one line's
partner has to have the user in the partner's list.
This customization removes the selection of the related address data, as it drastically decreases
query response time. Support for non-staff users is also removed.
"""
return Order._default_manager.select_related('user').prefetch_related('lines') # pylint: disable=protected-access
class OrderListView(CoreOrderListView): class OrderListView(CoreOrderListView):
def dispatch(self, request, *args, **kwargs):
# NOTE: This method is overridden so that we can use our override of `queryset_orders_for_user`.
# pylint: disable=attribute-defined-outside-init
# base_queryset is equal to all orders the user is allowed to access
self.base_queryset = queryset_orders_for_user(request.user).order_by('-date_placed')
# Bypass the CoreOrderListView.dispatch()
return super(CoreOrderListView, self).dispatch(request, *args, **kwargs) # pylint: disable=bad-super-call
def get_queryset(self): def get_queryset(self):
queryset = super(OrderListView, self).get_queryset() queryset = super(OrderListView, self).get_queryset()
......
...@@ -119,8 +119,6 @@ ...@@ -119,8 +119,6 @@
<th>{% trans "Number of items" %}</th> <th>{% trans "Number of items" %}</th>
<th>{% trans "Status" %}</th> <th>{% trans "Status" %}</th>
<th>{% trans "Username" %}</th> <th>{% trans "Username" %}</th>
<th>{% trans "Shipping address" %}</th>
<th>{% trans "Billing address" %}</th>
<th>{% trans "Date of purchase" %}</th> <th>{% trans "Date of purchase" %}</th>
<th></th> <th></th>
</tr> </tr>
...@@ -142,8 +140,6 @@ ...@@ -142,8 +140,6 @@
&lt;{% trans "Deleted" %}&gt; &lt;{% trans "Deleted" %}&gt;
{% endif %} {% endif %}
</td> </td>
<td>{{ order.shipping_address|default:"-" }}</td>
<td>{{ order.billing_address|default:"-" }}</td>
<td>{{ order.date_placed }}</td> <td>{{ order.date_placed }}</td>
<td> <td>
<a class="btn btn-info" <a class="btn btn-info"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment