Skip to content

Commit

Permalink
Merge pull request django-oscar#622 into releases/0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
codeinthehole committed Apr 8, 2013
2 parents b6ac663 + 6a10fee commit fcdf2d6
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 14 deletions.
13 changes: 8 additions & 5 deletions oscar/apps/catalogue/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ class ProductCategoryView(ListView):
template_name = 'catalogue/browse.html'
paginate_by = settings.OSCAR_PRODUCTS_PER_PAGE

def get(self, request, *args, **kwargs):
self.categories = self.get_categories()
return super(ProductCategoryView, self).get(request, *args, **kwargs)

def get_categories(self):
"""
Return a list of the current category and it's ancestors
Expand All @@ -127,15 +131,14 @@ def get_categories(self):
def get_context_data(self, **kwargs):
context = super(ProductCategoryView, self).get_context_data(**kwargs)

categories = self.get_categories()
context['categories'] = categories
context['category'] = categories[-1]
context['summary'] = categories[-1].name
context['categories'] = self.categories
context['category'] = self.categories[-1]
context['summary'] = self.categories[-1].name
return context

def get_queryset(self):
return get_product_base_queryset().filter(
categories__in=self.get_categories()
categories__in=self.categories
).distinct()


Expand Down
5 changes: 4 additions & 1 deletion oscar/apps/dashboard/orders/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,10 @@ def post(self, request, *args, **kwargs):
return self.reload_page_response()
else:
line_ids = request.POST.getlist('selected_line')
line_quantities = [int(qty) for qty in request.POST.getlist('selected_line_qty')]
line_quantities = []
for line_id in line_ids:
qty = request.POST.get('selected_line_qty_%s' % line_id)
line_quantities.append(int(qty))
lines = order.lines.filter(id__in=line_ids)
if lines.count() == 0:
messages.error(self.request, _("You must select some lines to act on"))
Expand Down
File renamed without changes.
30 changes: 30 additions & 0 deletions oscar/profiling/decorators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import cProfile
import pstats
import time


def profile(fn):
"""
Profile the decorated function, storing the profile output in /tmp
Inspired by https://speakerdeck.com/rwarren/a-brief-intro-to-profiling-in-python
"""
def profiled_fn(*args, **kwargs):
filepath = "/tmp/%s.profile" % fn.__name__
prof = cProfile.Profile()

start = time.time()
result = prof.runcall(fn, *args, **kwargs)
duration = time.time() - start

print "Function ran in %.6f seconds - output written to %s" % (
duration, filepath)
prof.dump_stats(filepath)

print "Printing stats"
stats = pstats.Stats(filepath)
stats.sort_stats('cumulative')
stats.print_stats()

return result
return profiled_fn
24 changes: 21 additions & 3 deletions oscar/middleware/profiling.py → oscar/profiling/middleware.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import sys
import os
import tempfile
import hotshot
import hotshot.stats
Expand All @@ -9,6 +8,23 @@
import pstats


def profile_this(fn):
def profiled_fn(*args, **kwargs):
filepath = "/tmp/%s.profile" % fn.__name__
prof = cProfile.Profile()
ret = prof.runcall(fn, *args, **kwargs)
print "Writing to %s" % filepath
prof.dump_stats(filepath)

print "Printing stats"
stats = pstats.Stats(filepath)
stats.sort_stats('cumulative')
stats.print_stats()

return ret
return profiled_fn


class BaseMiddleware(object):
query_param = None

Expand All @@ -18,8 +34,8 @@ def show_profile(self, request):
def process_request(self, request):
if self.show_profile(request):
if 'prof_file' in request.GET:
# It's sometimes useful to generate a file of output that can
# converted for use with kcachegrind. To convert this file,
# It's sometimes useful to generate a file of output that can
# converted for use with kcachegrind. To convert this file,
# use:
#
# pyprof2calltree -o /tmp/callgrind.stats -i /tmp/out.stats
Expand Down Expand Up @@ -47,6 +63,8 @@ def process_response(self, request, response):
if 'prof_strip' in request.GET:
stats.strip_dirs()
if 'prof_sort' in request.GET:
# See # http://docs.python.org/2/library/profile.html#pstats.Stats.sort_stats
# for the fields you can sort on.
stats.sort_stats(*request.GET['prof_sort'].split(','))
else:
stats.sort_stats('time', 'calls')
Expand Down
2 changes: 1 addition & 1 deletion oscar/templates/oscar/dashboard/orders/order_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ <h3>{% trans "Items ordered" %}</h3>
<tr>
<td>
<input type="checkbox" name="selected_line" value="{{ line.id }}" />
<input type="text" name="selected_line_qty" value="{{ line.quantity }}" class="span1" size="2" />
<input type="text" name="selected_line_qty_{{ line.id }}" value="{{ line.quantity }}" class="span1" size="2" />
</td>
<td>{{ line.quantity }}</td>
<td>{{ line.title }}</td>
Expand Down
4 changes: 2 additions & 2 deletions sites/sandbox/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,15 @@
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.transaction.TransactionMiddleware',
'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
'debug_toolbar.middleware.DebugToolbarMiddleware',
#'debug_toolbar.middleware.DebugToolbarMiddleware',
# Allow languages to be selected
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
# Ensure a valid basket is added to the request instance for every request
'oscar.apps.basket.middleware.BasketMiddleware',
# Enable the ProfileMiddleware, then add ?cprofile to any
# URL path to print out profile details
#'oscar.middleware.profiling.ProfileMiddleware',
#'oscar.profiling.middleware.ProfileMiddleware',
)

INTERNAL_IPS = ('127.0.0.1',)
Expand Down
6 changes: 4 additions & 2 deletions tests/functional/customer/profile_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,17 @@ def test_cant_update_their_email_address_if_it_already_exists(self):
'A user with this email address already exists')

def test_can_change_their_password(self):
new_password = 'bubblesgopop'
password_form_page = self.app.get(reverse('customer:change-password'),
user=self.user)
self.assertEqual(200, password_form_page.status_code)
form = password_form_page.forms['change_password_form']
form['old_password'] = self.password
form['new_password1'] = 'bubblesgopop'
form['new_password2'] = 'bubblesgopop'
form['new_password1'] = form['new_password2'] = new_password
response = form.submit()
self.assertRedirects(response, reverse('customer:summary'))
updated_user = User.objects.get(pk=self.user.pk)
self.assertTrue(updated_user.check_password(new_password))

def test_can_reorder_a_previous_order(self):
order_history_page = self.app.get(reverse('customer:order-list'),
Expand Down

0 comments on commit fcdf2d6

Please sign in to comment.