def add(request): if request.method == 'POST': form = AddForm(request.POST) if form.is_valid(): hostname = form.cleaned_data['hostname'] asset = form.cleaned_data['ip'] group_id = form.cleaned_data['group_id'] template_id = form.cleaned_data['template_id'] if asset.ip: ip = asset.ip elif asset.other_ip: ip = asset.other_ip else: ip = '127.0.0.1' if asset.asset_type in [2, 3]: returns = zabbixAPI.addSnmpDevice(hostname, ip, group_id, template_id) else: returns = zabbixAPI.addHost(hostname, ip, group_id, template_id) messages.add_message(request, messages.SUCCESS, u'创建成功:{0}'.format(returns)) return HttpResponseRedirect(reverse('ADD')) else: form = AddForm() return render(request, 'zabbix/add.html', locals())
def add(request): if request.method=='POST': form = AddForm(request.POST) if form.is_valid(): blog = form.save() return HttpResponseRedirect(reverse('blog_list')) return render_to_response('blog/add.html',RequestContext(request,{'form':AddForm()}))
def begin(request): def parse(feed): feed = feedparser.parse(settings.FEED_DIR+feed) feed.channel.description = feed.channel.description.encode('utf-8') return {'data': feed, 'edit_form': AddForm(QueryDict(urllib.urlencode(feed.channel)))} #feeds = map(parse, os.listdir(settings.FEED_DIR)) if request.method == 'POST': form = AddForm(request.POST) if form.is_valid(): rmg = RichMetadataGenerator.getInstance() m = rmg.getRichMetadata() m.setTitle(form.cleaned_data['title']) #m.setLanguage(form.cleaned_data['language']) #m.setGenre(form.cleaned_data['genre']) print rmg.prettyPrint(rmg.build(m)) return HttpResponseRedirect('/') else: form = AddForm() context = {'feeds': [], 'MEDIA_URL': settings.MEDIA_URL, 'add_form': form} context.update(csrf(request)) return render_to_response('browse.html', context)
def update(request,id): blog = get_object_or_404(Blog,pk=int(id)) if request.method == 'POST': form = AddForm(request.POST,instance=blog) if form.is_valid(): blog = form.save() return HttpResponseRedirect(reverse("blog_list")) return render_to_response('blog/add.html',RequestContext(request,{'form':AddForm(instance=blog)}))
def index(request): if request.method=='POST': #当提交表单 form=AddForm(request.POST) #form包含提交的数据 if form.is_valid():# 如果提交的数据合法 a=form.cleaned_data['a'] b=form.cleaned_data['b'] return HttpResponse(str(int(a)+int(b))) else: form=AddForm() return render(request,'index.html',{'form':form})
def new(request): if request.method == 'POST': form = AddForm(request.POST) if form.is_valid(): #cd = form.cleaned_data newtask_name = form.cleaned_data['taskname'] newtask_description = form.cleaned_data['taskdescription'] #newdeadline_date = form.cleaned_data['deadlinedate'] t = Task(task_name=newtask_name, task_description=newtask_description, deadline_date=timezone.now()) t.save() return HttpResponseRedirect('/tasker/') else: form = AddForm() time = str(timezone.now()) lol = time return render(request, 'tasker/new.html', {'form': form})
def add(request): form = AddForm(request.POST or None) if form.is_valid(): # add object data = { "status": "ok", "next_url": '/', } else: context = {'form': form, } html = render_to_string('main/form.html', context) data = { "status": 'invalid', "html": html } return HttpResponse(json.dumps(data), content_type="application/json")
def update(request,id): BookDB=get_object_or_404(Book,pk=int(id)) if request.method=="POST": form=AddForm(request.POST,instance=BookDB) if form.is_valid(): BookDB=form.save() return HttpResponseRedirect(reverse("BookDB_list")) return render_to_response('update.html', {'form': AddForm(instance=BookDB)})
def add(request): if request.method == 'POST': form = AddForm(request.POST) if form.is_valid(): newDate = form.cleaned_data['date'] newWeight = form.cleaned_data['weight'] w = Weight(weight=newWeight, date=newDate, username=request.user.username) w.save() return HttpResponseRedirect('/weight/') else: form = AddForm() t = loader.get_template('templates/weight_add.html') c = RequestContext(request,{ 'form': form, 'user':request.user, }) return HttpResponse(t.render(c))