##// END OF EJS Templates
templates: few small UI fixes
templates: few small UI fixes

File last commit:

r4914:49ad81de default
r5046:0c2a09c8 default
Show More
views.py
166 lines | 5.7 KiB | text/x-python | PythonLexer
search: moved search into pyramid views.
r1685 # -*- coding: utf-8 -*-
code: update copyrights to 2020
r4306 # Copyright (C) 2011-2020 RhodeCode GmbH
search: moved search into pyramid views.
r1685 #
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License, version 3
# (only), as published by the Free Software Foundation.
#
# 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 Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# This program is dual-licensed. If you wish to learn more about the
# RhodeCode Enterprise Edition, including its added features, Support services,
# and proprietary license terms, please see https://rhodecode.com/licenses/
import logging
python3: fix urllib usage
r4914 import urllib.request, urllib.parse, urllib.error
application: not use config.scan(), and replace all @add_view decorator into a explicit add_view call for faster app start.
r4610
dan
webhelpers: port most of the items from webhelpers to webhelpers2...
r4090 from webhelpers2.html.tools import update_params
search: moved search into pyramid views.
r1685
dan
search: add option to search within a repository group.
r3441 from rhodecode.apps._base import BaseAppView, RepoAppView, RepoGroupAppView
from rhodecode.lib.auth import (
LoginRequired, HasRepoPermissionAnyDecorator, HasRepoGroupPermissionAnyDecorator)
search: moved search into pyramid views.
r1685 from rhodecode.lib.helpers import Page
apps: cleanup imports
r2080 from rhodecode.lib.utils2 import safe_str
search: moved search into pyramid views.
r1685 from rhodecode.lib.index import searcher_from_config
from rhodecode.model import validation_schema
from rhodecode.model.validation_schema.schemas import search_schema
log = logging.getLogger(__name__)
dan
search: add option to search within a repository group.
r3441 def perform_search(request, tmpl_context, repo_name=None, repo_group_name=None):
search: moved search into pyramid views.
r1685 searcher = searcher_from_config(request.registry.settings)
formatted_results = []
execution_time = ''
schema = search_schema.SearchParamsSchema()
dan
search: new UI for search, and repo group context search...
r3442 search_tags = []
search: moved search into pyramid views.
r1685 search_params = {}
errors = []
search: allow result sorting for elasticsearch6
r3963
search: moved search into pyramid views.
r1685 try:
search_params = schema.deserialize(
dan
search: add support for elastic search 6...
r3319 dict(
search_query=request.GET.get('q'),
search_type=request.GET.get('type'),
search_sort=request.GET.get('sort'),
search_max_lines=request.GET.get('max_lines'),
page_limit=request.GET.get('page_limit'),
requested_page=request.GET.get('page'),
)
search: moved search into pyramid views.
r1685 )
except validation_schema.Invalid as e:
errors = e.children
dan
webhelpers: replaced paginate library with custom lib
r4091 def url_generator(page_num):
query_params = {
'page': page_num,
dan
search: remove excesive quoting on search pagination....
r4280 'q': safe_str(search_query),
dan
webhelpers: replaced paginate library with custom lib
r4091 'type': safe_str(search_type),
'max_lines': search_max_lines,
'sort': search_sort
}
python3: fix urllib usage
r4914 return '?' + urllib.parse.urlencode(query_params)
dan
webhelpers: replaced paginate library with custom lib
r4091
search: moved search into pyramid views.
r1685 c = tmpl_context
search_query = search_params.get('search_query')
search_type = search_params.get('search_type')
search_sort = search_params.get('search_sort')
dan
search: add support for elastic search 6...
r3319 search_max_lines = search_params.get('search_max_lines')
search: moved search into pyramid views.
r1685 if search_params.get('search_query'):
page_limit = search_params['page_limit']
requested_page = search_params['requested_page']
try:
search_result = searcher.search(
dan
search: add option to search within a repository group.
r3441 search_query, search_type, c.auth_user, repo_name, repo_group_name,
requested_page=requested_page, page_limit=page_limit, sort=search_sort)
search: moved search into pyramid views.
r1685
formatted_results = Page(
search_result['results'], page=requested_page,
item_count=search_result['count'],
dan
webhelpers: replaced paginate library with custom lib
r4091 items_per_page=page_limit, url_maker=url_generator)
search: moved search into pyramid views.
r1685 finally:
searcher.cleanup()
dan
search: new UI for search, and repo group context search...
r3442 search_tags = searcher.extract_search_tags(search_query)
search: moved search into pyramid views.
r1685 if not search_result['error']:
core: added more accurate time measurement for called functions
r3853 execution_time = '%s results (%.4f seconds)' % (
search: moved search into pyramid views.
r1685 search_result['count'],
search_result['runtime'])
elif not errors:
node = schema['search_query']
errors = [
validation_schema.Invalid(node, search_result['error'])]
c.perm_user = c.auth_user
c.repo_name = repo_name
dan
search: add option to search within a repository group.
r3441 c.repo_group_name = repo_group_name
search: moved search into pyramid views.
r1685 c.errors = errors
c.formatted_results = formatted_results
c.runtime = execution_time
c.cur_query = search_query
c.search_type = search_type
c.searcher = searcher
dan
search: new UI for search, and repo group context search...
r3442 c.search_tags = search_tags
search: moved search into pyramid views.
r1685
search: allow result sorting for elasticsearch6
r3963 direction, sort_field = searcher.get_sort(search_type, search_sort)
dan
search: added per-backend sorting fields....
r3968 sort_definition = searcher.sort_def(search_type, direction, sort_field)
c.sort = ''
c.sort_tag = None
search: allow result sorting for elasticsearch6
r3963 c.sort_tag_dir = direction
dan
search: added per-backend sorting fields....
r3968 if sort_definition:
c.sort = '{}:{}'.format(direction, sort_field)
c.sort_tag = sort_field
search: allow result sorting for elasticsearch6
r3963
search: moved search into pyramid views.
r1685
class SearchView(BaseAppView):
def load_default_context(self):
c = self._get_local_tmpl_context()
return c
@LoginRequired()
def search(self):
c = self.load_default_context()
dan
search: add option to search within a repository group.
r3441 perform_search(self.request, c)
search: moved search into pyramid views.
r1685 return self._get_template_context(c)
class SearchRepoView(RepoAppView):
def load_default_context(self):
c = self._get_local_tmpl_context()
ui: expose search as a visible option for repositories.
r3440 c.active = 'search'
search: moved search into pyramid views.
r1685 return c
@LoginRequired()
search: per-repo search shouldn't require admin permissions. Read is enought because we access the repo only
r2048 @HasRepoPermissionAnyDecorator(
'repository.read', 'repository.write', 'repository.admin')
search: moved search into pyramid views.
r1685 def search_repo(self):
c = self.load_default_context()
dan
search: add option to search within a repository group.
r3441 perform_search(self.request, c, repo_name=self.db_repo_name)
search: moved search into pyramid views.
r1685 return self._get_template_context(c)
dan
search: add option to search within a repository group.
r3441
class SearchRepoGroupView(RepoGroupAppView):
def load_default_context(self):
c = self._get_local_tmpl_context()
c.active = 'search'
return c
@LoginRequired()
@HasRepoGroupPermissionAnyDecorator(
'group.read', 'group.write', 'group.admin')
def search_repo_group(self):
c = self.load_default_context()
perform_search(self.request, c, repo_group_name=self.db_repo_group_name)
return self._get_template_context(c)