示例#1
0
 def get(self, pageno=None):
     if pageno is None:
         return jsonify({'result': dao.get_all_users()})
     else:
         offset = (pageno - 1) * 5
         pageno = 5
         return jsonify({'result': dao.get_all_users(pageno, offset)})
示例#2
0
def search():

    client = data.get_client()
    search_by = request.args.get('search_by')
    search_str = request.args.get('search')
    filter_by_cat = request.args.get('filter_by_cat')
    filter_by_rating = request.args.get('filter_by_rating')
    results = dao.search_by_query(client, search_str,
                                  search_by,
                                  filter_by_cat,
                                  filter_by_rating)

    no_of_result = results.count()
    categories = dao.get_all_categories(client)

    all_users = dao.get_all_users(client)

    if flask_login.current_user.is_authenticated:
        current_user = flask_login.current_user

        if current_user:
            user = dao.get_user_by_email(client, current_user.id)
    else:
        user = None

    return render_template('search_result.template.html',results=results, search_str=search_str, user=user, cat=categories, all_users=all_users, no_of_result=no_of_result)
示例#3
0
文件: app.py 项目: olizhu10/alley
def get_users():
    try:
        return success_response(dao.get_all_users())
    except Exception as e:
        return json.dumps({
            'success': False,
            'error': 'Exception: ' + str(e)
        }), 400
示例#4
0
def read_reviews():
    client = data.get_client()

    latest_review = client[DB_NAME].user_reviews.find().sort('posted', pymongo.DESCENDING).limit(4)

    users = dao.get_all_users(client)
    categories = dao.get_all_categories(client)

    skincare_reviews = client[DB_NAME].user_reviews.find(
        {
             'categories.name': 'Skin Care'
        }
    ).sort('posted', pymongo.DESCENDING).limit(4)

    cosmetic_reviews = client[DB_NAME].user_reviews.find(
        {
            'categories.name': 'Make Up'
        }
    ).sort('posted', pymongo.DESCENDING).limit(4)

    bodycare_reviews = client[DB_NAME].user_reviews.find(
        {
            'categories.name': 'Body Care'
        }
    ).sort('posted', pymongo.DESCENDING).limit(1)

    haircare_reviews = client[DB_NAME].user_reviews.find(
        {
            'categories.name': 'Hair Care'
        }
    ).sort('posted', pymongo.DESCENDING).limit(1)

    formen_reviews = client[DB_NAME].user_reviews.find(
        {
            'categories.name': 'For Men'
        }
    ).sort('posted', pymongo.DESCENDING).limit(1)

    user_list = []
    for user in users:
        user_list.append(user)

    if flask_login.current_user.is_authenticated:
        current_user = flask_login.current_user

        if current_user:
            user = dao.get_user_by_email(client, current_user.id)
        else:
            user = None


    return render_template('read_reviews.template.html', review=latest_review, cat=categories, users=user_list, skincare=skincare_reviews, cosmetics=cosmetic_reviews, bodycare=bodycare_reviews, haircare=haircare_reviews, formen=formen_reviews, user=user)
示例#5
0
def user_manager(username, role):
    if (role == 1):
        if (request.method == "POST"):
            if (request.form['type'] == 'Revoke'):
                change_user_role(request.form['username'], 0)
            elif (request.form['type'] == 'Grant'):
                change_user_role(request.form['username'], 1)
            elif (request.form['type'] == 'Reset'):
                change_user_password(request.form['username'], 'password')
            elif (request.form['type'] == 'Delete'):
                if (request.form['username'] != username):
                    delete_user(request.form['username'])
            elif (request.form['type'] == "Create"):
                if (not is_user(request.form['username'])):
                    create_user(request.form['username'], 'password', 0)
                    users = get_all_users()
                    return render_template("user_manager.html",
                                           role=role,
                                           users=users,
                                           username=username,
                                           msg="user successfully created")
                else:
                    users = get_all_users()
                    return render_template("user_manager.html",
                                           role=role,
                                           users=users,
                                           username=username,
                                           error="user already exists")
            else:
                pass
            return ""
        else:
            users = get_all_users()
            return render_template("user_manager.html",
                                   role=role,
                                   users=users,
                                   username=username)
    else:
        return redirect(url_for("login"))
示例#6
0
def view_review_details(review_id):

    client = data.get_client()

    review = dao.get_review_by_review_id(client, review_id)
    all_users = dao.get_all_users(client)
    all_cat = dao.get_all_categories(client)

    if flask_login.current_user.is_authenticated:
        current_user = flask_login.current_user

        if current_user:
            user = dao.get_user_by_email(client, current_user.id)
    else:
        user = None

    return render_template('review_details.template.html', cat=all_cat, review=review, user=user, all_users=all_users)
示例#7
0
def read_reviews_by_category(cat_id):

    client = data.get_client()
    reviews = dao.get_reviews_by_cat_id(client, cat_id)
    current_cat = dao.get_category_by_id(client, cat_id)
    all_cat = dao.get_all_categories(client)
    all_users = dao.get_all_users(client)

    if flask_login.current_user.is_authenticated:
        current_user = flask_login.current_user

        if current_user:
            user = dao.get_user_by_email(client, current_user.id)
    else:
        user = None

    return render_template('read_reviews_by_cat.template.html', current_cat=current_cat, cat=all_cat, reviews=reviews, user=user, all_users=all_users)
示例#8
0
def get_users():
    return success_response(dao.get_all_users())