Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Created new app for ranges

  • Loading branch information...
commit 30134677a9842a085ff64c38f80122f3dba59c29 1 parent 1ac7be3
@codeinthehole codeinthehole authored
View
1  oscar/__init__.py
@@ -55,6 +55,7 @@ def get_version():
'oscar.apps.dashboard.promotions',
'oscar.apps.dashboard.catalogue',
'oscar.apps.dashboard.offers',
+ 'oscar.apps.dashboard.ranges',
]
View
6 oscar/apps/dashboard/app.py
@@ -9,6 +9,7 @@
from oscar.apps.dashboard.catalogue.app import application as catalogue_app
from oscar.apps.dashboard.pages.app import application as pages_app
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 import views
@@ -23,6 +24,7 @@ class DashboardApplication(Application):
promotions_app = promotions_app
pages_app = pages_app
offers_app = offers_app
+ ranges_app = ranges_app
def get_urls(self):
urlpatterns = patterns('',
@@ -31,11 +33,11 @@ def get_urls(self):
url(r'^reports/', include(self.reports_app.urls)),
url(r'^orders/', include(self.orders_app.urls)),
url(r'^users/', include(self.users_app.urls)),
- url(r'^promotions/', include(self.promotions_app.urls)),
+ url(r'^content-blocks/', include(self.promotions_app.urls)),
url(r'^pages/', include(self.pages_app.urls)),
url(r'^offers/', include(self.offers_app.urls)),
+ url(r'^ranges/', include(self.ranges_app.urls)),
)
-
return self.post_process_urls(urlpatterns)
def get_url_decorator(self, url_name):
View
18 oscar/apps/dashboard/offers/app.py
@@ -9,11 +9,6 @@
node.add_child(Node('All offers', 'dashboard:offer-list'))
register(node, 50)
-node = Node('Ranges')
-node.add_child(Node('All ranges', 'dashboard:range-list'))
-register(node, 55)
-
-
class OffersDashboardApplication(Application):
name = None
list_view = views.OfferListView
@@ -25,12 +20,6 @@ class OffersDashboardApplication(Application):
delete_view = views.OfferDeleteView
detail_view = views.OfferDetailView
- range_list_view = views.RangeListView
- range_create_view = views.RangeCreateView
- range_update_view = views.RangeUpdateView
- range_delete_view = views.RangeDeleteView
- range_products_view = views.RangeProductListView
-
def get_urls(self):
urlpatterns = patterns('',
url(r'^$', self.list_view.as_view(), name='offer-list'),
@@ -48,13 +37,6 @@ def get_urls(self):
url(r'^(?P<pk>\d+)/delete/$', self.delete_view.as_view(), name='offer-delete'),
# Stats
url(r'^(?P<pk>\d+)/$', self.detail_view.as_view(), name='offer-detail'),
- # Ranges
- url(r'^ranges/$', self.range_list_view.as_view(), name='range-list'),
- url(r'^ranges/create/$', self.range_create_view.as_view(), name='range-create'),
- url(r'^ranges/(?P<pk>\d+)/$', self.range_update_view.as_view(), name='range-update'),
- url(r'^ranges/(?P<pk>\d+)/delete/$', self.range_delete_view.as_view(), name='range-delete'),
- url(r'^ranges/(?P<pk>\d+)/products/$',
- self.range_products_view.as_view(), name='range-products'),
)
return self.post_process_urls(urlpatterns)
View
23 oscar/apps/dashboard/offers/forms.py
@@ -33,26 +33,3 @@ class PreviewForm(forms.Form):
class OfferSearchForm(forms.Form):
name = forms.CharField(required=False, label="Offer name")
is_active = forms.BooleanField(required=False)
-
-
-def o():
- product_title = forms.CharField(required=False, label="Product name")
- product_id = forms.CharField(required=False, label="Product ID")
-
- status_choices = (('', '---------'),) + tuple([(v, v) for v in Order.all_statuses()])
- status = forms.ChoiceField(choices=status_choices, label="Status", required=False)
-
- date_formats = ('%d/%m/%Y',)
- date_from = forms.DateField(required=False, label="Date from", input_formats=date_formats)
- date_to = forms.DateField(required=False, label="Date to", input_formats=date_formats)
-
- voucher = forms.CharField(required=False, label="Voucher code")
-
- method_choices = (('', '---------'),) + tuple([(src.code, src.name) for src in SourceType.objects.all()])
- payment_method = forms.ChoiceField(label="Payment method", required=False,
- choices=method_choices)
-
- format_choices = (('html', 'HTML'),
- ('csv', 'CSV'),)
- response_format = forms.ChoiceField(widget=forms.RadioSelect,
- choices=format_choices, initial='html', label="Get results as")
View
0  oscar/apps/dashboard/ranges/__init__.py
No changes.
View
36 oscar/apps/dashboard/ranges/app.py
@@ -0,0 +1,36 @@
+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.ranges import views
+from oscar.apps.dashboard.nav import register, Node
+
+node = Node('Ranges')
+node.add_child(Node('All ranges', 'dashboard:range-list'))
+register(node, 55)
+
+
+class RangeDashboardApplication(Application):
+ name = None
+
+ list_view = views.RangeListView
+ create_view = views.RangeCreateView
+ update_view = views.RangeUpdateView
+ delete_view = views.RangeDeleteView
+ products_view = views.RangeProductListView
+
+ def get_urls(self):
+ urlpatterns = patterns('',
+ url(r'^$', self.list_view.as_view(), name='range-list'),
+ url(r'^create/$', self.create_view.as_view(), name='range-create'),
+ url(r'^(?P<pk>\d+)/$', self.update_view.as_view(), name='range-update'),
+ url(r'^(?P<pk>\d+)/delete/$', self.delete_view.as_view(), name='range-delete'),
+ url(r'^(?P<pk>\d+)/products/$', self.products_view.as_view(), name='range-products'),
+ )
+ return self.post_process_urls(urlpatterns)
+
+ def get_url_decorator(self, url_name):
+ return staff_member_required
+
+
+application = RangeDashboardApplication()
View
5 oscar/apps/dashboard/ranges/forms.py
@@ -0,0 +1,5 @@
+from django import forms
+
+
+class RangeProductForm(forms.Form):
+ pass
View
0  oscar/apps/dashboard/ranges/models.py
No changes.
View
63 oscar/apps/dashboard/ranges/views.py
@@ -0,0 +1,63 @@
+from django.views.generic import (ListView, DeleteView, CreateView, UpdateView)
+from django.db.models.loading import get_model
+from django.core.urlresolvers import reverse
+from django.contrib import messages
+from django.shortcuts import get_object_or_404
+
+from oscar.core.loading import get_classes
+
+Range = get_model('offer', 'Range')
+Product = get_model('catalogue', 'Product')
+RangeProductForm = get_classes('dashboard.ranges.forms', ['RangeProductForm'])
+
+
+class RangeListView(ListView):
+ model = Range
+ context_object_name = 'ranges'
+ template_name = 'dashboard/ranges/range_list.html'
+
+
+class RangeCreateView(CreateView):
+ model = Range
+ template_name = 'dashboard/ranges/range_form.html'
+
+ def get_success_url(self):
+ messages.success(self.request, "Range created")
+ return reverse('dashboard:range-list')
+
+
+class RangeUpdateView(UpdateView):
+ model = Range
+ template_name = 'dashboard/ranges/range_form.html'
+
+ def get_success_url(self):
+ messages.success(self.request, "Range updated")
+ return reverse('dashboard:range-list')
+
+
+class RangeDeleteView(DeleteView):
+ model = Range
+ template_name = 'dashboard/ranges/range_delete.html'
+ context_object_name = 'range'
+
+ def get_success_url(self):
+ messages.warning(self.request, "Range deleted")
+ return reverse('dashboard:range-list')
+
+
+class RangeProductListView(ListView):
+ model = Product
+ template_name = 'dashboard/ranges/range_product_list.html'
+ context_object_name = 'products'
+
+ def get(self, request, *args, **kwargs):
+ self.range = get_object_or_404(Range, id=self.kwargs['pk'])
+ return super(RangeProductListView, self).get(request, *args, **kwargs)
+
+ def get_queryset(self):
+ return self.range.included_products.all()
+
+ def get_context_data(self, **kwargs):
+ ctx = super(RangeProductListView, self).get_context_data(**kwargs)
+ ctx['range'] = self.range
+ return ctx
View
36 oscar/templates/dashboard/ranges/range_delete.html
@@ -0,0 +1,36 @@
+{% extends 'dashboard/layout.html' %}
+{% load currency_filters %}
+
+{% block title %}
+Delete range #{{ range.id }}? | Offer management | {{ block.super }}
+{% endblock %}
+
+{% block breadcrumbs %}
+<ul class="breadcrumb">
+ <li>
+ <a href="{% url dashboard:index %}">Dashboard</a>
+ <span class="divider">/</span>
+ </li>
+ <li>
+ <a href="{% url dashboard:offer-list %}">Offers</a>
+ <span class="divider">/</span>
+ </li>
+ <li class="active"><a href=".">Delete range #{{ range.id }}?</a></li>
+</ul>
+{% endblock %}
+
+{% block header %}
+<div class="page-header">
+ <h1>Delete range #{{ range.id }}?</h1>
+</div>
+{% endblock header %}
+
+{% block dashboard_content %}
+<form action="." method="post" class="">
+ {% csrf_token %}
+ <div class="form-actions">
+ <button class="btn btn-danger btn-large" type="submit">Delete</button> or
+ <a href="{% url dashboard:offer-list %}">cancel</a>
+ </div>
+</form>
+{% endblock dashboard_content %}
View
39 oscar/templates/dashboard/ranges/range_form.html
@@ -0,0 +1,39 @@
+{% extends 'dashboard/layout.html' %}
+{% load currency_filters %}
+
+{% block title %}
+Create range | Offer management | {{ block.super }}
+{% endblock %}
+
+{% block breadcrumbs %}
+<ul class="breadcrumb">
+ <li>
+ <a href="{% url dashboard:index %}">Dashboard</a>
+ <span class="divider">/</span>
+ </li>
+ <li>
+ <a href="{% url dashboard:offer-list %}">Offers</a>
+ <span class="divider">/</span>
+ </li>
+ <li class="active"><a href=".">Create range</a></li>
+</ul>
+{% endblock %}
+
+{% block header %}
+<div class="page-header">
+ <h1>Create range</h1>
+</div>
+{% endblock header %}
+
+{% block dashboard_content %}
+<form action="." method="post" class="">
+ {% csrf_token %}
+ {% include "partials/form_fields.html" with form=form %}
+ {% block form_actions %}
+ <div class="form-actions">
+ <button class="btn btn-primary btn-large" type="submit">Save</button> or
+ <a href="{% url dashboard:offer-list %}">cancel</a>
+ </div>
+ {% endblock form_actions %}
+</form>
+{% endblock dashboard_content %}
View
58 oscar/templates/dashboard/ranges/range_list.html
@@ -0,0 +1,58 @@
+{% extends 'dashboard/layout.html' %}
+{% load currency_filters %}
+
+{% block title %}
+Range management | {{ block.super }}
+{% endblock %}
+
+{% block breadcrumbs %}
+<ul class="breadcrumb">
+ <li>
+ <a href="{% url dashboard:index %}">Dashboard</a>
+ <span class="divider">/</span>
+ </li>
+ <li class="active"><a href=".">Range management</a></li>
+</ul>
+{% endblock %}
+
+{% block header %}
+<div class="page-header">
+ <h1>Range management</h1>
+</div>
+{% endblock header %}
+
+{% block dashboard_content %}
+
+ <p><a href="{% url dashboard:range-create %}" class="btn-large btn-primary">Create new range</a></p>
+
+ <div class="sub-header">
+ <h2>All ranges</h2>
+ </div>
+ {% if ranges.count %}
+ <table class="table table-striped table-bordered">
+ <tr>
+ <th>Name</th>
+ <th>Num products</th>
+ <th>Date created</th>
+ <th></th>
+ </tr>
+ {% for range in ranges %}
+ <tr>
+ <td>{{ range.name }}</td>
+ <td>{{ range.num_products|default:"-" }}</td>
+ <td>{{ range.date_created }}</td>
+ <td>
+ <a class="btn btn-primary" href="{% url dashboard:range-update range.id %}">Edit</a>
+ <a class="btn btn-primary" href="{% url dashboard:range-products range.id %}">Edit products</a>
+ <a class="btn btn-danger" href="{% url dashboard:range-delete range.id %}">Delete</a>
+ </td>
+ </tr>
+ {% endfor %}
+ </table>
+ {% if page_obj %}
+ {% include "catalogue/partials/pagination.html" %}
+ {% endif %}
+ {% else %}
+ <p>No ranges found.</p>
+ {% endif %}
+{% endblock dashboard_content %}
View
58 oscar/templates/dashboard/ranges/range_product_list.html
@@ -0,0 +1,58 @@
+{% extends 'dashboard/layout.html' %}
+{% load currency_filters %}
+
+{% block title %}
+Products in range {{ range.name }} | {{ block.super }}
+{% endblock %}
+
+{% block breadcrumbs %}
+<ul class="breadcrumb">
+ <li>
+ <a href="{% url dashboard:index %}">Dashboard</a>
+ <span class="divider">/</span>
+ </li>
+ <li>
+ <a href="{% url dashboard:range-update range.id %}">Range {{ range.name }}</a>
+ <span class="divider">/</span>
+ </li>
+ <li class="active"><a href=".">Products</a></li>
+</ul>
+{% endblock %}
+
+{% block header %}
+<div class="page-header">
+ <h1>Products in range {{ range.name }}</h1>
+</div>
+{% endblock header %}
+
+{% block dashboard_content %}
+ <div class="sub-header">
+ <h2>Products</h2>
+ </div>
+ {% if products.count %}
+ <form action="." method="post" class="order_table">
+ {% csrf_token %}
+ <table class="table table-striped table-bordered">
+ <tr>
+ <th>Title</th>
+ <th>Price</th>
+ <th></th>
+ </tr>
+ {% for product in products %}
+ <tr>
+ <td>{{ product.get_title }}</td>
+ <td>{{ product.stockrecord.price_incl_tax|currency }}</td>
+ <td>
+ <a class="btn btn-danger" href="">Remove</a>
+ </td>
+ </tr>
+ {% endfor %}
+ </table>
+ {% if page_obj %}
+ {% include "catalogue/partials/pagination.html" %}
+ {% endif %}
+ </form>
+ {% else %}
+ <p>No products found.</p>
+ {% endif %}
+{% endblock dashboard_content %}
Please sign in to comment.
Something went wrong with that request. Please try again.