@handle_response_format
@treeio_login_required
def dashboard_widget_edit(request, widget_id, response_format='html'):
 user = request.user.profile
 widget_object = get_object_or_404(Widget, pk=widget_id)
 if (widget_object.user == user):
  perspective = user.get_perspective()
  module = perspective.get_modules().filter(name=widget_object.module_name)[0]
  widget = _get_widget(request, module, widget_object.widget_name)
  widget_object.widget = widget
  if ('view' in widget):
   try:
    content = unicode(widget['view'](request, response_format=response_format).content, 'utf_8')
    widget_content = _get_widget_content(content, response_format=response_format)
   except Exception:
    widget_content = ''
   widget['content'] = widget_content
  if request.POST:
   form = WidgetForm(user, request.POST, instance=widget_object)
   if form.is_valid():
    form.save()
    return HttpResponseRedirect(reverse('core_dashboard_index'))
  else:
   form = WidgetForm(user, instance=widget_object)
  return render_to_response('core/dashboard/widget_edit', {'widget': widget_object, 'form': form}, context_instance=RequestContext(request), response_format=response_format)
 return HttpResponseRedirect(reverse('home'))

@ handle_response_format @ treeio_login_required def dashboard_widget_edit ( request , widget_id , response_format = 'html' ) : user = request . user . profile widget_object = get_object_or_404 ( Widget , pk = widget_id ) if ( widget_object . user == user ) : perspective = user . get_perspective ( ) module = perspective . get_modules ( ) . filter ( name = widget_object . module_name ) [ 0 ] widget = _get_widget ( request , module , widget_object . widget_name ) widget_object . widget = widget if ( 'view' in widget ) : try : content = unicode ( widget [ 'view' ] ( request , response_format = response_format ) . content , 'utf_8' ) widget_content = _get_widget_content ( content , response_format = response_format ) except Exception : widget_content = '' widget [ 'content' ] = widget_content if request . POST : form = WidgetForm ( user , request . POST , instance = widget_object ) if form . is_valid ( ) : form . save ( ) return HttpResponseRedirect ( reverse ( 'core_dashboard_index' ) ) else : form = WidgetForm ( user , instance = widget_object ) return render_to_response ( 'core/dashboard/widget_edit' , { 'widget' : widget_object , 'form' : form } , context_instance = RequestContext ( request ) , response_format = response_format ) return HttpResponseRedirect ( reverse ( 'home' ) )
edit an existing widget on the dashboard .