comparison pylons_app/controllers/hg.py @ 20:bbaab7501c1a

Added custom templates, did over check of code to make it work. Added templating for add repository, and styling. App globals now handles our custom static files. (logo etc can be changed)
author Marcin Kuzminski
date Sun, 28 Feb 2010 01:52:38 +0100
parents 5f30a6d558dc
children fac1f62a1d71
comparison
equal deleted inserted replaced
19:38235b614e3f 20:bbaab7501c1a
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # -*- coding: utf-8 -*- 2 # -*- coding: utf-8 -*-
3 import logging 3 import logging
4 from pylons_app.lib.base import BaseController 4 from pylons_app.lib.base import BaseController, render
5 from pylons import c, g, session, h, request 5 from pylons import c, g, session, h, request
6 from mako.template import Template 6 from mako.template import Template
7 from pprint import pprint 7 from pprint import pprint
8 import os 8 import os
9 from mercurial import ui, hg 9 from mercurial import ui, hg
18 18
19 def view(self, *args, **kwargs): 19 def view(self, *args, **kwargs):
20 return g.hgapp(request.environ, self.start_response) 20 return g.hgapp(request.environ, self.start_response)
21 21
22 def add_repo(self, new_repo): 22 def add_repo(self, new_repo):
23 tmpl = u''' 23 c.staticurl = g.statics
24 <html> 24
25 <body>
26 %(msg)s%(new_repo)s!<br \>
27 <a href="/">repos</a>
28 </body>
29 </html>
30 '''
31 #extra check it can be add since it's the command 25 #extra check it can be add since it's the command
32 if new_repo == 'add': 26 if new_repo == 'add':
33 return [tmpl % ({'new_repo':'', 'msg':'you basstard ! this repo is a command'})] 27 c.msg = 'you basstard ! this repo is a command'
28 c.new_repo = ''
29 return render('add.html')
34 30
35 new_repo = new_repo.replace(" ", "_") 31 new_repo = new_repo.replace(" ", "_")
36 new_repo = new_repo.replace("-", "_") 32 new_repo = new_repo.replace("-", "_")
37 33
38 try: 34 try:
39 self._create_repo(new_repo) 35 self._create_repo(new_repo)
36 c.new_repo = new_repo
37 c.msg = 'added repo'
40 except Exception as e: 38 except Exception as e:
41 return [tmpl % ({'new_repo':' Exception when adding: ' + new_repo, 'msg':str(e)})] 39 c.new_repo = 'Exception when adding: %s' % new_repo
40 c.msg = str(e)
42 41
43 return [tmpl % ({'new_repo':new_repo, 'msg':'added repo: '})] 42 return render('add.html')
44 43
45 def _check_repo(self, repo_name): 44 def _check_repo(self, repo_name):
46 p = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) 45 p = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
47 config_path = os.path.join(p, 'hgwebdir.config') 46 config_path = os.path.join(p, 'hgwebdir.config')
48 47