Permalink
Browse files

Merge branch 'features/voucher-dashboard'

  • Loading branch information...
codeinthehole committed May 18, 2012
2 parents 1f8142a + 87fd5c6 commit a40ac85ec29b3dfb92a1ddf0e13c643bc40a760c
View
@@ -56,6 +56,7 @@ def get_version():
'oscar.apps.dashboard.catalogue',
'oscar.apps.dashboard.offers',
'oscar.apps.dashboard.ranges',
+ 'oscar.apps.dashboard.vouchers',
]
@@ -57,6 +57,9 @@ class BasketVoucherForm(forms.Form):
def __init__(self, *args, **kwargs):
return super(BasketVoucherForm, self).__init__(*args,**kwargs)
+ def clean_code(self):
+ return self.cleaned_data['code'].strip().upper()
+
class ProductSelectionForm(forms.Form):
product_id = forms.IntegerField(min_value=1)
@@ -11,6 +11,7 @@
from oscar.apps.dashboard.offers.app import application as offers_app
from oscar.apps.dashboard.ranges.app import application as ranges_app
from oscar.apps.dashboard.reviews.app import application as reviews_app
+from oscar.apps.dashboard.vouchers.app import application as vouchers_app
from oscar.apps.dashboard import views
@@ -27,6 +28,7 @@ class DashboardApplication(Application):
offers_app = offers_app
ranges_app = ranges_app
reviews_app = reviews_app
+ vouchers_app = vouchers_app
def get_urls(self):
urlpatterns = patterns('',
@@ -40,6 +42,7 @@ def get_urls(self):
url(r'^offers/', include(self.offers_app.urls)),
url(r'^ranges/', include(self.ranges_app.urls)),
url(r'^reviews/', include(self.reviews_app.urls)),
+ url(r'^vouchers/', include(self.vouchers_app.urls)),
)
return self.post_process_urls(urlpatterns)
@@ -29,7 +29,7 @@ class OfferListView(ListView):
form_class = OfferSearchForm
def get_queryset(self):
- qs = self.model._default_manager.all()
+ qs = self.model._default_manager.filter(offer_type=ConditionalOffer.SITE)
self.description = "All offers"
self.form = self.form_class(self.request.GET)
@@ -8,7 +8,7 @@
node = Node('Orders')
node.add_child(Node('Orders', 'dashboard:order-list'))
node.add_child(Node('Statistics', 'dashboard:order-stats'))
-register(node, 60)
+register(node, 80)
class OrdersDashboardApplication(Application):
@@ -7,7 +7,7 @@
node = Node('Ranges')
node.add_child(Node('All ranges', 'dashboard:range-list'))
-register(node, 55)
+register(node, 70)
class RangeDashboardApplication(Application):
@@ -6,7 +6,7 @@
from oscar.apps.dashboard.nav import register, Node
node = Node('Reports', 'dashboard:reports-index')
-register(node, 70)
+register(node, 90)
class ReportsApplication(Application):
@@ -6,7 +6,7 @@
from oscar.apps.dashboard.reviews import views
node = Node('Reviews', 'dashboard:reviews-list')
-register(node, 80)
+register(node, 35)
class ReviewsApplication(Application):
@@ -7,7 +7,6 @@
from django.contrib.auth.models import User
from oscar.apps.basket.abstract_models import OPEN as basket_OPEN
-from oscar.apps.offer.models import SITE
from oscar.apps.promotions.models import AbstractPromotion
ConditionalOffer = get_model('offer', 'ConditionalOffer')
@@ -34,7 +33,7 @@ def get_active_site_offers(self):
the current date.
"""
return ConditionalOffer.objects.filter(end_date__gt=datetime.now(),
- offer_type=SITE)
+ offer_type=ConditionalOffer.SITE)
def get_active_vouchers(self):
"""
No changes.
@@ -0,0 +1,35 @@
+from django.conf.urls.defaults import patterns, url
+from django.contrib.admin.views.decorators import staff_member_required
+
+from oscar.core.application import Application
+from oscar.apps.dashboard.vouchers import views
+from oscar.apps.dashboard.nav import register, Node
+
+node = Node('Vouchers', 'dashboard:voucher-list')
+register(node, 60)
+
+
+class VoucherDashboardApplication(Application):
+ name = None
+
+ list_view = views.VoucherListView
+ create_view = views.VoucherCreateView
+ update_view = views.VoucherUpdateView
+ delete_view = views.VoucherDeleteView
+ stats_view = views.VoucherStatsView
+
+ def get_urls(self):
+ urlpatterns = patterns('',
+ url(r'^$', self.list_view.as_view(), name='voucher-list'),
+ url(r'^create/$', self.create_view.as_view(), name='voucher-create'),
+ url(r'^update/(?P<pk>\d+)/$', self.update_view.as_view(), name='voucher-update'),
+ url(r'^delete/(?P<pk>\d+)/$', self.delete_view.as_view(), name='voucher-delete'),
+ url(r'^stats/(?P<pk>\d+)/$', self.stats_view.as_view(), name='voucher-stats'),
+ )
+ return self.post_process_urls(urlpatterns)
+
+ def get_url_decorator(self, url_name):
+ return staff_member_required
+
+
+application = VoucherDashboardApplication()
@@ -0,0 +1,58 @@
+from django import forms
+from django.db.models.loading import get_model
+
+Voucher = get_model('voucher', 'Voucher')
+Benefit = get_model('offer', 'Benefit')
+Range = get_model('offer', 'Range')
+
+
+class VoucherForm(forms.Form):
+ """
+ A specialised form for creating a voucher and offer
+ model.
+ """
+ name = forms.CharField(label="Name")
+ code = forms.CharField(label="Code")
+ start_date = forms.DateField(label="Start date")
+ end_date = forms.DateField(label="End date")
+ usage = forms.ChoiceField(choices=Voucher.USAGE_CHOICES)
+
+ benefit_range = forms.ModelChoiceField(
+ label='Which products get a discount?',
+ queryset=Range.objects.all(),
+ )
+ type_choices = (
+ (Benefit.PERCENTAGE, '% off products in range'),
+ (Benefit.FIXED, 'Fixed amount off products in range'),
+ )
+ benefit_type = forms.ChoiceField(
+ choices=type_choices,
+ label='Discount type'
+ )
+ benefit_value = forms.DecimalField(
+ label='Discount value')
+
+ def __init__(self, voucher=None, *args, **kwargs):
+ self.voucher = voucher
+ super(VoucherForm, self).__init__(*args, **kwargs)
+
+ def clean_code(self):
+ code = self.cleaned_data['code'].strip().upper()
+ if not code:
+ raise forms.ValidationError("Please enter a voucher code")
+ try:
+ voucher = Voucher.objects.get(code=code)
+ except Voucher.DoesNotExist:
+ pass
+ else:
+ if voucher.id != self.voucher.id:
+ raise forms.ValidationError("The code '%s' is already in use" % code)
+ return code
+
+ def clean(self):
+ cleaned_data = super(VoucherForm, self).clean()
+ start_date = cleaned_data['start_date']
+ end_date = cleaned_data['end_date']
+ if end_date < start_date:
+ raise forms.ValidationError("The start date must be before the end date")
+ return cleaned_data
Oops, something went wrong.

0 comments on commit a40ac85

Please sign in to comment.