Project

General

Profile

Download (888 Bytes) Statistics
| Branch: | Tag: | Revision:

calebasse / calebasse / personnes / lookup.py @ 9090c9dd

1 c0f82cd1 Frédéric Péters
2 9f39f12f Jérôme Schneider
from calebasse.lookups import CalebasseLookup
3
4 c0f82cd1 Frédéric Péters
from models import Worker
5
6 9f39f12f Jérôme Schneider
class WorkerLookup(CalebasseLookup):
7 c0f82cd1 Frédéric Péters
    model = Worker
8
    search_field = 'display_name'
9
10
    def get_query(self,q,request):
11
        kwargs = { "%s__icontains" % self.search_field : q }
12 dea76c1b Jérôme Schneider
        return self.model.objects.filter(enabled=True).filter(**kwargs).order_by(self.search_field)
13 4e4c4c50 Jérôme Schneider
14
    def get_result(self, obj):
15
        return self.format_item_display(obj)
16
17
    def format_match(self, obj):
18
        return self.format_item_display(obj)
19
20
    def format_item_display(self,obj):
21
        text = obj.last_name.upper() + ' ' + obj.first_name
22
        return unicode(text)
23
24 48a85f96 Jérôme Schneider
class IntervenantLookup(WorkerLookup):
25
    model = Worker
26
    search_field = 'display_name'
27
28
    def get_query(self,q,request):
29
        qs = super(IntervenantLookup, self).get_query(q,request)
30
        return qs.filter(type__intervene=True)