Esempio n. 1
0
def editUser():
    form_data = request.form.to_dict()
    edited_user = json_to_dict(form_data['user'])
    exemptions = json_to_dict(form_data['exemptions'])
    edited_user['exemptions'] = exemptions

    original_id = form_data['original_id']

    try:
        users_df = cnf.get_users_df()
        user_mask = users_df['id'] == original_id

        # update the user with keys it hasn't have
        exist_user = users_df[user_mask].to_dict('records')[0]
        edited_user = {**exist_user, **edited_user}
        # delete from users_df
        users_df = users_df[users_df.id != original_id]
        # insert to users_df
        users_df = users_df.append(edited_user, ignore_index=True)

        cnf.update_users_file(users_df)

    except Exception as e:
        print(str(e))
        resp = {'success': False,\
                'message': str(e)}
        site_log.error(log_message(str(e)))

    else:
        resp = {'success': True,\
                'message': 'המשתמש עודכן בהצלחה'}
        site_log.info(log_message('edited user in json'))

    finally:
        return jsonify(resp)
Esempio n. 2
0
def addUser():
    new_user = request.form.to_dict()
    new_user['exemptions'] = json_to_dict(new_user['exemptions'])
    new_user = new_user_hundle(new_user)

    users_df = cnf.get_users_df()

    if new_user['id'] not in users_df['id'].unique():  # if its a new id
        try:
            users_df = users_df.append(new_user, ignore_index=True)
            cnf.update_users_file(users_df)

        except Exception as e:
            print(str(e))
            resp = {'success': False,\
                    'message': str(e)}
            site_log.error(log_message(str(e)))

        else:
            resp = {'success': True,\
                    'message': 'החייל הוסף למערכת'}
            site_log.info(log_message(f"added user {new_user['id']} to json"))

    else:
        resp = {'success': False,\
                'message': 'המספר האישי כבר נמצא במערכת'}
        site_log.error('tried to add a user that already exist on the db')

    return jsonify(resp)
Esempio n. 3
0
def add_workers(final_csv):
    global users_df
    users_df = cnf.get_users_df()
    for index, row in final_csv.iterrows():
        if row['date_type'] == 'אמצש':
            set_weekday_workers(final_csv, index, row)
        else:
            set_weekend_workers(final_csv, index, row)
    cnf.update_users_file(users_df)
    return final_csv
Esempio n. 4
0
def removeUser():
    user_id = request.form.to_dict()['id']
    try:
        users_df = cnf.get_users_df()
        users_df = users_df[users_df.id != user_id]

        cnf.update_users_file(users_df)

    except Exception as e:
        print(str(e))
        resp = {'success': False,\
                'message': str(e)}
        site_log.error(log_message(str(e)))

    else:
        resp = {'success': True,\
                'message': 'המשתמש נמחק בהצלחה'}
        site_log.info(log_message('removed user from json'))

    finally:
        return jsonify(resp)
Esempio n. 5
0
def remove_expired_exemptions():
    users_df = cnf.get_users_df()
    users_df['exemptions'] = users_df['exemptions'].apply(remove_exemptions)
    cnf.update_users_file(users_df)