コード例 #1
0
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.")
コード例 #2
0
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.")
コード例 #3
0
def level_5(db, migration):
    left_part_coupons = '<span class="hintLabel">Um mehr Termine vergeben zu können wenden Sie sich an '
    left_part_appointment = '<span class=\"hintLabel\">Kontaktieren Sie '
    rigth_part = '</span>'
    mail_extract = 'href="mailto:([a-zA-Z0-9!#$%&\'*+-/=?^_`{|}~.@]*)"'
    with db.atomic():
        try:
            frontend_config = FrontendConfig.get()

            contact_info_coupons = frontend_config.config['contactInfoCoupons']
            contact_info_appointment = frontend_config.config['contactInfoAppointment']
            contact_info_appointment = contact_info_appointment.lstrip(left_part_appointment).rstrip(rigth_part)
            contact_info_coupons = contact_info_coupons.lstrip(left_part_coupons).rstrip(rigth_part)
            if contact_info_coupons.find('@') >= 0:
                contact_info_coupons = re.findall(mail_extract, contact_info_coupons)[0]
            if contact_info_appointment.find('@') >= 0:
                contact_info_appointment = re.findall(mail_extract, contact_info_appointment)[0]
            frontend_config.config['contactInfoCoupons'] = contact_info_coupons
            frontend_config.config['contactInfoAppointment'] = contact_info_appointment
            frontend_config.config['formFields'] = ['base', 'address', 'dayOfBirth', 'reason']
            frontend_config.save()
            migration.version = 5
            migration.save()
        except IndexError:
            log.info("No frontendconfig stored. No row migration needed")