Skip to content

Commit

Permalink
Fixed set_kwargs so that it keys the slug_field dynamically to the kw…
Browse files Browse the repository at this point in the history
…args rather than hardcoding each one as 'slug'. I left in the old key though so that it will remain available to those who have used it in the past and just as a handy alias.
  • Loading branch information
palewire committed Dec 11, 2015
1 parent 55863c2 commit 253c7b9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
language: python
sudo: false

python:
- "2.7"
Expand All @@ -15,8 +16,6 @@ matrix:
- python: "3.5"
env: "DJANGO_VERSION=1.7.11"

sudo: false

install:
- pip install pyflakes pep8 coverage python-coveralls moto
- pip install django-celery
Expand Down
2 changes: 2 additions & 0 deletions bakery/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def get_absolute_url(self):

class MockDetailView(views.BuildableDetailView):
model = MockObject
slug_field = "the_slug"
template_name = 'detailview.html'


Expand Down Expand Up @@ -148,6 +149,7 @@ def test_detail_view(self):
)
self.assertTrue(os.path.exists(build_path))
v.unbuild_object(o)
self.assertTrue(v.kwargs['slug'] == v.kwargs['the_slug'])

def test_redirect_view(self):
v = views.BuildableRedirectView(
Expand Down
6 changes: 5 additions & 1 deletion bakery/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,13 @@ def get_build_path(self, obj):
return os.path.join(path, 'index.html')

def set_kwargs(self, obj):
slug_field = self.get_slug_field()
self.kwargs = {
'pk': getattr(obj, 'pk', None),
'slug': getattr(obj, self.get_slug_field(), None),
slug_field: getattr(obj, slug_field, None),
# Also alias the slug_field to the key `slug`
# so it can work for people who just toss that in
'slug': getattr(obj, slug_field, None),
}

def build_object(self, obj):
Expand Down

0 comments on commit 253c7b9

Please sign in to comment.