##// END OF EJS Templates
flake8: fix E226 missing whitespace around arithmetic operator
Mads Kiilerich -
r7726:2d8c254b default
parent child Browse files
Show More
@@ -1,179 +1,179 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 # This program is free software: you can redistribute it and/or modify
2 # This program is free software: you can redistribute it and/or modify
3 # it under the terms of the GNU General Public License as published by
3 # it under the terms of the GNU General Public License as published by
4 # the Free Software Foundation, either version 3 of the License, or
4 # the Free Software Foundation, either version 3 of the License, or
5 # (at your option) any later version.
5 # (at your option) any later version.
6 #
6 #
7 # This program is distributed in the hope that it will be useful,
7 # This program is distributed in the hope that it will be useful,
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 # GNU General Public License for more details.
10 # GNU General Public License for more details.
11 #
11 #
12 # You should have received a copy of the GNU General Public License
12 # You should have received a copy of the GNU General Public License
13 # along with this program. If not, see <http://www.gnu.org/licenses/>.
13 # along with this program. If not, see <http://www.gnu.org/licenses/>.
14 """
14 """
15 kallithea.controllers.forks
15 kallithea.controllers.forks
16 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
16 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
17
17
18 forks controller for Kallithea
18 forks controller for Kallithea
19
19
20 This file was forked by the Kallithea project in July 2014.
20 This file was forked by the Kallithea project in July 2014.
21 Original author and date, and relevant copyright and licensing information is below:
21 Original author and date, and relevant copyright and licensing information is below:
22 :created_on: Apr 23, 2011
22 :created_on: Apr 23, 2011
23 :author: marcink
23 :author: marcink
24 :copyright: (c) 2013 RhodeCode GmbH, and others.
24 :copyright: (c) 2013 RhodeCode GmbH, and others.
25 :license: GPLv3, see LICENSE.md for more details.
25 :license: GPLv3, see LICENSE.md for more details.
26 """
26 """
27
27
28 import logging
28 import logging
29 import traceback
29 import traceback
30
30
31 import formencode
31 import formencode
32 from formencode import htmlfill
32 from formencode import htmlfill
33 from tg import request
33 from tg import request
34 from tg import tmpl_context as c
34 from tg import tmpl_context as c
35 from tg.i18n import ugettext as _
35 from tg.i18n import ugettext as _
36 from webob.exc import HTTPFound
36 from webob.exc import HTTPFound
37
37
38 import kallithea.lib.helpers as h
38 import kallithea.lib.helpers as h
39 from kallithea.config.routing import url
39 from kallithea.config.routing import url
40 from kallithea.lib.auth import HasPermissionAny, HasPermissionAnyDecorator, HasRepoPermissionLevel, HasRepoPermissionLevelDecorator, LoginRequired
40 from kallithea.lib.auth import HasPermissionAny, HasPermissionAnyDecorator, HasRepoPermissionLevel, HasRepoPermissionLevelDecorator, LoginRequired
41 from kallithea.lib.base import BaseRepoController, render
41 from kallithea.lib.base import BaseRepoController, render
42 from kallithea.lib.page import Page
42 from kallithea.lib.page import Page
43 from kallithea.lib.utils2 import safe_int
43 from kallithea.lib.utils2 import safe_int
44 from kallithea.model.db import Repository, Ui, User, UserFollowing
44 from kallithea.model.db import Repository, Ui, User, UserFollowing
45 from kallithea.model.forms import RepoForkForm
45 from kallithea.model.forms import RepoForkForm
46 from kallithea.model.repo import RepoModel
46 from kallithea.model.repo import RepoModel
47 from kallithea.model.scm import AvailableRepoGroupChoices, ScmModel
47 from kallithea.model.scm import AvailableRepoGroupChoices, ScmModel
48
48
49
49
50 log = logging.getLogger(__name__)
50 log = logging.getLogger(__name__)
51
51
52
52
53 class ForksController(BaseRepoController):
53 class ForksController(BaseRepoController):
54
54
55 def __load_defaults(self):
55 def __load_defaults(self):
56 if HasPermissionAny('hg.create.write_on_repogroup.true')():
56 if HasPermissionAny('hg.create.write_on_repogroup.true')():
57 repo_group_perm_level = 'write'
57 repo_group_perm_level = 'write'
58 else:
58 else:
59 repo_group_perm_level = 'admin'
59 repo_group_perm_level = 'admin'
60 c.repo_groups = AvailableRepoGroupChoices(['hg.create.repository'], repo_group_perm_level)
60 c.repo_groups = AvailableRepoGroupChoices(['hg.create.repository'], repo_group_perm_level)
61
61
62 c.landing_revs_choices, c.landing_revs = ScmModel().get_repo_landing_revs()
62 c.landing_revs_choices, c.landing_revs = ScmModel().get_repo_landing_revs()
63
63
64 c.can_update = Ui.get_by_key('hooks', Ui.HOOK_UPDATE).ui_active
64 c.can_update = Ui.get_by_key('hooks', Ui.HOOK_UPDATE).ui_active
65
65
66 def __load_data(self):
66 def __load_data(self):
67 """
67 """
68 Load defaults settings for edit, and update
68 Load defaults settings for edit, and update
69 """
69 """
70 self.__load_defaults()
70 self.__load_defaults()
71
71
72 c.repo_info = c.db_repo
72 c.repo_info = c.db_repo
73 repo = c.db_repo.scm_instance
73 repo = c.db_repo.scm_instance
74
74
75 if c.repo_info is None:
75 if c.repo_info is None:
76 h.not_mapped_error(c.repo_name)
76 h.not_mapped_error(c.repo_name)
77 raise HTTPFound(location=url('repos'))
77 raise HTTPFound(location=url('repos'))
78
78
79 c.default_user_id = User.get_default_user().user_id
79 c.default_user_id = User.get_default_user().user_id
80 c.in_public_journal = UserFollowing.query() \
80 c.in_public_journal = UserFollowing.query() \
81 .filter(UserFollowing.user_id == c.default_user_id) \
81 .filter(UserFollowing.user_id == c.default_user_id) \
82 .filter(UserFollowing.follows_repository == c.repo_info).scalar()
82 .filter(UserFollowing.follows_repository == c.repo_info).scalar()
83
83
84 if c.repo_info.stats:
84 if c.repo_info.stats:
85 last_rev = c.repo_info.stats.stat_on_revision+1
85 last_rev = c.repo_info.stats.stat_on_revision + 1
86 else:
86 else:
87 last_rev = 0
87 last_rev = 0
88 c.stats_revision = last_rev
88 c.stats_revision = last_rev
89
89
90 c.repo_last_rev = repo.count() if repo.revisions else 0
90 c.repo_last_rev = repo.count() if repo.revisions else 0
91
91
92 if last_rev == 0 or c.repo_last_rev == 0:
92 if last_rev == 0 or c.repo_last_rev == 0:
93 c.stats_percentage = 0
93 c.stats_percentage = 0
94 else:
94 else:
95 c.stats_percentage = '%.2f' % ((float((last_rev)) /
95 c.stats_percentage = '%.2f' % ((float((last_rev)) /
96 c.repo_last_rev) * 100)
96 c.repo_last_rev) * 100)
97
97
98 defaults = RepoModel()._get_defaults(c.repo_name)
98 defaults = RepoModel()._get_defaults(c.repo_name)
99 # alter the description to indicate a fork
99 # alter the description to indicate a fork
100 defaults['description'] = ('fork of repository: %s \n%s'
100 defaults['description'] = ('fork of repository: %s \n%s'
101 % (defaults['repo_name'],
101 % (defaults['repo_name'],
102 defaults['description']))
102 defaults['description']))
103 # add suffix to fork
103 # add suffix to fork
104 defaults['repo_name'] = '%s-fork' % defaults['repo_name']
104 defaults['repo_name'] = '%s-fork' % defaults['repo_name']
105
105
106 return defaults
106 return defaults
107
107
108 @LoginRequired(allow_default_user=True)
108 @LoginRequired(allow_default_user=True)
109 @HasRepoPermissionLevelDecorator('read')
109 @HasRepoPermissionLevelDecorator('read')
110 def forks(self, repo_name):
110 def forks(self, repo_name):
111 p = safe_int(request.GET.get('page'), 1)
111 p = safe_int(request.GET.get('page'), 1)
112 repo_id = c.db_repo.repo_id
112 repo_id = c.db_repo.repo_id
113 d = []
113 d = []
114 for r in Repository.get_repo_forks(repo_id):
114 for r in Repository.get_repo_forks(repo_id):
115 if not HasRepoPermissionLevel('read')(r.repo_name, 'get forks check'):
115 if not HasRepoPermissionLevel('read')(r.repo_name, 'get forks check'):
116 continue
116 continue
117 d.append(r)
117 d.append(r)
118 c.forks_pager = Page(d, page=p, items_per_page=20)
118 c.forks_pager = Page(d, page=p, items_per_page=20)
119
119
120 if request.environ.get('HTTP_X_PARTIAL_XHR'):
120 if request.environ.get('HTTP_X_PARTIAL_XHR'):
121 return render('/forks/forks_data.html')
121 return render('/forks/forks_data.html')
122
122
123 return render('/forks/forks.html')
123 return render('/forks/forks.html')
124
124
125 @LoginRequired()
125 @LoginRequired()
126 @HasPermissionAnyDecorator('hg.admin', 'hg.fork.repository')
126 @HasPermissionAnyDecorator('hg.admin', 'hg.fork.repository')
127 @HasRepoPermissionLevelDecorator('read')
127 @HasRepoPermissionLevelDecorator('read')
128 def fork(self, repo_name):
128 def fork(self, repo_name):
129 c.repo_info = Repository.get_by_repo_name(repo_name)
129 c.repo_info = Repository.get_by_repo_name(repo_name)
130 if not c.repo_info:
130 if not c.repo_info:
131 h.not_mapped_error(repo_name)
131 h.not_mapped_error(repo_name)
132 raise HTTPFound(location=url('home'))
132 raise HTTPFound(location=url('home'))
133
133
134 defaults = self.__load_data()
134 defaults = self.__load_data()
135
135
136 return htmlfill.render(
136 return htmlfill.render(
137 render('forks/fork.html'),
137 render('forks/fork.html'),
138 defaults=defaults,
138 defaults=defaults,
139 encoding="UTF-8",
139 encoding="UTF-8",
140 force_defaults=False)
140 force_defaults=False)
141
141
142 @LoginRequired()
142 @LoginRequired()
143 @HasPermissionAnyDecorator('hg.admin', 'hg.fork.repository')
143 @HasPermissionAnyDecorator('hg.admin', 'hg.fork.repository')
144 @HasRepoPermissionLevelDecorator('read')
144 @HasRepoPermissionLevelDecorator('read')
145 def fork_create(self, repo_name):
145 def fork_create(self, repo_name):
146 self.__load_defaults()
146 self.__load_defaults()
147 c.repo_info = Repository.get_by_repo_name(repo_name)
147 c.repo_info = Repository.get_by_repo_name(repo_name)
148 _form = RepoForkForm(old_data={'repo_type': c.repo_info.repo_type},
148 _form = RepoForkForm(old_data={'repo_type': c.repo_info.repo_type},
149 repo_groups=c.repo_groups,
149 repo_groups=c.repo_groups,
150 landing_revs=c.landing_revs_choices)()
150 landing_revs=c.landing_revs_choices)()
151 form_result = {}
151 form_result = {}
152 task_id = None
152 task_id = None
153 try:
153 try:
154 form_result = _form.to_python(dict(request.POST))
154 form_result = _form.to_python(dict(request.POST))
155
155
156 # an approximation that is better than nothing
156 # an approximation that is better than nothing
157 if not Ui.get_by_key('hooks', Ui.HOOK_UPDATE).ui_active:
157 if not Ui.get_by_key('hooks', Ui.HOOK_UPDATE).ui_active:
158 form_result['update_after_clone'] = False
158 form_result['update_after_clone'] = False
159
159
160 # create fork is done sometimes async on celery, db transaction
160 # create fork is done sometimes async on celery, db transaction
161 # management is handled there.
161 # management is handled there.
162 task = RepoModel().create_fork(form_result, request.authuser.user_id)
162 task = RepoModel().create_fork(form_result, request.authuser.user_id)
163 task_id = task.task_id
163 task_id = task.task_id
164 except formencode.Invalid as errors:
164 except formencode.Invalid as errors:
165 return htmlfill.render(
165 return htmlfill.render(
166 render('forks/fork.html'),
166 render('forks/fork.html'),
167 defaults=errors.value,
167 defaults=errors.value,
168 errors=errors.error_dict or {},
168 errors=errors.error_dict or {},
169 prefix_error=False,
169 prefix_error=False,
170 encoding="UTF-8",
170 encoding="UTF-8",
171 force_defaults=False)
171 force_defaults=False)
172 except Exception:
172 except Exception:
173 log.error(traceback.format_exc())
173 log.error(traceback.format_exc())
174 h.flash(_('An error occurred during repository forking %s') %
174 h.flash(_('An error occurred during repository forking %s') %
175 repo_name, category='error')
175 repo_name, category='error')
176
176
177 raise HTTPFound(location=h.url('repo_creating_home',
177 raise HTTPFound(location=h.url('repo_creating_home',
178 repo_name=form_result['repo_name_full'],
178 repo_name=form_result['repo_name_full'],
179 task_id=task_id))
179 task_id=task_id))
@@ -1,213 +1,213 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 # This program is free software: you can redistribute it and/or modify
2 # This program is free software: you can redistribute it and/or modify
3 # it under the terms of the GNU General Public License as published by
3 # it under the terms of the GNU General Public License as published by
4 # the Free Software Foundation, either version 3 of the License, or
4 # the Free Software Foundation, either version 3 of the License, or
5 # (at your option) any later version.
5 # (at your option) any later version.
6 #
6 #
7 # This program is distributed in the hope that it will be useful,
7 # This program is distributed in the hope that it will be useful,
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 # GNU General Public License for more details.
10 # GNU General Public License for more details.
11 #
11 #
12 # You should have received a copy of the GNU General Public License
12 # You should have received a copy of the GNU General Public License
13 # along with this program. If not, see <http://www.gnu.org/licenses/>.
13 # along with this program. If not, see <http://www.gnu.org/licenses/>.
14 """
14 """
15 kallithea.controllers.home
15 kallithea.controllers.home
16 ~~~~~~~~~~~~~~~~~~~~~~~~~~
16 ~~~~~~~~~~~~~~~~~~~~~~~~~~
17
17
18 Home controller for Kallithea
18 Home controller for Kallithea
19
19
20 This file was forked by the Kallithea project in July 2014.
20 This file was forked by the Kallithea project in July 2014.
21 Original author and date, and relevant copyright and licensing information is below:
21 Original author and date, and relevant copyright and licensing information is below:
22 :created_on: Feb 18, 2010
22 :created_on: Feb 18, 2010
23 :author: marcink
23 :author: marcink
24 :copyright: (c) 2013 RhodeCode GmbH, and others.
24 :copyright: (c) 2013 RhodeCode GmbH, and others.
25 :license: GPLv3, see LICENSE.md for more details.
25 :license: GPLv3, see LICENSE.md for more details.
26
26
27 """
27 """
28
28
29 import logging
29 import logging
30
30
31 from sqlalchemy import or_
31 from sqlalchemy import or_
32 from tg import request
32 from tg import request
33 from tg import tmpl_context as c
33 from tg import tmpl_context as c
34 from tg.i18n import ugettext as _
34 from tg.i18n import ugettext as _
35 from webob.exc import HTTPBadRequest
35 from webob.exc import HTTPBadRequest
36
36
37 from kallithea.lib import helpers as h
37 from kallithea.lib import helpers as h
38 from kallithea.lib.auth import HasRepoPermissionLevelDecorator, LoginRequired
38 from kallithea.lib.auth import HasRepoPermissionLevelDecorator, LoginRequired
39 from kallithea.lib.base import BaseController, jsonify, render
39 from kallithea.lib.base import BaseController, jsonify, render
40 from kallithea.lib.utils import conditional_cache
40 from kallithea.lib.utils import conditional_cache
41 from kallithea.model.db import RepoGroup, Repository, User, UserGroup
41 from kallithea.model.db import RepoGroup, Repository, User, UserGroup
42 from kallithea.model.repo import RepoModel
42 from kallithea.model.repo import RepoModel
43 from kallithea.model.scm import UserGroupList
43 from kallithea.model.scm import UserGroupList
44
44
45
45
46 log = logging.getLogger(__name__)
46 log = logging.getLogger(__name__)
47
47
48
48
49 class HomeController(BaseController):
49 class HomeController(BaseController):
50
50
51 def about(self):
51 def about(self):
52 return render('/about.html')
52 return render('/about.html')
53
53
54 @LoginRequired(allow_default_user=True)
54 @LoginRequired(allow_default_user=True)
55 def index(self):
55 def index(self):
56 c.group = None
56 c.group = None
57
57
58 repo_groups_list = self.scm_model.get_repo_groups()
58 repo_groups_list = self.scm_model.get_repo_groups()
59 repos_list = Repository.query(sorted=True).filter_by(group=None).all()
59 repos_list = Repository.query(sorted=True).filter_by(group=None).all()
60
60
61 c.data = RepoModel().get_repos_as_dict(repos_list,
61 c.data = RepoModel().get_repos_as_dict(repos_list,
62 repo_groups_list=repo_groups_list,
62 repo_groups_list=repo_groups_list,
63 short_name=True)
63 short_name=True)
64
64
65 return render('/index.html')
65 return render('/index.html')
66
66
67 @LoginRequired(allow_default_user=True)
67 @LoginRequired(allow_default_user=True)
68 @jsonify
68 @jsonify
69 def repo_switcher_data(self):
69 def repo_switcher_data(self):
70 # wrapper for conditional cache
70 # wrapper for conditional cache
71 def _c():
71 def _c():
72 log.debug('generating switcher repo/groups list')
72 log.debug('generating switcher repo/groups list')
73 all_repos = Repository.query(sorted=True).all()
73 all_repos = Repository.query(sorted=True).all()
74 repo_iter = self.scm_model.get_repos(all_repos)
74 repo_iter = self.scm_model.get_repos(all_repos)
75 all_groups = RepoGroup.query(sorted=True).all()
75 all_groups = RepoGroup.query(sorted=True).all()
76 repo_groups_iter = self.scm_model.get_repo_groups(all_groups)
76 repo_groups_iter = self.scm_model.get_repo_groups(all_groups)
77
77
78 res = [{
78 res = [{
79 'text': _('Groups'),
79 'text': _('Groups'),
80 'children': [
80 'children': [
81 {'id': obj.group_name,
81 {'id': obj.group_name,
82 'text': obj.group_name,
82 'text': obj.group_name,
83 'type': 'group',
83 'type': 'group',
84 'obj': {}}
84 'obj': {}}
85 for obj in repo_groups_iter
85 for obj in repo_groups_iter
86 ],
86 ],
87 },
87 },
88 {
88 {
89 'text': _('Repositories'),
89 'text': _('Repositories'),
90 'children': [
90 'children': [
91 {'id': obj.repo_name,
91 {'id': obj.repo_name,
92 'text': obj.repo_name,
92 'text': obj.repo_name,
93 'type': 'repo',
93 'type': 'repo',
94 'obj': obj.get_dict()}
94 'obj': obj.get_dict()}
95 for obj in repo_iter
95 for obj in repo_iter
96 ],
96 ],
97 }]
97 }]
98
98
99 data = {
99 data = {
100 'more': False,
100 'more': False,
101 'results': res,
101 'results': res,
102 }
102 }
103 return data
103 return data
104
104
105 if request.is_xhr:
105 if request.is_xhr:
106 condition = False
106 condition = False
107 compute = conditional_cache('short_term', 'cache_desc',
107 compute = conditional_cache('short_term', 'cache_desc',
108 condition=condition, func=_c)
108 condition=condition, func=_c)
109 return compute()
109 return compute()
110 else:
110 else:
111 raise HTTPBadRequest()
111 raise HTTPBadRequest()
112
112
113 @LoginRequired(allow_default_user=True)
113 @LoginRequired(allow_default_user=True)
114 @HasRepoPermissionLevelDecorator('read')
114 @HasRepoPermissionLevelDecorator('read')
115 @jsonify
115 @jsonify
116 def repo_refs_data(self, repo_name):
116 def repo_refs_data(self, repo_name):
117 repo = Repository.get_by_repo_name(repo_name).scm_instance
117 repo = Repository.get_by_repo_name(repo_name).scm_instance
118 res = []
118 res = []
119 _branches = repo.branches.items()
119 _branches = repo.branches.items()
120 if _branches:
120 if _branches:
121 res.append({
121 res.append({
122 'text': _('Branch'),
122 'text': _('Branch'),
123 'children': [{'id': rev, 'text': name, 'type': 'branch'} for name, rev in _branches]
123 'children': [{'id': rev, 'text': name, 'type': 'branch'} for name, rev in _branches]
124 })
124 })
125 _closed_branches = repo.closed_branches.items()
125 _closed_branches = repo.closed_branches.items()
126 if _closed_branches:
126 if _closed_branches:
127 res.append({
127 res.append({
128 'text': _('Closed Branches'),
128 'text': _('Closed Branches'),
129 'children': [{'id': rev, 'text': name, 'type': 'closed-branch'} for name, rev in _closed_branches]
129 'children': [{'id': rev, 'text': name, 'type': 'closed-branch'} for name, rev in _closed_branches]
130 })
130 })
131 _tags = repo.tags.items()
131 _tags = repo.tags.items()
132 if _tags:
132 if _tags:
133 res.append({
133 res.append({
134 'text': _('Tag'),
134 'text': _('Tag'),
135 'children': [{'id': rev, 'text': name, 'type': 'tag'} for name, rev in _tags]
135 'children': [{'id': rev, 'text': name, 'type': 'tag'} for name, rev in _tags]
136 })
136 })
137 _bookmarks = repo.bookmarks.items()
137 _bookmarks = repo.bookmarks.items()
138 if _bookmarks:
138 if _bookmarks:
139 res.append({
139 res.append({
140 'text': _('Bookmark'),
140 'text': _('Bookmark'),
141 'children': [{'id': rev, 'text': name, 'type': 'book'} for name, rev in _bookmarks]
141 'children': [{'id': rev, 'text': name, 'type': 'book'} for name, rev in _bookmarks]
142 })
142 })
143 data = {
143 data = {
144 'more': False,
144 'more': False,
145 'results': res
145 'results': res
146 }
146 }
147 return data
147 return data
148
148
149 @LoginRequired()
149 @LoginRequired()
150 @jsonify
150 @jsonify
151 def users_and_groups_data(self):
151 def users_and_groups_data(self):
152 """
152 """
153 Returns 'results' with a list of users and user groups.
153 Returns 'results' with a list of users and user groups.
154
154
155 You can either use the 'key' GET parameter to get a user by providing
155 You can either use the 'key' GET parameter to get a user by providing
156 the exact user key or you can use the 'query' parameter to
156 the exact user key or you can use the 'query' parameter to
157 search for users by user key, first name and last name.
157 search for users by user key, first name and last name.
158 'types' defaults to just 'users' but can be set to 'users,groups' to
158 'types' defaults to just 'users' but can be set to 'users,groups' to
159 get both users and groups.
159 get both users and groups.
160 No more than 500 results (of each kind) will be returned.
160 No more than 500 results (of each kind) will be returned.
161 """
161 """
162 types = request.GET.get('types', 'users').split(',')
162 types = request.GET.get('types', 'users').split(',')
163 key = request.GET.get('key', '')
163 key = request.GET.get('key', '')
164 query = request.GET.get('query', '')
164 query = request.GET.get('query', '')
165 results = []
165 results = []
166 if 'users' in types:
166 if 'users' in types:
167 user_list = []
167 user_list = []
168 if key:
168 if key:
169 u = User.get_by_username(key)
169 u = User.get_by_username(key)
170 if u:
170 if u:
171 user_list = [u]
171 user_list = [u]
172 elif query:
172 elif query:
173 user_list = User.query() \
173 user_list = User.query() \
174 .filter(User.is_default_user == False) \
174 .filter(User.is_default_user == False) \
175 .filter(User.active == True) \
175 .filter(User.active == True) \
176 .filter(or_(
176 .filter(or_(
177 User.username.ilike("%%"+query+"%%"),
177 User.username.ilike("%%" + query + "%%"),
178 User.name.ilike("%%"+query+"%%"),
178 User.name.ilike("%%" + query + "%%"),
179 User.lastname.ilike("%%"+query+"%%"),
179 User.lastname.ilike("%%" + query + "%%"),
180 )) \
180 )) \
181 .order_by(User.username) \
181 .order_by(User.username) \
182 .limit(500) \
182 .limit(500) \
183 .all()
183 .all()
184 for u in user_list:
184 for u in user_list:
185 results.append({
185 results.append({
186 'type': 'user',
186 'type': 'user',
187 'id': u.user_id,
187 'id': u.user_id,
188 'nname': u.username,
188 'nname': u.username,
189 'fname': u.name,
189 'fname': u.name,
190 'lname': u.lastname,
190 'lname': u.lastname,
191 'gravatar_lnk': h.gravatar_url(u.email, size=28, default='default'),
191 'gravatar_lnk': h.gravatar_url(u.email, size=28, default='default'),
192 'gravatar_size': 14,
192 'gravatar_size': 14,
193 })
193 })
194 if 'groups' in types:
194 if 'groups' in types:
195 grp_list = []
195 grp_list = []
196 if key:
196 if key:
197 grp = UserGroup.get_by_group_name(key)
197 grp = UserGroup.get_by_group_name(key)
198 if grp:
198 if grp:
199 grp_list = [grp]
199 grp_list = [grp]
200 elif query:
200 elif query:
201 grp_list = UserGroup.query() \
201 grp_list = UserGroup.query() \
202 .filter(UserGroup.users_group_name.ilike("%%"+query+"%%")) \
202 .filter(UserGroup.users_group_name.ilike("%%" + query + "%%")) \
203 .filter(UserGroup.users_group_active == True) \
203 .filter(UserGroup.users_group_active == True) \
204 .order_by(UserGroup.users_group_name) \
204 .order_by(UserGroup.users_group_name) \
205 .limit(500) \
205 .limit(500) \
206 .all()
206 .all()
207 for g in UserGroupList(grp_list, perm_level='read'):
207 for g in UserGroupList(grp_list, perm_level='read'):
208 results.append({
208 results.append({
209 'type': 'group',
209 'type': 'group',
210 'id': g.users_group_id,
210 'id': g.users_group_id,
211 'grname': g.users_group_name,
211 'grname': g.users_group_name,
212 })
212 })
213 return dict(results=results)
213 return dict(results=results)
General Comments 0
You need to be logged in to leave comments. Login now