##// END OF EJS Templates
login: removed log_session model, and replaced it with two lines of code....
login: removed log_session model, and replaced it with two lines of code. - also remove usage of template context - having dedicated model for this operation wasn't really required.

File last commit:

r1305:b418df09 default
r1321:cb7ffeab default
Show More
navigation.py
140 lines | 5.2 KiB | text/x-python | PythonLexer
Martin Bornhold
admin: Move admin settings navigation to admin module.
r295 # -*- coding: utf-8 -*-
license: updated copyright year to 2017
r1271 # Copyright (C) 2016-2017 RhodeCode GmbH
Martin Bornhold
admin: Move admin settings navigation to admin module.
r295 #
# 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
import collections
Martin Bornhold
admin: Register and retrieve navigation registry from pyramids registry.
r297
Martin Bornhold
admin: Move admin settings navigation to admin module.
r295 from pylons import url
from zope.interface import implementer
from rhodecode.admin.interfaces import IAdminNavigationRegistry
Martin Bornhold
admin: Add helper to get the registry from requests.
r298 from rhodecode.lib.utils import get_registry
Martin Bornhold
admin: Use pyramid translation instead of pylons.
r299 from rhodecode.translation import _
Martin Bornhold
admin: Move admin settings navigation to admin module.
r295
log = logging.getLogger(__name__)
NavListEntry = collections.namedtuple('NavListEntry', ['key', 'name', 'url'])
class NavEntry(object):
Martin Bornhold
admin: Add helper to get the registry from requests.
r298 """
Represents an entry in the admin navigation.
:param key: Unique identifier used to store reference in an OrderedDict.
:param name: Display name, usually a translation string.
:param view_name: Name of the view, used generate the URL.
:param pyramid: Indicator to use pyramid for URL generation. This should
be removed as soon as we are fully migrated to pyramid.
"""
Martin Bornhold
admin: Move admin settings navigation to admin module.
r295
def __init__(self, key, name, view_name, pyramid=False):
self.key = key
self.name = name
self.view_name = view_name
self.pyramid = pyramid
def generate_url(self, request):
if self.pyramid:
if hasattr(request, 'route_path'):
return request.route_path(self.view_name)
else:
# TODO: johbo: Remove this after migrating to pyramid.
# We need the pyramid request here to generate URLs to pyramid
# views from within pylons views.
from pyramid.threadlocal import get_current_request
pyramid_request = get_current_request()
return pyramid_request.route_path(self.view_name)
else:
return url(self.view_name)
i18n: translate properly navList and also support proper translation into other admin views.
r1305 def get_localized_name(self, request):
if hasattr(request, 'translate'):
return request.translate(self.name)
else:
# TODO(marcink): Remove this after migrating to pyramid
from pyramid.threadlocal import get_current_request
pyramid_request = get_current_request()
return pyramid_request.translate(self.name)
Martin Bornhold
admin: Move admin settings navigation to admin module.
r295
@implementer(IAdminNavigationRegistry)
class NavigationRegistry(object):
_base_entries = [
Martin Bornhold
admin: Use pyramid translation instead of pylons.
r299 NavEntry('global', _('Global'), 'admin_settings_global'),
NavEntry('vcs', _('VCS'), 'admin_settings_vcs'),
NavEntry('visual', _('Visual'), 'admin_settings_visual'),
NavEntry('mapping', _('Remap and Rescan'), 'admin_settings_mapping'),
NavEntry('issuetracker', _('Issue Tracker'),
Martin Bornhold
admin: Move admin settings navigation to admin module.
r295 'admin_settings_issuetracker'),
Martin Bornhold
admin: Use pyramid translation instead of pylons.
r299 NavEntry('email', _('Email'), 'admin_settings_email'),
NavEntry('hooks', _('Hooks'), 'admin_settings_hooks'),
NavEntry('search', _('Full Text Search'), 'admin_settings_search'),
session: moved session cleanup to pyramid views.
r1301
dan
integrations: add integration support...
r411 NavEntry('integrations', _('Integrations'),
'global_integrations_home', pyramid=True),
i18n: translate properly navList and also support proper translation into other admin views.
r1305 NavEntry('system', _('System Info'),
'admin_settings_system', pyramid=True),
NavEntry('sessions', _('User Sessions'),
session: moved session cleanup to pyramid views.
r1301 'admin_settings_sessions', pyramid=True),
Martin Bornhold
admin: Use pyramid translation instead of pylons.
r299 NavEntry('open_source', _('Open Source Licenses'),
Martin Bornhold
admin: Move admin settings navigation to admin module.
r295 'admin_settings_open_source', pyramid=True),
sessions: added interface to show, and cleanup user auth sessions.
r1295
Martin Bornhold
admin: Move admin settings navigation to admin module.
r295 # TODO: marcink: we disable supervisor now until the supervisor stats
# page is fixed in the nix configuration
Martin Bornhold
admin: Use pyramid translation instead of pylons.
r299 # NavEntry('supervisor', _('Supervisor'), 'admin_settings_supervisor'),
Martin Bornhold
admin: Move admin settings navigation to admin module.
r295 ]
i18n: translate properly navList and also support proper translation into other admin views.
r1305 _labs_entry = NavEntry('labs', _('Labs'), 'admin_settings_labs')
Martin Bornhold
admin: Register and retrieve navigation registry from pyramids registry.
r297
def __init__(self, labs_active=False):
Martin Bornhold
admin: Move admin settings navigation to admin module.
r295 self._registered_entries = collections.OrderedDict([
(item.key, item) for item in self.__class__._base_entries
])
if labs_active:
Martin Bornhold
admin: Register and retrieve navigation registry from pyramids registry.
r297 self.add_entry(self._labs_entry)
Martin Bornhold
admin: Move admin settings navigation to admin module.
r295
def add_entry(self, entry):
self._registered_entries[entry.key] = entry
def get_navlist(self, request):
i18n: translate properly navList and also support proper translation into other admin views.
r1305 navlist = [NavListEntry(i.key, i.get_localized_name(request),
i.generate_url(request))
Martin Bornhold
admin: Move admin settings navigation to admin module.
r295 for i in self._registered_entries.values()]
return navlist
Martin Bornhold
admin: Register and retrieve navigation registry from pyramids registry.
r297
def navigation_registry(request):
"""
Helper that returns the admin navigation registry.
"""
Martin Bornhold
admin: Add helper to get the registry from requests.
r298 pyramid_registry = get_registry(request)
Martin Bornhold
admin: Register and retrieve navigation registry from pyramids registry.
r297 nav_registry = pyramid_registry.queryUtility(IAdminNavigationRegistry)
return nav_registry
def navigation_list(request):
"""
Helper that returns the admin navigation as list of NavListEntry objects.
"""
return navigation_registry(request).get_navlist(request)