Commit 39e1538f authored by luxcem's avatar luxcem

Adds a view for representatives details and a (embryonic) search

parent 09d2f394
......@@ -43,4 +43,4 @@ coverage.xml
*.mo
*.pot
# Django stuff:
*.log
\ No newline at end of file
*.log
......@@ -68,9 +68,17 @@ WSGI_APPLICATION = 'memopol.wsgi.application'
# https://docs.djangoproject.com/en/1.7/ref/settings/#databases
DATABASES = {
'default': {
'sqlite': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
},
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'memopol_dev',
'USER': 'dj',
'PASSWORD': "test",
'HOST': 'localhost',
'PORT': '',
}
}
......
- extends "base.html"
- block content
.row
.large-8.columns
- for representative in representative_list
.row
- include 'memopol_representatives/representative_block.html'
.large-4.columns
%p
hello
- include 'memopol_representatives/search.html'
%table
- for representative in representatives
%tr
- include 'memopol_representatives/representative_block.html'
.pagination
%span.step-links
- if representatives.has_previous
%a{'href': '?={queries.urlencode}&page=={representatives.previous_page_number}'} previous
%span.current
Page ={representatives.number} of ={representatives.paginator.num_pages}
- if representatives.has_next
%a{'href': '?={queries.urlencode}&page=={representatives.next_page_number}'} next
%p.small-2.columns
%img{'src':'={representative.photo}'}/
%p.small-4.columns
= representative.full_name
[ ={representative.country.code} ]
%td<
%a{'href': "{% url 'representatives.detail' ={representative.id} %}"}
%img{'src':'={representative.photo}'}/
%p.small-6.columns
%td<
%a{'href': "{% url 'representatives.detail' ={representative.id} %}"}
={representative.full_name} [={representative.country.code}]
%td<
- for mandate in representative.mandate_set.all
={mandate.group.name} - ={mandate.end_date} - ={mandate.active}
={mandate.group.name}
%br/a
<td>
<a href="{% url 'representatives:view' representative.id %}">
<img src="{{ representative.photo }}" />
</a>
</td>
<td>
<a href="{% url 'representatives:view' representative.id %}">
{{ representative.full_name }}&nbsp;[{{ representative.country.code }}]
</a>
</td>
<form action="{% url 'representatives:index' %}" method="get">
{% csrf_token %}
<label for="search">Search : </label>
<input id="search" type="text" name="search">
<input type="submit" value="Go">
</form>
{% extends 'base.html' %}
{% block content %}
<a href="{% url 'representatives:index' %}">Back</a>
<p style="float: left">
<img src="{{ representative.photo }}">
</p>
<h1>{{ representative.full_name }}</h1>
<p>
{{ representative.country.name }} {{ representative.gender }} <br>
Born in {{ representative.birth_place }} the {{ representative.birth_date }} <br>
</p>
<h2 style="clear: both">Mandates</h2>
{% for mandate in representative.mandate_set.all %}
<div class="mandate">
<h3>
{{ mandate.group.name }}
<small>
{{ mandate.role }}
</small>
</h3>
<p>
{{ mandate.begin_date }} to {{ mandate.end_date }} <br>
<strong>{{ mandate.group.kind }}</strong> : <em>{{ mandate.group.name }} ({{ mandate.group.abbreviation }})</em> <br>
Constituency : {{ mandate.constituency.name }} <br>
</p>
</div>
<hr>
{% endfor %}
{% endblock %}
......@@ -2,6 +2,8 @@ from django.conf.urls import patterns, include, url
from memopol_representatives import views
urlpatterns = patterns('',
url(r'^$', views.IndexView.as_view(), name='index'),
urlpatterns = patterns(
'',
url(r'^$', views.index, name='index'),
url(r'^view/(?P<num>\d+)$', views.view, name='view'),
)
# from django.shortcuts import render
from django.views import generic
from django.shortcuts import render, get_object_or_404
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.db.models import Q
from representatives.models import Representative
class IndexView(generic.ListView):
template_name = 'memopol_representatives/list.html'
def index(request):
context = {}
if request.GET.get('search'):
search = request.GET.get('search')
representative_list = Representative.objects.filter(
Q(full_name__icontains=search)
)
queries_without_page = request.GET.copy()
if 'page' in queries_without_page:
del queries_without_page['page']
context['queries'] = queries_without_page
else:
representative_list = Representative.objects.all()
def get_queryset(self):
return Representative.objects.all()
paginator = Paginator(representative_list, 5)
page = request.GET.get('page')
try:
representatives = paginator.page(page)
except PageNotAnInteger:
representatives = paginator.page(1)
except EmptyPage:
representatives = paginator.page(paginator.num_pages)
context['representatives'] = representatives
return render(
request,
'memopol_representatives/list.html',
context
)
def view(request, num):
representative = get_object_or_404(Representative, pk=num)
return render(
request,
'memopol_representatives/view.html',
{'representative': representative}
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment