Exemple #1
0
 def get(self):
     q = request.args.get('q')
     page = request.args.get('page')
     article_query, article_total = Quiz.search(q, 1, 5)
     account_query, account_total = AccountUser.search(q, 1, 5)
     articles = Quiz.get_all(page)
     accounts = AccountUser.get_all(page)
     if article_total:
         results = utils.MergeDictList([articles, {"type": "quiz"}])
         return jsonify(results)
     if account_total:
         results = utils.MergeDictList([accounts, {"type": "user"}])
         return jsonify(dict_ctx=results)
     results = {"count": 0, "results": []}
     return jsonify(results)
Exemple #2
0
 def get(self):
     logged_in_user = AccountUser.get_current_user()
     page = request.args.get('page')
     user_id = request.args.get('user_id')
     email = request.args.get('email')
     phone = request.args.get('phone')
     if user_id:
         account = AccountUser.get_by_id(user_id)
         user = AccountUser.get_user(account)
         if user:
             if user:
                 return jsonify(user)
         app.logger.warning(
             '{} submitted {} user id which does not exist'.format(
                 logged_in_user.name, user_id))
         return jsonify(message='{} does not exist'.format(user_id))
     if email:
         account = AccountUser.get_user_by_email(email)
         user = AccountUser.get_user(account)
         if user:
             return jsonify(user)
         app.logger.warning(
             '{} submitted {} email which does not exist'.format(
                 logged_in_user.name, email))
         return jsonify(message='{} does not exist'.format(email)), 404
     if phone:
         account = AccountUser.get_user_by_phone(phone)
         user = AccountUser.get_user(account)
         if user:
             return jsonify(user)
         app.logger.warning(
             '{} submitted {} phone number which does not exist'.format(
                 logged_in_user.name, phone))
         return jsonify(message='{} does not exist'.format(phone)), 404
     users = AccountUser.get_all(int(page) if page else None)
     results = []
     for v in users.items:
         del v._sa_instance_state
         results.append(v.__dict__)
     data = utils.response_dict(users, results, "/account/user/")
     return jsonify(data)