##// END OF EJS Templates
Moved repo creation to admin/repos, as part of crud controller. Now repo creation is based on a form, which can be auto filled with data from 404 page. Fixed the error controller to properly give the repo name.
marcink -
r215:70f645fa default
parent child Browse files
Show More
@@ -8,8 +8,9 b' from pylons.i18n.translation import _'
8 from pylons_app.lib.base import BaseController, render
8 from pylons_app.lib.base import BaseController, render
9 from pylons.middleware import media_path
9 from pylons.middleware import media_path
10 from pylons_app.lib.utils import check_repo
10 from pylons_app.lib.utils import check_repo
11 from pylons_app.lib.filters import clean_repo
12 log = logging.getLogger(__name__)
11
13
12 log = logging.getLogger(__name__)
13 class ErrorController(BaseController):
14 class ErrorController(BaseController):
14 """
15 """
15 Generates error documents as and when they are required.
16 Generates error documents as and when they are required.
@@ -20,9 +21,12 b' class ErrorController(BaseController):'
20 This behaviour can be altered by changing the parameters to the
21 This behaviour can be altered by changing the parameters to the
21 ErrorDocuments middleware in your config/middleware.py file.
22 ErrorDocuments middleware in your config/middleware.py file.
22 """
23 """
24 # def __before__(self):
25 # super(ErrorController, self).__before__()
23
26
24 def document(self):
27 def document(self):
25 resp = request.environ.get('pylons.original_response')
28 resp = request.environ.get('pylons.original_response')
29
26 log.debug(resp.status)
30 log.debug(resp.status)
27
31
28 e = request.environ
32 e = request.environ
@@ -33,7 +37,10 b' class ErrorController(BaseController):'
33
37
34
38
35 if resp.status_int == 404:
39 if resp.status_int == 404:
36 if check_repo(c.repo_name, g.base_path):
40 org_e = request.environ.get('pylons.original_request').environ
41 c.repo_name = repo_name = org_e['PATH_INFO'].split('/')[1]
42 c.repo_name_cleaned = clean_repo(c.repo_name)
43 if check_repo(repo_name, g.base_path):
37 return render('/errors/error_404.html')
44 return render('/errors/error_404.html')
38
45
39 c.error_message = cgi.escape(request.GET.get('code', str(resp.status)))
46 c.error_message = cgi.escape(request.GET.get('code', str(resp.status)))
@@ -1,14 +1,12 b''
1 from pylons import request, response, session, tmpl_context as c, url, \
2 app_globals as g
3 from pylons.controllers.util import abort, redirect
4 from pylons_app.lib.base import BaseController, render
5 from pylons_app.lib.utils import check_repo, invalidate_cache
1 import logging
6 import logging
2 import os
7 import os
3 from pylons import request, response, session, tmpl_context as c, url, app_globals as g
4 from pylons.controllers.util import abort, redirect
5 from pylons_app.lib import auth
6 from pylons_app.lib.base import BaseController, render
7 from pylons_app.model.db import Users, UserLogs
8 from pylons_app.model.hg_model import HgModel
9 from operator import itemgetter
10 import shutil
8 import shutil
11 from pylons_app.lib.utils import invalidate_cache
9 from pylons_app.lib.filters import clean_repo
12 log = logging.getLogger(__name__)
10 log = logging.getLogger(__name__)
13
11
14 class ReposController(BaseController):
12 class ReposController(BaseController):
@@ -31,10 +29,31 b' class ReposController(BaseController):'
31 def create(self):
29 def create(self):
32 """POST /repos: Create a new item"""
30 """POST /repos: Create a new item"""
33 # url('repos')
31 # url('repos')
32 name = request.POST.get('name')
33
34 try:
35 self._create_repo(name)
36 #clear our cached list for refresh with new repo
37 invalidate_cache('cached_repo_list')
38 except Exception as e:
39 log.error(e)
40
41 return redirect('repos')
42
43 def _create_repo(self, repo_name):
44 repo_path = os.path.join(g.base_path, repo_name)
45 if check_repo(repo_name, g.base_path):
46 log.info('creating repo %s in %s', repo_name, repo_path)
47 from vcs.backends.hg import MercurialRepository
48 MercurialRepository(repo_path, create=True)
49
34
50
35 def new(self, format='html'):
51 def new(self, format='html'):
36 """GET /repos/new: Form to create a new item"""
52 """GET /repos/new: Form to create a new item"""
37 # url('new_repo')
53 new_repo = request.GET.get('repo', '')
54 c.new_repo = clean_repo(new_repo)
55
56 return render('admin/repos/repo_add.html')
38
57
39 def update(self, id):
58 def update(self, id):
40 """PUT /repos/id: Update an existing item"""
59 """PUT /repos/id: Update an existing item"""
@@ -22,13 +22,14 b' from pylons_app.lib import filters'
22 </%def>
22 </%def>
23 <%def name="main()">
23 <%def name="main()">
24
24
25 <h2 class="no-link no-border">Not Found</h2>
25 <h2 class="no-link no-border">${_('Not Found')}</h2>
26 <p class="normal">The specified repository "${c.repo_name}" is unknown, sorry.</p>
26 <p class="normal">${_('The specified repository "%s" is unknown, sorry.') % c.repo_name}</p>
27 <p class="normal">
27 <p class="normal">
28 <a href="/_admin/add_repo/${c.repo_name|n,filters.clean_repo}">Create "${c.repo_name}" repository as ${c.repo_name|n,filters.clean_repo}</a>
28 <a href="${h.url('new_repo',repo=c.repo_name_cleaned)}">
29 ${_('Create "%s" repository as %s' % (c.repo_name,c.repo_name_cleaned))}</a>
29
30
30 </p>
31 </p>
31 <p class="normal">Go back to the ${h.link_to(_('main repository list page'),h.url('hg_home'))}.</p>
32 <p class="normal">${h.link_to(_('Go back to the main repository list page'),h.url('hg_home'))}</p>
32 <div class="page-footer">
33 <div class="page-footer">
33 </div>
34 </div>
34 </%def> No newline at end of file
35 </%def>
General Comments 0
You need to be logged in to leave comments. Login now