Project

General

Profile

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

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

1

    
2
from calebasse.lookups import CalebasseLookup
3

    
4
from models import Worker
5

    
6
class WorkerLookup(CalebasseLookup):
7
    model = Worker
8
    search_field = 'display_name'
9

    
10
    def get_query(self,q,request):
11
        kwargs = { "%s__icontains" % self.search_field : q }
12
        return self.model.objects.filter(enabled=True).filter(**kwargs).order_by(self.search_field)
13

    
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
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)
(4-4/8)