@login_required
@retry_resource(3)
def import_app(request, domain):
    user = request.couch_user
    if (not user.is_eula_signed()):
        messages.error(request, 'You must agree to our eula to download an app')
        return project_info(request, domain)
    from_project = Domain.get(domain)
    if ((request.method == 'POST') and from_project.is_snapshot):
        if (not from_project.published):
            messages.error(request, "This project is not published and can't be downloaded")
            return project_info(request, domain)
        to_project_name = request.POST['project']
        if (not user.is_member_of(to_project_name)):
            messages.error(request, _("You don't belong to that project"))
            return project_info(request, domain)
        full_apps = from_project.full_applications(include_builds=False)
        assert full_apps, 'Bad attempt to copy apps from a project without any!'
        for app in full_apps:
            new_doc = from_project.copy_component(app['doc_type'], app.get_id, to_project_name, user)
        clear_app_cache(request, to_project_name)
        from_project.downloads += 1
        from_project.save()
        messages.success(request, render_to_string('appstore/partials/view_wiki.html', {'pre': _('Application successfully imported!')}), extra_tags='html')
        return HttpResponseRedirect(reverse('view_app', args=[to_project_name, new_doc.id]))
    else:
        return HttpResponseRedirect(reverse('project_info', args=[domain]))
@login_required
@retry_resource(3)
def import_app(request, domain):
    user = request.couch_user
    if (not user.is_eula_signed()):
        messages.error(request, 'You must agree to our eula to download an app')
        return project_info(request, domain)
    from_project = Domain.get(domain)
    if ((request.method == 'POST') and from_project.is_snapshot):
        if (not from_project.published):
            messages.error(request, "This project is not published and can't be downloaded")
            return project_info(request, domain)
        to_project_name = request.POST['project']
        if (not user.is_member_of(to_project_name)):
            messages.error(request, _("You don't belong to that project"))
            return project_info(request, domain)
        full_apps = from_project.full_applications(include_builds=False)
        assert full_apps, 'Bad attempt to copy apps from a project without any!'
        for app in full_apps:
            new_doc = from_project.copy_component(app['doc_type'], app.get_id, to_project_name, user)
        clear_app_cache(request, to_project_name)
        from_project.downloads += 1
        from_project.save()
        messages.success(request, render_to_string('appstore/partials/view_wiki.html', {'pre': _('Application successfully imported!')}), extra_tags='html')
        return HttpResponseRedirect(reverse('view_app', args=[to_project_name, new_doc.id]))
    else:
        return HttpResponseRedirect(reverse('project_info', args=[domain]))