-
Notifications
You must be signed in to change notification settings - Fork 3
/
materialized_view.py
62 lines (49 loc) · 1.85 KB
/
materialized_view.py
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
53
54
55
56
57
58
59
60
61
62
from model import (
MaterializedWork,
MaterializedWorkWithGenre,
)
from feed import WorkFeed
class MaterializedWorkLaneFeed(WorkFeed):
"""A WorkFeed where all the works come from a predefined lane."""
active_facet_for_field = {
MaterializedWork.sort_title : "title",
MaterializedWork.sort_author : "author",
}
order_facet_to_database_field = {
"title" : MaterializedWork.sort_title,
"author" : MaterializedWork.sort_author,
}
default_sort_order = [
MaterializedWork.sort_title, MaterializedWork.sort_author,
MaterializedWork.license_pool_id
]
license_pool_field = MaterializedWork.license_pool
@classmethod
def factory(self, lane, *args, **kwargs):
if lane.genres:
feed = MaterializedWorkWithGenreLaneFeed(
lane, *args, **kwargs)
else:
feed = MaterializedWorkLaneFeed(lane, *args, **kwargs)
return feed
def __init__(self, lane, *args, **kwargs):
self.lane = lane
super(MaterializedWorkLaneFeed, self).__init__(*args, **kwargs)
def base_query(self, _db):
return self.lane.materialized_works(self.languages)
class MaterializedWorkWithGenreLaneFeed(MaterializedWorkLaneFeed):
"""A WorkFeed where all the works come from a predefined lane."""
active_facet_for_field = {
MaterializedWorkWithGenre.sort_title : "title",
MaterializedWorkWithGenre.sort_author : "author",
}
order_facet_to_database_field = {
"title" : MaterializedWorkWithGenre.sort_title,
"author" : MaterializedWorkWithGenre.sort_author,
}
default_sort_order = [
MaterializedWorkWithGenre.sort_title,
MaterializedWorkWithGenre.sort_author,
MaterializedWorkWithGenre.license_pool_id,
]
license_pool_field = MaterializedWorkWithGenre.license_pool