@@ -151,7 +151,7 @@ def _save_edit(self, id, context):
151151 context ['message' ] = data_dict .get ('log_message' , '' )
152152 data_dict ['id' ] = id
153153 context ['allow_partial_update' ] = True
154- group = self ._action ('group_update ' )(context , data_dict )
154+ group = self ._action ('querytool_group_update ' )(context , data_dict )
155155 if id != group ['name' ]:
156156 self ._force_reindex (group )
157157
@@ -164,3 +164,92 @@ def _save_edit(self, id, context):
164164 errors = e .error_dict
165165 error_summary = e .error_summary
166166 return self .edit (id , data_dict , errors , error_summary )
167+
168+ def delete (self , id ):
169+ group_type = self ._ensure_controller_matches_group_type (id )
170+
171+ if 'cancel' in request .params :
172+ self ._redirect_to_this_controller (action = 'edit' , id = id )
173+
174+ context = {'model' : model , 'session' : model .Session ,
175+ 'user' : c .user }
176+
177+ try :
178+ self ._check_access ('group_delete' , context , {'id' : id })
179+ except NotAuthorized :
180+ abort (403 , _ ('Unauthorized to delete group %s' ) % '' )
181+
182+ try :
183+ if request .method == 'POST' :
184+ self ._action ('querytool_group_delete' )(context , {'id' : id })
185+ if group_type == 'organization' :
186+ h .flash_notice (_ ('Organization has been deleted.' ))
187+ elif group_type == 'group' :
188+ h .flash_notice (_ ('Group has been deleted.' ))
189+ else :
190+ h .flash_notice (_ ('%s has been deleted.' )
191+ % _ (group_type .capitalize ()))
192+ #self._redirect_to_this_controller(action='index')
193+ h .redirect_to (controller = 'group' , action = 'index' )
194+ c .group_dict = self ._action ('group_show' )(context , {'id' : id })
195+ except NotAuthorized :
196+ abort (403 , _ ('Unauthorized to delete group %s' ) % '' )
197+ except NotFound :
198+ abort (404 , _ ('Group not found' ))
199+ return self ._render_template ('group/confirm_delete.html' , group_type )
200+
201+ def new (self , data = None , errors = None , error_summary = None ):
202+ if data and 'type' in data :
203+ group_type = data ['type' ]
204+ else :
205+ group_type = self ._guess_group_type (True )
206+ if data :
207+ data ['type' ] = group_type
208+
209+ context = {'model' : model , 'session' : model .Session ,
210+ 'user' : c .user ,
211+ 'save' : 'save' in request .params ,
212+ 'parent' : request .params .get ('parent' , None )}
213+ try :
214+ self ._check_access ('group_create' , context )
215+ except NotAuthorized :
216+ abort (403 , _ ('Unauthorized to create a group' ))
217+
218+ if context ['save' ] and not data :
219+ return self ._save_new (context , group_type )
220+
221+ data = data or {}
222+ if not data .get ('image_url' , '' ).startswith ('http' ):
223+ data .pop ('image_url' , None )
224+
225+ errors = errors or {}
226+ error_summary = error_summary or {}
227+ vars = {'data' : data , 'errors' : errors ,
228+ 'error_summary' : error_summary , 'action' : 'new' ,
229+ 'group_type' : group_type }
230+
231+ self ._setup_template_variables (context , data , group_type = group_type )
232+ c .form = render (self ._group_form (group_type = group_type ),
233+ extra_vars = vars )
234+ return render (self ._new_template (group_type ),
235+ extra_vars = {'group_type' : group_type })
236+
237+ def _save_new (self , context , group_type = None ):
238+ try :
239+ data_dict = clean_dict (dict_fns .unflatten (
240+ tuplize_dict (parse_params (request .params ))))
241+ data_dict ['type' ] = group_type or 'group'
242+ context ['message' ] = data_dict .get ('log_message' , '' )
243+ data_dict ['users' ] = [{'name' : c .user , 'capacity' : 'admin' }]
244+ group = self ._action ('querytool_group_create' )(context , data_dict )
245+
246+ # Redirect to the appropriate _read route for the type of group
247+ h .redirect_to (group ['type' ] + '_read' , id = group ['name' ])
248+ except (NotFound , NotAuthorized ), e :
249+ abort (404 , _ ('Group not found' ))
250+ except dict_fns .DataError :
251+ abort (400 , _ (u'Integrity Error' ))
252+ except ValidationError , e :
253+ errors = e .error_dict
254+ error_summary = e .error_summary
255+ return self .new (data_dict , errors , error_summary )
0 commit comments