示例#1
0
def copy_app(request, domain):
    app_id = request.POST.get("app")
    form = CopyApplicationForm(
        domain,
        app_id,
        request.POST,
        export_zipped_apps_enabled=toggles.EXPORT_ZIPPED_APPS.enabled(request.user.username),
    )
    if form.is_valid():
        gzip = request.FILES.get("gzip")
        if gzip:
            with zipfile.ZipFile(gzip, "r", zipfile.ZIP_DEFLATED) as z:
                source = z.read(z.filelist[0].filename)
            app_id_or_source = source
        else:
            app_id_or_source = app_id

        def _inner(request, domain, data):
            clear_app_cache(request, domain)
            if data["toggles"]:
                for slug in data["toggles"].split(","):
                    set_toggle(slug, domain, True, namespace=toggles.NAMESPACE_DOMAIN)
            app_copy = import_app_util(app_id_or_source, domain, {"name": data["name"]})
            return back_to_main(request, app_copy.domain, app_id=app_copy._id)

        return login_and_domain_required(_inner)(request, form.cleaned_data["domain"], form.cleaned_data)
    else:
        from corehq.apps.app_manager.views.view_generic import view_generic

        return view_generic(request, domain, app_id=app_id, copy_app_form=form)
示例#2
0
def copy_app(request, domain):
    app_id = request.POST.get('app')
    app = get_app(domain, app_id)
    form = CopyApplicationForm(
        domain, app, request.POST,
        export_zipped_apps_enabled=toggles.EXPORT_ZIPPED_APPS.enabled(request.user.username)
    )
    if not form.is_valid():
        from corehq.apps.app_manager.views.view_generic import view_generic
        return view_generic(request, domain, app_id=app_id, copy_app_form=form)

    gzip = request.FILES.get('gzip')
    if gzip:
        with zipfile.ZipFile(gzip, 'r', zipfile.ZIP_DEFLATED) as z:
            source = z.read(z.filelist[0].filename)
        app_id_or_source = source
    else:
        app_id_or_source = app_id

    def _inner(request, link_domain, data, master_domain=domain):
        clear_app_cache(request, link_domain)
        if data['toggles']:
            for slug in data['toggles'].split(","):
                set_toggle(slug, link_domain, True, namespace=toggles.NAMESPACE_DOMAIN)
        linked = data.get('linked')
        if linked:
            return _create_linked_app(request, app, link_domain, data['name'])
        else:
            return _copy_app_helper(
                request, master_domain, app_id_or_source, link_domain, data['name'], app_id)

    # having login_and_domain_required validates that the user
    # has access to the domain we're copying the app to
    return login_and_domain_required(_inner)(request, form.cleaned_data['domain'], form.cleaned_data)
示例#3
0
def copy_app(request, domain):
    app_id = request.POST.get('app')
    app = get_app(domain, app_id)
    form = CopyApplicationForm(domain, app, request.POST)
    if not form.is_valid():
        from corehq.apps.app_manager.views.view_generic import view_generic
        return view_generic(request, domain, app_id, copy_app_form=form)

    def _inner(request, to_domain, data, from_domain=domain):
        clear_app_cache(request, to_domain)

        if data['toggles']:
            for slug in data['toggles'].split(","):
                set_toggle(slug,
                           to_domain,
                           True,
                           namespace=toggles.NAMESPACE_DOMAIN)

        linked = data.get('linked')
        if linked:
            return _create_linked_app(request, app_id, data['build_id'],
                                      from_domain, to_domain, data['name'])
        else:
            return _copy_app_helper(request, data['build_id'] or app_id,
                                    to_domain, data['name'])

    # having login_and_domain_required validates that the user
    # has access to the domain we're copying the app to
    return login_and_domain_required(_inner)(request,
                                             form.cleaned_data['domain'],
                                             form.cleaned_data)
示例#4
0
def copy_app(request, domain):
    app_id = request.POST.get('app')
    app = get_app(domain, app_id)
    form = CopyApplicationForm(
        domain, app, request.POST,
        export_zipped_apps_enabled=toggles.EXPORT_ZIPPED_APPS.enabled(request.user.username)
    )
    if not form.is_valid():
        from corehq.apps.app_manager.views.view_generic import view_generic
        return view_generic(request, domain, app_id=app_id, copy_app_form=form)

    gzip = request.FILES.get('gzip')
    if gzip:
        with zipfile.ZipFile(gzip, 'r', zipfile.ZIP_DEFLATED) as z:
            source = z.read(z.filelist[0].filename)
        app_id_or_source = source
    else:
        app_id_or_source = app_id

    def _inner(request, link_domain, data, master_domain=domain):
        clear_app_cache(request, link_domain)
        if data['toggles']:
            for slug in data['toggles'].split(","):
                set_toggle(slug, link_domain, True, namespace=toggles.NAMESPACE_DOMAIN)
        linked = data.get('linked')
        if linked:
            return _create_linked_app(request, app, link_domain, data['name'])
        else:
            return _copy_app_helper(
                request, master_domain, app_id_or_source, link_domain, data['name'], app_id)

    # having login_and_domain_required validates that the user
    # has access to the domain we're copying the app to
    return login_and_domain_required(_inner)(request, form.cleaned_data['domain'], form.cleaned_data)
示例#5
0
def view_app(request, domain, app_id=None):
    from corehq.apps.app_manager.views.view_generic import view_generic
    return view_generic(request,
                        domain,
                        app_id,
                        release_manager=toggles.APP_MANAGER_V2.enabled(
                            request.user.username))
示例#6
0
def copy_app(request, domain):
    app_id = request.POST.get('app')
    form = CopyApplicationForm(
        domain,
        app_id,
        request.POST,
        export_zipped_apps_enabled=toggles.EXPORT_ZIPPED_APPS.enabled(
            request.user.username))
    if form.is_valid():
        gzip = request.FILES.get('gzip')
        if gzip:
            with zipfile.ZipFile(gzip, 'r', zipfile.ZIP_DEFLATED) as z:
                source = z.read(z.filelist[0].filename)
            app_id_or_source = source
        else:
            app_id_or_source = app_id

        def _inner(request, domain, data):
            clear_app_cache(request, domain)
            if data['toggles']:
                for slug in data['toggles'].split(","):
                    set_toggle(slug,
                               domain,
                               True,
                               namespace=toggles.NAMESPACE_DOMAIN)
            app_copy = import_app_util(app_id_or_source, domain,
                                       {'name': data['name']})
            return back_to_main(request, app_copy.domain, app_id=app_copy._id)

        return login_and_domain_required(_inner)(request,
                                                 form.cleaned_data['domain'],
                                                 form.cleaned_data)
    else:
        from corehq.apps.app_manager.views.view_generic import view_generic
        return view_generic(request, domain, app_id=app_id, copy_app_form=form)
示例#7
0
def copy_app(request, domain):
    app_id = request.POST.get('app')
    form = CopyApplicationForm(app_id, request.POST)
    if form.is_valid():
        return copy_app_check_domain(request, form.cleaned_data['domain'], form.cleaned_data['name'], app_id)
    else:
        from corehq.apps.app_manager.views.view_generic import view_generic
        return view_generic(request, domain, app_id=app_id, copy_app_form=form)
示例#8
0
def view_module_legacy(request, domain, app_id, module_id):
    """
    This view has been kept around to not break any documentation on example apps
    and partner-distributed documentation on existing apps.
    PLEASE DO NOT DELETE.
    """
    from corehq.apps.app_manager.views.view_generic import view_generic
    return view_generic(request, domain, app_id, module_id)
示例#9
0
def view_form_legacy(request, domain, app_id, module_id, form_id):
    """
    This view has been kept around to not break any documentation on example apps
    and partner-distributed documentation on existing apps.
    PLEASE DO NOT DELETE.
    """
    from corehq.apps.app_manager.views.view_generic import view_generic
    return view_generic(request, domain, app_id, module_id, form_id)
示例#10
0
def copy_app(request, domain):
    app_id = request.POST.get('app')
    app = get_app(domain, app_id)
    form = CopyApplicationForm(
        domain, app, request.POST,
        export_zipped_apps_enabled=toggles.EXPORT_ZIPPED_APPS.enabled(request.user.username)
    )
    if form.is_valid():
        gzip = request.FILES.get('gzip')
        if gzip:
            with zipfile.ZipFile(gzip, 'r', zipfile.ZIP_DEFLATED) as z:
                source = z.read(z.filelist[0].filename)
            app_id_or_source = source
        else:
            app_id_or_source = app_id

        def _inner(request, link_domain, data, master_domain=domain):
            clear_app_cache(request, link_domain)
            if data['toggles']:
                for slug in data['toggles'].split(","):
                    set_toggle(slug, link_domain, True, namespace=toggles.NAMESPACE_DOMAIN)
            linked = data.get('linked')
            if linked:
                for module in app.modules:
                    if isinstance(module, ReportModule):
                        messages.error(request, _('This linked application uses mobile UCRs which '
                                                  'are currently not supported. For this application to '
                                                  'function correctly, you will need to remove those modules.'))
                        return HttpResponseRedirect(reverse_util('app_settings', params={}, args=[domain, app_id]))

                master_version = get_latest_released_app_version(app.domain, app_id)
                if not master_version:
                    messages.error(request, _("Creating linked app failed."
                                              " Unable to get latest released version of your app."
                                              " Make sure you have at least one released build."))
                    return HttpResponseRedirect(reverse_util('app_settings', params={}, args=[domain, app_id]))

                linked_app = create_linked_app(master_domain, app_id, link_domain, data['name'])
                try:
                    update_linked_app(linked_app, request.couch_user.get_id)
                except AppLinkError as e:
                    messages.error(request, str(e))
                    return HttpResponseRedirect(reverse_util('app_settings', params={}, args=[domain, app_id]))

                messages.success(request, _('Application successfully copied and linked.'))
                return HttpResponseRedirect(reverse_util('app_settings', params={}, args=[link_domain, linked_app.get_id]))
            else:
                extra_properties = {'name': data['name']}
                app_copy = import_app_util(app_id_or_source, link_domain, extra_properties)
                return back_to_main(request, app_copy.domain, app_id=app_copy._id)

        # having login_and_domain_required validates that the user
        # has access to the domain we're copying the app to
        return login_and_domain_required(_inner)(request, form.cleaned_data['domain'], form.cleaned_data)
    else:
        from corehq.apps.app_manager.views.view_generic import view_generic
        return view_generic(request, domain, app_id=app_id, copy_app_form=form)
示例#11
0
def copy_app(request, domain):
    app_id = request.POST.get('app')
    app = get_app(domain, app_id)
    form = CopyApplicationForm(
        domain, app, request.POST,
        export_zipped_apps_enabled=toggles.EXPORT_ZIPPED_APPS.enabled(request.user.username)
    )
    if form.is_valid():
        gzip = request.FILES.get('gzip')
        if gzip:
            with zipfile.ZipFile(gzip, 'r', zipfile.ZIP_DEFLATED) as z:
                source = z.read(z.filelist[0].filename)
            app_id_or_source = source
        else:
            app_id_or_source = app_id

        def _inner(request, link_domain, data, master_domain=domain):
            clear_app_cache(request, link_domain)
            if data['toggles']:
                for slug in data['toggles'].split(","):
                    set_toggle(slug, link_domain, True, namespace=toggles.NAMESPACE_DOMAIN)
            linked = data.get('linked')
            if linked:
                master_version = get_latest_released_app_version(app.domain, app_id)
                if not master_version:
                    messages.error(request, _("Creating linked app failed."
                                              " Unable to get latest released version of your app."
                                              " Make sure you have at least one released build."))
                    return HttpResponseRedirect(reverse_util('app_settings', params={}, args=[domain, app_id]))

                linked_app = create_linked_app(master_domain, app_id, link_domain, data['name'])
                try:
                    update_linked_app(linked_app, request.couch_user.get_id)
                except AppLinkError as e:
                    linked_app.delete()
                    messages.error(request, str(e))
                    return HttpResponseRedirect(reverse_util('app_settings', params={}, args=[domain, app_id]))

                messages.success(request, _('Application successfully copied and linked.'))
                return HttpResponseRedirect(reverse_util('app_settings', params={}, args=[link_domain, linked_app.get_id]))
            else:
                extra_properties = {'name': data['name']}
                try:
                    app_copy = import_app_util(app_id_or_source, link_domain, extra_properties)
                except ReportConfigurationNotFoundError:
                    messages.error(request, _("Copying the application failed because "
                                              "your application contains a Report Module "
                                              "that references a static UCR configuration."))
                    return HttpResponseRedirect(reverse_util('app_settings', params={}, args=[domain, app_id]))
                return back_to_main(request, app_copy.domain, app_id=app_copy._id)

        # having login_and_domain_required validates that the user
        # has access to the domain we're copying the app to
        return login_and_domain_required(_inner)(request, form.cleaned_data['domain'], form.cleaned_data)
    else:
        from corehq.apps.app_manager.views.view_generic import view_generic
        return view_generic(request, domain, app_id=app_id, copy_app_form=form)
示例#12
0
def copy_app(request, domain):
    app_id = request.POST.get('app')
    app = get_app(domain, app_id)
    form = CopyApplicationForm(
        domain,
        app,
        request.POST,
        export_zipped_apps_enabled=toggles.EXPORT_ZIPPED_APPS.enabled(
            request.user.username))
    if form.is_valid():
        gzip = request.FILES.get('gzip')
        if gzip:
            with zipfile.ZipFile(gzip, 'r', zipfile.ZIP_DEFLATED) as z:
                source = z.read(z.filelist[0].filename)
            app_id_or_source = source
        else:
            app_id_or_source = app_id

        def _inner(request, domain, data):
            clear_app_cache(request, domain)
            if data['toggles']:
                for slug in data['toggles'].split(","):
                    set_toggle(slug,
                               domain,
                               True,
                               namespace=toggles.NAMESPACE_DOMAIN)
            extra_properties = {'name': data['name']}
            linked = data.get('linked')
            if linked:
                extra_properties['master'] = app_id
                extra_properties['doc_type'] = 'LinkedApplication'
                if domain not in app.linked_whitelist:
                    app.linked_whitelist.append(domain)
                    app.save()
            app_copy = import_app_util(app_id_or_source, domain,
                                       extra_properties)
            if linked:
                for module in app_copy.modules:
                    if isinstance(module, ReportModule):
                        messages.error(
                            request,
                            _('This linked application uses mobile UCRs which '
                              'are currently not supported. For this application to '
                              'function correctly, you will need to remove those modules.'
                              ))
                        break
            return back_to_main(request, app_copy.domain, app_id=app_copy._id)

        # having login_and_domain_required validates that the user
        # has access to the domain we're copying the app to
        return login_and_domain_required(_inner)(request,
                                                 form.cleaned_data['domain'],
                                                 form.cleaned_data)
    else:
        from corehq.apps.app_manager.views.view_generic import view_generic
        return view_generic(request, domain, app_id=app_id, copy_app_form=form)
示例#13
0
def view_app(request, domain, app_id=None):
    from corehq.apps.app_manager.views.view_generic import view_generic
    # redirect old m=&f= urls
    module_id = request.GET.get('m', None)
    form_id = request.GET.get('f', None)
    if module_id or form_id:
        soft_assert('{}@{}'.format('skelly', 'dimagi.com')).call(
            False, 'old m=&f= url still in use'
        )
        return back_to_main(request, domain, app_id=app_id, module_id=module_id,
                            form_id=form_id)

    return view_generic(request, domain, app_id)
示例#14
0
def copy_app(request, domain):
    app_id = request.POST.get('app')
    form = CopyApplicationForm(
        domain, app_id, request.POST,
        export_zipped_apps_enabled=toggles.EXPORT_ZIPPED_APPS.enabled(request.user.username)
    )
    if form.is_valid():
        gzip = request.FILES.get('gzip')
        if gzip:
            with zipfile.ZipFile(gzip, 'r', zipfile.ZIP_DEFLATED) as z:
                source = z.read(z.filelist[0].filename)
            app_id_or_source = source
        else:
            app_id_or_source = app_id

        return copy_app_check_domain(request, form.cleaned_data['domain'], form.cleaned_data['name'],
                                     app_id_or_source)
    else:
        from corehq.apps.app_manager.views.view_generic import view_generic
        return view_generic(request, domain, app_id=app_id, copy_app_form=form)
示例#15
0
文件: apps.py 项目: zbidi/commcare-hq
def app_settings(request, domain, app_id=None):
    from corehq.apps.app_manager.views.view_generic import view_generic
    return view_generic(request, domain, app_id)
示例#16
0
def view_module(request, domain, app_id, module_id):
    from corehq.apps.app_manager.views.view_generic import view_generic
    return view_generic(request, domain, app_id, module_id)
示例#17
0
def view_form(request, domain, app_id, form_unique_id):
    from corehq.apps.app_manager.views.view_generic import view_generic
    return view_generic(
        request, domain, app_id,
        form_unique_id=form_unique_id
    )
示例#18
0
def view_module(request, domain, app_id, module_id):
    from corehq.apps.app_manager.views.view_generic import view_generic
    return view_generic(request, domain, app_id, module_id)
示例#19
0
def view_user_registration(request, domain, app_id):
    from corehq.apps.app_manager.views.view_generic import view_generic
    return view_generic(request, domain, app_id, is_user_registration=True)
示例#20
0
def view_app(request, domain, app_id=None):
    from corehq.apps.app_manager.views.view_generic import view_generic
    return view_generic(request, domain, app_id, release_manager=True)
示例#21
0
def view_app(request, domain, app_id=None):
    from corehq.apps.app_manager.views.view_generic import view_generic

    return view_generic(request, domain, app_id)
示例#22
0
def view_form(request, domain, app_id, form_unique_id):
    from corehq.apps.app_manager.views.view_generic import view_generic
    return view_generic(
        request, domain, app_id,
        form_unique_id=form_unique_id
    )
示例#23
0
def release_manager(request, domain, app_id):
    from corehq.apps.app_manager.views.view_generic import view_generic
    return view_generic(request, domain, app_id=app_id, release_manager=True)