def verificar_parametros():
    # Verifica se os parametros do Magento Existem e caso
    # negativo o usuario é redirecionado para a tela de
    # configurações do magento
    from app.models.config import Config
    from app.core.utils import warning
    from app.views.configuracoes.views import index

    allowed_paths = ['/logout', '/integrador/produtos/imagens/enviar']
    is_authenticated = current_user.is_active and current_user.is_authenticated
    path = request.path

    if path not in allowed_paths and is_authenticated:
        parametros = Config.by_id(1)
        if not parametros or not parametros.baseUrl:
            warning('A URL base do sistema deve ser configurada.')
            return make_response(index())

        base_url = parametros.baseUrl
        upload_url = app.config['UPLOADS_DEFAULT_URL']
        upload_url = upload_url.rsplit(
            '/', 1)[0]  # retorna somente a url base sem o /uploads

        if not base_url or upload_url is not base_url:
            upload_url = f'{base_url}/uploads'
            app.config['UPLOADS_DEFAULT_URL'] = upload_url
Exemple #2
0
def index():
    template = 'configuracoes/main.html'
    config = Config.by_id(1)
    form = ConfigForm()

    if config and config.baseUrl and not form.baseURL.data:
        form.configId.data = config.id
        form.baseURL.data = config.baseUrl

    if form.validate_on_submit():
        import os
        config.baseUrl = form.baseURL.data

        uploadURL = os.path.join(form.baseURL.data, 'uploads')
        current_app.config.update(UPLOADS_DEFAULT_URL=uploadURL)
        configure_uploads(current_app, (imageSet, ))

        db.session.add(config)
        db.session.commit()

        success('Registro alterado com sucesso.')

    content = {'title': 'Configurações do Sistema', 'form': form}
    return render_template(template, **content)