##// END OF EJS Templates
fixed #746 unicodeDedode errors on feed controllers
fixed #746 unicodeDedode errors on feed controllers

File last commit:

r3098:a5f0bc86 merge rhodecode-0.0.1.5.0 default
r3355:06f77c32 default
Show More
admin.py
149 lines | 5.3 KiB | text/x-python | PythonLexer
Cleaned up scm model codes,Admin/admin permissions controller codes
r760 # -*- coding: utf-8 -*-
"""
some docs updates on controller
r853 rhodecode.controllers.admin.admin
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Cleaned up scm model codes,Admin/admin permissions controller codes
r760
dirty fix for issue #87
r825 Controller for Admin panel of Rhodecode
source code cleanup: remove trailing white space, normalize file endings
r1203
Cleaned up scm model codes,Admin/admin permissions controller codes
r760 :created_on: Apr 7, 2010
:author: marcink
2012 copyrights
r1824 :copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com>
Cleaned up scm model codes,Admin/admin permissions controller codes
r760 :license: GPLv3, see COPYING for more details.
"""
fixed license issue #149
r1206 # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
source code cleanup: remove trailing white space, normalize file endings
r1203 #
renamed project to rhodecode
r547 # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
source code cleanup: remove trailing white space, normalize file endings
r1203 #
renamed project to rhodecode
r547 # You should have received a copy of the GNU General Public License
fixed license issue #149
r1206 # along with this program. If not, see <http://www.gnu.org/licenses/>.
Cleaned up scm model codes,Admin/admin permissions controller codes
r760
renamed project to rhodecode
r547 import logging
fixes fixes fixes ! optimized queries on journal...
r1040
Implemented filtering of admin journal based on Whoosh Query language...
r3062 from pylons import request, tmpl_context as c, url
fixes fixes fixes ! optimized queries on journal...
r1040 from sqlalchemy.orm import joinedload
from webhelpers.paginate import Page
Implemented filtering of admin journal based on Whoosh Query language...
r3062 from whoosh.qparser.default import QueryParser
from whoosh import query
fixed tests, made the journal filter consistent accross different databases
r3072 from sqlalchemy.sql.expression import or_, and_, func
fixes fixes fixes ! optimized queries on journal...
r1040
from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator
renamed project to rhodecode
r547 from rhodecode.lib.base import BaseController, render
Implemented filtering of admin journal based on Whoosh Query language...
r3062 from rhodecode.model.db import UserLog, User
Implemented better support for Wildcard queries...
r3063 from rhodecode.lib.utils2 import safe_int, remove_prefix, remove_suffix
Implemented filtering of admin journal based on Whoosh Query language...
r3062 from rhodecode.lib.indexers import JOURNAL_SCHEMA
final implementation of #210 journal filtering.
r3070 from whoosh.qparser.dateparse import DateParserPlugin
Implemented filtering of admin journal based on Whoosh Query language...
r3062
renamed project to rhodecode
r547
log = logging.getLogger(__name__)
PEP8ify - controllers
r1245
final implementation of #210 journal filtering.
r3070 def _journal_filter(user_log, search_term):
Implemented filtering of admin journal based on Whoosh Query language...
r3062 """
Filters sqlalchemy user_log based on search_term with whoosh Query language
http://packages.python.org/Whoosh/querylang.html
:param user_log:
:param search_term:
"""
Implemented better support for Wildcard queries...
r3063 log.debug('Initial search term: %r' % search_term)
Implemented filtering of admin journal based on Whoosh Query language...
r3062 qry = None
if search_term:
qp = QueryParser('repository', schema=JOURNAL_SCHEMA)
final implementation of #210 journal filtering.
r3070 qp.add_plugin(DateParserPlugin())
Implemented filtering of admin journal based on Whoosh Query language...
r3062 qry = qp.parse(unicode(search_term))
Implemented better support for Wildcard queries...
r3063 log.debug('Filtering using parsed query %r' % qry)
def wildcard_handler(col, wc_term):
if wc_term.startswith('*') and not wc_term.endswith('*'):
#postfix == endswith
wc_term = remove_prefix(wc_term, prefix='*')
fixed tests, made the journal filter consistent accross different databases
r3072 return func.lower(col).endswith(wc_term)
Implemented better support for Wildcard queries...
r3063 elif wc_term.startswith('*') and wc_term.endswith('*'):
#wildcard == ilike
wc_term = remove_prefix(wc_term, prefix='*')
wc_term = remove_suffix(wc_term, suffix='*')
fixed tests, made the journal filter consistent accross different databases
r3072 return func.lower(col).contains(wc_term)
Implemented filtering of admin journal based on Whoosh Query language...
r3062
def get_filterion(field, val, term):
Implemented better support for Wildcard queries...
r3063
Implemented filtering of admin journal based on Whoosh Query language...
r3062 if field == 'repository':
field = getattr(UserLog, 'repository_name')
elif field == 'ip':
field = getattr(UserLog, 'user_ip')
elif field == 'date':
field = getattr(UserLog, 'action_date')
elif field == 'username':
Implemented better support for Wildcard queries...
r3063 field = getattr(UserLog, 'username')
Implemented filtering of admin journal based on Whoosh Query language...
r3062 else:
field = getattr(UserLog, field)
Implemented better support for Wildcard queries...
r3063 log.debug('filter field: %s val=>%s' % (field, val))
Implemented filtering of admin journal based on Whoosh Query language...
r3062
#sql filtering
if isinstance(term, query.Wildcard):
Implemented better support for Wildcard queries...
r3063 return wildcard_handler(field, val)
Implemented filtering of admin journal based on Whoosh Query language...
r3062 elif isinstance(term, query.Prefix):
fixed tests, made the journal filter consistent accross different databases
r3072 return func.lower(field).startswith(func.lower(val))
final implementation of #210 journal filtering.
r3070 elif isinstance(term, query.DateRange):
return and_(field >= val[0], field <= val[1])
fixed tests, made the journal filter consistent accross different databases
r3072 return func.lower(field) == func.lower(val)
Implemented filtering of admin journal based on Whoosh Query language...
r3062
final implementation of #210 journal filtering.
r3070 if isinstance(qry, (query.And, query.Term, query.Prefix, query.Wildcard,
query.DateRange)):
Implemented filtering of admin journal based on Whoosh Query language...
r3062 if not isinstance(qry, query.And):
qry = [qry]
for term in qry:
field = term.fieldname
final implementation of #210 journal filtering.
r3070 val = (term.text if not isinstance(term, query.DateRange)
else [term.startdate, term.enddate])
Implemented filtering of admin journal based on Whoosh Query language...
r3062 user_log = user_log.filter(get_filterion(field, val, term))
elif isinstance(qry, query.Or):
filters = []
for term in qry:
field = term.fieldname
final implementation of #210 journal filtering.
r3070 val = (term.text if not isinstance(term, query.DateRange)
else [term.startdate, term.enddate])
Implemented better support for Wildcard queries...
r3063 filters.append(get_filterion(field, val, term))
Implemented filtering of admin journal based on Whoosh Query language...
r3062 user_log = user_log.filter(or_(*filters))
return user_log
renamed project to rhodecode
r547 class AdminController(BaseController):
Cleaned up scm model codes,Admin/admin permissions controller codes
r760
renamed project to rhodecode
r547 @LoginRequired()
def __before__(self):
super(AdminController, self).__before__()
Cleaned up scm model codes,Admin/admin permissions controller codes
r760
@HasPermissionAllDecorator('hg.admin')
renamed project to rhodecode
r547 def index(self):
sqlalchemy sessions cleanup in admin...
r2662 users_log = UserLog.query()\
fixes fixes fixes ! optimized queries on journal...
r1040 .options(joinedload(UserLog.user))\
Implemented filtering of admin journal based on Whoosh Query language...
r3062 .options(joinedload(UserLog.repository))
#FILTERING
c.search_term = request.GET.get('filter')
try:
final implementation of #210 journal filtering.
r3070 users_log = _journal_filter(users_log, c.search_term)
Implemented filtering of admin journal based on Whoosh Query language...
r3062 except:
# we want this to crash for now
raise
users_log = users_log.order_by(UserLog.action_date.desc())
fixes fixes fixes ! optimized queries on journal...
r1040
failsafe the GET `page` argument
r2845 p = safe_int(request.params.get('page', 1), 1)
Implemented filtering of admin journal based on Whoosh Query language...
r3062
def url_generator(**kw):
return url.current(filter=c.search_term, **kw)
c.users_log = Page(users_log, page=p, items_per_page=10, url=url_generator)
renamed project to rhodecode
r547 c.log_data = render('admin/admin_log.html')
Javascripts rewrite: updated yui to latest 2.9, simplified ajax loading for multiple pages. Removed YUI dev package
r1421
if request.environ.get('HTTP_X_PARTIAL_XHR'):
renamed project to rhodecode
r547 return c.log_data
Cleaned up scm model codes,Admin/admin permissions controller codes
r760 return render('admin/admin.html')