Browse Source

Added page management for promotions

master
David Winterbottom 13 years ago
parent
commit
c9dac1caa6

+ 7
- 1
oscar/apps/dashboard/promotions/app.py View File

@@ -10,7 +10,9 @@ class PromotionsDashboardApplication(Application):
10 10
     name = None
11 11
     list_view = views.ListView
12 12
     page_list = views.PageListView
13
+    page_detail = views.PageDetailView
13 14
     create_redirect_view = views.CreateRedirectView
15
+    delete_page_promotion_view = views.DeletePagePromotionView
14 16
 
15 17
     for klass in PROMOTION_CLASSES:
16 18
         locals()['create_%s_view' % klass.classname()] = \
@@ -24,9 +26,13 @@ class PromotionsDashboardApplication(Application):
24 26
         urlpatterns = patterns('',
25 27
             url(r'^$', self.list_view.as_view(), name='promotion-list'),
26 28
             url(r'^pages/$', self.page_list.as_view(), name='promotion-list-by-page'),
29
+            url(r'^pages/(?P<path>.+)/$', self.page_detail.as_view(), name='promotion-list-by-url'),
27 30
             url(r'^create/$', 
28 31
                 self.create_redirect_view.as_view(), 
29
-                name='promotion-create-redirect'),)
32
+                name='promotion-create-redirect'),
33
+            url(r'^page-promotion/(?P<pk>\d+)/$', 
34
+                self.delete_page_promotion_view.as_view(), name='pagepromotion-delete')
35
+            )
30 36
 
31 37
         for klass in PROMOTION_CLASSES:
32 38
             code = klass.classname()

+ 2
- 7
oscar/apps/dashboard/promotions/forms.py View File

@@ -2,7 +2,7 @@ from django import forms
2 2
 
3 3
 from oscar.forms.fields import ExtendedURLField
4 4
 from oscar.core.loading import get_classes
5
-from oscar.apps.promotions.conf import PROMOTION_CLASSES
5
+from oscar.apps.promotions.conf import PROMOTION_CLASSES, PROMOTION_POSITIONS
6 6
 
7 7
 RawHTML, SingleProduct, PagePromotion = get_classes('promotions.models', 
8 8
     ['RawHTML', 'SingleProduct', 'PagePromotion'])
@@ -21,14 +21,9 @@ class RawHTMLForm(forms.ModelForm):
21 21
         model = RawHTML
22 22
 
23 23
 
24
-POSITION_CHOICES = (('page', 'Page'),
25
-                    ('right', 'Right-hand sidebar'),
26
-                    ('left', 'Left-hand sidebar'))
27
-
28
-
29 24
 class PagePromotionForm(forms.ModelForm):
30 25
     page_url = ExtendedURLField(label="URL")
31
-    position = forms.CharField(widget=forms.Select(choices=POSITION_CHOICES),
26
+    position = forms.CharField(widget=forms.Select(choices=PROMOTION_POSITIONS),
32 27
                                help_text="""Where in the page this content
33 28
                                             block will appear""")
34 29
 

+ 37
- 1
oscar/apps/dashboard/promotions/views.py View File

@@ -8,7 +8,8 @@ from django.http import HttpResponseRedirect
8 8
 from django.db.models import Count
9 9
 
10 10
 from oscar.core.loading import get_classes, get_class
11
-from oscar.apps.promotions.conf import PROMOTION_CLASSES
11
+from oscar.apps.promotions.layout import split_by_position
12
+from oscar.apps.promotions.conf import PROMOTION_CLASSES, PROMOTION_POSITIONS
12 13
 
13 14
 SingleProduct, RawHTML, Image, MultiImage, \
14 15
     AutomaticProductList, PagePromotion, HandPickedProductList = get_classes('promotions.models',
@@ -55,6 +56,31 @@ class PageListView(generic.TemplateView):
55 56
         return {'pages': pages}
56 57
 
57 58
 
59
+class PageDetailView(generic.TemplateView):
60
+    template_name = 'dashboard/promotions/page_detail.html'
61
+
62
+    def get_context_data(self, *args, **kwargs):
63
+        path = self.kwargs['path']
64
+        ctx = {'page_url': path,
65
+               'positions': self.get_positions_context_data(path),
66
+              }
67
+        return ctx
68
+
69
+    def get_positions_context_data(self, path):
70
+        ctx = []
71
+        for code, name in PROMOTION_POSITIONS:
72
+            promotions = PagePromotion._default_manager.select_related() \
73
+                                                       .filter(page_url=path,
74
+                                                               position=code) \
75
+                                                       .order_by('display_order')
76
+            ctx.append({
77
+                'code': code,
78
+                'name': name,
79
+                'promotions': promotions,
80
+            })
81
+        return ctx
82
+
83
+
58 84
 class PromotionMixin(object):
59 85
 
60 86
     def get_template_names(self):
@@ -62,6 +88,16 @@ class PromotionMixin(object):
62 88
                 'dashboard/promotions/form.html']
63 89
 
64 90
 
91
+class DeletePagePromotionView(generic.DeleteView):
92
+    template_name = 'dashboard/promotions/delete-pagepromotion.html'
93
+    model = PagePromotion
94
+
95
+    def get_success_url(self):
96
+        messages.info(self.request, "Promotion removed successfully")
97
+        return reverse('dashboard:promotion-list-by-url', 
98
+                       kwargs={'path': self.object.page_url})
99
+
100
+
65 101
 # ============
66 102
 # CREATE VIEWS
67 103
 # ============

+ 4
- 0
oscar/apps/promotions/conf.py View File

@@ -11,5 +11,9 @@ def get_promotion_classes():
11 11
             HandPickedProductList)
12 12
 
13 13
 
14
+PROMOTION_POSITIONS = (('page', 'Page'),
15
+                       ('right', 'Right-hand sidebar'),
16
+                       ('left', 'Left-hand sidebar'))
17
+
14 18
 
15 19
 PROMOTION_CLASSES = get_promotion_classes()

+ 1
- 0
oscar/apps/promotions/context_processors.py View File

@@ -27,6 +27,7 @@ def promotions(request):
27 27
 
28 28
     return context
29 29
 
30
+
30 31
 def _split_by_position(linked_promotions, context):
31 32
     """
32 33
     Split the list of promotions into separate lists, grouping

+ 13
- 0
oscar/apps/promotions/layout.py View File

@@ -0,0 +1,13 @@
1
+def split_by_position(linked_promotions, context):
2
+    """
3
+    Split the list of promotions into separate lists, grouping
4
+    by position, and write these lists to the passed context.
5
+    """
6
+    for linked_promotion in linked_promotions:
7
+        promotion = linked_promotion.content_object
8
+        if not promotion:
9
+            continue
10
+        key = 'promotions_%s' % linked_promotion.position.lower()
11
+        if key not in context:
12
+            context[key] = []
13
+        context[key].append(promotion)

+ 1
- 1
oscar/apps/promotions/models.py View File

@@ -21,7 +21,7 @@ class LinkedPromotion(models.Model):
21 21
     content_type = models.ForeignKey(ContentType)
22 22
     object_id = models.PositiveIntegerField()
23 23
     content_object = generic.GenericForeignKey('content_type', 'object_id')
24
-    
24
+
25 25
     position = models.CharField(_("Position"), max_length=100, help_text="Position on page")
26 26
     display_order = models.PositiveIntegerField(default=0)
27 27
     clicks = models.PositiveIntegerField(default=0)

+ 13
- 0
oscar/templates/dashboard/promotions/delete-pagepromotion.html View File

@@ -0,0 +1,13 @@
1
+{% extends 'dashboard/layout.html' %}
2
+
3
+
4
+{% block dashboard_content %}
5
+<h1>Remove promotion from page?</h1>
6
+
7
+<form action="." method="post">
8
+	{% csrf_token %}
9
+    <p>Remove {{ object.content_object.type }} content block <strong>{{ object.name }}</strong> from page <strong>{{ object.page_url }}</strong> - are you sure?</p>
10
+	<p><button type="submit" class="btn btn-danger">Remove</button>
11
+	or <a href="{% url dashboard:promotion-list %}">cancel</a></p>
12
+</form>
13
+{% endblock %}

+ 27
- 0
oscar/templates/dashboard/promotions/page_detail.html View File

@@ -0,0 +1,27 @@
1
+{% extends 'dashboard/layout.html' %}
2
+
3
+
4
+{% block dashboard_content %}
5
+
6
+<h1>Content blocks for page {{ page }}</h1>
7
+
8
+{% for position in positions %}
9
+<h2>Edit promotions in position '{{ position.name }}'</h2>
10
+{% if position.promotions %}
11
+<ul>
12
+    {% for promotion in position.promotions %}
13
+    <li>
14
+    {{ promotion.content_object.name }} - Type: {{ promotion.content_object.type }}
15
+    <a href="{% url dashboard:promotion-update promotion.content_object.code promotion.content_object.id %}" class="btn btn-success">Edit</a>
16
+    <a href="#" class="btn btn-info">Re-order</a>
17
+    <a href="{% url dashboard:pagepromotion-delete promotion.id %}" class="btn btn-danger">Remove</a>
18
+    </li>
19
+    {% endfor %}
20
+</ul>
21
+{% else %}
22
+    <p>No promotions in this position.</p>
23
+{% endif %}
24
+
25
+{% endfor %}
26
+
27
+{% endblock dashboard_content %}

+ 1
- 1
oscar/templates/dashboard/promotions/pagepromotion_list.html View File

@@ -26,7 +26,7 @@
26 26
 			<td>{{ page.page_url }}</td>
27 27
 			<td>{{ page.freq }}</td>
28 28
 			<td>
29
-				<a href="" class="btn btn-info">Edit</a>
29
+                <a href="{% url dashboard:promotion-list-by-url page.page_url %}" class="btn btn-info">Edit</a>
30 30
 			</td>
31 31
 			<td>
32 32
 			</td>

Loading…
Cancel
Save