Exemple #1
0
def level_3(db, migration, migrator):
    with db.atomic():
        log.info("creating table FrontendConfig...")
        db.create_tables([FrontendConfig])
        log.info("setting migration level to 3...")
        migration.version = 3
        migration.save()
        try:
            log.info("writing existing config to db...")
            config = FrontendSettings.by_env()
            FrontendConfig.create(config=config)
            log.info("wrote existing config to db.")
        except:
            log.warning("no config found for env, set values with cli command set_frontend_config.")
def load_frontend_config(db: directives.PeeweeSession, frontend_config_file: hug.types.text,
                         for_real: hug.types.smart_boolean = False):
    with db.atomic():
        with open(frontend_config_file, 'r') as j_file:
            try:
                new_config = json.load(j_file)
                if 'instanceName' not in new_config or 'longInstanceName' not in new_config or \
                        'contactInfoCoupons' not in new_config \
                        or 'contactInfoAppointment' not in new_config or 'formFields' not in new_config:
                    print(
                        f"Given file '{json.dumps(new_config, indent=2)}' missing required fields!")
                    sys.exit(1)
                elif type(new_config['formFields']) != list:
                    print("field formFields is not a list!")
                    sys.exit(1)
            except json.JSONDecodeError as e:
                print("The file can not decoded as json!")
                sys.exit(1)

            if not for_real:
                print(
                    f"This would update the config with '{json.dumps(new_config, indent=2)}'. "
                    f"Run with --for_real if you are sure.")
                sys.exit(1)
            else:
                print(
                    f"Updating the config with '{json.dumps(new_config, indent=2)}'.")
                try:
                    config = FrontendConfig.get()
                    config.config = new_config
                except FrontendConfig.DoesNotExist:
                    config = FrontendConfig.create(config=new_config)

                config.save()
                print("Done.")
def set_frontend_config(db: directives.PeeweeSession, instance_name: hug.types.text, long_instance_name: hug.types.text,
                        contact_info_bookings: hug.types.text, contact_info_appointments: hug.types.text = None,
                        form_fields: hug.types.text = "base,address,dayOfBirth,reason",
                        for_real: hug.types.smart_boolean = False):
    with db.atomic():

        if not contact_info_appointments:
            appointments_contact = contact_info_bookings
        else:
            appointments_contact = contact_info_appointments

        template = {
            "instanceName": f"{instance_name}",
            "longInstanceName": f"{long_instance_name}",
            "contactInfoCoupons": f"{contact_info_bookings}",
            "contactInfoAppointment": f"{appointments_contact}",
            "formFields": form_fields.split(","),
        }

        if not for_real:
            print(f"This would update the config with '{json.dumps(template, indent=2)}'. Run with --for_real if you "
                  f"are sure.")
            sys.exit(1)
        else:
            print(
                f"Updating the config with '{json.dumps(template, indent=2)}'.")
            try:
                config = FrontendConfig.get()
                config.config = template
            except FrontendConfig.DoesNotExist:
                config = FrontendConfig.create(config=template)

            config.save()
            print("Done.")
def set_frontend_config(db: directives.PeeweeSession,
                        instance_name: hug.types.text,
                        long_instance_name: hug.types.text,
                        contact_info_bookings: hug.types.text,
                        contact_info_appointments: hug.types.text = None,
                        for_real: hug.types.smart_boolean = False):
    with db.atomic():
        if "@" in contact_info_bookings:
            bookings_contact = f"<a href=\"mailto:{contact_info_bookings}\">{contact_info_bookings}</a>"
        else:
            bookings_contact = contact_info_bookings

        if not contact_info_appointments:
            appointments_contact = bookings_contact
        else:
            if "@" in contact_info_appointments:
                appointments_contact = f"<a href=\"mailto:{contact_info_appointments}\">{contact_info_appointments}</a>"
            else:
                appointments_contact = contact_info_appointments

        template = {
            "instanceName":
            f"{instance_name}",
            "longInstanceName":
            f"{long_instance_name}",
            "contactInfoCoupons":
            f"<span class=\"hintLabel\">Um mehr Termine vergeben zu können wenden Sie sich an "
            f"{bookings_contact}</span>",
            "contactInfoAppointment":
            f"<span class=\"hintLabel\">Kontaktieren Sie {appointments_contact}</span>"
        }

        if not for_real:
            print(
                f"This would update the config with '{json.dumps(template, indent=2)}'. Run with --for_real if you "
                f"are sure.")
            sys.exit(1)
        else:
            print(
                f"Updating the config with '{json.dumps(template, indent=2)}'."
            )
            config = FrontendConfig.create(config=template)
            config.save()
            print("Done.")