Files
@ b5e59e2b5cfe
Branch filter:
Location: kallithea/pylons_app/controllers/admin.py - annotation
b5e59e2b5cfe
3.7 KiB
text/x-python
moved cache invalidating to utils, as seperate function. Implemented invalidating in
2e1247e62c5b 919b5bcd8630 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b d924b931b488 a886f5eba757 a886f5eba757 a886f5eba757 4df4c0eac619 4df4c0eac619 6f524697f79d b5e59e2b5cfe b5e59e2b5cfe 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 25e516447a33 a886f5eba757 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b a886f5eba757 a886f5eba757 a886f5eba757 a886f5eba757 a886f5eba757 a886f5eba757 9db7782727b3 a886f5eba757 a886f5eba757 a886f5eba757 a886f5eba757 a886f5eba757 a886f5eba757 a886f5eba757 a886f5eba757 a886f5eba757 a886f5eba757 a886f5eba757 a886f5eba757 20dc7a5eb748 a886f5eba757 a886f5eba757 a886f5eba757 a886f5eba757 a886f5eba757 a886f5eba757 4df4c0eac619 4df4c0eac619 6f524697f79d 6f524697f79d 6f524697f79d 6f524697f79d 6f524697f79d 20dc7a5eb748 9fe23fdab9e9 9fe23fdab9e9 20dc7a5eb748 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b d924b931b488 d924b931b488 2e1247e62c5b 919b5bcd8630 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 919b5bcd8630 b5e59e2b5cfe 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 919b5bcd8630 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 2e1247e62c5b 919b5bcd8630 2811259dc12d 919b5bcd8630 919b5bcd8630 919b5bcd8630 919b5bcd8630 | 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.base import BaseController, render
from pylons_app.lib import auth
from pylons_app.model.forms import LoginForm
import formencode
import formencode.htmlfill as htmlfill
from pylons_app.model import meta
from pylons_app.model.db import Users, UserLogs
from webhelpers.paginate import Page
from pylons_app.lib.utils import check_repo, invalidate_cache
log = logging.getLogger(__name__)
class AdminController(BaseController):
def __before__(self):
c.admin_user = session.get('admin_user', False)
c.admin_username = session.get('admin_username')
def index(self):
# Return a rendered template
if request.POST:
#import Login Form validator class
login_form = LoginForm()
try:
c.form_result = login_form.to_python(dict(request.params))
if auth.admin_auth(c.form_result['username'], c.form_result['password']):
session['admin_user'] = True
session['admin_username'] = c.form_result['username']
session.save()
return redirect(url('admin_home'))
else:
raise formencode.Invalid('Login Error', None, None,
error_dict={'username':'invalid login',
'password':'invalid password'})
except formencode.Invalid, error:
c.form_result = error.value
c.form_errors = error.error_dict or {}
html = render('admin/admin.html')
return htmlfill.render(
html,
defaults=c.form_result,
encoding="UTF-8"
)
if c.admin_user:
sa = meta.Session
users_log = sa.query(UserLogs)\
.order_by(UserLogs.action_date.desc())
p = int(request.params.get('page', 1))
c.users_log = Page(users_log, page=p, items_per_page=10)
c.log_data = render('admin/admin_log.html')
if request.params.get('partial'):
return c.log_data
return render('admin/admin.html')
def hgrc(self, dirname):
filename = os.path.join(dirname, '.hg', 'hgrc')
return filename
def add_repo(self, new_repo):
#extra check it can be add since it's the command
if new_repo == '_admin':
c.msg = 'DENIED'
c.new_repo = ''
return render('admin/add.html')
new_repo = new_repo.replace(" ", "_")
new_repo = new_repo.replace("-", "_")
try:
self._create_repo(new_repo)
c.new_repo = new_repo
c.msg = 'added repo'
#clear our cached list for refresh with new repo
invalidate_cache('repo_list_2')
except Exception as e:
c.new_repo = 'Exception when adding: %s' % new_repo
c.msg = str(e)
return render('admin/add.html')
def _create_repo(self, repo_name):
if repo_name in [None, '', 'add']:
raise Exception('undefined repo_name of repo')
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)
|