Ejemplo n.º 1
0
def init(testing=False):
    """Initialize the database with the default job"""
    if not os.path.exists(APPLICATION_DIRECTORY):
        os.mkdir(APPLICATION_DIRECTORY)
    if not os.path.exists(DATABASE_FILE) or testing:
        print(f"Creating TimeClok Database and default job.....")
        DB.create_tables(BaseModel)
        try:
            j = Job(name="default")
            j.save()
            s = State()
            s.save()
            s.set_job(j)
        except IntegrityError:
            DB.session.rollback()
Ejemplo n.º 2
0
def import_(file_path: str = Argument(
    None,
    help="the path of the file to import. Only json files are supported at this "
    "time.",
)):
    """Import an exported json file to the database."""
    if os.path.isfile(file_path):
        with open(file_path) as f:
            dump_obj = json.loads(f.read())
        time_clok_jobs = dump_obj["time_clok_jobs"]
        time_clok = dump_obj["time_clok"]
        time_clok_state = dump_obj["time_clok_state"]
        time_clok_journal = dump_obj["time_clok_journal"]

        jobs = []
        for job in time_clok_jobs:
            jobs.append(Job(**job))
        add_items_to_database(jobs)

        cloks = []
        for clok in time_clok:
            cloks.append(Clok(**clok))
        add_items_to_database(cloks)

        journals = []
        for journal in time_clok_journal:
            journals.append(Journal(**journal))
        add_items_to_database(journals)
        try:
            s = State(**time_clok_state[0])
            s.save()
        except IntegrityError:
            pass

    else:
        raise FileNotFoundError(f"'{file_path}' does not exist.")
Ejemplo n.º 3
0
path = path + "/LogisWare/core/install/NIGERIA_STATES_AND_LGS.json"

with open(path) as json_file:
    json_data = json.load(json_file)

    for data in json_data:
        print()
        state_name = data['state']['name']
        print(state_name)

        try:
            State.objects.get(name=state_name)
        except Exception:
            state_model = State()
            state_model.name = state_name
            state_model.save()

        # try:
        #     State.objects.get( name = state_name )
        # except State.DoesNotExist:
        #     state_model = State()
        #     state_model.name = state_name
        #     state_model.save()

        # state_locals = data['state']['locals']
        # print("---------------")
        # for local in state_locals:
        #     local_name = local['name']
        #     if LGA.objects.filter( name = local_name ).count() == 0:
        #         print( local_name )
Ejemplo n.º 4
0
level = Level()
level.code = 'PERAK'
level.name = 'TAHAP PERAK'
level.daily_task_count = 50
level.save()

level = Level()
level.code = 'GANGSA'
level.name = 'TAHAP GANGSA'
level.daily_task_count = 20
level.save()

state = State()
state.code = 'WP'
state.name = 'WILAYAH PERSEKUTUAN'
state.save()

state = State()
state.code = 'SL'
state.name = 'SELANGOR'
state.save()

state = State()
state.code = 'PK'
state.name = 'PERAK'
state.save()

state = State()
state.code = 'NS'
state.name = 'NEGERI SEMBILAN'
state.save()