def remove_site(request): user = request.session.get('switched_user', request.user) try: object_id = request.POST['object_id'] spp = get_object_or_404(user.usersite_set, id=int(object_id)) if spp.owner != user: raise Exception("Forbidden operation") remove_app_preparation(spp) spp.delete() return JsonResponse("OK", {1: ugettext("Site was successfuly removed")}) except Exception, e: return JsonResponse("KO", {1: ugettext("Error deleting site")})
def rm(request): #try: user = request.session.get('switched_user', request.user) domain = get_object_or_404(user.domain_set, id=request.POST['object_id']) print domain if domain.owner == user: logging.info(_("Deleting domain %s") % domain.name) print "subdomains" for subdomain in Domain.objects.filter(parent=domain): print subdomain for app in subdomain.apps(): print app if app.domains_count <= 1: print "remove preparations" remove_app_preparation(app, remove_domains=False) print "delete" app.delete() subdomain.delete() print "apps" for app in domain.apps(): if app.domains_count <= 1: remove_app_preparation(app) app.delete() print "dns" if config.handle_dns and domain.dns: pri_br = BindRequest(user, "master") pri_br.remove_zone(domain) pri_br.mod_config() pri_br.reload() if config.handle_dns_secondary: sec_br = BindRequest(user, "slave") sec_br.mod_config() sec_br.reload() domain.delete() return JsonResponse("OK", {1: ugettext("Domain was successfuly deleted")})
def subdomains_list(request, domain_id): u = request.session.get('switched_user', request.user) superuser = request.user domain = get_object_or_404(u.domain_set, id=int(domain_id)) if request.GET.get("subdomain_name"): for name in request.GET.get("subdomain_name").split(","): # TODO: check for duplication subdomain = Domain() subdomain.name = name.strip() subdomain.serial = 0 subdomain.dns = False subdomain.mail = False subdomain.ipv4 = False subdomain.ipv6 = False subdomain.parent = domain subdomain.owner = u subdomain.save() elif request.GET.get("subdomain_id"): subdomain = get_object_or_404(u.domain_set, id=request.GET.get("subdomain_id")) for app in subdomain.apps(): if app.domains_count <= 1: remove_app_preparation(app, remove_domains=False) app.delete() subdomain.delete() return render_to_response('subdomains_list.html', { "domain": domain, "subdomains": Domain.objects.filter(parent=domain), "u": u, "superuser": superuser, "menu_active": "domains", }, context_instance=RequestContext(request) )
def subdomains_list(request, domain_id): u = request.session.get('switched_user', request.user) superuser = request.user domain = get_object_or_404(u.domain_set, id=int(domain_id)) if request.GET.get("subdomain_name"): for name in request.GET.get("subdomain_name").split(","): # TODO: check for duplication subdomain = Domain() subdomain.name = name.strip() subdomain.serial = 0 subdomain.dns = False subdomain.mail = False subdomain.ipv4 = False subdomain.ipv6 = False subdomain.parent = domain subdomain.owner = u subdomain.save() elif request.GET.get("subdomain_id"): subdomain = get_object_or_404(u.domain_set, id=request.GET.get("subdomain_id")) for app in subdomain.apps(): if app.domains_count <= 1: remove_app_preparation(app, remove_domains=False) app.delete() subdomain.delete() return render_to_response( 'subdomains_list.html', { "domain": domain, "subdomains": Domain.objects.filter(parent=domain), "u": u, "superuser": superuser, "menu_active": "domains", }, context_instance=RequestContext(request))