Skip to content

Commit

Permalink
refactor views: build urls with request.route_path
Browse files Browse the repository at this point in the history
  • Loading branch information
Cedrik Vanderhaegen committed Apr 18, 2014
1 parent bc5cad7 commit ee50315
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 35 deletions.
4 changes: 2 additions & 2 deletions atramhasis/static/js/vendor/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ $(document).ready(function () {
* Set form action for label search form
*/
$('#search-form').submit(function(){
var scheme = $("#scheme").val();
$("#search-form").attr("action", '/conceptschemes/' + scheme + '/c');
var url = $("#scheme").val();
$("#search-form").attr("action", url);
});
});
4 changes: 3 additions & 1 deletion atramhasis/templates/atramhasis.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

{% block html_title %}Home{% endblock %}



{% block content %}
<div class="row">
<div class="large-12 columns">
Expand All @@ -15,7 +17,7 @@
<div class="large-10 columns">
<select id="scheme">
{% for item in conceptschemes %}
<option>{{ item.id }}</option>
<option value="{{ request.route_path('search_result', scheme_id=item.id) }}">{{ item.id }}</option>
{% endfor %}
</select>
</div>
Expand Down
2 changes: 1 addition & 1 deletion atramhasis/templates/base.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<nav class="top-bar" data-topbar>
<ul class="title-area">
<li class="name">
<h1><a href="/">[atramhasis]</a></h1>
<h1><a href="{{ request.route_path('home') }}">[atramhasis]</a></h1>
</li>
</ul>
</nav>
Expand Down
38 changes: 10 additions & 28 deletions atramhasis/templates/concept.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@

{% block html_title %}Detail{% endblock %}

{% from "templates/macros.jinja2" import
render_relaties_lijst
%}

{% block content %}

<h1>[{{ conceptType }}] {{ concept.label().label}}</h1>
<ul>
<li>Id: {{ concept.id}}</li>
{% if concept.uri %}
<li>Uri: <a href="{{ concept.uri }}">{{ concept.uri }}</a></li>
{% endif %}
</ul>

<h2>Labels</h2>
Expand Down Expand Up @@ -39,42 +45,18 @@
</ul>

<h2>Narrower</h2>
<ul>
{%- for linkid in concept.narrower %}
<li>
<a href="{{ linkid }}">{{ linkid }}</a>
</li>
{%- endfor %}
</ul>
{{ render_relaties_lijst(request, concept.narrower, scheme_id) }}

<h2>Broader</h2>
<ul>
{%- for linkid in concept.broader %}
<li>
<a href="{{ linkid }}">{{ linkid }}</a>
</li>
{%- endfor %}
</ul>
{{ render_relaties_lijst(request, concept.broader, scheme_id) }}

<h2>Related</h2>
<ul>
{%- for linkid in concept.related %}
<li>
<a href="{{ linkid }}">{{ linkid }}</a>
</li>
{%- endfor %}
</ul>
{{ render_relaties_lijst(request, concept.related, scheme_id) }}
{% endif %}

{% if conceptType == 'Collection' %}
<h2>Members</h2>
<ul>
{%- for linkid in concept.members %}
<li>
<a href="{{ linkid }}">{{ linkid }}</a>
</li>
{%- endfor %}
</ul>
{{ render_relaties_lijst(request, concept.members, scheme_id) }}
{% endif %}

{% endblock %}
11 changes: 11 additions & 0 deletions atramhasis/templates/macros.jinja2
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% macro render_relaties_lijst(request, relaties, scheme_id) %}
{% if relaties|length > 0 %}
<ul>
{%- for linkid in relaties %}
<li>
<a href="{{ request.route_path('concept', scheme_id= scheme_id, c_id = linkid) }}">{{ linkid }}</a>
</li>
{%- endfor %}
</ul>
{% endif %}
{% endmacro %}
2 changes: 1 addition & 1 deletion atramhasis/templates/search_result.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<ul>
{%- for c in concepts %}
<li>{{ c.id }}: <a href="c/{{ c.id }}">{{ c.label }}</a></li>
<li>{{ c.id }}: <a href="{{ request.route_path('concept', scheme_id= scheme_id, c_id = c.id) }}">{{ c.label }}</a></li>
{%- endfor %}
</ul>

Expand Down
3 changes: 3 additions & 0 deletions atramhasis/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ def test_passing_view(self):
atramhasisview = AtramhasisView(request)
info = atramhasisview.concept_view()
self.assertIsNotNone(info['concept'])
self.assertEqual(info['conceptType'], 'Concept')
self.assertEqual(info['scheme_id'], 'TREES')

def test_provider_not_found(self):
request = testing.DummyRequest()
Expand Down Expand Up @@ -97,6 +99,7 @@ def test_find_by_label(self):
concept = info['concepts'][0]
self.assertIsNotNone(concept)
self.assertEqual(concept['label'], 'De Paardekastanje')
self.assertEqual(info['scheme_id'], 'TREES')

def test_no_querystring(self):
request = testing.DummyRequest()
Expand Down
4 changes: 2 additions & 2 deletions atramhasis/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def concept_view(self):
skostype = "Concept"
if isinstance(c, Collection):
skostype = "Collection"
return {'concept': c, 'conceptType': skostype}
return {'concept': c, 'conceptType': skostype, 'scheme_id': scheme_id}
return Response(content_type='text/plain', status_int=404)

@view_config(route_name='search_result', renderer='templates/search_result.jinja2')
Expand All @@ -65,5 +65,5 @@ def search_result(self):
concepts = provider.find({'label': label})
else:
concepts = provider.get_all()
return {'concepts': concepts}
return {'concepts': concepts, 'scheme_id': scheme_id}
return Response(content_type='text/plain', status_int=404)

0 comments on commit ee50315

Please sign in to comment.