def edit_stand(request): if request.method == "POST": form = StandForm(request.POST,instance=request.stand) if form.is_valid(): form.save() return HttpResponseRedirect("/_stand/") else: is_seed_stand = True if settings.DEBUG == False: # in production is_seed_stand = request.stand.hostname == "forest.ccnmtl.columbia.edu" return dict(stand=request.stand, form=StandForm(instance=request.stand), is_seed_stand=is_seed_stand )
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))
def add_stand(request): if not request.user.is_staff: return HttpResponse("only staff may access this") form = StandForm() if request.method == "POST": form = StandForm(request.POST) hostname = request.POST.get('hostname','') r = Stand.objects.filter(hostname=hostname) if r.count() > 0: return HttpResponse("a stand with that hostname already exists") if form.is_valid(): stand = form.save() su = StandUser.objects.create(stand=stand,user=request.user,access="admin") for pb in settings.PAGEBLOCKS: sapb = StandAvailablePageBlock.objects.create(stand=stand,block=pb) if hostname.endswith(".forest.ccnmtl.columbia.edu"): # if it's a *.forest site, just send them on their way return HttpResponseRedirect("http://%s/_stand/" % hostname) else: return dict(created=True,stand=stand) return dict(form=form)