diff --git a/pylons_app/controllers/error.py b/pylons_app/controllers/error.py --- a/pylons_app/controllers/error.py +++ b/pylons_app/controllers/error.py @@ -8,8 +8,9 @@ from pylons.i18n.translation import _ from pylons_app.lib.base import BaseController, render from pylons.middleware import media_path from pylons_app.lib.utils import check_repo +from pylons_app.lib.filters import clean_repo +log = logging.getLogger(__name__) -log = logging.getLogger(__name__) class ErrorController(BaseController): """ Generates error documents as and when they are required. @@ -20,9 +21,12 @@ class ErrorController(BaseController): This behaviour can be altered by changing the parameters to the ErrorDocuments middleware in your config/middleware.py file. """ +# def __before__(self): +# super(ErrorController, self).__before__() def document(self): resp = request.environ.get('pylons.original_response') + log.debug(resp.status) e = request.environ @@ -33,7 +37,10 @@ class ErrorController(BaseController): if resp.status_int == 404: - if check_repo(c.repo_name, g.base_path): + org_e = request.environ.get('pylons.original_request').environ + c.repo_name = repo_name = org_e['PATH_INFO'].split('/')[1] + c.repo_name_cleaned = clean_repo(c.repo_name) + if check_repo(repo_name, g.base_path): return render('/errors/error_404.html') c.error_message = cgi.escape(request.GET.get('code', str(resp.status))) diff --git a/pylons_app/controllers/repos.py b/pylons_app/controllers/repos.py --- a/pylons_app/controllers/repos.py +++ b/pylons_app/controllers/repos.py @@ -1,14 +1,12 @@ +from pylons import request, response, session, tmpl_context as c, url, \ + app_globals as g +from pylons.controllers.util import abort, redirect +from pylons_app.lib.base import BaseController, render +from pylons_app.lib.utils import check_repo, invalidate_cache import logging import os -from pylons import request, response, session, tmpl_context as c, url, app_globals as g -from pylons.controllers.util import abort, redirect -from pylons_app.lib import auth -from pylons_app.lib.base import BaseController, render -from pylons_app.model.db import Users, UserLogs -from pylons_app.model.hg_model import HgModel -from operator import itemgetter import shutil -from pylons_app.lib.utils import invalidate_cache +from pylons_app.lib.filters import clean_repo log = logging.getLogger(__name__) class ReposController(BaseController): @@ -31,10 +29,31 @@ class ReposController(BaseController): def create(self): """POST /repos: Create a new item""" # url('repos') + name = request.POST.get('name') + + try: + self._create_repo(name) + #clear our cached list for refresh with new repo + invalidate_cache('cached_repo_list') + except Exception as e: + log.error(e) + + return redirect('repos') + + def _create_repo(self, repo_name): + repo_path = os.path.join(g.base_path, repo_name) + if check_repo(repo_name, g.base_path): + log.info('creating repo %s in %s', repo_name, repo_path) + from vcs.backends.hg import MercurialRepository + MercurialRepository(repo_path, create=True) + def new(self, format='html'): """GET /repos/new: Form to create a new item""" - # url('new_repo') + new_repo = request.GET.get('repo', '') + c.new_repo = clean_repo(new_repo) + + return render('admin/repos/repo_add.html') def update(self, id): """PUT /repos/id: Update an existing item""" diff --git a/pylons_app/templates/errors/error_404.html b/pylons_app/templates/errors/error_404.html --- a/pylons_app/templates/errors/error_404.html +++ b/pylons_app/templates/errors/error_404.html @@ -22,13 +22,14 @@ from pylons_app.lib import filters %def> <%def name="main()"> -
The specified repository "${c.repo_name}" is unknown, sorry.
+${_('The specified repository "%s" is unknown, sorry.') % c.repo_name}
- Create "${c.repo_name}" repository as ${c.repo_name|n,filters.clean_repo} + + ${_('Create "%s" repository as %s' % (c.repo_name,c.repo_name_cleaned))}
-Go back to the ${h.link_to(_('main repository list page'),h.url('hg_home'))}.
+${h.link_to(_('Go back to the main repository list page'),h.url('hg_home'))}
%def> \ No newline at end of file