~widelands-dev/widelands-website/django_staticfiles

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from haystack import indexes
from wlhelp.models import Worker, Ware, Building
from haystack.fields import DateField
from datetime import date


class WorkerIndex(indexes.SearchIndex, indexes.Indexable):

    """Create a search index. Changes made here need to be reindexed. Defined
    fields are stored in the index, so when displaying the result the data is
    read from the index and do not hit the database.

    Except the 'text' field all defined fields will be in the index.

    'text' indicates the template where the concatenated data
           is gathered and the search runs over.

    """

    text = indexes.CharField(document=True, use_template=True)
    # To get date related search working
    # we assume the index is always up to date
    date = DateField(default=date.today())
    displayname = indexes.CharField(model_attr='displayname')
    help = indexes.CharField(model_attr='help')

    def get_model(self):
        return Worker

class WareIndex(indexes.SearchIndex, indexes.Indexable):

    text = indexes.CharField(document=True, use_template=True)
    # To get date related search working
    # we assume the index is always up to date 
    date = DateField(default=date.today())
    displayname = indexes.CharField(model_attr='displayname')
    help = indexes.CharField(model_attr='help')

    def get_model(self):
        return Ware

class BuildingIndex(indexes.SearchIndex, indexes.Indexable):

    text = indexes.CharField(document=True, use_template=True)
    # To get date related search working
    # we assume the index is always up to date
    date = DateField(default=date.today())
    displayname = indexes.CharField(model_attr='displayname')
    help = indexes.CharField(model_attr='help')

    def get_model(self):
        return Building