# HG changeset patch # User Marcin Kuzminski # Date 2011-04-11 20:47:27 # Node ID 5f2fbab7c42919c820bb592ae1e25a3cb2c089b4 # Parent 0eceb478c720a543372bf1ed9ac2a8f9353f6f1d PEP8ify - controllers diff --git a/rhodecode/controllers/admin/admin.py b/rhodecode/controllers/admin/admin.py --- a/rhodecode/controllers/admin/admin.py +++ b/rhodecode/controllers/admin/admin.py @@ -35,6 +35,7 @@ from rhodecode.model.db import UserLog log = logging.getLogger(__name__) + class AdminController(BaseController): @LoginRequired() diff --git a/rhodecode/controllers/admin/ldap_settings.py b/rhodecode/controllers/admin/ldap_settings.py --- a/rhodecode/controllers/admin/ldap_settings.py +++ b/rhodecode/controllers/admin/ldap_settings.py @@ -43,20 +43,19 @@ from sqlalchemy.exc import DatabaseError log = logging.getLogger(__name__) - class LdapSettingsController(BaseController): - search_scope_choices = [('BASE', _('BASE'),), + search_scope_choices = [('BASE', _('BASE'),), ('ONELEVEL', _('ONELEVEL'),), - ('SUBTREE', _('SUBTREE'),), + ('SUBTREE', _('SUBTREE'),), ] search_scope_default = 'SUBTREE' - tls_reqcert_choices = [('NEVER', _('NEVER'),), - ('ALLOW', _('ALLOW'),), - ('TRY', _('TRY'),), + tls_reqcert_choices = [('NEVER', _('NEVER'),), + ('ALLOW', _('ALLOW'),), + ('TRY', _('TRY'),), ('DEMAND', _('DEMAND'),), - ('HARD', _('HARD'),), + ('HARD', _('HARD'),), ] tls_reqcert_default = 'DEMAND' @@ -66,13 +65,13 @@ class LdapSettingsController(BaseControl c.admin_user = session.get('admin_user') c.admin_username = session.get('admin_username') c.search_scope_choices = self.search_scope_choices - c.tls_reqcert_choices = self.tls_reqcert_choices + c.tls_reqcert_choices = self.tls_reqcert_choices super(LdapSettingsController, self).__before__() def index(self): defaults = SettingsModel().get_ldap_settings() c.search_scope_cur = defaults.get('ldap_search_scope') - c.tls_reqcert_cur = defaults.get('ldap_tls_reqcert') + c.tls_reqcert_cur = defaults.get('ldap_tls_reqcert') return htmlfill.render( render('admin/ldap/ldap.html'), @@ -109,7 +108,7 @@ class LdapSettingsController(BaseControl except formencode.Invalid, errors: c.search_scope_cur = self.search_scope_default - c.tls_reqcert_cur = self.search_scope_default + c.tls_reqcert_cur = self.search_scope_default return htmlfill.render( render('admin/ldap/ldap.html'), diff --git a/rhodecode/controllers/admin/permissions.py b/rhodecode/controllers/admin/permissions.py --- a/rhodecode/controllers/admin/permissions.py +++ b/rhodecode/controllers/admin/permissions.py @@ -41,6 +41,7 @@ import traceback log = logging.getLogger(__name__) + class PermissionsController(BaseController): """REST Controller styled on the Atom Publishing Protocol""" # To properly map this controller, ensure your config/routing.py @@ -69,7 +70,6 @@ class PermissionsController(BaseControll self.create_choices = [('hg.create.none', _('Disabled')), ('hg.create.repository', _('Enabled'))] - def index(self, format='html'): """GET /permissions: All items in the collection""" # url('permissions') @@ -99,7 +99,7 @@ class PermissionsController(BaseControll try: form_result = _form.to_python(dict(request.POST)) - form_result.update({'perm_user_name':id}) + form_result.update({'perm_user_name': id}) permission_model.update(form_result) h.flash(_('Default permissions updated successfully'), category='success') @@ -123,8 +123,6 @@ class PermissionsController(BaseControll return redirect(url('edit_permission', id=id)) - - def delete(self, id): """DELETE /permissions/id: Delete an existing item""" # Forms posted to this method should contain a hidden field: @@ -147,8 +145,8 @@ class PermissionsController(BaseControll if id == 'default': default_user = UserModel().get_by_username('default') - defaults = {'_method':'put', - 'anonymous':default_user.active} + defaults = {'_method': 'put', + 'anonymous': default_user.active} for p in default_user.user_perms: if p.permission.permission_name.startswith('repository.'): diff --git a/rhodecode/controllers/admin/repos.py b/rhodecode/controllers/admin/repos.py --- a/rhodecode/controllers/admin/repos.py +++ b/rhodecode/controllers/admin/repos.py @@ -47,6 +47,7 @@ from rhodecode.model.repo import RepoMod log = logging.getLogger(__name__) + class ReposController(BaseController): """ REST Controller styled on the Atom Publishing Protocol""" @@ -65,8 +66,8 @@ class ReposController(BaseController): repo_model = RepoModel() c.repo_groups = [('', '')] - parents_link = lambda k:h.literal('»'.join( - map(lambda k:k.group_name, + parents_link = lambda k: h.literal('»'.join( + map(lambda k: k.group_name, k.parents + [k]) ) ) @@ -90,7 +91,6 @@ class ReposController(BaseController): repo_model = RepoModel() c.repo_info = repo_model.get_by_repo_name(repo_name) - if c.repo_info is None: h.flash(_('%s repository is not mapped to db perhaps' ' it was created or renamed from the filesystem' @@ -100,7 +100,6 @@ class ReposController(BaseController): return redirect(url('repos')) - c.default_user_id = User.by_username('default').user_id c.in_public_journal = self.sa.query(UserFollowing)\ .filter(UserFollowing.user_id == c.default_user_id)\ @@ -120,8 +119,6 @@ class ReposController(BaseController): c.stats_percentage = '%.2f' % ((float((last_rev)) / c.repo_last_rev) * 100) - - defaults = c.repo_info.get_dict() group, repo_name = c.repo_info.groups_and_repo defaults['repo_name'] = repo_name @@ -130,12 +127,11 @@ class ReposController(BaseController): #fill owner if c.repo_info.user: - defaults.update({'user':c.repo_info.user.username}) + defaults.update({'user': c.repo_info.user.username}) else: replacement_user = self.sa.query(User)\ .filter(User.admin == True).first().username - defaults.update({'user':replacement_user}) - + defaults.update({'user': replacement_user}) #fill repository users for p in c.repo_info.repo_to_perm: @@ -147,10 +143,8 @@ class ReposController(BaseController): defaults.update({'g_perm_%s' % p.users_group.users_group_name: p.permission.permission_name}) - return defaults - @HasPermissionAllDecorator('hg.admin') def index(self, format='html'): """GET /repos: All items in the collection""" @@ -232,7 +226,7 @@ class ReposController(BaseController): self.__load_defaults() repo_model = RepoModel() changed_name = repo_name - _form = RepoForm(edit=True, old_data={'repo_name':repo_name}, + _form = RepoForm(edit=True, old_data={'repo_name': repo_name}, repo_groups=c.repo_groups_choices)() try: form_result = _form.to_python(dict(request.POST)) diff --git a/rhodecode/controllers/admin/repos_groups.py b/rhodecode/controllers/admin/repos_groups.py --- a/rhodecode/controllers/admin/repos_groups.py +++ b/rhodecode/controllers/admin/repos_groups.py @@ -9,6 +9,7 @@ from rhodecode.model.db import Group log = logging.getLogger(__name__) + class ReposGroupsController(BaseController): """REST Controller styled on the Atom Publishing Protocol""" # To properly map this controller, ensure your config/routing.py @@ -68,7 +69,6 @@ class ReposGroupsController(BaseControll sort_key = current_sort_slug + '_sort' - #overwrite our cached list with current filter gr_filter = [r.repo_name for r in c.group_repos] c.cached_repo_list = self.scm_model.get_repos(all_repos=gr_filter) @@ -82,10 +82,8 @@ class ReposGroupsController(BaseControll c.repo_cnt = len(c.repos_list) - return render('admin/repos_groups/repos_groups.html') - def edit(self, id, format='html'): """GET /repos_groups/id/edit: Form to edit an existing item""" # url('edit_repos_group', id=ID) diff --git a/rhodecode/controllers/admin/settings.py b/rhodecode/controllers/admin/settings.py --- a/rhodecode/controllers/admin/settings.py +++ b/rhodecode/controllers/admin/settings.py @@ -57,14 +57,12 @@ class SettingsController(BaseController) # map.resource('setting', 'settings', controller='admin/settings', # path_prefix='/admin', name_prefix='admin_') - @LoginRequired() def __before__(self): c.admin_user = session.get('admin_user') c.admin_username = session.get('admin_username') super(SettingsController, self).__before__() - @HasPermissionAllDecorator('hg.admin') def index(self, format='html'): """GET /admin/settings: All items in the collection""" @@ -109,8 +107,8 @@ class SettingsController(BaseController) added, removed = repo2db_mapper(initial, rm_obsolete) h.flash(_('Repositories successfully' - ' rescanned added: %s,removed: %s') % (added, removed) - , category='success') + ' rescanned added: %s,removed: %s') % (added, removed), + category='success') if setting_id == 'whoosh': repo_location = self.get_hg_ui_settings()['paths_root_path'] @@ -127,15 +125,16 @@ class SettingsController(BaseController) try: hgsettings1 = settings_model.get('title') - hgsettings1.app_settings_value = form_result['rhodecode_title'] + hgsettings1.app_settings_value = \ + form_result['rhodecode_title'] hgsettings2 = settings_model.get('realm') - hgsettings2.app_settings_value = form_result['rhodecode_realm'] + hgsettings2.app_settings_value = \ + form_result['rhodecode_realm'] hgsettings3 = settings_model.get('ga_code') - hgsettings3.app_settings_value = form_result['rhodecode_ga_code'] - - + hgsettings3.app_settings_value = \ + form_result['rhodecode_ga_code'] self.sa.add(hgsettings1) self.sa.add(hgsettings2) @@ -147,12 +146,12 @@ class SettingsController(BaseController) except Exception: log.error(traceback.format_exc()) - h.flash(_('error occurred during updating application settings'), + h.flash(_('error occurred during updating ' + 'application settings'), category='error') self.sa.rollback() - except formencode.Invalid, errors: return htmlfill.render( render('admin/settings/settings.html'), @@ -176,24 +175,30 @@ class SettingsController(BaseController) .filter(RhodeCodeUi.ui_key == '/').one() hgsettings2.ui_value = form_result['paths_root_path'] - #HOOKS hgsettings3 = self.sa.query(RhodeCodeUi)\ .filter(RhodeCodeUi.ui_key == 'changegroup.update').one() - hgsettings3.ui_active = bool(form_result['hooks_changegroup_update']) + hgsettings3.ui_active = \ + bool(form_result['hooks_changegroup_update']) hgsettings4 = self.sa.query(RhodeCodeUi)\ - .filter(RhodeCodeUi.ui_key == 'changegroup.repo_size').one() - hgsettings4.ui_active = bool(form_result['hooks_changegroup_repo_size']) + .filter(RhodeCodeUi.ui_key == + 'changegroup.repo_size').one() + hgsettings4.ui_active = \ + bool(form_result['hooks_changegroup_repo_size']) hgsettings5 = self.sa.query(RhodeCodeUi)\ - .filter(RhodeCodeUi.ui_key == 'pretxnchangegroup.push_logger').one() - hgsettings5.ui_active = bool(form_result['hooks_pretxnchangegroup_push_logger']) + .filter(RhodeCodeUi.ui_key == + 'pretxnchangegroup.push_logger').one() + hgsettings5.ui_active = \ + bool(form_result['hooks_pretxnchangegroup' + '_push_logger']) hgsettings6 = self.sa.query(RhodeCodeUi)\ - .filter(RhodeCodeUi.ui_key == 'preoutgoing.pull_logger').one() - hgsettings6.ui_active = bool(form_result['hooks_preoutgoing_pull_logger']) - + .filter(RhodeCodeUi.ui_key == + 'preoutgoing.pull_logger').one() + hgsettings6.ui_active = \ + bool(form_result['hooks_preoutgoing_pull_logger']) self.sa.add(hgsettings1) self.sa.add(hgsettings2) @@ -208,12 +213,11 @@ class SettingsController(BaseController) except: log.error(traceback.format_exc()) - h.flash(_('error occurred during updating application settings'), - category='error') + h.flash(_('error occurred during updating ' + 'application settings'), category='error') self.sa.rollback() - except formencode.Invalid, errors: return htmlfill.render( render('admin/settings/settings.html'), @@ -222,8 +226,6 @@ class SettingsController(BaseController) prefix_error=False, encoding="UTF-8") - - return redirect(url('admin_settings')) @HasPermissionAllDecorator('hg.admin') @@ -238,12 +240,15 @@ class SettingsController(BaseController) @HasPermissionAllDecorator('hg.admin') def show(self, setting_id, format='html'): - """GET /admin/settings/setting_id: Show a specific item""" + """ + GET /admin/settings/setting_id: Show a specific item""" # url('admin_setting', setting_id=ID) @HasPermissionAllDecorator('hg.admin') def edit(self, setting_id, format='html'): - """GET /admin/settings/setting_id/edit: Form to edit an existing item""" + """ + GET /admin/settings/setting_id/edit: Form to + edit an existing item""" # url('admin_edit_setting', setting_id=ID) @NotAnonymous() @@ -282,8 +287,9 @@ class SettingsController(BaseController) # url('admin_settings_my_account_update', id=ID) user_model = UserModel() uid = self.rhodecode_user.user_id - _form = UserForm(edit=True, old_data={'user_id':uid, - 'email':self.rhodecode_user.email})() + _form = UserForm(edit=True, + old_data={'user_id': uid, + 'email': self.rhodecode_user.email})() form_result = {} try: form_result = _form.to_python(dict(request.POST)) @@ -319,8 +325,8 @@ class SettingsController(BaseController) """GET /_admin/create_repository: Form to create a new item""" c.repo_groups = [('', '')] - parents_link = lambda k:h.literal('»'.join( - map(lambda k:k.group_name, + parents_link = lambda k: h.literal('»'.join( + map(lambda k: k.group_name, k.parents + [k]) ) ) diff --git a/rhodecode/controllers/admin/users.py b/rhodecode/controllers/admin/users.py --- a/rhodecode/controllers/admin/users.py +++ b/rhodecode/controllers/admin/users.py @@ -32,7 +32,8 @@ from pylons import request, session, tmp from pylons.controllers.util import abort, redirect from pylons.i18n.translation import _ -from rhodecode.lib.exceptions import DefaultUserException, UserOwnsReposException +from rhodecode.lib.exceptions import DefaultUserException, \ + UserOwnsReposException from rhodecode.lib import helpers as h from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator from rhodecode.lib.base import BaseController, render @@ -43,6 +44,7 @@ from rhodecode.model.user import UserMod log = logging.getLogger(__name__) + class UsersController(BaseController): """REST Controller styled on the Atom Publishing Protocol""" # To properly map this controller, ensure your config/routing.py @@ -105,8 +107,8 @@ class UsersController(BaseController): user_model = UserModel() c.user = user_model.get(id) - _form = UserForm(edit=True, old_data={'user_id':id, - 'email':c.user.email})() + _form = UserForm(edit=True, old_data={'user_id': id, + 'email': c.user.email})() form_result = {} try: form_result = _form.to_python(dict(request.POST)) @@ -150,7 +152,6 @@ class UsersController(BaseController): """GET /users/id: Show a specific item""" # url('user', id=ID) - def edit(self, id, format='html'): """GET /users/id/edit: Form to edit an existing item""" # url('edit_user', id=ID) @@ -162,7 +163,8 @@ class UsersController(BaseController): h.flash(_("You can't edit this user"), category='warning') return redirect(url('users')) c.user.permissions = {} - c.granted_permissions = user_model.fill_perms(c.user).permissions['global'] + c.granted_permissions = user_model.fill_perms(c.user)\ + .permissions['global'] defaults = c.user.get_dict() diff --git a/rhodecode/controllers/admin/users_groups.py b/rhodecode/controllers/admin/users_groups.py --- a/rhodecode/controllers/admin/users_groups.py +++ b/rhodecode/controllers/admin/users_groups.py @@ -32,7 +32,6 @@ from pylons import request, session, tmp from pylons.controllers.util import abort, redirect from pylons.i18n.translation import _ -from rhodecode.lib.exceptions import DefaultUserException, UserOwnsReposException from rhodecode.lib import helpers as h from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator from rhodecode.lib.base import BaseController, render @@ -44,6 +43,7 @@ from rhodecode.model.users_group import log = logging.getLogger(__name__) + class UsersGroupsController(BaseController): """REST Controller styled on the Atom Publishing Protocol""" # To properly map this controller, ensure your config/routing.py @@ -72,8 +72,8 @@ class UsersGroupsController(BaseControll try: form_result = users_group_form.to_python(dict(request.POST)) users_group_model.create(form_result) - h.flash(_('created users group %s') % form_result['users_group_name'], - category='success') + h.flash(_('created users group %s') \ + % form_result['users_group_name'], category='success') #action_logger(self.rhodecode_user, 'new_user', '', '', self.sa) except formencode.Invalid, errors: return htmlfill.render( @@ -103,7 +103,6 @@ class UsersGroupsController(BaseControll # method='put') # url('users_group', id=ID) - users_group_model = UsersGroupModel() c.users_group = users_group_model.get(id) c.group_members = [(x.user_id, x.user.username) for x in @@ -119,7 +118,8 @@ class UsersGroupsController(BaseControll try: form_result = users_group_form.to_python(request.POST) users_group_model.update(id, form_result) - h.flash(_('updated users group %s') % form_result['users_group_name'], + h.flash(_('updated users group %s') \ + % form_result['users_group_name'], category='success') #action_logger(self.rhodecode_user, 'new_user', '', '', self.sa) except formencode.Invalid, errors: @@ -136,8 +136,6 @@ class UsersGroupsController(BaseControll return redirect(url('users_groups')) - - def delete(self, id): """DELETE /users_groups/id: Delete an existing item""" # Forms posted to this method should contain a hidden field: diff --git a/rhodecode/controllers/files.py b/rhodecode/controllers/files.py --- a/rhodecode/controllers/files.py +++ b/rhodecode/controllers/files.py @@ -184,9 +184,10 @@ class FilesController(BaseRepoController # do not just use the original mimetype, but force text/plain, # otherwise it would serve text/html and that might be unsafe. # Note: underlying vcs library fakes text/plain mimetype if the - # mimetype can not be determined and it thinks it is not binary. - # This might lead to erroneous text display in some cases, but - # helps in other cases, like with text files without extension. + # mimetype can not be determined and it thinks it is not + # binary.This might lead to erroneous text display in some + # cases, but helps in other cases, like with text files + # without extension. mimetype, dispo = 'text/plain', 'inline' if dispo == 'attachment':