def add_ys(request): if not request.user.has_perm('app.add_ys'): request.session['msg'] = u'你没有权限进行此操作!' request.session['type'] = 'warning' return HttpResponseRedirect('/') if request.method == 'POST': form = YSForm(request.POST) if form.is_valid(): #print request.POST.get('result') ys = form.save(commit=False) ys.save() request.session['msg'] = u'成功添加预决算!' request.session['type'] = 'success' #try: filelist = request.FILES.getlist('filelist') for f in filelist: filename,sysfilename = utils.upload_file(f) print filename,sysfilename,ys.id ysatt = YSatt(ys=ys, filename=filename, sysfilename=sysfilename) ysatt.save() #except Exception, e: # pass task = Task(name=ys.gc.name[0:30] + u'预决算审核', who='auth.audit', status='c', type='ys', item=ys.id) task.save() return HttpResponseRedirect('/') request.session['msg'] = u'添加预决算失败!请检查信息是否准确填写,或是联系管理员。' request.session['type'] = 'danger' return HttpResponseRedirect('/') else: form = YSForm() return render_to_response('app/add_ys.html',{'form': form, 'year':datetime.now().year,'title':u'创建工程','templates':Template.objects.all(),'norms': Norm.objects.all(), 'projects':GC.objects.filter(status='a')},RequestContext(request))
def add_pay(request): if not request.user.has_perm('app.add_pay'): request.session['msg'] = u'你没有权限进行此操作!' request.session['type'] = 'warning' return HttpResponseRedirect('/') if request.method == 'POST': form = YSForm(request.POST) if form.is_valid(): form.save() request.session['msg'] = u'成功添加预决算!' request.session['type'] = 'success' return HttpResponseRedirect('/') request.session['msg'] = u'添加预决算失败!请检查信息是否准确填写,或是联系管理员。' request.session['type'] = 'danger' return HttpResponseRedirect('/') else: form = YSForm() return render_to_response('app/add_pay.html',{'form': form, 'year':datetime.now().year,'title':u'创建工程','templates':Template.objects.all(), 'projects':GC.objects.filter(status='a')},RequestContext(request))