##// END OF EJS Templates
i18n: updated translation for Polish...
i18n: updated translation for Polish Currently translated at 56.5% (614 of 1087 strings)

File last commit:

r8079:1112e440 default
r8092:7fef5132 default
Show More
home.py
210 lines | 7.6 KiB | text/x-python | PythonLexer
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 # -*- coding: utf-8 -*-
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
kallithea.controllers.home
~~~~~~~~~~~~~~~~~~~~~~~~~~
Bradley M. Kuhn
General renaming to Kallithea
r4212 Home controller for Kallithea
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
Bradley M. Kuhn
RhodeCode GmbH is not the sole author of this work
r4211 This file was forked by the Kallithea project in July 2014.
Original author and date, and relevant copyright and licensing information is below:
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 :created_on: Feb 18, 2010
:author: marcink
Bradley M. Kuhn
RhodeCode GmbH is not the sole author of this work
r4211 :copyright: (c) 2013 RhodeCode GmbH, and others.
Bradley M. Kuhn
Correct licensing information in individual files....
r4208 :license: GPLv3, see LICENSE.md for more details.
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
"""
import logging
Mads Kiilerich
flake8: fix some F401 '...' imported but unused
r7719 from sqlalchemy import or_
Mads Kiilerich
scripts: initial run of import cleanup using isort
r7718 from tg import request
from tg import tmpl_context as c
Mads Kiilerich
tg: minimize future diff by some mocking and replacing some pylons imports with tg...
r6508 from tg.i18n import ugettext as _
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 from webob.exc import HTTPBadRequest
Mads Kiilerich
scripts: initial run of import cleanup using isort
r7718 from kallithea.lib import helpers as h
from kallithea.lib.auth import HasRepoPermissionLevelDecorator, LoginRequired
from kallithea.lib.base import BaseController, jsonify, render
Mads Kiilerich
py3: add safe_str where we really need it to get a str - probably from bytes
r8079 from kallithea.lib.utils2 import safe_str
Mads Kiilerich
scripts: initial run of import cleanup using isort
r7718 from kallithea.model.db import RepoGroup, Repository, User, UserGroup
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 from kallithea.model.repo import RepoModel
domruf
js: use ajax requests for select2 autocomplete...
r6892 from kallithea.model.scm import UserGroupList
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
Mads Kiilerich
scripts: initial run of import cleanup using isort
r7718
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 log = logging.getLogger(__name__)
class HomeController(BaseController):
def about(self):
return render('/about.html')
Mads Kiilerich
auth: refactor to introduce @LoginRequired(allow_default_user=True) and deprecate @NotAnonymous()...
r7019 @LoginRequired(allow_default_user=True)
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 def index(self):
c.group = None
Mads Kiilerich
index: show repositories and repository groups in the same table...
r6801 repo_groups_list = self.scm_model.get_repo_groups()
Mads Kiilerich
repositories: backend cleanups related to breadcrumbs
r6267 repos_list = Repository.query(sorted=True).filter_by(group=None).all()
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
Mads Kiilerich
repos: document get_repos_as_dict parameters - repos_list is mandatory
r7181 c.data = RepoModel().get_repos_as_dict(repos_list,
Mads Kiilerich
index: show repositories and repository groups in the same table...
r6801 repo_groups_list=repo_groups_list,
Mads Kiilerich
repos: document get_repos_as_dict parameters - repos_list is mandatory
r7181 short_name=True)
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
return render('/index.html')
Mads Kiilerich
auth: refactor to introduce @LoginRequired(allow_default_user=True) and deprecate @NotAnonymous()...
r7019 @LoginRequired(allow_default_user=True)
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 @jsonify
def repo_switcher_data(self):
Mads Kiilerich
home: drop disabled caching of repo_switcher_data...
r7874 if request.is_xhr:
Søren Løvborg
db: always do case-insensitive sorting of repository names...
r6187 all_repos = Repository.query(sorted=True).all()
Mads Kiilerich
scm: simplify get_repos and get rid of RepoList overloads...
r5734 repo_iter = self.scm_model.get_repos(all_repos)
Søren Løvborg
db: do case-insensitive explicit sorting of RepoGroup names...
r6189 all_groups = RepoGroup.query(sorted=True).all()
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 repo_groups_iter = self.scm_model.get_repo_groups(all_groups)
res = [{
'text': _('Groups'),
'children': [
Mads Kiilerich
scm: simplify get_repos and get rid of RepoList overloads...
r5734 {'id': obj.group_name,
'text': obj.group_name,
'type': 'group',
'obj': {}}
for obj in repo_groups_iter
],
},
{
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 'text': _('Repositories'),
'children': [
Mads Kiilerich
scm: simplify get_repos and get rid of RepoList overloads...
r5734 {'id': obj.repo_name,
'text': obj.repo_name,
'type': 'repo',
'obj': obj.get_dict()}
for obj in repo_iter
],
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 }]
Mads Kiilerich
home: don't send _changeset_cache in repo_switcher_data result...
r7881 for res_dict in res:
for child in (res_dict['children']):
child['obj'].pop('_changeset_cache', None) # bytes cannot be encoded in json ... but this value isn't relevant on client side at all ...
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 data = {
'more': False,
Mads Kiilerich
scm: simplify get_repos and get rid of RepoList overloads...
r5734 'results': res,
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 }
return data
else:
raise HTTPBadRequest()
Mads Kiilerich
auth: restore anonymous repository access...
r7038 @LoginRequired(allow_default_user=True)
Søren Løvborg
auth: simplify repository permission checks...
r6471 @HasRepoPermissionLevelDecorator('read')
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 @jsonify
def repo_refs_data(self, repo_name):
repo = Repository.get_by_repo_name(repo_name).scm_instance
res = []
_branches = repo.branches.items()
if _branches:
res.append({
'text': _('Branch'),
Mads Kiilerich
py3: add safe_str where we really need it to get a str - probably from bytes
r8079 'children': [{'id': safe_str(rev), 'text': safe_str(name), 'type': 'branch'} for name, rev in _branches]
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 })
Ante Ilic
menu: Added select2 box for "Switch To", work towards having general revision context...
r5572 _closed_branches = repo.closed_branches.items()
if _closed_branches:
res.append({
'text': _('Closed Branches'),
Mads Kiilerich
py3: add safe_str where we really need it to get a str - probably from bytes
r8079 'children': [{'id': safe_str(rev), 'text': safe_str(name), 'type': 'closed-branch'} for name, rev in _closed_branches]
Ante Ilic
menu: Added select2 box for "Switch To", work towards having general revision context...
r5572 })
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 _tags = repo.tags.items()
if _tags:
res.append({
'text': _('Tag'),
Mads Kiilerich
py3: add safe_str where we really need it to get a str - probably from bytes
r8079 'children': [{'id': safe_str(rev), 'text': safe_str(name), 'type': 'tag'} for name, rev in _tags]
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 })
_bookmarks = repo.bookmarks.items()
if _bookmarks:
res.append({
'text': _('Bookmark'),
Mads Kiilerich
py3: add safe_str where we really need it to get a str - probably from bytes
r8079 'children': [{'id': safe_str(rev), 'text': safe_str(name), 'type': 'book'} for name, rev in _bookmarks]
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 })
data = {
'more': False,
'results': res
}
return data
domruf
js: use ajax requests for select2 autocomplete...
r6892
domruf
auth: users_and_groups_data should not be available for anonymous/default user
r7068 @LoginRequired()
domruf
js: use ajax requests for select2 autocomplete...
r6892 @jsonify
def users_and_groups_data(self):
"""
Returns 'results' with a list of users and user groups.
You can either use the 'key' GET parameter to get a user by providing
the exact user key or you can use the 'query' parameter to
search for users by user key, first name and last name.
'types' defaults to just 'users' but can be set to 'users,groups' to
get both users and groups.
No more than 500 results (of each kind) will be returned.
"""
types = request.GET.get('types', 'users').split(',')
key = request.GET.get('key', '')
query = request.GET.get('query', '')
results = []
if 'users' in types:
user_list = []
if key:
u = User.get_by_username(key)
if u:
user_list = [u]
elif query:
user_list = User.query() \
.filter(User.is_default_user == False) \
.filter(User.active == True) \
.filter(or_(
Mads Kiilerich
flake8: fix E226 missing whitespace around arithmetic operator
r7726 User.username.ilike("%%" + query + "%%"),
User.name.ilike("%%" + query + "%%"),
User.lastname.ilike("%%" + query + "%%"),
domruf
js: use ajax requests for select2 autocomplete...
r6892 )) \
.order_by(User.username) \
.limit(500) \
.all()
for u in user_list:
results.append({
'type': 'user',
'id': u.user_id,
'nname': u.username,
'fname': u.name,
'lname': u.lastname,
'gravatar_lnk': h.gravatar_url(u.email, size=28, default='default'),
'gravatar_size': 14,
})
if 'groups' in types:
grp_list = []
if key:
grp = UserGroup.get_by_group_name(key)
if grp:
grp_list = [grp]
elif query:
grp_list = UserGroup.query() \
Mads Kiilerich
flake8: fix E226 missing whitespace around arithmetic operator
r7726 .filter(UserGroup.users_group_name.ilike("%%" + query + "%%")) \
domruf
js: use ajax requests for select2 autocomplete...
r6892 .filter(UserGroup.users_group_active == True) \
.order_by(UserGroup.users_group_name) \
.limit(500) \
.all()
for g in UserGroupList(grp_list, perm_level='read'):
results.append({
'type': 'group',
'id': g.users_group_id,
'grname': g.users_group_name,
})
return dict(results=results)