def region_add(request): form = RegionForm(request.POST or None) if form.is_valid(): form.save() return redirect('limeade_cluster_region_list') return render_to_response("limeade_cluster/region_add.html", {"form": form}, context_instance = RequestContext(request))
def region_edit(request, slug): region = Region.objects.get(pk=slug) form = RegionForm(request.POST or None, instance=region) if form.is_valid(): form.save() return redirect('limeade_cluster_region_list') return render_to_response("limeade_cluster/region_edit.html", {"form": form}, context_instance = RequestContext(request))
def regionedit(request, codigo): if request.method == 'POST': profile = Usuario.objects.get(user = request.user) region = Region.objects.get(numreg=int(codigo)) region.idusuario_mod=profile.numero frmregion = RegionForm(request.POST, instance=region,error_class=DivErrorList) # A form bound to the POST data if frmregion.is_valid(): frmregion.save() return redirect(reverse('ogcs-mantenimiento-region-consulta')+'?m=edit') else: region = get_object_or_404(Region, numreg=int(codigo)) frmregion = RegionForm(instance=region) return render_to_response('ubigeo/region.html', {'frmregion': frmregion,'opcion':'edit','codigo':codigo}, context_instance=RequestContext(request),)
def addnew(request): groups = request.META.get('ADFS_GROUP','') groupsList = groups.split(';') ; userIsSuperUser = isSuperUser(groupsList) ## Check user cloudman resource manager privileges if not userIsSuperUser: message = "You don't have cloudman resource manager privileges. Hence you are not authorized to add new Region"; html = "<html><body> %s.</body></html>" % message return HttpResponse(html) if request.method == 'POST': form = RegionForm(request.POST) ### Check whether all the fields for creating a region are provided with non-empty values if form.is_valid(): redirectURL = '/cloudman/message/?msg=' name = form.cleaned_data['name'] regionExists = checkNameIgnoreCase(name) if regionExists: msgAlreadyExists = 'Region ' + name + ' already exists. Hence Add Region Operation Stopped' return HttpResponseRedirect(redirectURL + msgAlreadyExists) description = form.cleaned_data['description'] admin_group = form.cleaned_data['admin_group'] comment = form.cleaned_data['comment'] ## Check that name provided as admin_group exists in the EGroups TABLE ## If not, then check its existence in external egroup database through ldap ## If not present there also, then raise an alert or else add the group name to EGroups table also egroup = None try: egroup = Egroups.objects.get(name=admin_group) except Egroups.DoesNotExist: if not (checkEGroup(admin_group)): errorMessage = 'Selected Admin E-Group ' + admin_group + ' does not exists' return HttpResponseRedirect(redirectURL + errorMessage) egroup = Egroups(name=admin_group) egroup.save() ## Create the Region with all the required values regionObj = Region(name=name, description=description, admin_group=egroup) regionObj.save() regionObj = Region.objects.get(name=name) if addLog(request,name,comment,regionObj,None,'region','add',True): transaction.commit() ## Return the Success message msgSuccess = 'New region ' + name + ' added successfully' else: transaction.rollback() msgSuccess = 'Error in creating New region ' + name html = "<html><HEAD><meta HTTP-EQUIV=\"REFRESH\" content=\"4; url=/cloudman/region/list/\"></HEAD><body> %s.</body></html>" % msgSuccess return HttpResponse(html) else: ## If not POST operation, then return the Region Creation Form form = RegionForm() return render_to_response('region/addnew.html',locals(),context_instance=RequestContext(request))
def regionedit(request, codigo): mensaje="" if request.method == 'POST': profile = Usuario.objects.get(user = request.user) region = Region.objects.get(numreg=int(codigo)) region.idusuario_mod=profile.numero frmregion = RegionForm(request.POST, instance=region) # A form bound to the POST data if frmregion.is_valid(): frmregion.save() mensaje="Registro modificado satisfactoriamente." # Crear un parametro en home para mostrar los mensajes de exito. else: region = get_object_or_404(Region, numreg=int(codigo)) frmregion = RegionForm(instance=region) return render_to_response('ubigeo/region.html', {'frmregion': frmregion,'opcion':'edit','codigo':codigo,'usuario':request.session['nombres'],'fecha':request.session['login_date'],'mensaje':mensaje}, context_instance=RequestContext(request),)
def region_add(request): """Add a new region to the cluster. :param request: the request object :returns: an edit form template """ form = RegionForm(request.POST or None) if form.is_valid(): form.save() return redirect('limeade_cluster_region_list') return render_to_response("limeade_cluster/region_add.html", {"form": form}, context_instance=RequestContext(request))
def region_add(request): """Add a new region to the cluster. :param request: the request object :returns: an edit form template """ form = RegionForm(request.POST or None) if form.is_valid(): form.save() return redirect("limeade_cluster_region_list") return render_to_response( "limeade_cluster/region_add.html", {"form": form}, context_instance=RequestContext(request) )
def region_edit(request, slug): """Edit a region. :param request: the request object :param slug: the id of the region :returns: an edit form template """ region = Region.objects.get(pk=slug) form = RegionForm(request.POST or None, instance=region) if form.is_valid(): form.save() return redirect('limeade_cluster_region_list') return render_to_response("limeade_cluster/region_edit.html", {"form": form}, context_instance=RequestContext(request))
def region_edit(request, slug): """Edit a region. :param request: the request object :param slug: the id of the region :returns: an edit form template """ region = Region.objects.get(pk=slug) form = RegionForm(request.POST or None, instance=region) if form.is_valid(): form.save() return redirect("limeade_cluster_region_list") return render_to_response( "limeade_cluster/region_edit.html", {"form": form}, context_instance=RequestContext(request) )
def regionadd(request): mensaje="" if request.method == 'POST': profile = Usuario.objects.get(user = request.user) num = Region.objects.values("numreg").order_by("-numreg",)[:1] num = 1 if len(num)==0 else int(num[0]["numreg"])+1 region = Region(numreg=num,estado=Estado.objects.get(pk=1),idusuario_creac=profile.numero,) frmregion = RegionForm(request.POST, instance=region) # A form bound to the POST data if frmregion.is_valid(): for campo in frmregion.fields: frmregion.fields[campo]=request.POST[campo].upper() frmregion.save() frmregion = RegionForm() # Crear un parametro en home para mostrar los mensajes de exito. mensaje="Registro grabado satisfactoriamente." else: frmregion = RegionForm() return render_to_response('ubigeo/region.html', {'frmregion': frmregion,'opcion':'add','usuario':request.session['nombres'],'fecha':request.session['login_date'],'mensaje':mensaje}, context_instance=RequestContext(request),)