Changeset - ec7b76d4bda4
[Not reviewed]
default
0 4 0
Marcin Kuzminski - 15 years ago 2010-07-27 14:41:43
marcin@python-works.com
Added initial query skipp when seting up the app.
Added internal server error when deleting user using ajax permission form
removed graph unneded code
4 files changed with 11 insertions and 27 deletions:
0 comments (0 inline, 0 general)
pylons_app/config/environment.py
Show inline comments
 
@@ -6,25 +6,25 @@ from pylons_app.config.routing import ma
 
from pylons_app.lib.auth import set_available_permissions, set_base_path
 
from pylons_app.lib.utils import repo2db_mapper, make_ui, set_hg_app_config
 
from pylons_app.model import init_model
 
from pylons_app.model.hg_model import _get_repos_cached_initial
 
from sqlalchemy import engine_from_config
 
import logging
 
import os
 
import pylons_app.lib.app_globals as app_globals
 
import pylons_app.lib.helpers
 

	
 
log = logging.getLogger(__name__)
 

	
 
def load_environment(global_conf, app_conf):
 
def load_environment(global_conf, app_conf, initial=False):
 
    """Configure the Pylons environment via the ``pylons.config``
 
    object
 
    """
 
    config = PylonsConfig()
 
    
 
    # Pylons paths
 
    root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
 
    paths = dict(root=root,
 
                 controllers=os.path.join(root, 'controllers'),
 
                 static_files=os.path.join(root, 'public'),
 
                 templates=[os.path.join(root, 'templates')])
 

	
 
@@ -54,20 +54,20 @@ def load_environment(global_conf, app_co
 
    # Setup the SQLAlchemy database engine
 
    if config['debug']:
 
        #use query time debugging.
 
        from pylons_app.lib.timerproxy import TimerProxy
 
        sa_engine_db1 = engine_from_config(config, 'sqlalchemy.db1.',
 
                                                            proxy=TimerProxy())
 
    else:
 
        sa_engine_db1 = engine_from_config(config, 'sqlalchemy.db1.')
 

	
 
    init_model(sa_engine_db1)
 
    config['pylons.app_globals'].baseui = make_ui('db')
 
    
 
    repo2db_mapper(_get_repos_cached_initial(config['pylons.app_globals']))
 
    repo2db_mapper(_get_repos_cached_initial(config['pylons.app_globals'], initial))
 
    set_available_permissions(config)
 
    set_base_path(config)
 
    set_hg_app_config(config)
 
    # CONFIGURATION OPTIONS HERE (note: all config options will override
 
    # any Pylons config options)
 
    
 
    return config
pylons_app/controllers/admin/repos.py
Show inline comments
 
@@ -7,44 +7,46 @@
 
# as published by the Free Software Foundation; version 2
 
# of the License or (at your opinion) any later version of the license.
 
# 
 
# 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.
 
# 
 
# You should have received a copy of the GNU General Public License
 
# along with this program; if not, write to the Free Software
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 
# MA  02110-1301, USA.
 
"""
 
Created on April 7, 2010
 
admin controller for pylons
 
@author: marcink
 
"""
 
from formencode import htmlfill
 
from operator import itemgetter
 
from pylons import request, response, session, tmpl_context as c, url
 
from pylons.controllers.util import abort, redirect
 
from pylons.i18n.translation import _
 
from pylons_app.lib import helpers as h
 
from pylons_app.lib.auth import LoginRequired, HasPermissionAllDecorator
 
from pylons_app.lib.base import BaseController, render
 
from pylons_app.lib.utils import invalidate_cache
 
from pylons_app.model.forms import RepoForm
 
from pylons_app.model.hg_model import HgModel
 
from pylons_app.model.repo_model import RepoModel
 
import formencode
 
import logging
 
import traceback
 
"""
 
Created on April 7, 2010
 
admin controller for pylons
 
@author: marcink
 
"""
 
from paste.httpexceptions import HTTPInternalServerError
 

	
 
log = logging.getLogger(__name__)
 

	
 
class ReposController(BaseController):
 
    """REST Controller styled on the Atom Publishing Protocol"""
 
    # To properly map this controller, ensure your config/routing.py
 
    # file has a resource setup:
 
    #     map.resource('repo', 'repos')
 
    
 
    @LoginRequired()
 
    @HasPermissionAllDecorator('hg.admin')
 
    def __before__(self):
 
        c.admin_user = session.get('admin_user')
 
@@ -121,25 +123,24 @@ class ReposController(BaseController):
 
            return htmlfill.render(
 
                render('admin/repos/repo_edit.html'),
 
                defaults=errors.value,
 
                errors=errors.error_dict or {},
 
                prefix_error=False,
 
                encoding="UTF-8")
 
 
 
        except Exception:
 
            log.error(traceback.format_exc())
 
            h.flash(_('error occured during update of repository %s') \
 
                    % repo_name, category='error')
 
            
 
        
 
        return redirect(url('edit_repo', repo_name=changed_name))
 
    
 
    def delete(self, repo_name):
 
        """DELETE /repos/repo_name: Delete an existing item"""
 
        # Forms posted to this method should contain a hidden field:
 
        #    <input type="hidden" name="_method" value="DELETE" />
 
        # Or using helpers:
 
        #    h.form(url('repo', repo_name=ID),
 
        #           method='delete')
 
        # url('repo', repo_name=ID)
 
        
 
        repo_model = RepoModel()
 
@@ -165,25 +166,25 @@ class ReposController(BaseController):
 
    def delete_perm_user(self, repo_name):
 
        """
 
        DELETE an existing repository permission user
 
        @param repo_name:
 
        """
 
        
 
        try:
 
            repo_model = RepoModel()
 
            repo_model.delete_perm_user(request.POST, repo_name)            
 
        except Exception as e:
 
            h.flash(_('An error occured during deletion of repository user'),
 
                    category='error')
 
        
 
            raise HTTPInternalServerError()
 
        
 
    def show(self, repo_name, format='html'):
 
        """GET /repos/repo_name: Show a specific item"""
 
        # url('repo', repo_name=ID)
 
        
 
    def edit(self, repo_name, format='html'):
 
        """GET /repos/repo_name/edit: Form to edit an existing item"""
 
        # url('edit_repo', repo_name=ID)
 
        repo_model = RepoModel()
 
        c.repo_info = repo = repo_model.get(repo_name)
 
        if not repo:
 
            h.flash(_('%s repository is not mapped to db perhaps' 
pylons_app/controllers/summary.py
Show inline comments
 
@@ -63,50 +63,33 @@ class SummaryController(BaseController):
 
        for name, hash in c.repo_info.branches.items()[:10]:
 
            c.repo_branches[name] = c.repo_info.get_changeset(hash)
 

	
 
        c.commit_data = self.__get_commit_stats(c.repo_info)
 
        
 
        return render('summary/summary.html')
 

	
 

	
 

	
 
    def __get_commit_stats(self, repo):
 
        aggregate = OrderedDict()
 
        
 
        
 
        #graph range
 
        td = datetime.today() 
 
        y = td.year
 
        m = td.month
 
        d = td.day
 
        c.ts_min = mktime((y, (td - timedelta(days=calendar.mdays[m] - 1)).month, d, 0, 0, 0, 0, 0, 0,))
 
        c.ts_max = mktime((y, m, d, 0, 0, 0, 0, 0, 0,))
 
        
 
        
 
#        #generate this monhts keys
 
#        dates_range = OrderedDict()
 
#        year_range = range(2010, datetime.today().year + 1)
 
#        month_range = range(1, datetime.today().month + 1)
 
#        
 
#
 
#        
 
#        for y in year_range:
 
#            for m in month_range:
 
#                for d in range(1, calendar.mdays[m] + 1):
 
#                    k = '%s-%s-%s' % (y, m, d)
 
#                    timetupple = [int(x) for x in k.split('-')]
 
#                    timetupple.extend([0 for _ in xrange(6)])
 
#                    k = mktime(timetupple)                    
 
#                    dates_range[k] = 0
 
        
 
        def author_key_cleaner(k):
 
            k = person(k)
 
            return k
 
                
 
        for cs in repo:
 
            k = '%s-%s-%s' % (cs.date.timetuple()[0], cs.date.timetuple()[1],
 
                              cs.date.timetuple()[2])
 
            timetupple = [int(x) for x in k.split('-')]
 
            timetupple.extend([0 for _ in xrange(6)])
 
            k = mktime(timetupple)
 
            if aggregate.has_key(author_key_cleaner(cs.author)):
 
                if aggregate[author_key_cleaner(cs.author)].has_key(k):
pylons_app/websetup.py
Show inline comments
 
@@ -10,14 +10,14 @@ import sys
 
log = logging.getLogger(__name__)
 

	
 
ROOT = dn(dn(os.path.realpath(__file__)))
 
sys.path.append(ROOT)
 

	
 
def setup_app(command, conf, vars):
 
    """Place any commands to setup pylons_app here"""
 
    dbmanage = DbManage(log_sql=True)
 
    dbmanage.create_tables(override=True)
 
    dbmanage.config_prompt()
 
    dbmanage.admin_prompt()
 
    dbmanage.create_permissions()
 
    load_environment(conf.global_conf, conf.local_conf)
 
    load_environment(conf.global_conf, conf.local_conf, initial=True)
 

	
0 comments (0 inline, 0 general)