Просмотр исходного кода

Added basic structure for product update view

master
David Winterbottom 14 лет назад
Родитель
Сommit
9586f3cc71

+ 6
- 6
oscar/app.py Просмотреть файл

@@ -23,12 +23,12 @@ class Shop(Application):
23 23
     
24 24
     def get_urls(self):
25 25
         urlpatterns = patterns('',
26
-            (r'products/', include(self.catalogue_app.urls)),
27
-            (r'basket/', include(self.basket_app.urls)),
28
-            (r'checkout/', include(self.checkout_app.urls)),
29
-            (r'accounts/', include(self.customer_app.urls)),
30
-            (r'search/', include(self.search_app.urls)),
31
-            (r'dashboard/', include(self.dashboard_app.urls)),
26
+            (r'^products/', include(self.catalogue_app.urls)),
27
+            (r'^basket/', include(self.basket_app.urls)),
28
+            (r'^checkout/', include(self.checkout_app.urls)),
29
+            (r'^accounts/', include(self.customer_app.urls)),
30
+            (r'^search/', include(self.search_app.urls)),
31
+            (r'^dashboard/', include(self.dashboard_app.urls)),
32 32
             (r'', include(self.promotions_app.urls)),             
33 33
         )
34 34
         return urlpatterns

+ 9
- 2
oscar/apps/dashboard/catalogue/app.py Просмотреть файл

@@ -1,19 +1,26 @@
1 1
 from django.conf.urls.defaults import patterns, url
2
+from django.contrib.admin.views.decorators import staff_member_required
2 3
 
3 4
 from oscar.core.application import Application
4
-from oscar.apps.dashboard.catalogue.views import ProductListView
5
+from oscar.apps.dashboard.catalogue import views
5 6
 
6 7
 
7 8
 class CatalogueApplication(Application):
8 9
     name = None
9
-    product_list_view = ProductListView
10
+    product_list_view = views.ProductListView
11
+    product_update_view = views.ProductUpdateView
10 12
 
11 13
     def get_urls(self):
12 14
         urlpatterns = patterns('',
15
+            url(r'^products/(?P<pk>\d+)/$', self.product_update_view.as_view(),
16
+                name='catalogue-product'),
13 17
             url(r'^$', self.product_list_view.as_view(),
14 18
                 name='catalogue-product-list'),
15 19
         )
16 20
         return self.post_process_urls(urlpatterns)
17 21
 
22
+    def get_url_decorator(self, url_name):
23
+        return staff_member_required
24
+
18 25
 
19 26
 application = CatalogueApplication()

+ 8
- 0
oscar/apps/dashboard/catalogue/views.py Просмотреть файл

@@ -9,3 +9,11 @@ class ProductListView(generic.ListView):
9 9
     model = Product
10 10
     context_object_name = 'products'
11 11
     paginate_by = 20
12
+
13
+
14
+class ProductUpdateView(generic.UpdateView):
15
+    template_name = 'dashboard/catalogue/product_update.html'
16
+    model = Product
17
+    context_object_name = 'product'
18
+
19
+

+ 1
- 1
oscar/templates/dashboard/catalogue/product_list.html Просмотреть файл

@@ -49,7 +49,7 @@
49 49
 			<td>{{ stockrecord.num_in_stock }}</td>
50 50
 		{% endwith %}
51 51
 		<td>
52
-			<a class="btn btn-info" href="">Edit</a>
52
+			<a class="btn btn-info" href="{% url dashboard:catalogue-product product.id %}">Edit</a>
53 53
 		</td>
54 54
     </tr>
55 55
     {% endfor %}

+ 23
- 0
oscar/templates/dashboard/catalogue/product_update.html Просмотреть файл

@@ -0,0 +1,23 @@
1
+{% extends 'dashboard/layout.html' %}
2
+{% load currency_filters %}
3
+
4
+{% block header %}
5
+<h2>Edit product '{{ product.title }}'</h2>
6
+{% endblock header %}
7
+
8
+{% block dashboard_content %}
9
+
10
+<form action="." method="post">
11
+	{% csrf_token %}
12
+	<table class="table">
13
+		{{ form.as_table }}
14
+		<tr>
15
+			<th></th>
16
+			<td><button class="btn" type="submit">Save</button> or 
17
+				<a class="btn" href="{% url dashboard:catalogue-product-list">cancel</a>.
18
+			</td>
19
+		</tr>
20
+	</table>
21
+</form>
22
+
23
+{% endblock dashboard_content %}

Загрузка…
Отмена
Сохранить