##// END OF EJS Templates
PEP8ify - controllers
marcink -
r1245:5f2fbab7 beta
parent child Browse files
Show More
@@ -35,6 +35,7 b' from rhodecode.model.db import UserLog'
35 35
36 36 log = logging.getLogger(__name__)
37 37
38
38 39 class AdminController(BaseController):
39 40
40 41 @LoginRequired()
@@ -43,20 +43,19 b' from sqlalchemy.exc import DatabaseError'
43 43 log = logging.getLogger(__name__)
44 44
45 45
46
47 46 class LdapSettingsController(BaseController):
48 47
49 search_scope_choices = [('BASE', _('BASE'),),
48 search_scope_choices = [('BASE', _('BASE'),),
50 49 ('ONELEVEL', _('ONELEVEL'),),
51 ('SUBTREE', _('SUBTREE'),),
50 ('SUBTREE', _('SUBTREE'),),
52 51 ]
53 52 search_scope_default = 'SUBTREE'
54 53
55 tls_reqcert_choices = [('NEVER', _('NEVER'),),
56 ('ALLOW', _('ALLOW'),),
57 ('TRY', _('TRY'),),
54 tls_reqcert_choices = [('NEVER', _('NEVER'),),
55 ('ALLOW', _('ALLOW'),),
56 ('TRY', _('TRY'),),
58 57 ('DEMAND', _('DEMAND'),),
59 ('HARD', _('HARD'),),
58 ('HARD', _('HARD'),),
60 59 ]
61 60 tls_reqcert_default = 'DEMAND'
62 61
@@ -66,13 +65,13 b' class LdapSettingsController(BaseControl'
66 65 c.admin_user = session.get('admin_user')
67 66 c.admin_username = session.get('admin_username')
68 67 c.search_scope_choices = self.search_scope_choices
69 c.tls_reqcert_choices = self.tls_reqcert_choices
68 c.tls_reqcert_choices = self.tls_reqcert_choices
70 69 super(LdapSettingsController, self).__before__()
71 70
72 71 def index(self):
73 72 defaults = SettingsModel().get_ldap_settings()
74 73 c.search_scope_cur = defaults.get('ldap_search_scope')
75 c.tls_reqcert_cur = defaults.get('ldap_tls_reqcert')
74 c.tls_reqcert_cur = defaults.get('ldap_tls_reqcert')
76 75
77 76 return htmlfill.render(
78 77 render('admin/ldap/ldap.html'),
@@ -109,7 +108,7 b' class LdapSettingsController(BaseControl'
109 108 except formencode.Invalid, errors:
110 109
111 110 c.search_scope_cur = self.search_scope_default
112 c.tls_reqcert_cur = self.search_scope_default
111 c.tls_reqcert_cur = self.search_scope_default
113 112
114 113 return htmlfill.render(
115 114 render('admin/ldap/ldap.html'),
@@ -41,6 +41,7 b' import traceback'
41 41
42 42 log = logging.getLogger(__name__)
43 43
44
44 45 class PermissionsController(BaseController):
45 46 """REST Controller styled on the Atom Publishing Protocol"""
46 47 # To properly map this controller, ensure your config/routing.py
@@ -69,7 +70,6 b' class PermissionsController(BaseControll'
69 70 self.create_choices = [('hg.create.none', _('Disabled')),
70 71 ('hg.create.repository', _('Enabled'))]
71 72
72
73 73 def index(self, format='html'):
74 74 """GET /permissions: All items in the collection"""
75 75 # url('permissions')
@@ -99,7 +99,7 b' class PermissionsController(BaseControll'
99 99
100 100 try:
101 101 form_result = _form.to_python(dict(request.POST))
102 form_result.update({'perm_user_name':id})
102 form_result.update({'perm_user_name': id})
103 103 permission_model.update(form_result)
104 104 h.flash(_('Default permissions updated successfully'),
105 105 category='success')
@@ -123,8 +123,6 b' class PermissionsController(BaseControll'
123 123
124 124 return redirect(url('edit_permission', id=id))
125 125
126
127
128 126 def delete(self, id):
129 127 """DELETE /permissions/id: Delete an existing item"""
130 128 # Forms posted to this method should contain a hidden field:
@@ -147,8 +145,8 b' class PermissionsController(BaseControll'
147 145
148 146 if id == 'default':
149 147 default_user = UserModel().get_by_username('default')
150 defaults = {'_method':'put',
151 'anonymous':default_user.active}
148 defaults = {'_method': 'put',
149 'anonymous': default_user.active}
152 150
153 151 for p in default_user.user_perms:
154 152 if p.permission.permission_name.startswith('repository.'):
@@ -47,6 +47,7 b' from rhodecode.model.repo import RepoMod'
47 47
48 48 log = logging.getLogger(__name__)
49 49
50
50 51 class ReposController(BaseController):
51 52 """
52 53 REST Controller styled on the Atom Publishing Protocol"""
@@ -65,8 +66,8 b' class ReposController(BaseController):'
65 66 repo_model = RepoModel()
66 67
67 68 c.repo_groups = [('', '')]
68 parents_link = lambda k:h.literal('»'.join(
69 map(lambda k:k.group_name,
69 parents_link = lambda k: h.literal('»'.join(
70 map(lambda k: k.group_name,
70 71 k.parents + [k])
71 72 )
72 73 )
@@ -90,7 +91,6 b' class ReposController(BaseController):'
90 91 repo_model = RepoModel()
91 92 c.repo_info = repo_model.get_by_repo_name(repo_name)
92 93
93
94 94 if c.repo_info is None:
95 95 h.flash(_('%s repository is not mapped to db perhaps'
96 96 ' it was created or renamed from the filesystem'
@@ -100,7 +100,6 b' class ReposController(BaseController):'
100 100
101 101 return redirect(url('repos'))
102 102
103
104 103 c.default_user_id = User.by_username('default').user_id
105 104 c.in_public_journal = self.sa.query(UserFollowing)\
106 105 .filter(UserFollowing.user_id == c.default_user_id)\
@@ -120,8 +119,6 b' class ReposController(BaseController):'
120 119 c.stats_percentage = '%.2f' % ((float((last_rev)) /
121 120 c.repo_last_rev) * 100)
122 121
123
124
125 122 defaults = c.repo_info.get_dict()
126 123 group, repo_name = c.repo_info.groups_and_repo
127 124 defaults['repo_name'] = repo_name
@@ -130,12 +127,11 b' class ReposController(BaseController):'
130 127
131 128 #fill owner
132 129 if c.repo_info.user:
133 defaults.update({'user':c.repo_info.user.username})
130 defaults.update({'user': c.repo_info.user.username})
134 131 else:
135 132 replacement_user = self.sa.query(User)\
136 133 .filter(User.admin == True).first().username
137 defaults.update({'user':replacement_user})
138
134 defaults.update({'user': replacement_user})
139 135
140 136 #fill repository users
141 137 for p in c.repo_info.repo_to_perm:
@@ -147,10 +143,8 b' class ReposController(BaseController):'
147 143 defaults.update({'g_perm_%s' % p.users_group.users_group_name:
148 144 p.permission.permission_name})
149 145
150
151 146 return defaults
152 147
153
154 148 @HasPermissionAllDecorator('hg.admin')
155 149 def index(self, format='html'):
156 150 """GET /repos: All items in the collection"""
@@ -232,7 +226,7 b' class ReposController(BaseController):'
232 226 self.__load_defaults()
233 227 repo_model = RepoModel()
234 228 changed_name = repo_name
235 _form = RepoForm(edit=True, old_data={'repo_name':repo_name},
229 _form = RepoForm(edit=True, old_data={'repo_name': repo_name},
236 230 repo_groups=c.repo_groups_choices)()
237 231 try:
238 232 form_result = _form.to_python(dict(request.POST))
@@ -9,6 +9,7 b' from rhodecode.model.db import Group'
9 9
10 10 log = logging.getLogger(__name__)
11 11
12
12 13 class ReposGroupsController(BaseController):
13 14 """REST Controller styled on the Atom Publishing Protocol"""
14 15 # To properly map this controller, ensure your config/routing.py
@@ -68,7 +69,6 b' class ReposGroupsController(BaseControll'
68 69
69 70 sort_key = current_sort_slug + '_sort'
70 71
71
72 72 #overwrite our cached list with current filter
73 73 gr_filter = [r.repo_name for r in c.group_repos]
74 74 c.cached_repo_list = self.scm_model.get_repos(all_repos=gr_filter)
@@ -82,10 +82,8 b' class ReposGroupsController(BaseControll'
82 82
83 83 c.repo_cnt = len(c.repos_list)
84 84
85
86 85 return render('admin/repos_groups/repos_groups.html')
87 86
88
89 87 def edit(self, id, format='html'):
90 88 """GET /repos_groups/id/edit: Form to edit an existing item"""
91 89 # url('edit_repos_group', id=ID)
@@ -57,14 +57,12 b' class SettingsController(BaseController)'
57 57 # map.resource('setting', 'settings', controller='admin/settings',
58 58 # path_prefix='/admin', name_prefix='admin_')
59 59
60
61 60 @LoginRequired()
62 61 def __before__(self):
63 62 c.admin_user = session.get('admin_user')
64 63 c.admin_username = session.get('admin_username')
65 64 super(SettingsController, self).__before__()
66 65
67
68 66 @HasPermissionAllDecorator('hg.admin')
69 67 def index(self, format='html'):
70 68 """GET /admin/settings: All items in the collection"""
@@ -109,8 +107,8 b' class SettingsController(BaseController)'
109 107 added, removed = repo2db_mapper(initial, rm_obsolete)
110 108
111 109 h.flash(_('Repositories successfully'
112 ' rescanned added: %s,removed: %s') % (added, removed)
113 , category='success')
110 ' rescanned added: %s,removed: %s') % (added, removed),
111 category='success')
114 112
115 113 if setting_id == 'whoosh':
116 114 repo_location = self.get_hg_ui_settings()['paths_root_path']
@@ -127,15 +125,16 b' class SettingsController(BaseController)'
127 125
128 126 try:
129 127 hgsettings1 = settings_model.get('title')
130 hgsettings1.app_settings_value = form_result['rhodecode_title']
128 hgsettings1.app_settings_value = \
129 form_result['rhodecode_title']
131 130
132 131 hgsettings2 = settings_model.get('realm')
133 hgsettings2.app_settings_value = form_result['rhodecode_realm']
132 hgsettings2.app_settings_value = \
133 form_result['rhodecode_realm']
134 134
135 135 hgsettings3 = settings_model.get('ga_code')
136 hgsettings3.app_settings_value = form_result['rhodecode_ga_code']
137
138
136 hgsettings3.app_settings_value = \
137 form_result['rhodecode_ga_code']
139 138
140 139 self.sa.add(hgsettings1)
141 140 self.sa.add(hgsettings2)
@@ -147,12 +146,12 b' class SettingsController(BaseController)'
147 146
148 147 except Exception:
149 148 log.error(traceback.format_exc())
150 h.flash(_('error occurred during updating application settings'),
149 h.flash(_('error occurred during updating '
150 'application settings'),
151 151 category='error')
152 152
153 153 self.sa.rollback()
154 154
155
156 155 except formencode.Invalid, errors:
157 156 return htmlfill.render(
158 157 render('admin/settings/settings.html'),
@@ -176,24 +175,30 b' class SettingsController(BaseController)'
176 175 .filter(RhodeCodeUi.ui_key == '/').one()
177 176 hgsettings2.ui_value = form_result['paths_root_path']
178 177
179
180 178 #HOOKS
181 179 hgsettings3 = self.sa.query(RhodeCodeUi)\
182 180 .filter(RhodeCodeUi.ui_key == 'changegroup.update').one()
183 hgsettings3.ui_active = bool(form_result['hooks_changegroup_update'])
181 hgsettings3.ui_active = \
182 bool(form_result['hooks_changegroup_update'])
184 183
185 184 hgsettings4 = self.sa.query(RhodeCodeUi)\
186 .filter(RhodeCodeUi.ui_key == 'changegroup.repo_size').one()
187 hgsettings4.ui_active = bool(form_result['hooks_changegroup_repo_size'])
185 .filter(RhodeCodeUi.ui_key ==
186 'changegroup.repo_size').one()
187 hgsettings4.ui_active = \
188 bool(form_result['hooks_changegroup_repo_size'])
188 189
189 190 hgsettings5 = self.sa.query(RhodeCodeUi)\
190 .filter(RhodeCodeUi.ui_key == 'pretxnchangegroup.push_logger').one()
191 hgsettings5.ui_active = bool(form_result['hooks_pretxnchangegroup_push_logger'])
191 .filter(RhodeCodeUi.ui_key ==
192 'pretxnchangegroup.push_logger').one()
193 hgsettings5.ui_active = \
194 bool(form_result['hooks_pretxnchangegroup'
195 '_push_logger'])
192 196
193 197 hgsettings6 = self.sa.query(RhodeCodeUi)\
194 .filter(RhodeCodeUi.ui_key == 'preoutgoing.pull_logger').one()
195 hgsettings6.ui_active = bool(form_result['hooks_preoutgoing_pull_logger'])
196
198 .filter(RhodeCodeUi.ui_key ==
199 'preoutgoing.pull_logger').one()
200 hgsettings6.ui_active = \
201 bool(form_result['hooks_preoutgoing_pull_logger'])
197 202
198 203 self.sa.add(hgsettings1)
199 204 self.sa.add(hgsettings2)
@@ -208,12 +213,11 b' class SettingsController(BaseController)'
208 213
209 214 except:
210 215 log.error(traceback.format_exc())
211 h.flash(_('error occurred during updating application settings'),
212 category='error')
216 h.flash(_('error occurred during updating '
217 'application settings'), category='error')
213 218
214 219 self.sa.rollback()
215 220
216
217 221 except formencode.Invalid, errors:
218 222 return htmlfill.render(
219 223 render('admin/settings/settings.html'),
@@ -222,8 +226,6 b' class SettingsController(BaseController)'
222 226 prefix_error=False,
223 227 encoding="UTF-8")
224 228
225
226
227 229 return redirect(url('admin_settings'))
228 230
229 231 @HasPermissionAllDecorator('hg.admin')
@@ -238,12 +240,15 b' class SettingsController(BaseController)'
238 240
239 241 @HasPermissionAllDecorator('hg.admin')
240 242 def show(self, setting_id, format='html'):
241 """GET /admin/settings/setting_id: Show a specific item"""
243 """
244 GET /admin/settings/setting_id: Show a specific item"""
242 245 # url('admin_setting', setting_id=ID)
243 246
244 247 @HasPermissionAllDecorator('hg.admin')
245 248 def edit(self, setting_id, format='html'):
246 """GET /admin/settings/setting_id/edit: Form to edit an existing item"""
249 """
250 GET /admin/settings/setting_id/edit: Form to
251 edit an existing item"""
247 252 # url('admin_edit_setting', setting_id=ID)
248 253
249 254 @NotAnonymous()
@@ -282,8 +287,9 b' class SettingsController(BaseController)'
282 287 # url('admin_settings_my_account_update', id=ID)
283 288 user_model = UserModel()
284 289 uid = self.rhodecode_user.user_id
285 _form = UserForm(edit=True, old_data={'user_id':uid,
286 'email':self.rhodecode_user.email})()
290 _form = UserForm(edit=True,
291 old_data={'user_id': uid,
292 'email': self.rhodecode_user.email})()
287 293 form_result = {}
288 294 try:
289 295 form_result = _form.to_python(dict(request.POST))
@@ -319,8 +325,8 b' class SettingsController(BaseController)'
319 325 """GET /_admin/create_repository: Form to create a new item"""
320 326
321 327 c.repo_groups = [('', '')]
322 parents_link = lambda k:h.literal('»'.join(
323 map(lambda k:k.group_name,
328 parents_link = lambda k: h.literal('»'.join(
329 map(lambda k: k.group_name,
324 330 k.parents + [k])
325 331 )
326 332 )
@@ -32,7 +32,8 b' from pylons import request, session, tmp'
32 32 from pylons.controllers.util import abort, redirect
33 33 from pylons.i18n.translation import _
34 34
35 from rhodecode.lib.exceptions import DefaultUserException, UserOwnsReposException
35 from rhodecode.lib.exceptions import DefaultUserException, \
36 UserOwnsReposException
36 37 from rhodecode.lib import helpers as h
37 38 from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator
38 39 from rhodecode.lib.base import BaseController, render
@@ -43,6 +44,7 b' from rhodecode.model.user import UserMod'
43 44
44 45 log = logging.getLogger(__name__)
45 46
47
46 48 class UsersController(BaseController):
47 49 """REST Controller styled on the Atom Publishing Protocol"""
48 50 # To properly map this controller, ensure your config/routing.py
@@ -105,8 +107,8 b' class UsersController(BaseController):'
105 107 user_model = UserModel()
106 108 c.user = user_model.get(id)
107 109
108 _form = UserForm(edit=True, old_data={'user_id':id,
109 'email':c.user.email})()
110 _form = UserForm(edit=True, old_data={'user_id': id,
111 'email': c.user.email})()
110 112 form_result = {}
111 113 try:
112 114 form_result = _form.to_python(dict(request.POST))
@@ -150,7 +152,6 b' class UsersController(BaseController):'
150 152 """GET /users/id: Show a specific item"""
151 153 # url('user', id=ID)
152 154
153
154 155 def edit(self, id, format='html'):
155 156 """GET /users/id/edit: Form to edit an existing item"""
156 157 # url('edit_user', id=ID)
@@ -162,7 +163,8 b' class UsersController(BaseController):'
162 163 h.flash(_("You can't edit this user"), category='warning')
163 164 return redirect(url('users'))
164 165 c.user.permissions = {}
165 c.granted_permissions = user_model.fill_perms(c.user).permissions['global']
166 c.granted_permissions = user_model.fill_perms(c.user)\
167 .permissions['global']
166 168
167 169 defaults = c.user.get_dict()
168 170
@@ -32,7 +32,6 b' from pylons import request, session, tmp'
32 32 from pylons.controllers.util import abort, redirect
33 33 from pylons.i18n.translation import _
34 34
35 from rhodecode.lib.exceptions import DefaultUserException, UserOwnsReposException
36 35 from rhodecode.lib import helpers as h
37 36 from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator
38 37 from rhodecode.lib.base import BaseController, render
@@ -44,6 +43,7 b' from rhodecode.model.users_group import '
44 43
45 44 log = logging.getLogger(__name__)
46 45
46
47 47 class UsersGroupsController(BaseController):
48 48 """REST Controller styled on the Atom Publishing Protocol"""
49 49 # To properly map this controller, ensure your config/routing.py
@@ -72,8 +72,8 b' class UsersGroupsController(BaseControll'
72 72 try:
73 73 form_result = users_group_form.to_python(dict(request.POST))
74 74 users_group_model.create(form_result)
75 h.flash(_('created users group %s') % form_result['users_group_name'],
76 category='success')
75 h.flash(_('created users group %s') \
76 % form_result['users_group_name'], category='success')
77 77 #action_logger(self.rhodecode_user, 'new_user', '', '', self.sa)
78 78 except formencode.Invalid, errors:
79 79 return htmlfill.render(
@@ -103,7 +103,6 b' class UsersGroupsController(BaseControll'
103 103 # method='put')
104 104 # url('users_group', id=ID)
105 105
106
107 106 users_group_model = UsersGroupModel()
108 107 c.users_group = users_group_model.get(id)
109 108 c.group_members = [(x.user_id, x.user.username) for x in
@@ -119,7 +118,8 b' class UsersGroupsController(BaseControll'
119 118 try:
120 119 form_result = users_group_form.to_python(request.POST)
121 120 users_group_model.update(id, form_result)
122 h.flash(_('updated users group %s') % form_result['users_group_name'],
121 h.flash(_('updated users group %s') \
122 % form_result['users_group_name'],
123 123 category='success')
124 124 #action_logger(self.rhodecode_user, 'new_user', '', '', self.sa)
125 125 except formencode.Invalid, errors:
@@ -136,8 +136,6 b' class UsersGroupsController(BaseControll'
136 136
137 137 return redirect(url('users_groups'))
138 138
139
140
141 139 def delete(self, id):
142 140 """DELETE /users_groups/id: Delete an existing item"""
143 141 # Forms posted to this method should contain a hidden field:
@@ -184,9 +184,10 b' class FilesController(BaseRepoController'
184 184 # do not just use the original mimetype, but force text/plain,
185 185 # otherwise it would serve text/html and that might be unsafe.
186 186 # Note: underlying vcs library fakes text/plain mimetype if the
187 # mimetype can not be determined and it thinks it is not binary.
188 # This might lead to erroneous text display in some cases, but
189 # helps in other cases, like with text files without extension.
187 # mimetype can not be determined and it thinks it is not
188 # binary.This might lead to erroneous text display in some
189 # cases, but helps in other cases, like with text files
190 # without extension.
190 191 mimetype, dispo = 'text/plain', 'inline'
191 192
192 193 if dispo == 'attachment':
General Comments 0
You need to be logged in to leave comments. Login now