def importer(request): if request.method == "GET": return {} file = request.FILES['file'] zipfile = ZipFile(file) # If we exported the morx.com site, and we are now # visiting http://fleem.com/import/, we don't want # to touch the morx.com hierarchy -- instead we want # to import the bundle to the fleem.com hierarchy. hierarchy_name = request.get_host() hierarchy = import_zip(zipfile, hierarchy_name) url = hierarchy.get_absolute_url() url = '/' + url.lstrip('/') # sigh return HttpResponseRedirect(url)
def cloner(request): if request.method == "GET": return {} new_hierarchy = request.POST['new_hierarchy'] old_stand = get_stand(request.get_host()) fake_request = HttpRequest() fake_request.method = "POST" fake_request.POST['hostname'] = new_hierarchy fake_request.POST['title'] = old_stand.title fake_request.POST['css'] = old_stand.css fake_request.POST['description'] = old_stand.description fake_request.POST['access'] = old_stand.access form = StandForm(fake_request.POST) stand = form.save() su = StandUser.objects.create(stand=stand, user=request.user, access="admin") if request.POST.get('copy_userperms'): for standuser in StandUser.objects.filter(stand=old_stand).exclude(user=request.user): StandUser.objects.create(stand=stand, user=standuser.user, access=standuser.access ).save() for old_sapb in old_stand.standavailablepageblock_set.all(): StandAvailablePageBlock.objects.create( stand=stand, block=old_sapb.block).save() hierarchy = request.get_host() section = get_section_from_path('/', hierarchy=hierarchy) zip_filename = export_zip(section.hierarchy) zipfile = ZipFile(zip_filename) hierarchy_name = new_hierarchy hierarchy = import_zip(zipfile, hierarchy_name) os.unlink(zip_filename) if new_hierarchy.endswith(".forest.ccnmtl.columbia.edu"): # if it's a *.forest site, just send them on their way return HttpResponseRedirect("http://%s/_stand/" % new_hierarchy) else: return cloner_created(request, dict(created=True,stand=stand))