Преглед изворни кода

Tided up download options on dashboard order list page.

This can still be extended easily, but is now prettier for single option
downloads which is the default.
master
David Winterbottom пре 13 година
родитељ
комит
cbbb783a78

+ 1
- 1
oscar/apps/dashboard/orders/app.py Прегледај датотеку

@@ -5,7 +5,7 @@ from oscar.core.application import Application
5 5
 from oscar.apps.dashboard.orders import views
6 6
 from oscar.apps.dashboard.nav import register, Node
7 7
 
8
-node = Node('Manage orders')
8
+node = Node('Orders')
9 9
 node.add_child(Node('Orders', 'dashboard:order-list'))
10 10
 node.add_child(Node('Statistics', 'dashboard:order-summary'))
11 11
 register(node)

+ 4
- 1
oscar/apps/dashboard/orders/views.py Прегледај датотеку

@@ -181,9 +181,12 @@ class OrderListView(ListView, BulkEditMixin):
181 181
             return self.download_selected_orders(self.request, context['object_list'])
182 182
         return super(OrderListView, self).render_to_response(context)
183 183
 
184
+    def get_download_filename(self, request):
185
+        return 'orders.csv'
186
+
184 187
     def download_selected_orders(self, request, orders):
185 188
         response = HttpResponse(mimetype='text/csv')
186
-        response['Content-Disposition'] = 'attachment; filename=orders.csv'
189
+        response['Content-Disposition'] = 'attachment; filename=%s' % self.get_download_filename(request)
187 190
         writer = csv.writer(response, delimiter=',')
188 191
 
189 192
         meta_data = (('number', 'Order number'),

+ 9
- 1
oscar/apps/dashboard/views.py Прегледај датотеку

@@ -6,6 +6,11 @@ from django.http import HttpResponseRedirect
6 6
 
7 7
 
8 8
 class BulkEditMixin():
9
+    """
10
+    Mixin for views that have a bulk editing facility.  This is normally in the
11
+    form of tabular data where each row has a checkbox.  The UI allows a number
12
+    of rows to be selected and then some 'action' to be performed on them.
13
+    """
9 14
     actions = None
10 15
     current_view = None
11 16
     checkbox_object_name = None
@@ -20,13 +25,16 @@ class BulkEditMixin():
20 25
             return None
21 26
 
22 27
     def post(self, request, *args, **kwargs):
28
+        # Dynamic dispatch patter - we forward POST requests onto a method
29
+        # designated by the 'action' parameter.  The action has to be in a
30
+        # whitelist to avoid security issues.
23 31
         action = request.POST.get('action', '').lower()
24 32
         if not self.actions or action not in self.actions:
25 33
             messages.error(self.request, "Invalid action")
26 34
             return HttpResponseRedirect(reverse(self.current_view))
27 35
         ids = request.POST.getlist('selected_%s' % self.get_checkbox_object_name())
28 36
         if not ids:
29
-            messages.error(self.request, "You need to select some %s" % self.get_checkbox_object_name())
37
+            messages.error(self.request, "You need to select some %ss" % self.get_checkbox_object_name())
30 38
             return HttpResponseRedirect(reverse(self.current_view))
31 39
 
32 40
         raw_objects = self.model.objects.in_bulk(ids)

+ 7
- 6
oscar/templates/dashboard/orders/order_list.html Прегледај датотеку

@@ -78,12 +78,6 @@ Order management | {{ block.super }}
78 78
 {% if orders.count %}
79 79
 <form action="." method="post" class="order_table">
80 80
     {% csrf_token %}
81
-    <div class="well well-danger">
82
-        <h3 class="app-ico ico_logout icon">Download</h3>
83
-        <label>With selected orders: Download as CSV </label>
84
-        <input type="radio" name="action" value="download_selected_orders" /> 
85
-        <button type="submit" class="btn btn-primary">Download</button>
86
-    </div>
87 81
 <table class="table table-striped table-bordered">
88 82
     <tr>
89 83
         <th></th>
@@ -115,6 +109,13 @@ Order management | {{ block.super }}
115 109
     {% endfor %}
116 110
 </table>
117 111
 
112
+<div class="well well-danger">
113
+	<h3 class="app-ico ico_logout icon">Download</h3>
114
+	<label>Download selected orders as a CSV</label>
115
+	<input type="hidden" name="action" value="download_selected_orders" />
116
+	<button type="submit" class="btn btn-primary">Download</button>
117
+</div>
118
+
118 119
 {% if page_obj %}
119 120
     {% include "catalogue/partials/pagination.html" %}
120 121
 {% endif %}

Loading…
Откажи
Сачувај