Toutes les briques sont maintenant triées comme sur l'accueil.
Les chercheurs peuvent en plus être triés par nom, établissement ou pays.
On garde tout de même un tri par pertinence lorsqu'on fait une recherche par
mots-clés dans les ressources et les sites.
Demande #722.
def index(request):
"""Répertoire des chercheurs"""
search_form = RepertoireSearchForm(request.GET)
- chercheurs = search_form.get_query_set()
+ chercheurs = search_form.get_query_set().select_related('personne', 'etablissement', 'etablissement__pays', 'etablissement_autre_pays')
+ sort = request.GET.get('tri')
+ if sort is not None and sort.endswith('_desc'):
+ sort = sort[:-5]
+ direction = '-'
+ else:
+ direction = ''
+ if sort == 'nom':
+ chercheurs = chercheurs.order_by(direction + 'personne__nom', 'personne__prenom', '-date_modification')
+ elif sort == 'etablissement':
+ chercheurs = chercheurs.extra(select=dict(nom_etablissement='IFNULL(ref_etablissement.nom, chercheurs_chercheur.etablissement_autre_nom)'),
+ order_by=[direction + 'nom_etablissement', '-date_modification'])
+ elif sort == 'pays':
+ chercheurs = chercheurs.extra(select=dict(pays_etablissement='IFNULL(ref_pays.nom, T5.nom)'),
+ order_by=[direction + 'pays_etablissement', '-date_modification'])
+ else:
+ chercheurs = chercheurs.order_by('-date_modification')
+
nb_chercheurs = chercheurs.count()
return render_to_response("chercheurs/index.html",
dict(chercheurs=chercheurs, nb_chercheurs=nb_chercheurs, search_form=search_form),
region = self.cleaned_data['region']
if region:
records = records.filter_region(region)
+
+ if not q:
+ """Montrer les résultats les plus récents si on n'a pas fait
+ une recherche par mots-clés."""
+ records = records.order_by('-id')
return records.all()
class ActualiteSearchForm(forms.Form):
class Meta:
db_table = u'actualite'
- ordering = ["-date",]
+ ordering = ["-date"]
def __unicode__ (self):
return "%s" % (self.titre)
discipline_active=discipline_active, region_active=region_active,
request=context['request'])
+@register.inclusion_tag('sort_link.html', takes_context=True)
+def sort_link(context, field, label):
+ request = context['request']
+ params = request.GET.copy()
+ current_sort = params.get('tri')
+ if current_sort == field:
+ sort = field + '_desc'
+ indicator = u' (croissant)'
+ else:
+ sort = field
+ if current_sort == field + '_desc':
+ indicator = u' (décroissant)'
+ else:
+ indicator = ''
+
+ params['tri'] = sort
+ url = request.path + '?' + params.urlencode()
+ return dict(label=label, url=url, indicator=indicator)
+
class URLNode(template.Node):
def __init__(self, view_name, args, kwargs, asvar):
self.view_name = view_name
def test_chercheurs(self):
self.check_status_200('/chercheurs/')
+ self.check_status_200('/chercheurs/', dict(tri='nom'))
+ self.check_status_200('/chercheurs/', dict(tri='nom_desc'))
+ self.check_status_200('/chercheurs/', dict(tri='etablissement'))
+ self.check_status_200('/chercheurs/', dict(tri='etablissement_desc'))
+ self.check_status_200('/chercheurs/', dict(tri='pays'))
+ self.check_status_200('/chercheurs/', dict(tri='pays_desc'))
def test_sites(self):
self.check_status_200('/sites/')
kwargs['region'] = region
return HttpResponseRedirect(reverse('savoirs.views.index', kwargs=kwargs))
- actualites = Actualite.objects.search(query)
- evenements = Evenement.objects.search(query)
+ actualites = Actualite.objects.search(query).order_by('-date')
+ evenements = Evenement.objects.search(query).order_by('-debut')
ressources = Record.objects.search(query)
- chercheurs = Chercheur.objects.search(query)
+ chercheurs = Chercheur.objects.search(query).order_by('-date_modification')
sites = Site.objects.search(query)
if discipline:
discipline = Discipline.objects.get(pk=discipline)
'django.contrib.auth.middleware.AuthenticationMiddleware',
'djangoflash.middleware.FlashMiddleware',
'pagination.middleware.PaginationMiddleware',
- 'django_sorting.middleware.SortingMiddleware',
'django.middleware.doc.XViewMiddleware',
)
'django.contrib.sessions',
'django.contrib.admin',
'pagination',
- 'django_sorting',
'compressor',
'django_roa',
'savoirs',
pays = self.cleaned_data["pays"]
if pays:
sites = sites.filter_pays(pays=pays)
+
+ if not q:
+ sites = sites.order_by('-date_maj')
+
return sites.all()
DROP KEY courriel,
ADD KEY courriel (courriel);
+-- Certains chercheurs ont un nom qui commence par un espace
+
+UPDATE chercheurs_personne SET nom = TRIM(nom), prenom = TRIM(prenom);
+UPDATE chercheurs_chercheur SET etablissement_autre_nom = TRIM(etablissement_autre_nom);
+UPDATE chercheurs_chercheur SET diplome = '' WHERE diplome = '.';
+UPDATE chercheurs_chercheur SET etablissement_autre_nom = '' WHERE etablissement_autre_nom = '.';
+UPDATE chercheurs_chercheur SET theme_recherche = '' WHERE theme_recherche = '.';
{% extends "container_base.html" %}
{% load pagination_tags %}
{% load form_tags %}
+{% load sep %}
{% block contenu %}
{% autopaginate chercheurs 20 %}
<div class="centre">{% paginate %}</div>
<table id="repertoire">
<tr>
- <th>Nom</th>
- <th>Établissement</th>
- <th>Localisation</th>
+ <th>{% sort_link "nom" "Nom" %}</th>
+ <th>{% sort_link "etablissement" "Établissement" %}</th>
+ <th>{% sort_link "pays" "Pays" %}</th>
</tr>
{% for chercheur in chercheurs %}
<tr class="{% cycle 'odd' 'notodd' %}">
<td><a href="{% url chercheurs.views.retrieve id=chercheur.id %}">{{ chercheur }}</a></td>
- <td>{% firstof chercheur.etablissement chercheur.etablissement_autre_nom %}</td>
- <td>{% firstof chercheur.etablissement.pays chercheur.etablissement_autre_pays %}</td>
+ <td>{% firstof chercheur.etablissement.nom chercheur.etablissement_autre_nom %}</td>
+ <td>{% firstof chercheur.etablissement.pays.nom chercheur.etablissement_autre_pays.nom %}</td>
</tr>
{% endfor %}
</table>
{% extends "container_base.html" %}
{% load pagination_tags %}
-{% load sorting_tags %}
{% block contenu %}
{% autopaginate sites 10 %}
--- /dev/null
+<a href="{{ url }}">{{ label }}</a>{{ indicator }}