Project

General

Profile

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

calebasse / calebasse / personnes / lookup.py @ 48a85f96

1

    
2
from ajax_select import LookupChannel
3
from models import Worker
4

    
5
class WorkerLookup(LookupChannel):
6
    model = Worker
7
    search_field = 'display_name'
8

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

    
13
    def get_result(self, obj):
14
        return self.format_item_display(obj)
15

    
16
    def format_match(self, obj):
17
        return self.format_item_display(obj)
18

    
19
    def format_item_display(self,obj):
20
        text = obj.last_name.upper() + ' ' + obj.first_name
21
        return unicode(text)
22

    
23
class IntervenantLookup(WorkerLookup):
24
    model = Worker
25
    search_field = 'display_name'
26

    
27
    def get_query(self,q,request):
28
        qs = super(IntervenantLookup, self).get_query(q,request)
29
        return qs.filter(type__intervene=True)
(4-4/8)