##// END OF EJS Templates
fixed improper redirect for repos groups
marcink -
r1394:416dacac beta
parent child Browse files
Show More
@@ -1,238 +1,238 b''
1 1 import logging
2 2 import traceback
3 3 import formencode
4 4
5 5 from formencode import htmlfill
6 6 from operator import itemgetter
7 7
8 8 from pylons import request, response, session, tmpl_context as c, url
9 9 from pylons.controllers.util import abort, redirect
10 10 from pylons.i18n.translation import _
11 11
12 12 from rhodecode.lib import helpers as h
13 13 from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator, \
14 14 HasPermissionAnyDecorator
15 15 from rhodecode.lib.base import BaseController, render
16 16 from rhodecode.model.db import Group
17 17 from rhodecode.model.repos_group import ReposGroupModel
18 18 from rhodecode.model.forms import ReposGroupForm
19 19
20 20 log = logging.getLogger(__name__)
21 21
22 22
23 23 class ReposGroupsController(BaseController):
24 24 """REST Controller styled on the Atom Publishing Protocol"""
25 25 # To properly map this controller, ensure your config/routing.py
26 26 # file has a resource setup:
27 27 # map.resource('repos_group', 'repos_groups')
28 28
29 29 @LoginRequired()
30 30 def __before__(self):
31 31 super(ReposGroupsController, self).__before__()
32 32
33 33 def __load_defaults(self):
34 34
35 35 c.repo_groups = [('', '')]
36 36 parents_link = lambda k: h.literal('»'.join(
37 37 map(lambda k: k.group_name,
38 38 k.parents + [k])
39 39 )
40 40 )
41 41
42 42 c.repo_groups.extend([(x.group_id, parents_link(x)) for \
43 43 x in self.sa.query(Group).all()])
44 44
45 45 c.repo_groups = sorted(c.repo_groups,
46 46 key=lambda t: t[1].split('»')[0])
47 47 c.repo_groups_choices = map(lambda k: unicode(k[0]), c.repo_groups)
48 48
49 49 def __load_data(self, group_id):
50 50 """
51 51 Load defaults settings for edit, and update
52 52
53 53 :param group_id:
54 54 """
55 55 self.__load_defaults()
56 56
57 57 repo_group = Group.get(group_id)
58 58
59 59 data = repo_group.get_dict()
60 60
61 61 return data
62 62
63 63 @HasPermissionAnyDecorator('hg.admin')
64 64 def index(self, format='html'):
65 65 """GET /repos_groups: All items in the collection"""
66 66 # url('repos_groups')
67 67
68 68 sk = lambda g:g.parents[0].group_name if g.parents else g.group_name
69 69 c.groups = sorted(Group.query().all(), key=sk)
70 70 return render('admin/repos_groups/repos_groups_show.html')
71 71
72 72 @HasPermissionAnyDecorator('hg.admin')
73 73 def create(self):
74 74 """POST /repos_groups: Create a new item"""
75 75 # url('repos_groups')
76 76 self.__load_defaults()
77 77 repos_group_model = ReposGroupModel()
78 78 repos_group_form = ReposGroupForm(available_groups=
79 79 c.repo_groups_choices)()
80 80 try:
81 81 form_result = repos_group_form.to_python(dict(request.POST))
82 82 repos_group_model.create(form_result)
83 83 h.flash(_('created repos group %s') \
84 84 % form_result['group_name'], category='success')
85 85 #TODO: in futureaction_logger(, '', '', '', self.sa)
86 86 except formencode.Invalid, errors:
87 87
88 88 return htmlfill.render(
89 89 render('admin/repos_groups/repos_groups_add.html'),
90 90 defaults=errors.value,
91 91 errors=errors.error_dict or {},
92 92 prefix_error=False,
93 93 encoding="UTF-8")
94 94 except Exception:
95 95 log.error(traceback.format_exc())
96 96 h.flash(_('error occurred during creation of repos group %s') \
97 97 % request.POST.get('group_name'), category='error')
98 98
99 99 return redirect(url('repos_groups'))
100 100
101 101
102 102 @HasPermissionAnyDecorator('hg.admin')
103 103 def new(self, format='html'):
104 104 """GET /repos_groups/new: Form to create a new item"""
105 105 # url('new_repos_group')
106 106 self.__load_defaults()
107 107 return render('admin/repos_groups/repos_groups_add.html')
108 108
109 109 @HasPermissionAnyDecorator('hg.admin')
110 110 def update(self, id):
111 111 """PUT /repos_groups/id: Update an existing item"""
112 112 # Forms posted to this method should contain a hidden field:
113 113 # <input type="hidden" name="_method" value="PUT" />
114 114 # Or using helpers:
115 115 # h.form(url('repos_group', id=ID),
116 116 # method='put')
117 117 # url('repos_group', id=ID)
118 118
119 119 self.__load_defaults()
120 120 c.repos_group = Group.get(id)
121 121
122 122 repos_group_model = ReposGroupModel()
123 123 repos_group_form = ReposGroupForm(edit=True,
124 124 old_data=c.repos_group.get_dict(),
125 125 available_groups=
126 126 c.repo_groups_choices)()
127 127 try:
128 128 form_result = repos_group_form.to_python(dict(request.POST))
129 129 repos_group_model.update(id, form_result)
130 130 h.flash(_('updated repos group %s') \
131 131 % form_result['group_name'], category='success')
132 132 #TODO: in futureaction_logger(, '', '', '', self.sa)
133 133 except formencode.Invalid, errors:
134 134
135 135 return htmlfill.render(
136 136 render('admin/repos_groups/repos_groups_edit.html'),
137 137 defaults=errors.value,
138 138 errors=errors.error_dict or {},
139 139 prefix_error=False,
140 140 encoding="UTF-8")
141 141 except Exception:
142 142 log.error(traceback.format_exc())
143 143 h.flash(_('error occurred during update of repos group %s') \
144 144 % request.POST.get('group_name'), category='error')
145 145
146 146 return redirect(url('repos_groups'))
147 147
148 148
149 149 @HasPermissionAnyDecorator('hg.admin')
150 150 def delete(self, id):
151 151 """DELETE /repos_groups/id: Delete an existing item"""
152 152 # Forms posted to this method should contain a hidden field:
153 153 # <input type="hidden" name="_method" value="DELETE" />
154 154 # Or using helpers:
155 155 # h.form(url('repos_group', id=ID),
156 156 # method='delete')
157 157 # url('repos_group', id=ID)
158 158
159 159 repos_group_model = ReposGroupModel()
160 160 gr = Group.get(id)
161 161 repos = gr.repositories.all()
162 162 if repos:
163 163 h.flash(_('This group contains %s repositores and cannot be '
164 164 'deleted' % len(repos)),
165 165 category='error')
166 166 return redirect(url('repos_groups'))
167 167
168 168
169 169 try:
170 170 repos_group_model.delete(id)
171 171 h.flash(_('removed repos group %s' % gr.group_name), category='success')
172 172 #TODO: in futureaction_logger(, '', '', '', self.sa)
173 173 except Exception:
174 174 log.error(traceback.format_exc())
175 175 h.flash(_('error occurred during deletion of repos group %s' % gr.group_name),
176 176 category='error')
177 177
178 178 return redirect(url('repos_groups'))
179 179
180 180 def show(self, id, format='html'):
181 181 """GET /repos_groups/id: Show a specific item"""
182 182 # url('repos_group', id=ID)
183 183
184 184 gr = c.group = Group.get(id)
185 185
186 186 if c.group:
187 187 c.group_repos = c.group.repositories.all()
188 188 else:
189 return redirect(url('repos_group'))
189 return redirect(url('home'))
190 190
191 191
192 192 sortables = ['name', 'description', 'last_change', 'tip', 'owner']
193 193 current_sort = request.GET.get('sort', 'name')
194 194 current_sort_slug = current_sort.replace('-', '')
195 195
196 196 if current_sort_slug not in sortables:
197 197 c.sort_by = 'name'
198 198 current_sort_slug = c.sort_by
199 199 else:
200 200 c.sort_by = current_sort
201 201 c.sort_slug = current_sort_slug
202 202
203 203 sort_key = current_sort_slug + '_sort'
204 204
205 205 #overwrite our cached list with current filter
206 206 gr_filter = c.group_repos
207 207 c.cached_repo_list = self.scm_model.get_repos(all_repos=gr_filter)
208 208
209 209 c.repos_list = c.cached_repo_list
210 210
211 211 c.repo_cnt = 0
212 212
213 213 c.groups = self.sa.query(Group).order_by(Group.group_name)\
214 214 .filter(Group.group_parent_id == id).all()
215 215
216 216 return render('admin/repos_groups/repos_groups.html')
217 217
218 218 @HasPermissionAnyDecorator('hg.admin')
219 219 def edit(self, id, format='html'):
220 220 """GET /repos_groups/id/edit: Form to edit an existing item"""
221 221 # url('edit_repos_group', id=ID)
222 222
223 223 id = int(id)
224 224
225 225 c.repos_group = Group.get(id)
226 226 defaults = self.__load_data(id)
227 227
228 228 # we need to exclude this group from the group list for editing
229 229 c.repo_groups = filter(lambda x:x[0] != id, c.repo_groups)
230 230
231 231 return htmlfill.render(
232 232 render('admin/repos_groups/repos_groups_edit.html'),
233 233 defaults=defaults,
234 234 encoding="UTF-8",
235 235 force_defaults=False
236 236 )
237 237
238 238
General Comments 0
You need to be logged in to leave comments. Login now