1 from mygpo
.core
.models
import SanitizingRule
2 from mygpo
.cache
import cache_result
3 from mygpo
.couch
import get_main_database
6 class SanitizingRuleStub(object):
10 @cache_result(timeout
=60*60)
11 def sanitizingrules_by_obj_type(obj_type
):
12 r
= SanitizingRule
.view('sanitizing_rules/by_target',
14 startkey
= [obj_type
, None],
15 endkey
= [obj_type
, {}],
19 obj
= SanitizingRuleStub()
21 obj
.applies_to
= list(rule
.applies_to
)
22 obj
.search
= rule
.search
23 obj
.replace
= rule
.replace
24 obj
.priority
= rule
.priority
25 obj
.description
= rule
.description
29 @cache_result(timeout
=60*60)
30 def sanitizingrule_for_slug(slug
):
31 r
= SanitizingRule
.view('sanitizing_rules/by_slug',
36 return r
.one() if r
else None
39 def missing_slug_count(doc_type
, start
, end
):
40 db
= get_main_database()
41 res
= db
.view('slugs/missing',
42 startkey
= [doc_type
] + end
,
43 endkey
= [doc_type
] + start
,
49 return res
.first()['value'] if res
else 0
52 def missing_slugs(doc_type
, start
, end
, wrapper
, **kwargs
):
54 db
= get_main_database()
55 return multi_request_view(db
, 'slugs/missing',
56 startkey
= [doc_type
] + end
,
57 endkey
= [doc_type
] + start
,