Skip to content
GitLab
Explorer
Connexion
Navigation principale
Rechercher ou aller à…
Projet
D
django-representatives
Gestion
Activité
Membres
Labels
Programmation
Tickets
Tableaux des tickets
Jalons
Code
Requêtes de fusion
Dépôt
Branches
Validations
Étiquettes
Graphe du dépôt
Comparer les révisions
Compilation
Pipelines
Jobs
Planifications de pipeline
Artéfacts
Déploiement
Releases
Registre de conteneurs
Registre de modèles
Opération
Environnements
Surveillance
Incidents
Analyse
Données d'analyse des chaînes de valeur
Analyse des contributeurs
Données d'analyse CI/CD
Données d'analyse du dépôt
Expériences du modèle
Aide
Aide
Support
Documentation de GitLab
Comparer les forfaits GitLab
Forum de la communauté
Contribuer à GitLab
Donner votre avis
Conditions générales et politique de confidentialité
Raccourcis clavier
?
Extraits de code
Groupes
Projets
Ce projet est archivé. Le dépôt et les autres ressources du projet sont en lecture seule.
Afficher davantage de fils d'Ariane
La Quadrature du Net
Political Memory
django-representatives
Validations
0a6b37c3
Valider
0a6b37c3
rédigé
9 years ago
par
Jamesie Pic
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
Added views
parent
4d0ccecb
Branches
Branches contenant la validation
Étiquettes
Étiquettes contenant la validation
Aucune requête de fusion associée trouvée
Modifications
3
Masquer les modifications d'espaces
En ligne
Côte à côte
Affichage de
3 fichiers modifiés
representatives/models.py
+4
-1
4 ajouts, 1 suppression
representatives/models.py
representatives/urls.py
+32
-0
32 ajouts, 0 suppression
representatives/urls.py
representatives/views.py
+87
-3
87 ajouts, 3 suppressions
representatives/views.py
avec
123 ajouts
et
4 suppressions
representatives/models.py
+
4
−
1
Voir le fichier @
0a6b37c3
# coding: utf-8
import
hashlib
from
datetime
import
datetime
,
date
from
datetime
import
datetime
from
django.db
import
models
from
django.utils.encoding
import
smart_str
,
smart_unicode
...
...
@@ -114,6 +114,9 @@ class Representative(HashableModel, TimeStampedModel):
class
Meta
:
ordering
=
[
'
last_name
'
,
'
first_name
'
]
def
get_absolute_url
(
self
):
return
reverse
(
'
representatives:representative-detail
'
,
args
=
(
self
.
slug
,))
# Contact related models
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
representatives/urls.py
0 → 100644
+
32
−
0
Voir le fichier @
0a6b37c3
from
django.conf.urls
import
url
from
.
import
views
urlpatterns
=
[
url
(
r
'
^representative/(?P<group_kind>\w+)/(?P<group>.+)/$
'
,
views
.
RepresentativeList
.
as_view
(),
name
=
'
representative-list
'
),
url
(
r
'
^representative/(?P<slug>[-\w]+)/$
'
,
views
.
RepresentativeDetail
.
as_view
(),
name
=
'
representative-detail
'
),
url
(
r
'
representative/
'
,
views
.
RepresentativeList
.
as_view
(),
name
=
'
representative-list
'
),
url
(
r
'
^groups/$
'
,
views
.
GroupList
.
as_view
(),
name
=
'
group-list
'
),
url
(
r
'
^groups/(?P<kind>\w+)/$
'
,
views
.
GroupList
.
as_view
(),
name
=
'
group-list
'
),
]
Ce diff est replié.
Cliquez pour l'agrandir.
representatives/views.py
+
87
−
3
Voir le fichier @
0a6b37c3
import
datetime
from
django.db
import
models
from
django.views
import
generic
from
django.utils.text
import
slugify
from
.models
import
Mandate
from
.models
import
Mandate
,
Representative
,
Group
class
RepresentativeViewMixin
(
object
):
...
...
@@ -42,11 +44,93 @@ class RepresentativeViewMixin(object):
representative
.
country
=
m
.
constituency
.
country
if
(
m
.
end_date
>
today
and
m
.
group
.
kind
==
'
group
'
and
not
representative
.
main_mandate
):
not
representative
.
main_mandate
):
representative
.
main_mandate
=
m
if
representative
.
country
and
not
representative
.
main_mandate
:
if
representative
.
country
and
representative
.
main_mandate
:
break
return
representative
class
RepresentativeList
(
RepresentativeViewMixin
,
generic
.
ListView
):
def
get_context_data
(
self
,
**
kwargs
):
c
=
super
(
RepresentativeList
,
self
).
get_context_data
(
**
kwargs
)
c
[
'
object_list
'
]
=
[
self
.
add_representative_country_and_main_mandate
(
r
)
for
r
in
c
[
'
object_list
'
]
]
return
c
def
search_filter
(
self
,
qs
):
search
=
self
.
request
.
GET
.
get
(
'
search
'
,
None
)
if
search
:
qs
=
qs
.
filter
(
slug__icontains
=
slugify
(
search
))
return
qs
def
group_filter
(
self
,
qs
):
group_kind
=
self
.
kwargs
.
get
(
'
group_kind
'
,
None
)
group
=
self
.
kwargs
.
get
(
'
group
'
,
None
)
if
group_kind
and
group
:
if
group
.
isnumeric
():
# Search group based on pk
qs
=
qs
.
filter
(
mandates__group_id
=
int
(
group
),
mandates__end_date__gte
=
datetime
.
now
()
)
else
:
# Search group based on abbreviation
qs
=
qs
.
filter
(
mandates__group__name
=
group
,
mandates__group__kind
=
group_kind
,
mandates__end_date__gte
=
datetime
.
date
.
today
()
)
return
qs
def
prefetch_related
(
self
,
qs
):
qs
=
qs
.
select_related
(
'
score
'
)
qs
=
self
.
prefetch_for_representative_country_and_main_mandate
(
qs
)
return
qs
def
get_queryset
(
self
):
qs
=
Representative
.
objects
.
filter
(
active
=
True
)
qs
=
self
.
group_filter
(
qs
)
qs
=
self
.
search_filter
(
qs
)
qs
=
self
.
prefetch_related
(
qs
)
return
qs
class
RepresentativeDetail
(
RepresentativeViewMixin
,
generic
.
DetailView
):
def
get_queryset
(
self
):
qs
=
super
(
RepresentativeDetail
,
self
).
get_queryset
()
qs
=
self
.
prefetch_for_representative_country_and_main_mandate
(
qs
)
return
qs
def
get_context_data
(
self
,
**
kwargs
):
c
=
super
(
RepresentativeDetail
,
self
).
get_context_data
(
**
kwargs
)
self
.
add_representative_country_and_main_mandate
(
c
[
'
object
'
])
c
[
'
votes
'
]
=
c
[
'
object
'
].
votes
.
all
()
c
[
'
mandates
'
]
=
c
[
'
object
'
].
mandates
.
all
()
c
[
'
positions
'
]
=
c
[
'
object
'
].
positions
.
filter
(
published
=
True
).
prefetch_related
(
'
tags
'
)
return
c
class
GroupList
(
generic
.
ListView
):
def
get_queryset
(
self
):
qs
=
Group
.
objects
.
filter
(
mandates__end_date__gte
=
datetime
.
date
.
today
()
)
kind
=
self
.
kwargs
.
get
(
'
kind
'
,
None
)
if
kind
:
qs
=
qs
.
filter
(
kind
=
kind
).
distinct
()
return
qs
Ce diff est replié.
Cliquez pour l'agrandir.
Aperçu
0%
Chargement en cours
Veuillez réessayer
ou
joindre un nouveau fichier
.
Annuler
You are about to add
0
people
to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Enregistrer le commentaire
Annuler
Veuillez vous
inscrire
ou vous
se connecter
pour commenter