def addcart(): loginform = loginForm() num = request.cookies.get('num') buydict = request.cookies.get('buydict') refer = request.headers.get('Referer') response = make_response(redirect(refer)) for x in request.form: if int(request.form[x]) <= int( Product.getdata(str(x).rsplit('-', 1)[0]).get('orderdict')[int( str(x).rsplit('-', 1)[1])].get('much')): if num is None: num = 0 if buydict is None: buydict = str({}) buydict = ast.literal_eval(str(buydict)) num = str(int(num) + int(request.form[x])) if buydict.get(x) == None: buydict[x] = 0 buydict[x] = int(buydict.get(x)) + int(request.form[x]) buydict = dict((x, y) for x, y in buydict.items() if y != 0) else: return render_template('err_tic.html', **locals()) response.set_cookie('num', num) print(buydict) response.set_cookie('buydict', str(buydict)) return response
def showinfo(url): loginform = loginForm() data = Product.getdata(url) if Product.count(str(url)) == 0 or data.get( 'activity') == True or data.get('verfiy') == False: return render_template('404.html', **locals()) return render_template('proinfo-show.html', **locals())
def shop1(): loop1 = [1] buydict = request.cookies.get('buydict') allmoney = 0 if buydict is None: buyinfo = [] else: buydict = ast.literal_eval(str(buydict)) buyinfo = [] for x in buydict: title = Product.getdata(str(x).rsplit( '-', 1)[0]).get('orderdict')[int(str(x).rsplit('-', 1)[1])].get('name') price = Product.getdata(str(x).rsplit( '-', 1)[0]).get('orderdict')[int(str(x).rsplit('-', 1)[1])].get('cost') much = int(buydict.get(x)) price = int(price) tempinfo = [title, price, much] buyinfo.append(tempinfo) allmoney = allmoney + (price * much) loginform = loginForm() return render_template('proinfo-shop01.html', **locals())
def porinfosearch(): loginform = loginForm() # category = request.args.get('category') title = request.args.get('title') if title == None: pass else: title = title.rsplit(' ') for index, item in enumerate(title): title[index] = re.compile('' + item + '') # if 'search' not in dir(Product): # return render_template('404.html',**locals()),404 search = False q = request.args.get('q') if q: search = True allpd = Product.searchmozz(title) page = request.args.get('page', type=int, default=1) pagepd = allpd.sort('$natural', -1).limit(9).skip((int(page) - 1) * 9) pagin = Pagination(page=page, per_page=9, bs_version=3, total=allpd.count(), search=search, record_name='allpd') return render_template('proinfo.html', **locals())
def login(): loginform = loginForm() if request.method == 'POST' and loginform.validate_on_submit(): user = dbUser.usercheck(loginform.email.data) if user and dbUser.login(loginform.email.data, loginform.password.data): user_obj = User(user['email']) flask_login.login_user(user_obj) return redirect(request.args.get("next") or url_for('main.index')) return render_template('login_err.html', loginform=loginform) else: return render_template('login_err.html', loginform=loginform)
def serve_picture(sha1): try: f = Pictures.getpicture(sha1) if f is None: raise IOError() if request.headers.get('If-modified-Since') == f['time'].ctime(): return Response(status=304) resp = Response(f['content'], mimetype='image/' + f['mime']) resp.headers['Last-Modified'] = f['time'].ctime() return resp except IOError: loginform = loginForm() return render_template('404.html', **locals()), 404
def tickerdash(): loginform = loginForm() buyertic = Product.getbuyer(current_user.email()) creatortic_raw = Product.getcreator(current_user.email()) creatortic = [] for x in creatortic_raw: title = x.get('title') url = x.get('url') temp_ticket_count = 0 for xx in x.get('orderdict'): temp_ticket_count = int(xx.get('much')) + int(temp_ticket_count) crawdict = {"url": url, "title": title, "much": temp_ticket_count} creatortic.append(crawdict) return render_template('tdash.html', **locals())
def reg_gen(): form = registerFormgen() loginform = loginForm() if request.method == 'POST' and not form.validate_on_submit(): return render_template('reg_err.html', **locals()) elif form.validate_on_submit(): if form.fbid.data == "": fbuuid = None else: fbuuid = form.fbid.data dbUser.addgen(form.email.data, form.password.data, form.name.data, form.birthday.data, form.country.data, form.phone.data, form.postnum.data, form.address.data, form.industry.data, form.companyname.data, form.jobtitle.data, form.lineid.data, fbuuid) return render_template('reg_info.html', **locals()) return render_template('member-general.html', **locals())
def porinfo(): loginform = loginForm() search = False q = request.args.get('q') if q: search = True allpd = Product.verfiyclass() page = request.args.get('page', type=int, default=1) pagepd = Product.verfiyclass().sort('$natural', -1).limit(9).skip( (int(page) - 1) * 9) pagin = Pagination(page=page, per_page=9, bs_version=3, total=allpd.count(), search=search, record_name='allpd') return render_template('proinfo-class.html', **locals())
def reg_stu(): form = registerForm() loginform = loginForm() fbtoken = request.cookies.get('fbToken') if fbtoken: fbname = facebook.getData(fbtoken) if request.method == 'POST' and not form.validate_on_submit(): return render_template('reg_err.html', **locals()) elif form.validate_on_submit(): if form.fbid.data == "": fbuuid = None else: fbuuid = form.fbid.data dbUser.add(form.email.data, form.password.data, form.name.data, form.birthday.data, form.country.data, form.phone.data, form.postnum.data, form.address.data, form.education.data, form.grade.data, form.school.data, form.major.data, form.lineid.data, fbuuid) return render_template('reg_info.html', **locals()) return render_template('member-student.html', **locals())
def porbill(): if request.method == 'POST': loop1 = [1] buydict = request.cookies.get('buydict') allmoney = 0 if buydict is None: buyinfo = [] else: buydict = ast.literal_eval(str(buydict)) buyinfo = [] for x in buydict: title = Product.getdata( str(x).rsplit('-', 1)[0]).get('orderdict')[int( str(x).rsplit('-', 1)[1])].get('name') price = Product.getdata( str(x).rsplit('-', 1)[0]).get('orderdict')[int( str(x).rsplit('-', 1)[1])].get('cost') url = Product.getdata(str(x).rsplit('-', 1)[0]).get('url') tid = Product.getdata(str(x).rsplit( '-', 1)[0]).get('orderdict')[int(str(x).rsplit('-', 1)[1])].get('id') much = int(buydict.get(x)) price = int(price) tempinfo = [title, price, much] buyinfo.append(tempinfo) allmoney = allmoney + (price * much) if Product.ticupdate(url, tid, much) == 'NoTic': return render_template('err_tic.html', **locals()) Product.ticadd(tid, url, title, current_user.name(), current_user.info().get('phone'), current_user.email(), much, int(price * much)) loginform = loginForm() pform = productForm() response = make_response( render_template('proinfo-shop03.html', **locals())) response.set_cookie('num', '', expires=0) response.set_cookie('buydict', '', expires=0) return response
def submitpro(): loginform = loginForm() form = submitclassinfo() if request.method == 'GET': return render_template('lesson.html', **locals()) elif request.method == 'POST' and form.validate_on_submit() and len( list(filter(None, request.form.getlist('ticket[]')))) >= 3: address = form.address.data link = form.link.data flavor = form.organize.data organize = current_user.name() daterange = form.daterange.data labout = form.labout.data cover = url_for('serve_picture', sha1=uploadcover(base64.b64decode( form.cover.data[23:]))) name = form.name.data name_pinyin = p.get_pinyin(str(name)).replace('-', '').replace(' ', '')[0:14] url = str( datetime.datetime.now().strftime('%y%m%d%H%M')) + '-' + name_pinyin content = form.content.data ticket = request.form.getlist('ticket[]') count = 0 dticket = [] for x, y, z in zip(ticket[0::3], ticket[1::3], ticket[2::3]): dtickettemp = {"id": count, "name": x, "cost": y, "much": z} count = count + 1 dticket.append(dtickettemp) Product.init(False, current_user.email(), url, False, name, labout, cover, daterange, address, link, flavor, organize, content, "noproddata", dticket) return redirect(url_for('classrom.showverinfo')) else: """偷懶debug區""" """不要送任何可以測資讓認證可過即可直接測試""" return render_template('reg_err.html', **locals())
def allmdbr(): infopp = info.prophoto()['url'] loginform = loginForm() return dict(infopp=infopp, loginform=loginform)
def info(): loginform = loginForm() form = registerForm() return render_template('member-info.html', **locals())
def showverinfo(): loginform = loginForm() return render_template('wait.html', **locals())
def admpreview(url): loginform = loginForm() data = dbprod.getdata(url) if dbprod.count(str(url)) == 0: return render_template('404.html',**locals()) return render_template('proinfo-show.html',**locals())
def tickemem(url): loginform = loginForm() if current_user.email() == Product.geturlcreator(url): title = Product.geturlname(url) ticitem = Product.getticmem(url) return render_template('tmem.html', **locals())