into proper repo group names
+ _group = request.db_repo_group.group_name
+ elif getattr(request, 'matchdict', None):
+ # pyramid
+ _group = request.matchdict.get('repo_group_name')
- # TODO(marcink): remove after pylons migration...
- if not _group:
- _group = request.environ['pylons.routes_dict'].get('group_name')
if _group:
_group = _group.rstrip('/')
@@ -137,26 +129,21 @@ def get_repo_group_slug(request):
def get_user_group_slug(request):
_user_group = ''
- if isinstance(request, Request):
- if hasattr(request, 'db_user_group'):
- _user_group = request.db_user_group.users_group_name
- elif getattr(request, 'matchdict', None):
- # pyramid
- _user_group = request.matchdict.get('user_group_id')
+ if hasattr(request, 'db_user_group'):
+ _user_group = request.db_user_group.users_group_name
+ elif getattr(request, 'matchdict', None):
+ # pyramid
+ _user_group = request.matchdict.get('user_group_id')
- try:
- _user_group = UserGroup.get(_user_group)
- if _user_group:
- _user_group = _user_group.users_group_name
- except Exception:
- log.exception('Failed to get user group by id')
- # catch all failures here
- return None
-
- # TODO(marcink): remove after pylons migration...
- if not _user_group:
- _user_group = request.environ['pylons.routes_dict'].get('user_group_id')
+ try:
+ _user_group = UserGroup.get(_user_group)
+ if _user_group:
+ _user_group = _user_group.users_group_name
+ except Exception:
+ log.exception('Failed to get user group by id')
+ # catch all failures here
+ return None
return _user_group
@@ -438,7 +425,7 @@ def get_enabled_hook_classes(ui_settings
def set_rhodecode_config(config):
"""
- Updates pylons config with new settings from database
+ Updates pyramid config with new settings from database
:param config:
"""
@@ -881,19 +868,6 @@ def read_opensource_licenses():
return _license_cache
-def get_registry(request):
- """
- Utility to get the pyramid registry from a request. During migration to
- pyramid we sometimes want to use the pyramid registry from pylons context.
- Therefore this utility returns `request.registry` for pyramid requests and
- uses `get_current_registry()` for pylons requests.
- """
- try:
- return request.registry
- except AttributeError:
- return get_current_registry()
-
-
def generate_platform_uuid():
"""
Generates platform UUID based on it's name
diff --git a/rhodecode/model/__init__.py b/rhodecode/model/__init__.py
--- a/rhodecode/model/__init__.py
+++ b/rhodecode/model/__init__.py
@@ -18,27 +18,6 @@
# RhodeCode Enterprise Edition, including its added features, Support services,
# and proprietary license terms, please see https://rhodecode.com/licenses/
-"""
-The application's model objects
-
-:example:
-
- .. code-block:: python
-
- from paste.deploy import appconfig
- from pylons import config
- from sqlalchemy import engine_from_config
- from rhodecode.config.environment import load_environment
-
- conf = appconfig('config:development.ini', relative_to = './../../')
- load_environment(conf.global_conf, conf.local_conf)
-
- engine = engine_from_config(config, 'sqlalchemy.')
- init_model(engine)
- # RUN YOUR CODE HERE
-
-"""
-
import logging
diff --git a/rhodecode/model/comment.py b/rhodecode/model/comment.py
--- a/rhodecode/model/comment.py
+++ b/rhodecode/model/comment.py
@@ -26,7 +26,6 @@ import logging
import traceback
import collections
-from pylons.i18n.translation import _
from pyramid.threadlocal import get_current_registry, get_current_request
from sqlalchemy.sql.expression import null
from sqlalchemy.sql.functions import coalesce
@@ -68,8 +67,8 @@ class CommentsModel(BaseModel):
user_objects.append(user_obj)
return user_objects
- def _get_renderer(self, global_renderer='rst'):
- request = get_current_request()
+ def _get_renderer(self, global_renderer='rst', request=None):
+ request = request or get_current_request()
try:
global_renderer = request.call_context.visual.default_renderer
@@ -194,9 +193,11 @@ class CommentsModel(BaseModel):
if not text:
log.warning('Missing text for comment, skipping...')
return
+ request = get_current_request()
+ _ = request.translate
if not renderer:
- renderer = self._get_renderer()
+ renderer = self._get_renderer(request=request)
repo = self._get_repo(repo)
user = self._get_user(user)
@@ -268,7 +269,7 @@ class CommentsModel(BaseModel):
cs_author = repo.user
recipients += [cs_author]
- commit_comment_url = self.get_url(comment)
+ commit_comment_url = self.get_url(comment, request=request)
target_repo_url = h.link_to(
repo.repo_name,
diff --git a/rhodecode/model/forms.py b/rhodecode/model/forms.py
--- a/rhodecode/model/forms.py
+++ b/rhodecode/model/forms.py
@@ -48,7 +48,7 @@ import formencode
from pkg_resources import resource_filename
from formencode import All, Pipe
-from pylons.i18n.translation import _
+from rhodecode.translation import temp_translation_factory as _
from pyramid.threadlocal import get_current_request
from rhodecode import BACKENDS
@@ -75,7 +75,9 @@ form_renderer = RhodecodeFormZPTRenderer
deform.Form.set_default_renderer(form_renderer)
-def LoginForm():
+def LoginForm(localizer):
+ _ = localizer
+
class _LoginForm(formencode.Schema):
allow_extra_fields = True
filter_extra_fields = True
@@ -101,33 +103,37 @@ def LoginForm():
remember = v.StringBoolean(if_missing=False)
- chained_validators = [v.ValidAuth()]
+ chained_validators = [v.ValidAuth(localizer)]
return _LoginForm
-def UserForm(edit=False, available_languages=[], old_data={}):
+def UserForm(localizer, edit=False, available_languages=None, old_data=None):
+ old_data = old_data or {}
+ available_languages = available_languages or []
+ _ = localizer
+
class _UserForm(formencode.Schema):
allow_extra_fields = True
filter_extra_fields = True
username = All(v.UnicodeString(strip=True, min=1, not_empty=True),
- v.ValidUsername(edit, old_data))
+ v.ValidUsername(localizer, edit, old_data))
if edit:
new_password = All(
- v.ValidPassword(),
+ v.ValidPassword(localizer),
v.UnicodeString(strip=False, min=6, max=72, not_empty=False)
)
password_confirmation = All(
- v.ValidPassword(),
+ v.ValidPassword(localizer),
v.UnicodeString(strip=False, min=6, max=72, not_empty=False),
)
admin = v.StringBoolean(if_missing=False)
else:
password = All(
- v.ValidPassword(),
+ v.ValidPassword(localizer),
v.UnicodeString(strip=False, min=6, max=72, not_empty=True)
)
password_confirmation = All(
- v.ValidPassword(),
+ v.ValidPassword(localizer),
v.UnicodeString(strip=False, min=6, max=72, not_empty=False)
)
@@ -137,17 +143,18 @@ def UserForm(edit=False, available_langu
active = v.StringBoolean(if_missing=False)
firstname = v.UnicodeString(strip=True, min=1, not_empty=False)
lastname = v.UnicodeString(strip=True, min=1, not_empty=False)
- email = All(v.Email(not_empty=True), v.UniqSystemEmail(old_data))
+ email = All(v.Email(not_empty=True), v.UniqSystemEmail(localizer, old_data))
extern_name = v.UnicodeString(strip=True)
extern_type = v.UnicodeString(strip=True)
language = v.OneOf(available_languages, hideList=False,
testValueList=True, if_missing=None)
- chained_validators = [v.ValidPasswordsMatch()]
+ chained_validators = [v.ValidPasswordsMatch(localizer)]
return _UserForm
-def UserGroupForm(edit=False, old_data=None, allow_disabled=False):
+def UserGroupForm(localizer, edit=False, old_data=None, allow_disabled=False):
old_data = old_data or {}
+ _ = localizer
class _UserGroupForm(formencode.Schema):
allow_extra_fields = True
@@ -155,7 +162,7 @@ def UserGroupForm(edit=False, old_data=N
users_group_name = All(
v.UnicodeString(strip=True, min=1, not_empty=True),
- v.ValidUserGroup(edit, old_data)
+ v.ValidUserGroup(localizer, edit, old_data)
)
user_group_description = v.UnicodeString(strip=True, min=1,
not_empty=False)
@@ -166,12 +173,13 @@ def UserGroupForm(edit=False, old_data=N
# this is user group owner
user = All(
v.UnicodeString(not_empty=True),
- v.ValidRepoUser(allow_disabled))
+ v.ValidRepoUser(localizer, allow_disabled))
return _UserGroupForm
-def RepoGroupForm(edit=False, old_data=None, available_groups=None,
- can_create_in_root=False, allow_disabled=False):
+def RepoGroupForm(localizer, edit=False, old_data=None, available_groups=None,
+ can_create_in_root=False, allow_disabled=False):
+ _ = localizer
old_data = old_data or {}
available_groups = available_groups or []
@@ -180,7 +188,7 @@ def RepoGroupForm(edit=False, old_data=N
filter_extra_fields = False
group_name = All(v.UnicodeString(strip=True, min=1, not_empty=True),
- v.SlugifyName(),)
+ v.SlugifyName(localizer),)
group_description = v.UnicodeString(strip=True, min=1,
not_empty=False)
group_copy_permissions = v.StringBoolean(if_missing=False)
@@ -189,53 +197,57 @@ def RepoGroupForm(edit=False, old_data=N
testValueList=True, not_empty=True)
enable_locking = v.StringBoolean(if_missing=False)
chained_validators = [
- v.ValidRepoGroup(edit, old_data, can_create_in_root)]
+ v.ValidRepoGroup(localizer, edit, old_data, can_create_in_root)]
if edit:
# this is repo group owner
user = All(
v.UnicodeString(not_empty=True),
- v.ValidRepoUser(allow_disabled))
-
+ v.ValidRepoUser(localizer, allow_disabled))
return _RepoGroupForm
-def RegisterForm(edit=False, old_data={}):
+def RegisterForm(localizer, edit=False, old_data=None):
+ _ = localizer
+ old_data = old_data or {}
+
class _RegisterForm(formencode.Schema):
allow_extra_fields = True
filter_extra_fields = True
username = All(
- v.ValidUsername(edit, old_data),
+ v.ValidUsername(localizer, edit, old_data),
v.UnicodeString(strip=True, min=1, not_empty=True)
)
password = All(
- v.ValidPassword(),
+ v.ValidPassword(localizer),
v.UnicodeString(strip=False, min=6, max=72, not_empty=True)
)
password_confirmation = All(
- v.ValidPassword(),
+ v.ValidPassword(localizer),
v.UnicodeString(strip=False, min=6, max=72, not_empty=True)
)
active = v.StringBoolean(if_missing=False)
firstname = v.UnicodeString(strip=True, min=1, not_empty=False)
lastname = v.UnicodeString(strip=True, min=1, not_empty=False)
- email = All(v.Email(not_empty=True), v.UniqSystemEmail(old_data))
+ email = All(v.Email(not_empty=True), v.UniqSystemEmail(localizer, old_data))
- chained_validators = [v.ValidPasswordsMatch()]
-
+ chained_validators = [v.ValidPasswordsMatch(localizer)]
return _RegisterForm
-def PasswordResetForm():
+def PasswordResetForm(localizer):
+ _ = localizer
+
class _PasswordResetForm(formencode.Schema):
allow_extra_fields = True
filter_extra_fields = True
- email = All(v.ValidSystemEmail(), v.Email(not_empty=True))
+ email = All(v.ValidSystemEmail(localizer), v.Email(not_empty=True))
return _PasswordResetForm
-def RepoForm(edit=False, old_data=None, repo_groups=None, landing_revs=None,
- allow_disabled=False):
+def RepoForm(localizer, edit=False, old_data=None, repo_groups=None,
+ landing_revs=None, allow_disabled=False):
+ _ = localizer
old_data = old_data or {}
repo_groups = repo_groups or []
landing_revs = landing_revs or []
@@ -245,8 +257,8 @@ def RepoForm(edit=False, old_data=None,
allow_extra_fields = True
filter_extra_fields = False
repo_name = All(v.UnicodeString(strip=True, min=1, not_empty=True),
- v.SlugifyName(), v.CannotHaveGitSuffix())
- repo_group = All(v.CanWriteGroup(old_data),
+ v.SlugifyName(localizer), v.CannotHaveGitSuffix(localizer))
+ repo_group = All(v.CanWriteGroup(localizer, old_data),
v.OneOf(repo_groups, hideList=True))
repo_type = v.OneOf(supported_backends, required=False,
if_missing=old_data.get('repo_type'))
@@ -264,77 +276,91 @@ def RepoForm(edit=False, old_data=None,
# this is repo owner
user = All(
v.UnicodeString(not_empty=True),
- v.ValidRepoUser(allow_disabled))
+ v.ValidRepoUser(localizer, allow_disabled))
clone_uri_change = v.UnicodeString(
not_empty=False, if_missing=v.Missing)
- chained_validators = [v.ValidCloneUri(),
- v.ValidRepoName(edit, old_data)]
+ chained_validators = [v.ValidCloneUri(localizer),
+ v.ValidRepoName(localizer, edit, old_data)]
return _RepoForm
-def RepoPermsForm():
+def RepoPermsForm(localizer):
+ _ = localizer
+
class _RepoPermsForm(formencode.Schema):
allow_extra_fields = True
filter_extra_fields = False
- chained_validators = [v.ValidPerms(type_='repo')]
+ chained_validators = [v.ValidPerms(localizer, type_='repo')]
return _RepoPermsForm
-def RepoGroupPermsForm(valid_recursive_choices):
+def RepoGroupPermsForm(localizer, valid_recursive_choices):
+ _ = localizer
+
class _RepoGroupPermsForm(formencode.Schema):
allow_extra_fields = True
filter_extra_fields = False
recursive = v.OneOf(valid_recursive_choices)
- chained_validators = [v.ValidPerms(type_='repo_group')]
+ chained_validators = [v.ValidPerms(localizer, type_='repo_group')]
return _RepoGroupPermsForm
-def UserGroupPermsForm():
+def UserGroupPermsForm(localizer):
+ _ = localizer
+
class _UserPermsForm(formencode.Schema):
allow_extra_fields = True
filter_extra_fields = False
- chained_validators = [v.ValidPerms(type_='user_group')]
+ chained_validators = [v.ValidPerms(localizer, type_='user_group')]
return _UserPermsForm
-def RepoFieldForm():
+def RepoFieldForm(localizer):
+ _ = localizer
+
class _RepoFieldForm(formencode.Schema):
filter_extra_fields = True
allow_extra_fields = True
- new_field_key = All(v.FieldKey(),
+ new_field_key = All(v.FieldKey(localizer),
v.UnicodeString(strip=True, min=3, not_empty=True))
new_field_value = v.UnicodeString(not_empty=False, if_missing=u'')
new_field_type = v.OneOf(['str', 'unicode', 'list', 'tuple'],
if_missing='str')
new_field_label = v.UnicodeString(not_empty=False)
new_field_desc = v.UnicodeString(not_empty=False)
-
return _RepoFieldForm
-def RepoForkForm(edit=False, old_data={}, supported_backends=BACKENDS.keys(),
- repo_groups=[], landing_revs=[]):
+def RepoForkForm(localizer, edit=False, old_data=None,
+ supported_backends=BACKENDS.keys(), repo_groups=None,
+ landing_revs=None):
+ _ = localizer
+ old_data = old_data or {}
+ repo_groups = repo_groups or []
+ landing_revs = landing_revs or []
+
class _RepoForkForm(formencode.Schema):
allow_extra_fields = True
filter_extra_fields = False
repo_name = All(v.UnicodeString(strip=True, min=1, not_empty=True),
- v.SlugifyName())
- repo_group = All(v.CanWriteGroup(),
+ v.SlugifyName(localizer))
+ repo_group = All(v.CanWriteGroup(localizer, ),
v.OneOf(repo_groups, hideList=True))
- repo_type = All(v.ValidForkType(old_data), v.OneOf(supported_backends))
+ repo_type = All(v.ValidForkType(localizer, old_data), v.OneOf(supported_backends))
description = v.UnicodeString(strip=True, min=1, not_empty=True)
private = v.StringBoolean(if_missing=False)
copy_permissions = v.StringBoolean(if_missing=False)
fork_parent_id = v.UnicodeString()
- chained_validators = [v.ValidForkName(edit, old_data)]
+ chained_validators = [v.ValidForkName(localizer, edit, old_data)]
landing_rev = v.OneOf(landing_revs, hideList=True)
-
return _RepoForkForm
-def ApplicationSettingsForm():
+def ApplicationSettingsForm(localizer):
+ _ = localizer
+
class _ApplicationSettingsForm(formencode.Schema):
allow_extra_fields = True
filter_extra_fields = False
@@ -346,11 +372,12 @@ def ApplicationSettingsForm():
rhodecode_captcha_private_key = v.UnicodeString(strip=True, min=1, not_empty=False)
rhodecode_create_personal_repo_group = v.StringBoolean(if_missing=False)
rhodecode_personal_repo_group_pattern = v.UnicodeString(strip=True, min=1, not_empty=False)
-
return _ApplicationSettingsForm
-def ApplicationVisualisationForm():
+def ApplicationVisualisationForm(localizer):
+ _ = localizer
+
class _ApplicationVisualisationForm(formencode.Schema):
allow_extra_fields = True
filter_extra_fields = False
@@ -370,11 +397,11 @@ def ApplicationVisualisationForm():
rhodecode_support_url = v.UnicodeString()
rhodecode_show_revision_number = v.StringBoolean(if_missing=False)
rhodecode_show_sha_length = v.Int(min=4, not_empty=True)
-
return _ApplicationVisualisationForm
class _BaseVcsSettingsForm(formencode.Schema):
+
allow_extra_fields = True
filter_extra_fields = False
hooks_changegroup_repo_size = v.StringBoolean(if_missing=False)
@@ -403,48 +430,54 @@ class _BaseVcsSettingsForm(formencode.Sc
vcs_svn_proxy_http_server_url = v.UnicodeString(strip=True, if_missing=None)
-def ApplicationUiSettingsForm():
+def ApplicationUiSettingsForm(localizer):
+ _ = localizer
+
class _ApplicationUiSettingsForm(_BaseVcsSettingsForm):
web_push_ssl = v.StringBoolean(if_missing=False)
paths_root_path = All(
- v.ValidPath(),
+ v.ValidPath(localizer),
v.UnicodeString(strip=True, min=1, not_empty=True)
)
largefiles_usercache = All(
- v.ValidPath(),
+ v.ValidPath(localizer),
v.UnicodeString(strip=True, min=2, not_empty=True))
vcs_git_lfs_store_location = All(
- v.ValidPath(),
+ v.ValidPath(localizer),
v.UnicodeString(strip=True, min=2, not_empty=True))
extensions_hgsubversion = v.StringBoolean(if_missing=False)
extensions_hggit = v.StringBoolean(if_missing=False)
- new_svn_branch = v.ValidSvnPattern(section='vcs_svn_branch')
- new_svn_tag = v.ValidSvnPattern(section='vcs_svn_tag')
-
+ new_svn_branch = v.ValidSvnPattern(localizer, section='vcs_svn_branch')
+ new_svn_tag = v.ValidSvnPattern(localizer, section='vcs_svn_tag')
return _ApplicationUiSettingsForm
-def RepoVcsSettingsForm(repo_name):
+def RepoVcsSettingsForm(localizer, repo_name):
+ _ = localizer
+
class _RepoVcsSettingsForm(_BaseVcsSettingsForm):
inherit_global_settings = v.StringBoolean(if_missing=False)
- new_svn_branch = v.ValidSvnPattern(
+ new_svn_branch = v.ValidSvnPattern(localizer,
section='vcs_svn_branch', repo_name=repo_name)
- new_svn_tag = v.ValidSvnPattern(
+ new_svn_tag = v.ValidSvnPattern(localizer,
section='vcs_svn_tag', repo_name=repo_name)
-
return _RepoVcsSettingsForm
-def LabsSettingsForm():
+def LabsSettingsForm(localizer):
+ _ = localizer
+
class _LabSettingsForm(formencode.Schema):
allow_extra_fields = True
filter_extra_fields = False
-
return _LabSettingsForm
def ApplicationPermissionsForm(
- register_choices, password_reset_choices, extern_activate_choices):
+ localizer, register_choices, password_reset_choices,
+ extern_activate_choices):
+ _ = localizer
+
class _DefaultPermissionsForm(formencode.Schema):
allow_extra_fields = True
filter_extra_fields = True
@@ -454,12 +487,13 @@ def ApplicationPermissionsForm(
default_register_message = v.UnicodeString()
default_password_reset = v.OneOf(password_reset_choices)
default_extern_activate = v.OneOf(extern_activate_choices)
-
return _DefaultPermissionsForm
-def ObjectPermissionsForm(repo_perms_choices, group_perms_choices,
+def ObjectPermissionsForm(localizer, repo_perms_choices, group_perms_choices,
user_group_perms_choices):
+ _ = localizer
+
class _ObjectPermissionsForm(formencode.Schema):
allow_extra_fields = True
filter_extra_fields = True
@@ -469,13 +503,14 @@ def ObjectPermissionsForm(repo_perms_cho
default_repo_perm = v.OneOf(repo_perms_choices)
default_group_perm = v.OneOf(group_perms_choices)
default_user_group_perm = v.OneOf(user_group_perms_choices)
-
return _ObjectPermissionsForm
-def UserPermissionsForm(create_choices, create_on_write_choices,
+def UserPermissionsForm(localizer, create_choices, create_on_write_choices,
repo_group_create_choices, user_group_create_choices,
fork_choices, inherit_default_permissions_choices):
+ _ = localizer
+
class _DefaultPermissionsForm(formencode.Schema):
allow_extra_fields = True
filter_extra_fields = True
@@ -488,21 +523,24 @@ def UserPermissionsForm(create_choices,
default_repo_group_create = v.OneOf(repo_group_create_choices)
default_fork_create = v.OneOf(fork_choices)
default_inherit_default_permissions = v.OneOf(inherit_default_permissions_choices)
-
return _DefaultPermissionsForm
-def UserIndividualPermissionsForm():
+def UserIndividualPermissionsForm(localizer):
+ _ = localizer
+
class _DefaultPermissionsForm(formencode.Schema):
allow_extra_fields = True
filter_extra_fields = True
inherit_default_permissions = v.StringBoolean(if_missing=False)
-
return _DefaultPermissionsForm
-def DefaultsForm(edit=False, old_data={}, supported_backends=BACKENDS.keys()):
+def DefaultsForm(localizer, edit=False, old_data=None, supported_backends=BACKENDS.keys()):
+ _ = localizer
+ old_data = old_data or {}
+
class _DefaultsForm(formencode.Schema):
allow_extra_fields = True
filter_extra_fields = True
@@ -511,34 +549,39 @@ def DefaultsForm(edit=False, old_data={}
default_repo_enable_statistics = v.StringBoolean(if_missing=False)
default_repo_enable_downloads = v.StringBoolean(if_missing=False)
default_repo_enable_locking = v.StringBoolean(if_missing=False)
-
return _DefaultsForm
-def AuthSettingsForm():
+def AuthSettingsForm(localizer):
+ _ = localizer
+
class _AuthSettingsForm(formencode.Schema):
allow_extra_fields = True
filter_extra_fields = True
- auth_plugins = All(v.ValidAuthPlugins(),
- v.UniqueListFromString()(not_empty=True))
-
+ auth_plugins = All(v.ValidAuthPlugins(localizer),
+ v.UniqueListFromString(localizer)(not_empty=True))
return _AuthSettingsForm
-def UserExtraEmailForm():
+def UserExtraEmailForm(localizer):
+ _ = localizer
+
class _UserExtraEmailForm(formencode.Schema):
- email = All(v.UniqSystemEmail(), v.Email(not_empty=True))
+ email = All(v.UniqSystemEmail(localizer), v.Email(not_empty=True))
return _UserExtraEmailForm
-def UserExtraIpForm():
+def UserExtraIpForm(localizer):
+ _ = localizer
+
class _UserExtraIpForm(formencode.Schema):
- ip = v.ValidIp()(not_empty=True)
+ ip = v.ValidIp(localizer)(not_empty=True)
return _UserExtraIpForm
+def PullRequestForm(localizer, repo_id):
+ _ = localizer
-def PullRequestForm(repo_id):
class ReviewerForm(formencode.Schema):
user_id = v.Int(not_empty=True)
reasons = All()
@@ -553,8 +596,8 @@ def PullRequestForm(repo_id):
source_ref = v.UnicodeString(strip=True, required=True)
target_repo = v.UnicodeString(strip=True, required=True)
target_ref = v.UnicodeString(strip=True, required=True)
- revisions = All(#v.NotReviewedRevisions(repo_id)(),
- v.UniqueList()(not_empty=True))
+ revisions = All(#v.NotReviewedRevisions(localizer, repo_id)(),
+ v.UniqueList(localizer)(not_empty=True))
review_members = formencode.ForEach(ReviewerForm())
pullrequest_title = v.UnicodeString(strip=True, required=True)
pullrequest_desc = v.UnicodeString(strip=True, required=False)
@@ -562,9 +605,11 @@ def PullRequestForm(repo_id):
return _PullRequestForm
-def IssueTrackerPatternsForm():
+def IssueTrackerPatternsForm(localizer):
+ _ = localizer
+
class _IssueTrackerPatternsForm(formencode.Schema):
allow_extra_fields = True
filter_extra_fields = False
- chained_validators = [v.ValidPattern()]
+ chained_validators = [v.ValidPattern(localizer)]
return _IssueTrackerPatternsForm
diff --git a/rhodecode/model/scm.py b/rhodecode/model/scm.py
--- a/rhodecode/model/scm.py
+++ b/rhodecode/model/scm.py
@@ -30,7 +30,7 @@ import logging
import cStringIO
import pkg_resources
-from pylons.i18n.translation import _
+from rhodecode.translation import temp_translation_factory as _
from sqlalchemy import func
from zope.cachedescriptors.property import Lazy as LazyProperty
diff --git a/rhodecode/model/user.py b/rhodecode/model/user.py
--- a/rhodecode/model/user.py
+++ b/rhodecode/model/user.py
@@ -26,7 +26,7 @@ import logging
import traceback
import datetime
-from pylons.i18n.translation import _
+from rhodecode.translation import temp_translation_factory as _
import ipaddress
from sqlalchemy.exc import DatabaseError
@@ -754,14 +754,12 @@ class UserModel(BaseModel):
:param user:
:param email:
"""
- from rhodecode.model import forms
- form = forms.UserExtraEmailForm()()
- data = form.to_python({'email': email})
+
user = self._get_user(user)
obj = UserEmailMap()
obj.user = user
- obj.email = data['email']
+ obj.email = email
self.sa.add(obj)
return obj
@@ -811,14 +809,11 @@ class UserModel(BaseModel):
:param user:
:param ip:
"""
- from rhodecode.model import forms
- form = forms.UserExtraIpForm()()
- data = form.to_python({'ip': ip})
+
user = self._get_user(user)
-
obj = UserIpMap()
obj.user = user
- obj.ip_addr = data['ip']
+ obj.ip_addr = ip
obj.description = description
self.sa.add(obj)
return obj
diff --git a/rhodecode/model/validators.py b/rhodecode/model/validators.py
--- a/rhodecode/model/validators.py
+++ b/rhodecode/model/validators.py
@@ -22,10 +22,11 @@
Set of generic validators
"""
-import logging
+
import os
import re
-from collections import defaultdict
+import logging
+import collections
import formencode
import ipaddress
@@ -33,7 +34,7 @@ from formencode.validators import (
UnicodeString, OneOf, Int, Number, Regex, Email, Bool, StringBoolean, Set,
NotEmpty, IPAddress, CIDR, String, FancyValidator
)
-from pylons.i18n.translation import _
+
from sqlalchemy.sql.expression import true
from sqlalchemy.util import OrderedSet
from webhelpers.pylonslib.secure_form import authentication_token
@@ -62,17 +63,11 @@ log = logging.getLogger(__name__)
class _Missing(object):
pass
+
Missing = _Missing()
-class StateObj(object):
- """
- this is needed to translate the messages using _() in validators
- """
- _ = staticmethod(_)
-
-
-def M(self, key, state=None, **kwargs):
+def M(self, key, state, **kwargs):
"""
returns string from self.message based on given key,
passed kw params are used to substitute %(named)s params inside
@@ -81,16 +76,16 @@ def M(self, key, state=None, **kwargs):
:param msg:
:param state:
"""
- if state is None:
- state = StateObj()
- else:
- state._ = staticmethod(_)
+
+ #state._ = staticmethod(_)
# inject validator into state object
return self.message(key, state, **kwargs)
-def UniqueList(convert=None):
- class _UniqueList(formencode.FancyValidator):
+def UniqueList(localizer, convert=None):
+ _ = localizer
+
+ class _validator(formencode.FancyValidator):
"""
Unique List !
"""
@@ -123,20 +118,23 @@ def UniqueList(convert=None):
def empty_value(self, value):
return []
-
- return _UniqueList
+ return _validator
-def UniqueListFromString():
- class _UniqueListFromString(UniqueList()):
+def UniqueListFromString(localizer):
+ _ = localizer
+
+ class _validator(UniqueList(localizer)):
def _to_python(self, value, state):
if isinstance(value, basestring):
value = aslist(value, ',')
- return super(_UniqueListFromString, self)._to_python(value, state)
- return _UniqueListFromString
+ return super(_validator, self)._to_python(value, state)
+ return _validator
-def ValidSvnPattern(section, repo_name=None):
+def ValidSvnPattern(localizer, section, repo_name=None):
+ _ = localizer
+
class _validator(formencode.validators.FancyValidator):
messages = {
'pattern_exists': _(u'Pattern already exists'),
@@ -154,7 +152,10 @@ def ValidSvnPattern(section, repo_name=N
return _validator
-def ValidUsername(edit=False, old_data={}):
+def ValidUsername(localizer, edit=False, old_data=None):
+ _ = localizer
+ old_data = old_data or {}
+
class _validator(formencode.validators.FancyValidator):
messages = {
'username_exists': _(u'Username "%(username)s" already exists'),
@@ -187,13 +188,9 @@ def ValidUsername(edit=False, old_data={
return _validator
-def ValidRegex(msg=None):
- class _validator(formencode.validators.Regex):
- messages = {'invalid': msg or _(u'The input is not valid')}
- return _validator
+def ValidRepoUser(localizer, allow_disabled=False):
+ _ = localizer
-
-def ValidRepoUser(allow_disabled=False):
class _validator(formencode.validators.FancyValidator):
messages = {
'invalid_username': _(u'Username %(username)s is not valid'),
@@ -213,11 +210,13 @@ def ValidRepoUser(allow_disabled=False):
raise formencode.Invalid(
msg, value, state, error_dict={'username': msg}
)
-
return _validator
-def ValidUserGroup(edit=False, old_data={}):
+def ValidUserGroup(localizer, edit=False, old_data=None):
+ _ = localizer
+ old_data = old_data or {}
+
class _validator(formencode.validators.FancyValidator):
messages = {
'invalid_group': _(u'Invalid user group name'),
@@ -254,11 +253,13 @@ def ValidUserGroup(edit=False, old_data=
raise formencode.Invalid(
msg, value, state, error_dict={'users_group_name': msg}
)
-
return _validator
-def ValidRepoGroup(edit=False, old_data={}, can_create_in_root=False):
+def ValidRepoGroup(localizer, edit=False, old_data=None, can_create_in_root=False):
+ _ = localizer
+ old_data = old_data or {}
+
class _validator(formencode.validators.FancyValidator):
messages = {
'group_parent_id': _(u'Cannot assign this group as parent'),
@@ -375,11 +376,12 @@ def ValidRepoGroup(edit=False, old_data=
msg = M(self, 'repo_exists', state, group_name=group_name)
raise formencode.Invalid(
msg, value, state, error_dict={'group_name': msg})
-
return _validator
-def ValidPassword():
+def ValidPassword(localizer):
+ _ = localizer
+
class _validator(formencode.validators.FancyValidator):
messages = {
'invalid_password':
@@ -395,24 +397,11 @@ def ValidPassword():
return _validator
-def ValidOldPassword(username):
- class _validator(formencode.validators.FancyValidator):
- messages = {
- 'invalid_password': _(u'Invalid old password')
- }
+def ValidPasswordsMatch(
+ localizer, passwd='new_password',
+ passwd_confirmation='password_confirmation'):
+ _ = localizer
- def validate_python(self, value, state):
- from rhodecode.authentication.base import authenticate, HTTP_TYPE
- if not authenticate(username, value, '', HTTP_TYPE):
- msg = M(self, 'invalid_password', state)
- raise formencode.Invalid(
- msg, value, state, error_dict={'current_password': msg}
- )
- return _validator
-
-
-def ValidPasswordsMatch(
- passwd='new_password', passwd_confirmation='password_confirmation'):
class _validator(formencode.validators.FancyValidator):
messages = {
'password_mismatch': _(u'Passwords do not match'),
@@ -430,7 +419,9 @@ def ValidPasswordsMatch(
return _validator
-def ValidAuth():
+def ValidAuth(localizer):
+ _ = localizer
+
class _validator(formencode.validators.FancyValidator):
messages = {
'invalid_password': _(u'invalid password'),
@@ -464,7 +455,9 @@ def ValidAuth():
return _validator
-def ValidAuthToken():
+def ValidAuthToken(localizer):
+ _ = localizer
+
class _validator(formencode.validators.FancyValidator):
messages = {
'invalid_token': _(u'Token mismatch')
@@ -477,7 +470,10 @@ def ValidAuthToken():
return _validator
-def ValidRepoName(edit=False, old_data={}):
+def ValidRepoName(localizer, edit=False, old_data=None):
+ old_data = old_data or {}
+ _ = localizer
+
class _validator(formencode.validators.FancyValidator):
messages = {
'invalid_repo_name':
@@ -558,11 +554,15 @@ def ValidRepoName(edit=False, old_data={
return _validator
-def ValidForkName(*args, **kwargs):
- return ValidRepoName(*args, **kwargs)
+def ValidForkName(localizer, *args, **kwargs):
+ _ = localizer
+
+ return ValidRepoName(localizer, *args, **kwargs)
-def SlugifyName():
+def SlugifyName(localizer):
+ _ = localizer
+
class _validator(formencode.validators.FancyValidator):
def _to_python(self, value, state):
@@ -570,11 +570,12 @@ def SlugifyName():
def validate_python(self, value, state):
pass
-
return _validator
-def CannotHaveGitSuffix():
+def CannotHaveGitSuffix(localizer):
+ _ = localizer
+
class _validator(formencode.validators.FancyValidator):
messages = {
'has_git_suffix':
@@ -590,11 +591,12 @@ def CannotHaveGitSuffix():
self, 'has_git_suffix', state)
raise formencode.Invalid(
msg, value, state, error_dict={'repo_name': msg})
-
return _validator
-def ValidCloneUri():
+def ValidCloneUri(localizer):
+ _ = localizer
+
class InvalidCloneUrl(Exception):
allowed_prefixes = ()
@@ -652,19 +654,22 @@ def ValidCloneUri():
url_handler(repo_type, url)
except InvalidCloneUrl as e:
log.warning(e)
- msg = M(self, 'invalid_clone_uri', rtype=repo_type,
+ msg = M(self, 'invalid_clone_uri', state, rtype=repo_type,
allowed_prefixes=','.join(e.allowed_prefixes))
raise formencode.Invalid(msg, value, state,
error_dict={'clone_uri': msg})
except Exception:
log.exception('Url validation failed')
- msg = M(self, 'clone_uri', rtype=repo_type)
+ msg = M(self, 'clone_uri', state, rtype=repo_type)
raise formencode.Invalid(msg, value, state,
error_dict={'clone_uri': msg})
return _validator
-def ValidForkType(old_data={}):
+def ValidForkType(localizer, old_data=None):
+ _ = localizer
+ old_data = old_data or {}
+
class _validator(formencode.validators.FancyValidator):
messages = {
'invalid_fork_type': _(u'Fork have to be the same type as parent')
@@ -679,7 +684,9 @@ def ValidForkType(old_data={}):
return _validator
-def CanWriteGroup(old_data=None):
+def CanWriteGroup(localizer, old_data=None):
+ _ = localizer
+
class _validator(formencode.validators.FancyValidator):
messages = {
'permission_denied': _(
@@ -730,11 +737,11 @@ def CanWriteGroup(old_data=None):
raise formencode.Invalid(
msg, value, state, error_dict={'repo_type': msg}
)
-
return _validator
-def ValidPerms(type_='repo'):
+def ValidPerms(localizer, type_='repo'):
+ _ = localizer
if type_ == 'repo_group':
EMPTY_PERM = 'group.none'
elif type_ == 'repo':
@@ -756,8 +763,8 @@ def ValidPerms(type_='repo'):
# Read the perm_new_member/perm_del_member attributes and group
# them by they IDs
- new_perms_group = defaultdict(dict)
- del_perms_group = defaultdict(dict)
+ new_perms_group = collections.defaultdict(dict)
+ del_perms_group = collections.defaultdict(dict)
for k, v in value.copy().iteritems():
if k.startswith('perm_del_member'):
# delete from org storage so we don't process that later
@@ -851,29 +858,9 @@ def ValidPerms(type_='repo'):
return _validator
-def ValidSettings():
- class _validator(formencode.validators.FancyValidator):
- def _to_python(self, value, state):
- # settings form for users that are not admin
- # can't edit certain parameters, it's extra backup if they mangle
- # with forms
-
- forbidden_params = [
- 'user', 'repo_type', 'repo_enable_locking',
- 'repo_enable_downloads', 'repo_enable_statistics'
- ]
+def ValidPath(localizer):
+ _ = localizer
- for param in forbidden_params:
- if param in value:
- del value[param]
- return value
-
- def validate_python(self, value, state):
- pass
- return _validator
-
-
-def ValidPath():
class _validator(formencode.validators.FancyValidator):
messages = {
'invalid_path': _(u'This is not a valid path')
@@ -888,7 +875,10 @@ def ValidPath():
return _validator
-def UniqSystemEmail(old_data={}):
+def UniqSystemEmail(localizer, old_data=None):
+ _ = localizer
+ old_data = old_data or {}
+
class _validator(formencode.validators.FancyValidator):
messages = {
'email_taken': _(u'This e-mail address is already taken')
@@ -908,7 +898,9 @@ def UniqSystemEmail(old_data={}):
return _validator
-def ValidSystemEmail():
+def ValidSystemEmail(localizer):
+ _ = localizer
+
class _validator(formencode.validators.FancyValidator):
messages = {
'non_existing_email': _(u'e-mail "%(email)s" does not exist.')
@@ -924,11 +916,11 @@ def ValidSystemEmail():
raise formencode.Invalid(
msg, value, state, error_dict={'email': msg}
)
-
return _validator
-def NotReviewedRevisions(repo_id):
+def NotReviewedRevisions(localizer, repo_id):
+ _ = localizer
class _validator(formencode.validators.FancyValidator):
messages = {
'rev_already_reviewed':
@@ -960,7 +952,9 @@ def NotReviewedRevisions(repo_id):
return _validator
-def ValidIp():
+def ValidIp(localizer):
+ _ = localizer
+
class _validator(CIDR):
messages = {
'badFormat': _(u'Please enter a valid IPv4 or IpV6 address'),
@@ -984,11 +978,12 @@ def ValidIp():
except ValueError:
raise formencode.Invalid(self.message('badFormat', state),
value, state)
-
return _validator
-def FieldKey():
+def FieldKey(localizer):
+ _ = localizer
+
class _validator(formencode.validators.FancyValidator):
messages = {
'badFormat': _(
@@ -1003,7 +998,9 @@ def FieldKey():
return _validator
-def ValidAuthPlugins():
+def ValidAuthPlugins(localizer):
+ _ = localizer
+
class _validator(formencode.validators.FancyValidator):
messages = {
'import_duplicate': _(
@@ -1033,11 +1030,11 @@ def ValidAuthPlugins():
log.exception(
'Exception during import of auth legacy plugin "{}"'
.format(plugin_id))
- msg = M(self, 'import_error', plugin_id=plugin_id)
+ msg = M(self, 'import_error', state, plugin_id=plugin_id)
raise formencode.Invalid(msg, value, state)
if not hasattr(plugin, 'includeme'):
- msg = M(self, 'missing_includeme', plugin_id=plugin_id)
+ msg = M(self, 'missing_includeme', state, plugin_id=plugin_id)
raise formencode.Invalid(msg, value, state)
return plugin
@@ -1051,7 +1048,7 @@ def ValidAuthPlugins():
plugin = loadplugin(plugin_id)
if plugin is None:
- msg = M(self, 'no_plugin', plugin_id=plugin_id)
+ msg = M(self, 'no_plugin', state, plugin_id=plugin_id)
raise formencode.Invalid(msg, value, state)
return plugin
@@ -1074,13 +1071,13 @@ def ValidAuthPlugins():
next_to_load=plugin)
raise formencode.Invalid(msg, value, state)
unique_names[plugin.name] = plugin
-
return _validator
-def ValidPattern():
+def ValidPattern(localizer):
+ _ = localizer
- class _Validator(formencode.validators.FancyValidator):
+ class _validator(formencode.validators.FancyValidator):
messages = {
'bad_format': _(u'Url must start with http or /'),
}
@@ -1129,4 +1126,4 @@ def ValidPattern():
delete_patterns = [delete_patterns]
value['delete_patterns'] = delete_patterns
return value
- return _Validator
+ return _validator
diff --git a/rhodecode/subscribers.py b/rhodecode/subscribers.py
--- a/rhodecode/subscribers.py
+++ b/rhodecode/subscribers.py
@@ -21,7 +21,6 @@ import io
import re
import datetime
import logging
-import pylons
import Queue
import subprocess32
import os
@@ -36,14 +35,11 @@ from threading import Thread
from rhodecode.translation import _ as tsf
from rhodecode.config.jsroutes import generate_jsroutes_content
from rhodecode.lib import auth
+from rhodecode.lib.base import get_auth_user
+
import rhodecode
-from pylons.i18n.translation import _get_translator
-from pylons.util import ContextObj
-from routes.util import URLGenerator
-
-from rhodecode.lib.base import attach_context_attributes, get_auth_user
log = logging.getLogger(__name__)
@@ -51,11 +47,6 @@ log = logging.getLogger(__name__)
def add_renderer_globals(event):
from rhodecode.lib import helpers
- # NOTE(marcink):
- # Put pylons stuff into the context. This will be removed as soon as
- # migration to pyramid is finished.
- event['c'] = pylons.tmpl_context
-
# TODO: When executed in pyramid view context the request is not available
# in the event. Find a better solution to get the request.
request = event['request'] or get_current_request()
@@ -68,12 +59,11 @@ def add_renderer_globals(event):
def add_localizer(event):
request = event.request
- localizer = get_localizer(request)
+ localizer = request.localizer
def auto_translate(*args, **kwargs):
return localizer.translate(tsf(*args, **kwargs))
- request.localizer = localizer
request.translate = auto_translate
request.plularize = localizer.pluralize
@@ -108,39 +98,6 @@ def add_request_user_context(event):
request.environ['rc_auth_user'] = auth_user
-def add_pylons_context(event):
- request = event.request
-
- config = rhodecode.CONFIG
- environ = request.environ
- session = request.session
-
- if hasattr(request, 'vcs_call'):
- # skip vcs calls
- return
-
- # Setup pylons globals.
- pylons.config._push_object(config)
- pylons.request._push_object(request)
- pylons.session._push_object(session)
- pylons.translator._push_object(_get_translator(config.get('lang')))
-
- pylons.url._push_object(URLGenerator(config['routes.map'], environ))
- session_key = (
- config['pylons.environ_config'].get('session', 'beaker.session'))
- environ[session_key] = session
-
- if hasattr(request, 'rpc_method'):
- # skip api calls
- return
-
- # Setup the pylons context object ('c')
- context = ContextObj()
- context.rhodecode_user = request.user
- attach_context_attributes(context, request, request.user.user_id)
- pylons.tmpl_context._push_object(context)
-
-
def inject_app_settings(event):
settings = event.app.registry.settings
# inject info about available permissions
diff --git a/rhodecode/templates/admin/admin_audit_log_entry.mako b/rhodecode/templates/admin/admin_audit_log_entry.mako
--- a/rhodecode/templates/admin/admin_audit_log_entry.mako
+++ b/rhodecode/templates/admin/admin_audit_log_entry.mako
@@ -61,14 +61,14 @@
% if c.audit_log_entry.version == c.audit_log_entry.VERSION_1:
- ${h.action_parser(l)[0]()}
+ ${h.action_parser(request, l)[0]()}
% else:
${h.literal(c.audit_log_entry.action)}
% endif
% if c.audit_log_entry.version == c.audit_log_entry.VERSION_1:
- ${h.literal(h.action_parser(l)[1]())}
+ ${h.literal(h.action_parser(request, l)[1]())}
% endif
|
diff --git a/rhodecode/templates/admin/admin_audit_logs.mako b/rhodecode/templates/admin/admin_audit_logs.mako
--- a/rhodecode/templates/admin/admin_audit_logs.mako
+++ b/rhodecode/templates/admin/admin_audit_logs.mako
@@ -14,7 +14,7 @@
${_('Audit logs')} - ${_ungettext('%s entry', '%s entries', c.audit_logs.item_count) % (c.audit_logs.item_count)}
${h.end_form()}
- ${_('Example Queries')}
+ ${_('Example Queries')}
%def>
<%def name="menu_bar_nav()">
diff --git a/rhodecode/templates/admin/admin_log_base.mako b/rhodecode/templates/admin/admin_log_base.mako
--- a/rhodecode/templates/admin/admin_log_base.mako
+++ b/rhodecode/templates/admin/admin_log_base.mako
@@ -26,14 +26,14 @@
% if l.version == l.VERSION_1:
- ${h.action_parser(l)[0]()}
+ ${h.action_parser(request, l)[0]()}
% else:
${h.literal(l.action)}
% endif
% if l.version == l.VERSION_1:
- ${h.literal(h.action_parser(l)[1]())}
+ ${h.literal(h.action_parser(request, l)[1]())}
% endif
|
diff --git a/rhodecode/templates/admin/repos/repo_edit_audit.mako b/rhodecode/templates/admin/repos/repo_edit_audit.mako
--- a/rhodecode/templates/admin/repos/repo_edit_audit.mako
+++ b/rhodecode/templates/admin/repos/repo_edit_audit.mako
@@ -14,7 +14,7 @@
${h.end_form()}
- ${_('Example Queries')}
+ ${_('Example Queries')}
<%include file="/admin/admin_log_base.mako" />
diff --git a/rhodecode/templates/admin/users/user_edit_audit.mako b/rhodecode/templates/admin/users/user_edit_audit.mako
--- a/rhodecode/templates/admin/users/user_edit_audit.mako
+++ b/rhodecode/templates/admin/users/user_edit_audit.mako
@@ -14,7 +14,7 @@
${h.end_form()}
- ${_('Example Queries')}
+ ${_('Example Queries')}
<%include file="/admin/admin_log_base.mako" />
diff --git a/rhodecode/templates/base/plugins_base.mako b/rhodecode/templates/base/plugins_base.mako
--- a/rhodecode/templates/base/plugins_base.mako
+++ b/rhodecode/templates/base/plugins_base.mako
@@ -1,11 +1,8 @@
-<%
-from pyramid.renderers import render as pyramid_render
-from pyramid.threadlocal import get_current_registry, get_current_request
-pyramid_registry = get_current_registry()
-%>
-% for plugin, config in getattr(pyramid_registry, 'rhodecode_plugins', {}).items():
-% if config['template_hooks'].get('plugin_init_template'):
-${pyramid_render(config['template_hooks'].get('plugin_init_template'),
-{'config':config}, request=get_current_request(), package='rc_ae')|n}
-% endif
+
+% for plugin, config in getattr(request.registry, 'rhodecode_plugins', {}).items():
+ <% tmpl = config['template_hooks'].get('plugin_init_template') %>
+
+ % if tmpl:
+ <%include file="${tmpl}" args="config=config"/>
+ % endif
% endfor
diff --git a/rhodecode/templates/channelstream/plugin_init.mako b/rhodecode/templates/channelstream/plugin_init.mako
--- a/rhodecode/templates/channelstream/plugin_init.mako
+++ b/rhodecode/templates/channelstream/plugin_init.mako
@@ -1,3 +1,5 @@
+<%page args="config"/>
+