def edit_action(request,action_id): #check if a user is allowed to edit the event action = get_action(action_id) if request.user.id == action.organizer.id: # Create a dictionary out of db data to populate the edit form action_data = action.__dict__ # Action_type key must have value of action_id to get # SELECT element of the form to display the proper element action_data['action_type'] = action.action_type_id action_form = ActionForm(data=action_data) if request.method == "POST": action_form = ActionForm(data=request.POST) if action_form.is_valid(): action_data = action_form.cleaned_data action_data["action_type_id"]=action_data["action_type"].id action = create_or_update_action(action_id,**action_data) action_id = action.id return HttpResponseRedirect(reverse('web.view_action', args=[action_id])) context= {"form" : action_form} return render_to_response("pages/create_action.html", context, context_instance=RequestContext(request))
def decorator(request,*args,**kwargs): action = get_action(kwargs['action_id']) if request.user.id == action.organizer.id: return func(request,*args,**kwargs) else: return HttpResponseRedirect(reverse('web.index'))