Skip to content

Commit

Permalink
fix for index views
Browse files Browse the repository at this point in the history
  • Loading branch information
jmg committed Aug 30, 2013
1 parent b7da2bb commit aa5a913
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
11 changes: 6 additions & 5 deletions django_conventions/conventions.py
@@ -1,5 +1,5 @@
END_VIEW_NAME = "View"
INDEX_VIEW_PREFIX = "index/"
INDEX_VIEW_PREFIX = "index"

def _get_module(view):

Expand Down Expand Up @@ -30,12 +30,13 @@ def get_url(view):
url = r"^"
url += _get_namespace(view)
url += _get_module(view)
url += _get_name(view)

if url.endswith(INDEX_VIEW_PREFIX):
url = url[:-len(INDEX_VIEW_PREFIX)]
name = _get_name(view)
if name != INDEX_VIEW_PREFIX:
url += r"%s/$" % name
else:
url += r"$"

url += r"/$"
return url

def get_resource(view):
Expand Down
5 changes: 2 additions & 3 deletions setup.py
Expand Up @@ -4,15 +4,14 @@

setup(
name="django_conventions",
version="0.1.2",
version="0.1.3",
description="Django Convention Over Configuration",
author="Juan Manuel García",
author_email = "jmg.utn@gmail.com",
license = "GPL v3",
keywords = "Django Routing Convetion Over Configuration",
packages=find_packages(exclude=["tests"]),
install_requires=[
"django",
install_requires=[
],
url='https://github.com/jmg/django_conventions',
)
5 changes: 5 additions & 0 deletions tests/testproject/testapp/tests.py
Expand Up @@ -16,6 +16,11 @@ def test_convention_url(self):
response = client.get("/index/main/")
assert_response_ok(self, response, "index.main")

def test_index_convention_url(self):

response = client.get("/index/")
assert_response_ok(self, response, "index.index")

def test_template_render(self):

response = client.get("/index/maintemplate/")
Expand Down
11 changes: 11 additions & 0 deletions tests/testproject/testapp/views/index.py
Expand Up @@ -13,6 +13,17 @@ def get(self, *args, **kwargs):
return HttpResponse("index.main")


class IndexView(TemplateView):
"""
The url for this class should be /index/
(based on the file and that it is an index view)
"""

def get(self, *args, **kwargs):

return HttpResponse("index.index")


class MainTemplateView(TemplateView):
"""
The url for this class should be /index/maintemplate/
Expand Down

0 comments on commit aa5a913

Please sign in to comment.