def create_store(request): logger.debug('calling store.views.create_store()') if request.method == 'POST': store_form = StoreForm(data=request.POST) if store_form.is_valid(): store = store_form.save(commit=False) store.owner = request.user print 'user = {0}'.format(vars(request.user)) store.save() return owner_profile(request) else: print store_form.errors return HttpResponse("Create store is failed.") else: # for visitor, generate empty menu menu = MenuService.new_user_menu(request.user) store_form = StoreForm() requestContext = RequestContext(request, {'menu':menu, 'store_form': store_form, 'page_title': 'Create store'} ) # Render the template depending on the context. return render_to_response('new.html', requestContext)
def storage(): form = StoreForm() if form.validate_on_submit(): book = Book.query.filter_by(isbn=request.form.get('isbn')).first() exist = Inventory.query.filter_by( barcode=request.form.get('barcode')).first() if book is None: flash(u'添加失败,请注意本书信息是否已录入,若未登记,请在‘新书入库’窗口录入信息。') else: if len(request.form.get('barcode')) != 6: flash(u'图书编码长度错误') else: if exist is not None: flash(u'该编号已经存在!') else: item = Inventory() item.barcode = request.form.get('barcode') item.isbn = request.form.get('isbn') item.admin = current_user.admin_id item.location = request.form.get('location') item.status = True item.withdraw = False today_date = datetime.date.today() today_str = today_date.strftime("%Y-%m-%d") today_stamp = time.mktime( time.strptime(today_str + ' 00:00:00', '%Y-%m-%d %H:%M:%S')) item.storage_date = int(today_stamp) * 1000 db.session.add(item) db.session.commit() flash(u'入库成功!') return redirect(url_for('storage')) return render_template('storage.html', name=session.get('name'), form=form)
def store_apply(request): """ 店铺入驻 :param request: :return: 'name','seller','business','kinds','link','industry','character','phone','QQ',,'introduction,, 'headpicture','companyname','connectioner','connection_number','company_adress','company_QQ','business_license' """ user = request.user print user if request.method =='POST': form = StoreForm(request.POST or None, request.FILES or None) print "uiosdhfui" print form.errors if form.is_valid(): name=form.cleaned_data['name'] business=form.cleaned_data['business'] kinds=form.cleaned_data['kinds'] link=form.cleaned_data['link'] industry=form.cleaned_data['industry'] character=form.cleaned_data['character'] phone=form.cleaned_data['phone'] QQ=form.cleaned_data['QQ'] introduction=form.cleaned_data['introduction'] headpicture=form.cleaned_data['headpicture'] companyname = form.cleaned_data['companyname'] connectioner=form.cleaned_data['connectioner'] connection_number=form.cleaned_data['connection_number'] company_adress=form.cleaned_data['company_adress'] company_QQ = form.cleaned_data['company_QQ'] business_license = form.cleaned_data['business_license'] company_introduce=form.cleaned_data['company_introduce'] print headpicture print business_license print kinds # kind = big_goods_type.objects.get(id=kinds) # print kind # #头像保存 path = default_storage.save(str(headpicture), ContentFile(headpicture.read())) tmp_file = os.path.join(settings.MEDIA_ROOT, path) headpicture = str(headpicture) #营业执照保存 path = default_storage.save(str(business_license), ContentFile(business_license.read())) tmp_file = os.path.join(settings.MEDIA_ROOT, path) business_license = str(business_license) s=Store.objects.create(name=name, phone=phone, QQ=QQ,seller=user, business=business, industry=industry,kinds=kinds, character=character, introduction=introduction, headpicture=headpicture, companyname=companyname,link=link, connectioner=connectioner, connection_number=connection_number, company_adress=company_adress, company_QQ=company_QQ, business_license=business_license, company_introduce=company_introduce) return render(request,'person_rzcg.html') else: msg=u'参数填写错误' return render(request,'person_dpsq.html',{'msg':msg}) else: return render(request, 'person_dpsq.html', {'forms': StoreForm(),'user':user})
def add_store(request,user_id=1): if request.POST: user = auth.get_user(request).id form = StoreForm(request.POST) if form.is_valid(): Store = form.save(commit=False) Store.store_user_add_store = request.user form.save() return redirect('/')
def new_store(): """ Add a new store """ form = StoreForm(request.form) if request.method == 'POST' and form.validate(): # save the store store = Store() save_changes(store, form, new=True) flash('Store created successfully!') return redirect('/') return render_template('new_store.html', form=form)
def edit(id): qry = db_session.query(Store).filter( Store.id==id) store = qry.first() if store: form = StoreForm(formdata=request.form, obj=store) if request.method == 'POST' and form.validate(): # save edits save_changes(store, form) flash('Store updated successfully!') return redirect('/') return render_template('edit_store.html', form=form) else: return 'Error loading #{id}'.format(id=id)
def get_context_data(self, **kwargs): """Return dictionary representing passed in context.""" context = super(AddStore, self).get_context_data(**kwargs) context['stores'] = Store.objects.all() context['username'] = self.request.user.username context['addstoreform'] = StoreForm() return context
def addstore(request, user_id=1): add_store = StoreForm() args = {} args.update(csrf(request)) args['form'] = add_store args['username'] = auth.get_user(request).username args['user_id'] = auth.get_user(request).id return render_to_response('addstore.html', args)
def delete(id): """ Delete the item in the database that matches the specified id in the URL """ qry = db_session.query(Store).filter( Store.id==id) store = qry.first() if store: form = StoreForm(formdata=request.form, obj=store) if request.method == 'POST' and form.validate(): # delete the item from the database db_session.delete(store) db_session.commit() flash('Store deleted successfully!') return redirect('/') return render_template('delete_store.html', form=form) else: return 'Error deleting #{id}'.format(id=id)
def add_store(request, user_id=1): if request.POST: user = auth.get_user(request).id form = StoreForm(request.POST) if form.is_valid(): Store = form.save(commit=False) Store.store_user_add_store = request.user form.save() return redirect('/')
def store_edit(request): """ 商店资料编辑 :param request: :param store_id: :return: ['name','seller','business','kinds','link','industry','character','phone','QQ','is_create','is_design','is_custom','is_work_design','company','introduction','post','connector'] """ try: user = request.user store = Store.objects.filter(status=2).get(seller=user) Aform = StoreForm(instance=store) except: return HttpResponseRedirect('/Store/store_apply') if request.method == 'POST': name = request.POST.get('name') business = request.POST.get('business') kinds = request.POST.get('kinds') link = request.POST.get('link') industry = request.POST.get('industry') character = request.POST.get('character') phone = request.POST.get('phone') QQ = request.POST.get('QQ') introduction = request.POST.get('introduction') headpicture = request.FILES.get('headpicture','') companyname = request.POST.get('companyname') connectioner = request.POST.get('connectioner') connection_number = request.POST.get('connection_number') company_adress = request.POST.get('company_adress') company_QQ = request.POST.get('company_QQ') business_license = request.FILES.get('business_license','') company_introduce = request.POST.get('company_introduce') kind = big_goods_type.objects.get(id=kinds) # 头像保存保存# 营业执照保存 if not headpicture : headpicture = store.headpicture else: path = default_storage.save(str(headpicture), ContentFile(headpicture.read())) tmp_file = os.path.join(settings.MEDIA_ROOT, path) headpicture = str(headpicture) if not business_license: business_license = store.business_license else: path = default_storage.save(str(business_license), ContentFile(business_license.read())) tmp_file = os.path.join(settings.MEDIA_ROOT, path) business_license = str(business_license) s = Store(name=name, phone=phone, QQ=QQ, link=link, kinds=kind,seller=user, business=business, industry=industry, character=character, introduction=introduction, headpicture=headpicture, companyname=companyname, connectioner=connectioner, connection_number=connection_number, company_adress=company_adress, company_QQ=company_QQ, business_license=business_license, company_introduce=company_introduce) s.id = store.id s.save() return HttpResponse('修改成功啦') else: return render(request,'person_dpbj.html',{'form':Aform}) # else: