Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
TAlone
memopol
Commits
39e1538f
Commit
39e1538f
authored
Mar 13, 2015
by
luxcem
Browse files
Adds a view for representatives details and a (embryonic) search
parent
09d2f394
Changes
11
Hide whitespace changes
Inline
Side-by-side
.gitignore
View file @
39e1538f
...
@@ -43,4 +43,4 @@ coverage.xml
...
@@ -43,4 +43,4 @@ coverage.xml
*.mo
*.mo
*.pot
*.pot
# Django stuff:
# Django stuff:
*.log
*.log
\ No newline at end of file
memopol/.gitignore
0 → 100644
View file @
39e1538f
settings.py
memopol/settings.py
→
memopol/settings.py
.example
View file @
39e1538f
...
@@ -68,9 +68,17 @@ WSGI_APPLICATION = 'memopol.wsgi.application'
...
@@ -68,9 +68,17 @@ WSGI_APPLICATION = 'memopol.wsgi.application'
# https://docs.djangoproject.com/en/1.7/ref/settings/#databases
# https://docs.djangoproject.com/en/1.7/ref/settings/#databases
DATABASES = {
DATABASES = {
'
default
'
:
{
'
sqlite
': {
'ENGINE': 'django.db.backends.sqlite3',
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.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': '',
}
}
}
}
...
...
memopol_representatives/templates/memopol_representatives/list.haml
View file @
39e1538f
-
extends
"base.html"
-
extends
"base.html"
-
block
content
-
block
content
.row
-
include
'memopol_representatives/search.html'
.large-8.columns
-
for
representative
in
representative_list
%table
.row
-
for
representative
in
representatives
-
include
'memopol_representatives/representative_block.html'
%tr
-
include
'memopol_representatives/representative_block.html'
.large-4.columns
%p
.pagination
hello
%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
memopol_representatives/templates/memopol_representatives/representative_block.haml
View file @
39e1538f
%p
.small-2.columns
%td<
%img
{
'src'
:
'
=
{
representative
.
photo
}
'
}
/
%a
{
'href'
:
"{% url 'representatives.detail' ={representative.id} %}"
}
%p
.small-4.columns
%img
{
'src'
:
'
=
{
representative
.
photo
}
'
}
/
=
representative
.
full_name
[ ={representative.country.code} ]
%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
-
for
mandate
in
representative
.
mandate_set
.
all
={
mandate
.
group
.
name
}
-
=
{
mandate
.
end_date
}
-
=
{
mandate
.
active
}
={
mandate
.
group
.
name
}
%br
/
a
%br
/
a
memopol_representatives/templates/memopol_representatives/representative_block.html
0 → 100644
View file @
39e1538f
<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 }}
[{{ representative.country.code }}]
</a>
</td>
memopol_representatives/templates/memopol_representatives/search.html
0 → 100644
View file @
39e1538f
<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>
memopol_representatives/templates/memopol_representatives/view.html
0 → 100644
View file @
39e1538f
{% 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 %}
memopol_representatives/urls.py
View file @
39e1538f
...
@@ -2,6 +2,8 @@ from django.conf.urls import patterns, include, url
...
@@ -2,6 +2,8 @@ from django.conf.urls import patterns, include, url
from
memopol_representatives
import
views
from
memopol_representatives
import
views
urlpatterns
=
patterns
(
''
,
urlpatterns
=
patterns
(
url
(
r
'^$'
,
views
.
IndexView
.
as_view
(),
name
=
'index'
),
''
,
url
(
r
'^$'
,
views
.
index
,
name
=
'index'
),
url
(
r
'^view/(?P<num>\d+)$'
,
views
.
view
,
name
=
'view'
),
)
)
memopol_representatives/views.py
View file @
39e1538f
# from django.shortcuts import render
from
django.shortcuts
import
render
,
get_object_or_404
from
django.views
import
generic
from
django.core.paginator
import
Paginator
,
EmptyPage
,
PageNotAnInteger
from
django.db.models
import
Q
from
representatives.models
import
Representative
from
representatives.models
import
Representative
class
IndexView
(
generic
.
ListView
):
def
index
(
request
):
template_name
=
'memopol_representatives/list.html'
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
):
paginator
=
Paginator
(
representative_list
,
5
)
return
Representative
.
objects
.
all
()
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
}
)
static/.gitignore
0 → 100644
View file @
39e1538f
CACHE
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment