Permalink
Browse files

args and kwargs are now passed to get_object() in DetailView. This ma…

…kes simple cases way simpler, but needs a design decision
  • Loading branch information...
bfirsh committed Sep 8, 2010
1 parent 55676c8 commit c4df75f5bc0a2ec99725a965ab4faba8e79cbf50
Showing with 14 additions and 14 deletions.
  1. +5 −5 class_based_views/dates.py
  2. +6 −6 class_based_views/detail.py
  3. +3 −3 class_based_views/edit.py
View
@@ -344,13 +344,13 @@ class DateDetailView(DetailView):
day_format = '%d'
allow_future = False
- def get_object(self):
+ def get_object(self, year, month, day, pk=None, slug=None):
"""
Get the object this request displays.
"""
- date = _date_from_string(self.kwargs['year'], '%Y',
- self.kwargs['month'], self.get_month_format(),
- self.kwargs['day'], self.get_day_format())
+ date = _date_from_string(year, '%Y',
+ month, self.get_month_format(),
+ day, self.get_day_format())
qs = self.get_queryset()
@@ -367,7 +367,7 @@ def get_object(self):
lookup = _date_lookup_for_field(field, date)
qs = qs.filter(**lookup)
- return super(DateDetailView, self).get_object(queryset=qs)
+ return super(DateDetailView, self).get_object(pk=pk, slug=slug, queryset=qs)
def get_date_field(self):
"""
@@ -11,7 +11,7 @@ class SingleObjectMixin(object):
queryset = None
slug_field = 'slug'
- def get_object(self, queryset=None):
+ def get_object(self, pk=None, slug=None, queryset=None):
"""
Returns the object the view is displaying.
@@ -24,13 +24,13 @@ def get_object(self, queryset=None):
queryset = self.get_queryset()
# Next, try looking up by primary key.
- if 'pk' in self.kwargs:
- queryset = queryset.filter(pk=self.kwargs['pk'])
+ if pk is not None:
+ queryset = queryset.filter(pk=pk)
# Next, try looking up by slug.
- elif 'slug' in self.kwargs:
+ elif slug is not None:
slug_field = self.get_slug_field()
- queryset = queryset.filter(**{slug_field: self.kwargs['slug']})
+ queryset = queryset.filter(**{slug_field: slug})
# If none of those are defined, it's an error.
else:
@@ -76,7 +76,7 @@ class DetailView(SingleObjectMixin, TemplateView):
template_name_field = None
def GET(self, request, *args, **kwargs):
- obj = self.get_object()
+ obj = self.get_object(*args, **kwargs)
context = self.get_context(obj)
return self.render_to_response(self.get_template_names(obj), context)
@@ -45,12 +45,12 @@ def get_form(self):
self.request.POST,
self.request.FILES,
initial=self.initial,
- instance=self.get_object(),
+ instance=self.get_object(*self.args, **self.kwargs),
)
else:
return self.form(
initial=self.initial,
- instance=self.get_object(),
+ instance=self.get_object(*self.args, **self.kwargs),
)
@@ -132,7 +132,7 @@ class UpdateView(ModelFormMixin, DisplayModelFormView, ProcessModelFormView):
class DeleteView(DetailView):
def POST(self, request, *args, **kwargs):
- obj = self.get_object()
+ obj = self.get_object(*args, **kwargs)
obj.delete()
return HttpResponseRedirect(self.redirect_to(obj))

0 comments on commit c4df75f

Please sign in to comment.