Skip to content

Commit

Permalink
added search form, view and templates
Browse files Browse the repository at this point in the history
  • Loading branch information
robmoorman committed Mar 14, 2016
1 parent 7769dca commit 6e9d940
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 3 deletions.
6 changes: 6 additions & 0 deletions technology_radar/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django import forms
from django.utils.translation import ugettext as _


class SearchForm(forms.Form):
q = forms.CharField(label=_('keywords'), max_length=128)
1 change: 1 addition & 0 deletions technology_radar/templates/technology_radar/radar.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ <h2>{{ area.name }}</h2>
{% endif %}
{% endfor %}
<p>
<a href="{% url 'radar-blip-list' radar.slug %}">{% trans "Search A-Z" %}</a>
<a href="{% url 'radar-detail-download' radar.slug %}">{% trans "Download" %}</a>
</p>
25 changes: 25 additions & 0 deletions technology_radar/templates/technology_radar/radar_blip_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{% load i18n technology_radar_tags %}

<h1>{{ radar.name }}</h1>
<form action="{% url 'radar-blip-list' radar.slug %}" method="GET">
{% if form.q.errors %}
<p>
{% for error in form.q.errors %}
{{ error }}
{% endfor %}
</p>
{% endif %}
{{ form.q }}
<input type="submit" value="{% trans "Search" %}" />
</form>
{% if blips %}
<ul>
{% for blip in blips %}
<li>
<a href="{% url 'blip-detail' radar.slug blip.area.slug blip.slug %}">{{ blip.name }} ({{ blip.status }}){% if blip.is_new %} <span class="badge">{% trans "new" %}</span>{% endif %}</a>
</li>
{% endfor %}
</ul>
{% else %}
<p>{% trans "No blips are available." %}</p>
{% endif %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{% load i18n technology_radar_tags %}

<h1>{{ radar.name }}</h1>
<h2>{% trans "Search results" %}</h2>
6 changes: 5 additions & 1 deletion technology_radar/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
from technology_radar.utils import import_class
from technology_radar import utils # noqa


def test_import_class_raise_error():
pass


def get_alphabetically_sorted_list():
pass
2 changes: 2 additions & 0 deletions technology_radar/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
url(r'^$', views.index, name='radar-index'),
url(r'^(?P<radar>[\w-]+)/$', views.radar_detail,
name='radar-detail'),
url(r'^(?P<radar>[\w-]+)/a-z/$', views.radar_blip_list,
name='radar-blip-list'),
url(r'^(?P<radar>[\w-]+)/download/$', views.radar_detail_download,
name='radar-detail-download'),
url(r'^(?P<radar>[\w-]+)/(?P<area>[\w-]+)/$', views.area_detail,
Expand Down
9 changes: 9 additions & 0 deletions technology_radar/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import importlib


ALPHABETICALLY_CHARACTERS = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
'u', 'v', 'w', 'x', 'y', 'z']


def import_class(name):
module_name, class_name = name.rsplit('.', 1)
return getattr(importlib.import_module(module_name), class_name)


def get_alphabetically_sorted_list(items, attribute='name'):
return items
27 changes: 25 additions & 2 deletions technology_radar/views/radar.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
from django.shortcuts import get_object_or_404
from django.template import loader

from technology_radar.forms import SearchForm
from technology_radar.models import Area, Blip, Radar
from technology_radar.utils import import_class


__all__ = ['index', 'radar_detail', 'radar_detail_download', 'area_detail',
'blip_detail']
__all__ = ['index', 'radar_detail', 'radar_blip_list', 'radar_detail_download',
'area_detail', 'blip_detail']


def index(request):
Expand All @@ -31,6 +32,28 @@ def radar_detail(request, radar):
return HttpResponse(template.render(context, request))


def radar_blip_list(request, radar):
radar_obj = get_object_or_404(Radar, slug=radar)
q = request.GET.get('q', None)
is_valid = False
if q:
form = SearchForm(request.GET)
if form.is_valid():
is_valid = True
template = loader.get_template(
'technology_radar/radar_blip_list_results.html')
else:
form = SearchForm()
if not is_valid:
template = loader.get_template('technology_radar/radar_blip_list.html')
context = {
'form': form,
'radar': radar_obj,
'blips': radar_obj.blips.all()
}
return HttpResponse(template.render(context, request))


def radar_detail_download(request, radar):
radar_obj = get_object_or_404(Radar, slug=radar)
renderer = import_class(getattr(settings, 'TECHNOLOGY_RADAR_RENDER_CLASS',
Expand Down

0 comments on commit 6e9d940

Please sign in to comment.