Exemple #1
0
def get_users():
    try:
        pagination = find_users(request.args)
        users = pagination.items
    except Exception as e:
        return jsonify({
            'code':500,
            'message':str(e),
            'users':None
        })
    return jsonify({
        'code':200,
        'total':pagination.total,
        'users':[{
            'id':user.id,
            'username':user.username,
            'name':user.name,
            'start_time':convert_datetime_to_string(user.start_time),
            'end_time':convert_datetime_to_string(user.end_time),
            'sex':user.sex,
            'email':user.email,
            'phone':user.phone,
            'state':user.state,
            'unit':user.unit,
            'status':user.status,
            'work_state':user.work_state,
            'prorank':user.prorank,
            'skill':user.skill,
            'group':user.group,
            'role_names':[role.name for role in user.roles]
        } for user in users]
    })
Exemple #2
0
def get_current():
    try:
        user = User.query.filter(
            User.username == current_user.username).first()
    except Exception as e:
        return jsonify({"code": 500, "message": str(e)})
    return jsonify({
        "code": 200,
        "message": "",
        "user": {
            'id': user.id,
            'username': user.username,
            'name': user.name,
            'start_time': convert_datetime_to_string(user.start_time),
            'end_time': convert_datetime_to_string(user.end_time),
            'sex': user.sex,
            'email': user.email,
            'phone': user.phone,
            'state': user.state,
            'unit': user.unit,
            'status': user.status,
            'work_state': user.work_state,
            'prorank': user.prorank,
            'skill': user.skill,
            'group': user.group,
            'role_names': [role.name for role in user.roles]
        }
    })
Exemple #3
0
def get_user(username):
    try:
        user = find_user(username)
    except Exception as e:
        return jsonify({
            'code':500,
            'message':str(e),
            'users':None
        })
    return jsonify({
        'code': 200,
        'user': {
            'id': user.id,
            'username': user.username,
            'name': user.name,
            'start_time': convert_datetime_to_string(user.start_time),
            'end_time': convert_datetime_to_string(user.end_time),
            'sex': user.sex,
            'email': user.email,
            'phone': user.phone,
            'state': user.state,
            'unit': user.unit,
            'status': user.status,
            'work_state': user.work_state,
            'prorank': user.prorank,
            'skill': user.skill,
            'group': user.group,
            'role_names': [role.name for role in user.roles]
        }
    })
Exemple #4
0
def get_term_now():
    try:
        term = find_now_term()
    except Exception as e:
        return jsonify({
            'code': 500,
            'message': str(e),
            'users': None
        })
    return jsonify({
        'code': 200,
        'term': {
            'id': term.id,
            'name': term.name,
            'begin_time': convert_datetime_to_string(term.begin_time),
            'end_time': convert_datetime_to_string(term.end_time)
        }
    })
Exemple #5
0
def get_terms():
    try:
        pagination = find_terms(request.args)
        terms = pagination.items
    except Exception as e:
        return jsonify({
            'code': 500,
            'message': str(e),
            'users': None
        })
    return jsonify({
        'code': 200,
        'terms': [{
            'id': term.id,
            'name': term.name,
            'begin_time': convert_datetime_to_string(term.begin_time),
            'end_time':convert_datetime_to_string(term.end_time)
        } for term in terms]
    })
def run_back():
    for c in COLLECTIONS:
        cmd = "mongoexport -h {} -u {} -p {} -d {}  -o {} -c {}".format(
            DB_HOST, DB_USER, DB_PASSWD, DB_NAME,
            BACK_DB_FILE.format(
                c,
                convert_datetime_to_string(datetime.datetime.now(),
                                           "%Y-%m-%d-%H-%M")), c)
        print(cmd)
        print(os.system(cmd))
Exemple #7
0
 def formatter(cls, activity):
     if activity is None:
         return None
     try:
         activity_dict = {
             'id':
             activity.id,
             'name':
             activity.name,
             'teacher':
             activity.teacher,
             'start_time':
             convert_datetime_to_string(activity.start_time),
             'end_time':
             convert_datetime_to_string(activity.end_time),
             'place':
             activity.place,
             'state':
             activity.state,
             'information':
             activity.information,
             'all_num':
             activity.all_num,
             'attend_num':
             activity.attend_num,
             'remainder_num':
             activity.remainder_num,
             'term':
             activity.term,
             'apply_start_time':
             convert_datetime_to_string(activity.apply_start_time),
             'apply_end_time':
             convert_datetime_to_string(activity.apply_end_time),
             'apply_state':
             activity.apply_state
         }
     except Exception as e:
         raise CustomError(500, 500, str(e))
     return activity_dict