def edit_view(self, request, oe_model, object_id=None, form_view_id=False): object_id = int(object_id) ItemModel = request.user.get_model(str(oe_model)) ctx = request.user.get_default_context() if object_id: item = get_object_or_404(ItemModel, id=object_id) else: item = None if not request.POST: raise Http404 form_view = OpenERPFormView(model_class=ItemModel, instance=item, data=request.POST, view_id=form_view_id) #form_view.remove_notview_model_fields() data = {'id': object_id or 0} if form_view.is_valid(): inst = form_view.save() data['id'] = inst.id data['save'] = True else: errs = {} for k, v in form_view.errors.iteritems(): errs[k] = u'%s: %s' % (form_view.form[k].label, v) data['errors'] = errs return data
def ajax_edit_view(self, request, oe_model, object_id=None, form_view_id=False): ItemModel = request.user.get_model(str(oe_model)) ctx = request.user.get_default_context() if object_id: item = get_object_or_404(ItemModel, id=object_id) else: item = None if request.POST: form_view = OpenERPFormView(model_class=ItemModel, instance=item, data=request.POST, view_id=form_view_id) data = {'id': object_id or 0} if form_view.is_valid(): try: form_view.save() except OpenERPException, e: data['errors'] = {'': e.as_html()} else: data['href'] = '../../' else: errs = {} for k, v in form_view.errors.iteritems(): if k.startswith('_'): continue errs[k] = u'%s: %s' % (form_view.form[k].label, v) data['errors'] = errs return HttpResponse(simplejson.dumps(data))
def edit(request, section_id, menu_id, object_id=None): menu_id = int(menu_id) ctx = request.user.get_default_context() klass = request.user.objects('ir.values', 'get', 'action', 'tree_but_open', [('ir.ui.menu', menu_id)])[0][2] model_name = klass['res_model'] ItemModel = request.user.get_model(model_name) if object_id: item = get_object_or_404(ItemModel, id=object_id) else: item = None if request.POST: form_view = OpenERPFormView(model_class=ItemModel, instance=item, data=request.POST, view_id=False) print '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@' print form_view.form.data if form_view.is_valid(): print form_view.form.cleaned_data form_view.save() #raise return redirect('submenu', section_id=section_id, menu_id=menu_id) print 333333333333333333333 print form_view.errors else: form_view = OpenERPFormView(model_class=ItemModel, instance=item, view_id=False) Menu = request.user.get_model('ir.ui.menu') section = get_object_or_404(Menu, id=section_id) menu = get_object_or_404(Menu, id=menu_id) sections = Menu.objects.filter(parent_id__isnull=True) menu_list = get_menu_childs(Menu.objects.filter(parent_id=section), Menu) print form_view.get_html() return render_to_response('djoe/client/edit.html', {'section_list': sections, 'menu_list': menu_list, 'current_section': section, 'current_menu': menu, 'form_view':form_view}, context_instance=RequestContext(request))