Skip to content

Commit

Permalink
Add a form for weight based shipping methods
Browse files Browse the repository at this point in the history
The dashboard views for the weight based shipping methods didn't specify
a form nor an explicit field list. That is not allowed in Django 1.8 any
more. I addressed this by adding a form (similar to the weight band)
that explicitly specifies all fields, which is what happened before.
  • Loading branch information
maiksprenger committed Apr 9, 2015
1 parent c495a4a commit 676ebd7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/oscar/apps/dashboard/shipping/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
from oscar.core.loading import get_model


class WeightBasedForm(forms.ModelForm):

class Meta:
model = get_model('shipping', 'WeightBased')
fields = ['name', 'description', 'default_weight', 'countries']


class WeightBandForm(forms.ModelForm):

def __init__(self, method, *args, **kwargs):
Expand Down
9 changes: 6 additions & 3 deletions src/oscar/apps/dashboard/shipping/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
from django.template.loader import render_to_string
from django.views import generic

from oscar.core.loading import get_model, get_class
from oscar.core.loading import get_model, get_classes

WeightBandForm = get_class('dashboard.shipping.forms', 'WeightBandForm')
WeightBandForm, WeightBasedForm = get_classes(
'dashboard.shipping.forms', ['WeightBandForm', 'WeightBasedForm'])
WeightBased = get_model('shipping', 'WeightBased')
WeightBand = get_model('shipping', 'WeightBand')

Expand All @@ -19,6 +20,7 @@ class WeightBasedListView(generic.ListView):

class WeightBasedCreateView(generic.CreateView):
model = WeightBased
form_class = WeightBasedForm
template_name = "dashboard/shipping/weight_based_form.html"

def get_success_url(self):
Expand All @@ -32,8 +34,8 @@ def get_success_url(self):

class WeightBasedDetailView(generic.CreateView):
model = WeightBand
template_name = "dashboard/shipping/weight_based_detail.html"
form_class = WeightBandForm
template_name = "dashboard/shipping/weight_based_detail.html"

def dispatch(self, request, *args, **kwargs):
self.method = shortcuts.get_object_or_404(
Expand Down Expand Up @@ -62,6 +64,7 @@ def get_success_url(self):

class WeightBasedUpdateView(generic.UpdateView):
model = WeightBased
form_class = WeightBasedForm
template_name = "dashboard/shipping/weight_based_form.html"
context_object_name = "method"

Expand Down

0 comments on commit 676ebd7

Please sign in to comment.