-
Notifications
You must be signed in to change notification settings - Fork 2k
/
tag.py
72 lines (56 loc) · 2.16 KB
/
tag.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
63
64
65
66
67
68
69
70
71
72
from pylons.i18n import _
from pylons import request, c, config
import ckan.logic as logic
import ckan.model as model
import ckan.lib.base as base
import ckan.lib.helpers as h
LIMIT = 25
class TagController(base.BaseController):
def __before__(self, action, **env):
base.BaseController.__before__(self, action, **env)
try:
context = {'model': model, 'user': c.user or c.author}
logic.check_access('site_read', context)
except logic.NotAuthorized:
base.abort(401, _('Not authorized to see this page'))
def index(self):
c.q = request.params.get('q', '')
context = {'model': model, 'session': model.Session,
'user': c.user or c.author, 'for_view': True}
data_dict = {'all_fields': True}
if c.q:
page = int(request.params.get('page', 1))
data_dict['q'] = c.q
data_dict['limit'] = LIMIT
data_dict['offset'] = (page - 1) * LIMIT
data_dict['return_objects'] = True
results = logic.get_action('tag_list')(context, data_dict)
if c.q:
c.page = h.Page(
collection=results,
page=page,
item_count=len(results),
items_per_page=LIMIT
)
c.page.items = results
else:
c.page = h.AlphaPage(
collection=results,
page=request.params.get('page', 'A'),
alpha_attribute='name',
other_text=_('Other'),
)
return base.render('tag/index.html')
def read(self, id):
context = {'model': model, 'session': model.Session,
'user': c.user or c.author, 'for_view': True}
data_dict = {'id': id}
try:
c.tag = logic.get_action('tag_show')(context, data_dict)
except logic.NotFound:
base.abort(404, _('Tag not found'))
if h.asbool(config.get('ckan.legacy_templates', False)):
return base.render('tag/read.html')
else:
h.redirect_to(controller='package', action='search',
tags=c.tag.get('name'))