Exemple #1
0
    def get_timing_context(app):
        with app.timing_context:
            errors = app.validate_app()
            assert not errors, errors

            with app.timing_context("build_zip"):
                build_application_zip(
                    include_multimedia_files=True,
                    include_index_files=True,
                    app=app,
                    download_id=None,
                    compress_zip=True,
                    filename='app-profile-test.ccz',
                )

        return app.timing_context
Exemple #2
0
def direct_ccz(request, domain):
    if 'app_id' in request.GET:
        app = get_app(domain, request.GET['app_id'])
        app.set_media_versions(None)
        download = DownloadBase()
        build_application_zip(
            include_multimedia_files=False,
            include_index_files=True,
            app=app,
            download_id=download.download_id,
            compress_zip=True,
            filename='{}.ccz'.format(slugify(app.name)),
        )
        return DownloadBase.get(download.download_id).toHttpResponse()
    msg = "You must specify `app_id` in your GET parameters"
    return json_response({'status': 'error', 'message': msg}, status_code=400)
Exemple #3
0
def get_direct_ccz(domain,
                   app,
                   lang,
                   langs,
                   version=None,
                   include_multimedia=False,
                   visit_scheduler_enabled=False):
    if not app.copy_of:
        errors = app.validate_app()
    else:
        errors = None

    if errors:
        error_html = render_to_string(
            "app_manager/partials/build_errors.html", {
                'app': app,
                'build_errors': errors,
                'domain': domain,
                'langs': langs,
                'lang': lang,
                'visit_scheduler_enabled': visit_scheduler_enabled,
            })
        return json_response(
            {'error_html': error_html},
            status_code=400,
        )

    app.set_media_versions()
    download = FileDownload('application-{}-{}'.format(app.get_id, version))
    errors = build_application_zip(
        include_multimedia_files=include_multimedia,
        include_index_files=True,
        domain=app.domain,
        app_id=app.id,
        download_id=download.download_id,
        compress_zip=True,
        filename='{}.ccz'.format(slugify(app.name)),
    )

    if errors is not None and errors['errors']:
        return json_response(
            errors,
            status_code=400,
        )
    return FileDownload.get(download.download_id).toHttpResponse()
Exemple #4
0
def get_direct_ccz(domain, app, lang, langs, version=None, include_multimedia=False, visit_scheduler_enabled=False):
    if not app.copy_of:
        errors = app.validate_app()
    else:
        errors = None

    if errors:
        error_html = render_to_string("app_manager/partials/build_errors.html", {
            'app': app,
            'build_errors': errors,
            'domain': domain,
            'langs': langs,
            'lang': lang,
            'visit_scheduler_enabled': visit_scheduler_enabled,
        })
        return json_response(
            {'error_html': error_html},
            status_code=400,
        )

    app.set_media_versions()
    download = FileDownload('application-{}-{}'.format(app.get_id, version))
    errors = build_application_zip(
        include_multimedia_files=include_multimedia,
        include_index_files=True,
        app=app,
        download_id=download.download_id,
        compress_zip=True,
        filename='{}.ccz'.format(slugify(app.name)),
    )

    if errors is not None and errors['errors']:
        return json_response(
            errors,
            status_code=400,
        )
    return FileDownload.get(download.download_id).toHttpResponse()
Exemple #5
0
def direct_ccz(request, domain):
    """
    You must specify an app_id, and you may specify either 'version' or 'latest'
    latest can be one of:
        release: Latest starred version
        build: Latest version regardless of star
        save: Latest saved version of the application (even without a build)
    If 'version' and 'latest' aren't specified it will default to latest save
    You may also set 'include_multimedia=true' if you need multimedia.
    """
    def error(msg, code=400):
        return json_response({
            'status': 'error',
            'message': msg
        },
                             status_code=code)

    def get_app(app_id, version, latest):
        if version:
            return get_build_doc_by_version(domain, app_id, version)
        elif latest == 'build':
            return get_latest_build_doc(domain, app_id)
        elif latest == 'release':
            return get_latest_released_app_doc(domain, app_id)
        else:
            # either latest=='save' or they didn't specify
            return get_current_app(domain, app_id)

    app_id = request.GET.get('app_id', None)
    version = request.GET.get('version', None)
    latest = request.GET.get('latest', None)
    include_multimedia = request.GET.get('include_multimedia',
                                         'false').lower() == 'true'

    # Make sure URL params make sense
    if not app_id:
        return error("You must specify `app_id` in your GET parameters")
    if version and latest:
        return error("You can't specify both 'version' and 'latest'")
    if latest not in (
            None,
            'release',
            'build',
            'save',
    ):
        return error("latest must be either 'release', 'build', or 'save'")
    if version:
        try:
            version = int(version)
        except ValueError:
            return error("'version' must be an integer")

    try:
        app = get_app(app_id, version, latest)
        if not app:
            raise ResourceNotFound()
        app = app if isinstance(app, Document) else wrap_app(app)
    except (ResourceNotFound, DocTypeError):
        return error("Application not found", code=404)

    if not app.copy_of:
        errors = app.validate_app()
    else:
        errors = None

    if errors:
        lang, langs = get_langs(request, app)
        template = get_app_manager_template(
            domain, 'app_manager/v1/partials/build_errors.html',
            'app_manager/v2/partials/build_errors.html')
        error_html = render_to_string(
            template, {
                'request': request,
                'app': app,
                'build_errors': errors,
                'domain': domain,
                'langs': langs,
                'lang': lang
            })
        return json_response(
            {'error_html': error_html},
            status_code=400,
        )

    app.set_media_versions(None)
    download = DownloadBase()
    errors = build_application_zip(
        include_multimedia_files=include_multimedia,
        include_index_files=True,
        app=app,
        download_id=download.download_id,
        compress_zip=True,
        filename='{}.ccz'.format(slugify(app.name)),
    )

    if errors is not None and errors['errors']:
        return json_response(
            errors,
            status_code=400,
        )
    return DownloadBase.get(download.download_id).toHttpResponse()
Exemple #6
0
def direct_ccz(request, domain):
    """
    You must specify an app_id, and you may specify either 'version' or 'latest'
    latest can be one of:
        release: Latest starred version
        build: Latest version regardless of star
        save: Latest saved version of the application (even without a build)
    If 'version' and 'latest' aren't specified it will default to latest save
    You may also set 'include_multimedia=true' if you need multimedia.
    """
    def error(msg, code=400):
        return json_response({'status': 'error', 'message': msg}, status_code=code)

    def get_app(app_id, version, latest):
        if version:
            return get_build_doc_by_version(domain, app_id, version)
        elif latest == 'build':
            return get_latest_build_doc(domain, app_id)
        elif latest == 'release':
            return get_latest_released_app_doc(domain, app_id)
        else:
            # either latest=='save' or they didn't specify
            return get_current_app(domain, app_id)

    app_id = request.GET.get('app_id', None)
    version = request.GET.get('version', None)
    latest = request.GET.get('latest', None)
    include_multimedia = request.GET.get('include_multimedia', 'false').lower() == 'true'

    # Make sure URL params make sense
    if not app_id:
        return error("You must specify `app_id` in your GET parameters")
    if version and latest:
        return error("You can't specify both 'version' and 'latest'")
    if latest not in (None, 'release', 'build', 'save',):
        return error("latest must be either 'release', 'build', or 'save'")
    if version:
        try:
            version = int(version)
        except ValueError:
            return error("'version' must be an integer")

    try:
        app = get_app(app_id, version, latest)
        if not app:
            raise ResourceNotFound()
        app = app if isinstance(app, Document) else wrap_app(app)
    except (ResourceNotFound, DocTypeError):
        return error("Application not found", code=404)

    app.set_media_versions(None)
    download = DownloadBase()
    build_application_zip(
        include_multimedia_files=include_multimedia,
        include_index_files=True,
        app=app,
        download_id=download.download_id,
        compress_zip=True,
        filename='{}.ccz'.format(slugify(app.name)),
    )
    return DownloadBase.get(download.download_id).toHttpResponse()