Commit | Line | Data |
---|---|---|
3121c13c OL |
1 | # -*- encoding: utf-8 -*- |
2 | ||
3 | from rh_v1.models import Poste, Dossier | |
4 | from django.db.models import Q | |
5 | ||
6 | class Responsable(object): | |
7 | ||
8 | def get_query(self,q,request): | |
9 | return Poste.objects.filter( | |
10 | Q(poste1__complement1__icontains=q) | | |
11 | Q(type_poste__nom__icontains=q) | | |
12 | Q(poste1__employe__nom__icontains=q) | | |
13 | Q(poste1__employe__prenom__icontains=q) | |
14 | ).distinct() | |
15 | ||
16 | def format_result(self, poste): | |
17 | dossiers = poste.poste1.all().order_by("-id") | |
18 | complement1 = "" | |
19 | employe = "" | |
20 | if len(dossiers) > 0: | |
21 | complement1 = dossiers[0].complement1 | |
22 | employe = unicode(dossiers[0].employe) | |
23 | return "[%s] %s %s (%s) (%s)" % (poste.implantation.id, poste.type_poste.nom, complement1, poste.id, employe) | |
24 | ||
25 | def format_item(self, poste): | |
26 | """ the display of a currently selected object in the area below the search box. html is OK """ | |
27 | return self.format_result(poste) | |
28 | ||
29 | def get_objects(self, ids): | |
30 | """ given a list of ids, return the objects ordered as you would like them on the admin page. | |
31 | this is for displaying the currently selected items (in the case of a ManyToMany field) | |
32 | """ | |
33 | return Poste.objects.filter(pk__in=ids) |