##// END OF EJS Templates
Code refactor number 2
marcink -
r1022:4f834b0a beta
parent child Browse files
Show More
@@ -40,7 +40,7 b' from rhodecode.lib import helpers as h'
40 40 from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator, \
41 41 HasPermissionAnyDecorator
42 42 from rhodecode.lib.base import BaseController, render
43 from rhodecode.lib.utils import invalidate_cache, action_logger
43 from rhodecode.lib.utils import invalidate_cache, action_logger, repo_name_slug
44 44 from rhodecode.model.db import User
45 45 from rhodecode.model.forms import RepoForm
46 46 from rhodecode.model.scm import ScmModel
@@ -118,7 +118,7 b' class ReposController(BaseController):'
118 118 def new(self, format='html'):
119 119 """GET /repos/new: Form to create a new item"""
120 120 new_repo = request.GET.get('repo', '')
121 c.new_repo = h.repo_name_slug(new_repo)
121 c.new_repo = repo_name_slug(new_repo)
122 122
123 123 return render('admin/repos/repo_add.html')
124 124
@@ -29,7 +29,7 b' import logging'
29 29 import traceback
30 30 import formencode
31 31
32 from operator import itemgetter
32 from sqlalchemy import func
33 33 from formencode import htmlfill
34 34 from pylons import request, session, tmpl_context as c, url, app_globals as g, \
35 35 config
@@ -50,8 +50,6 b' from rhodecode.model.scm import ScmModel'
50 50 from rhodecode.model.settings import SettingsModel
51 51 from rhodecode.model.user import UserModel
52 52
53 from sqlalchemy import func
54
55 53
56 54 log = logging.getLogger(__name__)
57 55
@@ -324,7 +322,7 b' class SettingsController(BaseController)'
324 322 def create_repository(self):
325 323 """GET /_admin/create_repository: Form to create a new item"""
326 324 new_repo = request.GET.get('repo', '')
327 c.new_repo = h.repo_name_slug(new_repo)
325 c.new_repo = repo_name_slug(new_repo)
328 326
329 327 return render('admin/repos/repo_add_create_repository.html')
330 328
@@ -8,9 +8,11 b' import hashlib'
8 8 import StringIO
9 9 from pygments.formatters import HtmlFormatter
10 10 from pygments import highlight as code_highlight
11 from pylons import url, app_globals as g
11 from pylons import url
12 12 from pylons.i18n.translation import _, ungettext
13 13 from vcs.utils.annotate import annotate_highlight
14 from rhodecode.lib.utils import repo_name_slug
15
14 16 from webhelpers.html import literal, HTML, escape
15 17 from webhelpers.html.tools import *
16 18 from webhelpers.html.builder import make_tag
@@ -73,23 +75,6 b' class _GetError(object):'
73 75
74 76 get_error = _GetError()
75 77
76 def recursive_replace(str, replace=' '):
77 """Recursive replace of given sign to just one instance
78
79 :param str: given string
80 :param replace: char to find and replace multiple instances
81
82 Examples::
83 >>> recursive_replace("Mighty---Mighty-Bo--sstones",'-')
84 'Mighty-Mighty-Bo-sstones'
85 """
86
87 if str.find(replace * 2) == -1:
88 return str
89 else:
90 str = str.replace(replace * 2, replace)
91 return recursive_replace(str, replace)
92
93 78 class _ToolTip(object):
94 79
95 80 def __call__(self, tooltip_title, trim_at=50):
@@ -357,21 +342,6 b' def pygmentize_annotation(filenode, **kw'
357 342 return uri
358 343 return literal(annotate_highlight(filenode, url_func, **kwargs))
359 344
360 def repo_name_slug(value):
361 """Return slug of name of repository
362 This function is called on each creation/modification
363 of repository to prevent bad names in repo
364 """
365
366 slug = remove_formatting(value)
367 slug = strip_tags(slug)
368
369 for c in """=[]\;'"<>,/~!@#$%^&*()+{}|: """:
370 slug = slug.replace(c, '-')
371 slug = recursive_replace(slug, '-')
372 slug = collapse(slug, '-')
373 return slug
374
375 345 def get_changeset_safe(repo, rev):
376 346 from vcs.backends.base import BaseRepository
377 347 from vcs.exceptions import RepositoryError
@@ -29,15 +29,17 b' import os'
29 29 import logging
30 30 import datetime
31 31 import traceback
32 import paste
33 import beaker
34
35 from paste.script.command import Command, BadCommand
32 36
33 37 from UserDict import DictMixin
34 38
35 39 from mercurial import ui, config, hg
36 40 from mercurial.error import RepoError
37 41
38 import paste
39 import beaker
40 from paste.script.command import Command, BadCommand
42 from webhelpers.text import collapse, remove_formatting, strip_tags
41 43
42 44 from vcs.backends.base import BaseChangeset
43 45 from vcs.utils.lazy import LazyProperty
@@ -51,6 +53,38 b' from rhodecode.model.user import UserMod'
51 53 log = logging.getLogger(__name__)
52 54
53 55
56 def recursive_replace(str, replace=' '):
57 """Recursive replace of given sign to just one instance
58
59 :param str: given string
60 :param replace: char to find and replace multiple instances
61
62 Examples::
63 >>> recursive_replace("Mighty---Mighty-Bo--sstones",'-')
64 'Mighty-Mighty-Bo-sstones'
65 """
66
67 if str.find(replace * 2) == -1:
68 return str
69 else:
70 str = str.replace(replace * 2, replace)
71 return recursive_replace(str, replace)
72
73 def repo_name_slug(value):
74 """Return slug of name of repository
75 This function is called on each creation/modification
76 of repository to prevent bad names in repo
77 """
78
79 slug = remove_formatting(value)
80 slug = strip_tags(slug)
81
82 for c in """=[]\;'"<>,/~!@#$%^&*()+{}|: """:
83 slug = slug.replace(c, '-')
84 slug = recursive_replace(slug, '-')
85 slug = collapse(slug, '-')
86 return slug
87
54 88 def get_repo_slug(request):
55 89 return request.environ['pylons.routes_dict'].get('repo_name')
56 90
@@ -29,8 +29,9 b' from formencode.validators import Unicod'
29 29 Email, Bool, StringBoolean, Set
30 30
31 31 from pylons.i18n.translation import _
32 from webhelpers.pylonslib.secure_form import authentication_token
32 33
33 import rhodecode.lib.helpers as h
34 from rhodecode.lib.utils import repo_name_slug
34 35 from rhodecode.lib.auth import authenticate, get_crypt_password
35 36 from rhodecode.lib.exceptions import LdapImportError
36 37 from rhodecode.model import meta
@@ -40,8 +41,6 b' from rhodecode.model.users_group import '
40 41 from rhodecode.model.db import User, UsersGroup
41 42 from rhodecode import BACKENDS
42 43
43 from webhelpers.pylonslib.secure_form import authentication_token
44
45 44 log = logging.getLogger(__name__)
46 45
47 46 #this is needed to translate the messages using _() in validators
@@ -214,7 +213,7 b' def ValidRepoName(edit, old_data):'
214 213 class _ValidRepoName(formencode.validators.FancyValidator):
215 214
216 215 def to_python(self, value, state):
217 slug = h.repo_name_slug(value)
216 slug = repo_name_slug(value)
218 217 if slug in ['_admin']:
219 218 raise formencode.Invalid(_('This repository name is disallowed'),
220 219 value, state)
@@ -29,30 +29,29 b' import time'
29 29 import traceback
30 30 import logging
31 31
32 from mercurial import ui
33
34 from sqlalchemy.orm import joinedload
35 from sqlalchemy.orm.session import make_transient
36 from sqlalchemy.exc import DatabaseError
37
38 from beaker.cache import cache_region, region_invalidate
39
32 40 from vcs import get_backend
33 41 from vcs.utils.helpers import get_scm
34 42 from vcs.exceptions import RepositoryError, VCSError
35 43 from vcs.utils.lazy import LazyProperty
36 44
37 from mercurial import ui
38
39 from beaker.cache import cache_region, region_invalidate
40
41 45 from rhodecode import BACKENDS
42 46 from rhodecode.lib import helpers as h
43 47 from rhodecode.lib.auth import HasRepoPermissionAny
44 48 from rhodecode.lib.utils import get_repos as get_filesystem_repos, make_ui, action_logger
45 49 from rhodecode.model import BaseModel
46 50 from rhodecode.model.user import UserModel
47
48 51 from rhodecode.model.db import Repository, RhodeCodeUi, CacheInvalidation, \
49 52 UserFollowing, UserLog
50 53 from rhodecode.model.caching_query import FromCache
51 54
52 from sqlalchemy.orm import joinedload
53 from sqlalchemy.orm.session import make_transient
54 from sqlalchemy.exc import DatabaseError
55
56 55 log = logging.getLogger(__name__)
57 56
58 57
General Comments 0
You need to be logged in to leave comments. Login now