def site_migrate(request): form = Migrate(request.POST if request.POST else None) if form.is_valid(): #what sites: l = request.GET['ids'].split(',') site_ids = [int(i) for i in l] sites = Site.objects.filter(pk__in=site_ids) platform = Platform.objects.get(pk=request.POST['new_platform']) for site in sites: ctask = migrate.delay(site, platform) event = Event(task_id=ctask.task_id, site=site, user=request.user, event='migrate') event.save() messages.add_message( request, messages.INFO, "The migration of the site %s has been queued: %s" % (site, ctask.task_id)) # this needs to redirect or something. return redirect(urlresolvers.reverse('admin:deploy_site_changelist')) data = { 'user': request.user, 'form': form, } return render_to_response('migrate.html', data)
def site_manage(request, sid): site = get_object_or_404(Site, pk=sid) events = Event.objects.filter(site=site).order_by("date") callbacks = Event.objects.filter(site=site, event="status").order_by("date") # this is gross and I would really like to be rid of it. op = request.POST.get("submit", None) form_instance = request.POST if request.method == "POST" else None forms = { "clone": Clone(form_instance if op == "clone" else None), "migrate": Migrate(form_instance if op == "migrate" else None), "drush": Drush(form_instance if op == "drush" else None), } ctask = None if not op == None: if op == "enable": ctask = enable.delay(site) elif op == "disable": ctask = disable.delay(site) elif op == "cache": ctask = cacheclear.delay(site) elif op == "varnish": ctask = varnishclear.delay(site) elif op == "verify": ctask = verify.delay(site) elif op == "migrate": if forms["migrate"].is_valid(): new_platform = Platform.objects.get(pk=forms["migrate"].cleaned_data["new_platform"]) if new_platform: ctask = migrate.delay(site, new_platform) elif op == "clone" or op == "rename": if forms["clone"].is_valid(): new_name = forms["clone"].cleaned_data["new_name"] ctask = rename.delay(site, new_name, op == "clone") if not ctask == None: # record the task as an event, that way it will display in the task log. event = Event(task_id=ctask.task_id, site=site, user=request.user, event=op) event.save() messages.add_message( request, messages.INFO, "The %s of the site %s has been queued as '%s'." % (op, site, ctask.task_id) ) return redirect(urlresolvers.reverse("deploy.views.site_manage", args=(sid,))) data = {"events": events, "user": request.user, "site": site, "callbacks": callbacks, "forms": forms} return render_to_response("site-manage.html", data)
def site_migrate(request): form = Migrate(request.POST if request.POST else None) if form.is_valid(): # what sites: l = request.GET["ids"].split(",") site_ids = [int(i) for i in l] sites = Site.objects.filter(pk__in=site_ids) platform = Platform.objects.get(pk=request.POST["new_platform"]) for site in sites: ctask = migrate.delay(site, platform) event = Event(task_id=ctask.task_id, site=site, user=request.user, event="migrate") event.save() messages.add_message( request, messages.INFO, "The migration of the site %s has been queued: %s" % (site, ctask.task_id) ) # this needs to redirect or something. return redirect(urlresolvers.reverse("admin:deploy_site_changelist")) data = {"user": request.user, "form": form} return render_to_response("migrate.html", data)
def site_manage(request, sid): site = get_object_or_404(Site, pk=sid) events = Event.objects.filter(site=site).order_by('date') callbacks = Event.objects.filter(site=site, event='status').order_by('date') # this is gross and I would really like to be rid of it. op = request.POST.get('submit', None) form_instance = request.POST if request.method == 'POST' else None forms = { 'clone': Clone(form_instance if op == 'clone' else None), 'migrate': Migrate(form_instance if op == 'migrate' else None), 'drush': Drush(form_instance if op == 'drush' else None), } ctask = None if not op == None: if op == 'enable': ctask = enable.delay(site) elif op == 'disable': ctask = disable.delay(site) elif op == 'cache': ctask = cacheclear.delay(site) elif op == 'varnish': ctask = varnishclear.delay(site) elif op == 'verify': ctask = verify.delay(site) elif op == 'migrate': if forms['migrate'].is_valid(): new_platform = Platform.objects.get( pk=forms['migrate'].cleaned_data['new_platform']) if new_platform: ctask = migrate.delay(site, new_platform) elif op == 'clone' or op == 'rename': if forms['clone'].is_valid(): new_name = forms['clone'].cleaned_data['new_name'] ctask = rename.delay(site, new_name, op == 'clone') if not ctask == None: #record the task as an event, that way it will display in the task log. event = Event(task_id=ctask.task_id, site=site, user=request.user, event=op) event.save() messages.add_message( request, messages.INFO, "The %s of the site %s has been queued as '%s'." % (op, site, ctask.task_id)) return redirect( urlresolvers.reverse('deploy.views.site_manage', args=(sid, ))) data = { 'events': events, 'user': request.user, 'site': site, 'callbacks': callbacks, 'forms': forms } return render_to_response('site-manage.html', data)