def import_app(request, snapshot): user = request.couch_user if not user.is_eula_signed(): messages.error(request, 'You must agree to our eula to download an app') return HttpResponseRedirect(reverse(ProjectInformationView.urlname, args=[snapshot])) from_project = Domain.get(snapshot) 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 HttpResponseRedirect(reverse(ProjectInformationView.urlname, args=[snapshot])) 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 HttpResponseRedirect(reverse(ProjectInformationView.urlname, args=[snapshot])) 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(ProjectInformationView.urlname, args=[snapshot]))