Ejemplo n.º 1
0
def confirm_role_details():
    redis_store.set('roles_seen', 0)
    if request.method == 'POST':
        redis_store.hmset('contact', request.form.to_dict())
    data = {
        'role': {
            'caption': 'Role details',
            'row_data': redis_store.hgetall('role')
        },
        'logistics': {
            'caption': 'Logistical details',
            'row_data': redis_store.hgetall('logistics')
        },
        'security': {
            'caption': 'Security details',
            'row_data': redis_store.hgetall('security')
        }
    }
    skills = redis_store.lrange('skills', 0, -1)
    for s in skills:
        skill_data = {
            'row_data': json.loads(redis_store.get(s)),
            'caption': s
        }
        data[s] = skill_data
    return render_template('submit/confirm-role-details.html', data=data)
Ejemplo n.º 2
0
def fenYe(request, fenyeno, hashname):
    all = redis_store.hgetall(hashname)
    allkeys = redis_store.hkeys(hashname)
    allCounts = redis_store.hlen(hashname)

    try:
        curPage = int(request.args.get('curPage', '1'))
        allPage = int(request.args.get('allPage', '1'))
        pageType = str(request.args.get('pageType', ''))
    except ValueError:
        curPage = 1
        allPage = 1
        pageType = ''
    if pageType == 'pageDown':
        curPage += 1
    elif pageType == 'pageUp':
        curPage -= 1
    startPos = (curPage - 1) * fenyeno
    endPos = startPos + fenyeno

    posts = allkeys[startPos:endPos]

    if curPage == 1 and allPage == 1:
        allPage = allCounts / fenyeno
        remainPost = allCounts % fenyeno
        if remainPost > 0:
            allPage += 1
    return posts, allPage, curPage, allCounts, all
Ejemplo n.º 3
0
def nginxedit(domain):
    if request.method == 'POST':
        ipsstr=request.form['ips'].strip()
        ips=ipsstr.split(',')
        #编辑时只允许编辑IP
        #校验IP
        from app.utils.verify import verify_ip
        ipflag=0
        for ip in ips:
            if verify_ip(ip) is False:
                ipflag=ipflag+1
                flash(u'IP校验失败,请检查')


        #ip都校验通过后则进行保存到redis动作
        if ipflag == 0:
            redis_store.hset('nginxip',domain,ipsstr)
            return redirect(url_for('nginx'))

    
    #如果不是post则是get,并做如下动作
    k=domain
    v=redis_store.hgetall('nginxip')[k]
    r = {'k':k,'v':v}
    return render_template('nginx/edit.html',r=r)
Ejemplo n.º 4
0
 def get(self):
     proxies = redis_store.hgetall(KEY)
     if proxies:
         proxy = random.choice(list(proxies.keys()))
         return {
             "code": 0,
             "msg": "success",
             "proxy": proxy.decode("utf-8")
         }
     else:
         return {"code": 1, "msg": "no more proxy"}
Ejemplo n.º 5
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    form = LoginForm()
    # заполняем SelectField пользователями сайта
    choices = [(key, redis_store.hgetall(key)['username'])
               for key in redis_store.hkeys('site_users')]
    if len(choices) > 0:
        form.username.choices = choices
    if form.validate_on_submit():
        user = redis_store.exists(form.username.data)
        password_hash = '' if redis_store.hget(
            form.username.data, 'password_hash') == None else redis_store.hget(
                form.username.data, 'password_hash')
        if not user or not check_password_hash(password_hash,
                                               form.password.data):
            flash('Неверный логин или пароль!')
            return redirect(url_for('auth.login'))
        user_data = redis_store.hgetall(form.username.data)
        user_id = form.username.data
        username = user_data['username']
        # email           = user_data['email']
        password_hash = user_data['password_hash']
        operating_mode = user_data['operating_mode']
        role = user_data['role']
        user = User(user_id=user_id,
                    username=username,
                    password_hash=password_hash,
                    operating_mode=operating_mode,
                    role=role)
        login_user(user)
        next_page = request.args.get('next')
        if not next_page or url_parse(next_page).netloc != '':
            next_page = url_for('main.index')
        return redirect(next_page)
    return render_template('auth/login.html', form=form)
Ejemplo n.º 6
0
def load_user(id):
    user_data = redis_store.hgetall(id)    
    if user_data == {}:
        return None
    else:    
        username        = user_data['username']
        #email           = user_data['email']
        password_hash   = user_data['password_hash']
        operating_mode  = user_data['operating_mode']
        role            = user_data['role']        
        user = User(user_id=id,
                    username=username,
                    # email=email, 
                    password_hash=password_hash,
                    operating_mode=operating_mode,
                    role=role)
        return user    
Ejemplo n.º 7
0
def productpage(pid):
    uid = request.cookies.get('sessionuid')
    if uid is not None:
        cart = redis_store.hgetall('cart:' + uid)
        print '---cart---'
        product = Product.query.filter_by(id=pid).first_or_404()
        if pid in cart:
            print 'YEYEYEYEEY'
            print cart[pid]
            product.incart = cart[pid]
        else:
            print "NOENEONEON"
            product.incart = 0

        product = checkMinimumPrice(product)
        return render_template("product.html",
                               title=product.name,
                               product=product)
Ejemplo n.º 8
0
def showcart():
    uid = request.cookies.get('sessionuid')
    cart = {}
    if uid is not None:
        cart = redis_store.hgetall('cart:' + uid)
        newcart = {}
        total = 0
        #         print type(cart.items())

        for x in cart:
            product = Product.query.filter_by(id=x).first()
            print "TOTAL"
            print total
            # if product is not None:
            # ensure that admin has not deleted the product while it was in someones cart
            a = {}
            oos = {}
            deleted = {}
            product = checkMinimumPrice(product)
            print product.name
            print '--------SQ---'
            print product.quantity
            print '--------PQ---'
            print int(cart[x])

            if product.quantity > 0:
                #see if product is in stock on the backend
                a['stockquantity'] = product.quantity
                a['quantity'] = int(cart[x])
                a['importantmessage'] = ''
                if a['stockquantity'] < a['quantity']:
                    #insufficient stock, auto update stock on redis and cart page
                    a['quantity'] = a['stockquantity']
                    a['importantmessage'] = "Quantity changed from " + str(
                        cart[x]) + "->" + str(a['stockquantity'])
                    redis_store.hset('cart:' + uid, x, a['stockquantity'])
                    print a['importantmessage']
                a['name'] = product.name
                a['id'] = product.id
                a['maxprice'] = product.price
                a['status'] = 'available'
                #Dealing with coupon
                if product.minpricecoupon is not 0:
                    a['minprice'] = product.minpricecoupon.afterprice
                    if product.minpricecoupon.upto > 0:
                        a['couponused'] = product.minpricecoupon.name + " upto Rs." + product.minpricecoupon.upto
                    else:
                        a['couponused'] = product.minpricecoupon.name
                else:
                    a['minprice'] = product.price
                    a['couponused'] = ''

                a['total'] = a['quantity'] * a['minprice']
                total += a['total']
                newcart[x] = a
            else:
                # if product is not in stock
                oos['quantity'] = int(cart[x])
                oos['name'] = product.name
                oos['id'] = product.id
                oos['maxprice'] = product.price
                oos['couponused'] = ''
                oos['minprice'] = product.price
                if product.quantity == -1:
                    #Deleted product
                    oos['status'] = 'deleted'
                    oos['quantity'] = 0
                else:
                    #Out of Stock
                    oos['status'] = 'oos'

                newcart[x] = oos

            # else:
            #if admin has deleted the product, auto-delete it from cart
            # rare case, that it has been removed from database
            # redis_store.hset('cart:' + uid,x,-1)

    return render_template("cart.html",
                           title="Your Cart",
                           cart=newcart,
                           total=total)
Ejemplo n.º 9
0
def getEventConnections(eventName):
    return {
        key: json.loads(value)
        for key, value in redis_store.hgetall(eventName +
                                              '.connection').iteritems()
    }
Ejemplo n.º 10
0
def getEventConnections(eventName):
    return {key: json.loads(value) for key, value in redis_store.hgetall(eventName + '.connection').iteritems()}