Beispiel #1
0
def create_xls_template():
    d = {
        'Sheet 1': [[
            'DATE', 'Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi',
            'Vendredi', 'Samedi'
        ]]
    }
    employe_sorted = users.sort_employe("poste", is_ascending=False)
    caisse = []
    cuisine = []
    respo = []
    for i, e in enumerate(employe_sorted):

        if e['poste'] == 'caisse':
            caisse.append(employe_sorted.pop(i))
        elif e['poste'] == 'cuisine':
            cuisine.append(employe_sorted.pop(i))
        elif e['poste'] == 'respo':
            respo.app

    d['Sheet 1'].append(
        ["{} {}".format(e.get('nom'), e.get("nom de famille"))])
    try:
        pyexcel.save_book_as(
            bookdict=d,
            dest_file_name=schedule_maker.get_full_path_name("template.xls"))
    except Exception as x:
        print(UI_String.UNHANDLED_EXCEPTION.format(type(x), x))
Beispiel #2
0
def save_json_settings():
    try:
        with open(
                schedule_maker.get_full_path_name("setting_for_schedule.json"),
                'w',
                encoding='utf-8') as fout:
            fout.write(json.dumps(settings))
    except Exception as x:
        print(type(x), x)
Beispiel #3
0
def load_employe_data():
    path = schedule_maker.get_full_path_name("employe.json")
    try:
        with open(path, "r", encoding="utf-8") as fin:
            try:  # Essaie de loader le fichier
                de_data = json.loads(fin.read())
                return de_data
            except json.decoder.JSONDecodeError:  # Si le fichier est vide
                return []
    except FileNotFoundError:
        save_employe_data()
        return load_employe_data()
Beispiel #4
0
def load_xls_template():
    try:
        raw = pyexcel.get_book_dict(
            file_name=schedule_maker.get_full_path_name('template.xls'),
            name_columns_by_row=0)
        temp = []
        for l in raw:
            pass
        return raw

    except FileNotFoundError:
        print(UI_String.SCHEDULE_TEMPLATE_NOT_FOUND)
        create_xls_template()
        load_xls_template()
    except Exception as x:
        print(type(x), x)
Beispiel #5
0
def load_json_settings():
    r = {}
    try:
        with open(
                schedule_maker.get_full_path_name("setting_for_schedule.json"),
                'r',
                encoding='utf-8') as fin:
            r = json.loads(fin.read())
    except FileNotFoundError:
        print(UI_String.SCHEDULE_COULDNT_FIND_SETTING_FILE)
    except json.decoder.JSONDecodeError:
        print(UI_String.SCHEDULE_SETTING_IS_EMPTY)
    except Exception as e:
        print("Unhandled exception:\n{}, {} ".format(type(e), e))
    finally:
        return r
Beispiel #6
0
def save_employe_data():
    path = schedule_maker.get_full_path_name("employe.json")
    with open(path, "w", encoding="utf-8") as fout:
        # TODO Format json before/while dumping it
        fout.write(json.dumps(employe, indent=4))
        print(UI_String.DATA_EMPLOYE_SAVED)