Ejemplo n.º 1
0
def allowed_file_extension(form, field):
    """
    Check the file extension is in allowed list.
    :param form:
    :param field:
    :return:
    """

    files = request.files.getlist("file")
    valid_extensions = ', '.join(FlicketConfig.valid_extensions())

    if files[0].filename == '':
        return False

    for file in files:
        filename = file.filename

        if '.' not in filename:
            field.errors.append(
                gettext('"{}" Is not a valid filename.'.format(filename)))
            return False

        if FlicketConfig.extension_allowed(filename):
            return True
        else:
            field.errors.append(
                gettext(
                    '"{}" Is not a an allowed extension. '
                    'Only the following are currently allowed: "{}"'.format(
                        filename, valid_extensions)))
            return False

    field.errors.append(
        gettext('There was a problem with the file attachment.'))
    return False
Ejemplo n.º 2
0
    def set_db_config_defaults(silent=False):

        print('Please enter site base url including port. For example this would be "http://192.168.1.1:8000".')
        base_url = input('Base url> ')

        count = FlicketConfig.query.count()
        if count > 0:
            if not silent:
                print('Flicket Config database seems to already be populated. Check values via application.')
            return

        set_config = FlicketConfig(
            posts_per_page=flicket_config['posts_per_page'],
            allowed_extensions=', '.join(flicket_config['allowed_extensions']),
            ticket_upload_folder=flicket_config['ticket_upload_folder'],
            avatar_upload_folder=flicket_config['avatar_upload_folder'],
            base_url=base_url,
            application_title='Flicket',
            mail_max_emails=10,
            mail_port=465
        )

        if not silent:
            print('Adding config values to database.')

        db.session.add(set_config)
        db.session.commit()
Ejemplo n.º 3
0
def set_db_config_defaults(silent=False):

    with open(config_file, "r") as f:
        config_data = json.load(f)

    base_url = config_data["base_url"]

    count = FlicketConfig.query.count()
    if count > 0:
        if not silent:
            print(
                "Flicket Config database seems to already be populated. Check values via application."
            )
        return

    set_config = FlicketConfig(
        posts_per_page=flicket_config["posts_per_page"],
        allowed_extensions=", ".join(flicket_config["allowed_extensions"]),
        ticket_upload_folder=flicket_config["ticket_upload_folder"],
        avatar_upload_folder=flicket_config["avatar_upload_folder"],
        base_url=base_url,
        application_title="Clicket",
        mail_max_emails=10,
        mail_port=465,
    )

    if not silent:
        print("Adding config values to database.")

    db.session.add(set_config)
    db.session.commit()
Ejemplo n.º 4
0
    def set_db_config_defaults_testing(silent=False):
        """
        Set config defaults. Only used for unit testing
        :param silent:
        :return:
        """

        set_config = FlicketConfig(
            posts_per_page=10,
            allowed_extensions='txt,  jpg',
            ticket_upload_folder='tmp/uploads',
            base_url='',
            mail_debug=True,
            mail_suppress_send=True,
        )

        if not silent:
            print('Adding config values to database.')

        db.session.add(set_config)
        db.session.commit()