Esempio n. 1
0
def edit(request, shared_id, subcompo, pk):
    '''
    Selects which subcomponent will be added, 
        for that uses the subcompo variable
    '''
    usrattr = GetUserAttr(request, shared_id)
    if subcompo == 'Cartografia':
        instance = get_object_or_404(inidcardatg, id = pk)
    elif subcompo == 'Imagenes':
        instance = get_object_or_404(inidimagsat, id = pk)
    elif subcompo == 'Fotografias':
        instance = get_object_or_404(inidfotogra, id = pk)
    else:
        instance = get_object_or_404(inididestud, id = pk)
    ####
    if request.method == 'POST':
        formlist = {
            u'Cartografia' : forms.CartografiaForm(request.POST, instance = instance),
            u'Imagenes' : forms.ImagenesForm(request.POST, instance = instance),
            u'Fotografias' : forms.FotografiasForm(request.POST, instance = instance),
            u'Suelos' : forms.SuelosForm(request.POST, instance = instance),
            u'Hidrologia' : forms.HidrologiaForm(request.POST, instance = instance),
            u'Variabilida': forms.HidroloVariabilidaForm(request.POST, instance = instance),
            u'CalcuCaudal': forms.HidroloCalcuCaudalForm(request.POST, instance = instance),
            u'Hidrogeologia' : forms.HidrogeologiaForm(request.POST, instance = instance),
            u'CalidadDeAgua' : forms.CalidadDeAguaForm(request.POST, instance = instance),
            u'CargasContaminantes' : forms.CargasContaminantesForm(request.POST, instance = instance),
            u'Cobertura' : forms.CoberturaForm(request.POST, instance = instance),
            u'FloraYFauna' : forms.FloraYFaunaForm(request.POST, instance = instance),
            u'PMEcosistemas' : forms.PMEcosistemasForm(request.POST, instance = instance),
            u'Amenazas' : forms.AmenazasForm(request.POST, instance = instance),
            u'Riesgos' : forms.RiesgosForm(request.POST, instance = instance),
            u'seActoresSoc' : forms.seActoresSocForm(request.POST, instance = instance),
            u'seEstrParticip' : forms.seEstrParticipForm(request.POST, instance = instance),
            u'seParticComuEtnicas' : forms.seParticComuEtnicasForm(request.POST, instance = instance),
            u'seDiagSocioEconom' : forms.seDiagSocioEconomForm(request.POST, instance = instance),
            u'seCaractCultural' : forms.seCaractCulturalForm(request.POST, instance = instance),
            u'seValorServicEcos' : forms.seValorServicEcosForm(request.POST, instance = instance),
            u'seRelaFuncUrbaRegio' : forms.seRelaFuncUrbaRegioForm(request.POST, instance = instance),
        }
        form = formlist[subcompo] 
        if form.is_valid():
            #f = AuthorForm(request.POST)
            #new_Author = f.save(commit=False)
            #new_Author.some_field = 'some_value'
            #new_Author.save()
            #f.save_m2m()
            informacion = form.save(commit = False)
            informacion.inieswhu = usrattr.user #Updates the user who updates
            #I should validate that the form belongs to the user and watersheed
            # that is connected.
            informacion.save(force_update = True)
            return HttpResponseRedirect(reverse('matriz_infoidentifi.views.resume', args=(shared_id, subcompo,)))
        return render(request, 'forms.html', {
            'form': form,
            'title' : GetName(), 
            'shared_id' : shared_id,
            'subcompo' : subcompo,
            'pk' : pk,
            'watersheed': GetUserWatersheed(GetUserCorpo(request.user), shared_id),
            #'compo' : GetCompo(),
        })
    else:
        formlist = {
            u'Cartografia' : forms.CartografiaForm(request.POST or None, instance = instance),
            u'Imagenes' : forms.ImagenesForm(request.POST or None, instance = instance),
            u'Fotografias' : forms.FotografiasForm(request.POST or None, instance = instance),
            u'Suelos' : forms.SuelosForm(request.POST or None, instance = instance),
            u'Hidrologia' : forms.HidrologiaForm(request.POST or None, instance = instance),
            u'Hidrogeologia' : forms.HidrogeologiaForm(request.POST or None, instance = instance),
            u'Variabilida': forms.HidroloVariabilidaForm(request.POST or None, instance = instance),
            u'CalcuCaudal': forms.HidroloCalcuCaudalForm(request.POST or None, instance = instance),
            u'CalidadDeAgua' : forms.CalidadDeAguaForm(request.POST or None, instance = instance),
            u'CargasContaminantes' : forms.CargasContaminantesForm(request.POST or None, instance = instance),
            u'Cobertura' : forms.CoberturaForm(request.POST or None, instance = instance),
            u'FloraYFauna' : forms.FloraYFaunaForm(request.POST or None, instance = instance),
            u'PMEcosistemas' : forms.PMEcosistemasForm(request.POST or None, instance = instance),
            u'Amenazas' : forms.AmenazasForm(request.POST or None, instance = instance),
            u'Riesgos' : forms.RiesgosForm(request.POST or None, instance = instance),
            u'seActoresSoc' : forms.seActoresSocForm(request.POST or None, instance = instance),
            u'seEstrParticip' : forms.seEstrParticipForm(request.POST or None, instance = instance),
            u'seParticComuEtnicas' : forms.seParticComuEtnicasForm(request.POST or None, instance = instance),
            u'seDiagSocioEconom' : forms.seDiagSocioEconomForm(request.POST or None, instance = instance),
            u'seCaractCultural' : forms.seCaractCulturalForm(request.POST or None, instance = instance),
            u'seValorServicEcos' : forms.seValorServicEcosForm(request.POST or None, instance = instance),
            u'seRelaFuncUrbaRegio' : forms.seRelaFuncUrbaRegioForm(request.POST or None, instance = instance),
        }
        form = formlist[subcompo] 
        return render(request, 'forms.html', {
            'form': form,
            'title' : GetName(), 
            'shared_id' : shared_id,
            'subcompo' : subcompo,
            'pk' : pk,
            'watersheed': GetUserWatersheed(GetUserCorpo(request.user), shared_id),
            #'compo' : GetCompo(),
        })
Esempio n. 2
0
def add(request, shared_id, subcompo):
    '''
    Selects which subcomponent will be added, 
        for that uses the subcompo variable
    '''
    usrattr = GetUserAttr(request, shared_id)
    ####
    if request.method == 'POST':
        formlist = {
            u'Cartografia' : forms.CartografiaForm(request.POST),
            u'Imagenes' : forms.ImagenesForm(request.POST),
            u'Fotografias' : forms.FotografiasForm(request.POST),
            u'Suelos' : forms.SuelosForm(request.POST),
            u'Hidrologia' : forms.HidrologiaForm(request.POST),
            u'Variabilida': forms.HidroloVariabilidaForm(request.POST),
            u'CalcuCaudal': forms.HidroloCalcuCaudalForm(request.POST),
            u'Hidrogeologia' : forms.HidrogeologiaForm(request.POST),
            u'CalidadDeAgua' : forms.CalidadDeAguaForm(request.POST),
            u'CargasContaminantes' : forms.CargasContaminantesForm(request.POST),
            u'Cobertura' : forms.CoberturaForm(request.POST),
            u'FloraYFauna' : forms.FloraYFaunaForm(request.POST),
            u'PMEcosistemas' : forms.PMEcosistemasForm(request.POST),
            u'Amenazas' : forms.AmenazasForm(request.POST),
            u'Riesgos' : forms.RiesgosForm(request.POST),
            u'seActoresSoc' : forms.seActoresSocForm(request.POST),
            u'seEstrParticip' : forms.seEstrParticipForm(request.POST),
            u'seParticComuEtnicas' : forms.seParticComuEtnicasForm(request.POST),
            u'seDiagSocioEconom' : forms.seDiagSocioEconomForm(request.POST),
            u'seCaractCultural' : forms.seCaractCulturalForm(request.POST),
            u'seValorServicEcos' : forms.seValorServicEcosForm(request.POST),
            u'seRelaFuncUrbaRegio' : forms.seRelaFuncUrbaRegioForm(request.POST),
        }
        form = formlist[subcompo] 
        if form.is_valid():
            informacion = form.save(commit = False)
            informacion.iniescor = usrattr.corpora[0]
            informacion.iniescue = usrattr.watersheed
            informacion.inieswho = usrattr.user
            informacion.inieswhu = usrattr.user
            if subcompo != 'Amenazas':
                informacion.inidsubc = subcompo
            informacion.save()
            if subcompo == 'Amenazas':
                #Amenazas is he only one which uses it many2many
                form.save_m2m()
            return HttpResponseRedirect(reverse('matriz_infoidentifi.views.resume', args=(shared_id, subcompo,)))
        return render(request, 'forms.html', {
            'form': form,
            'title' : GetName(), 
            'shared_id' : shared_id,
            'subcompo' : subcompo,
            #'compo' : GetCompo(),
        })

    else:
        formlist = {
            u'Cartografia' : forms.CartografiaForm(),
            u'Imagenes' : forms.ImagenesForm(),
            u'Fotografias' : forms.FotografiasForm(),
            u'Suelos' : forms.SuelosForm(),
            u'Hidrologia' : forms.HidrologiaForm(),
            u'Variabilida': forms.HidroloVariabilidaForm(),
            u'CalcuCaudal': forms.HidroloCalcuCaudalForm(),
            u'Hidrogeologia' : forms.HidrogeologiaForm(),
            u'CalidadDeAgua' : forms.CalidadDeAguaForm(),
            u'CargasContaminantes' : forms.CargasContaminantesForm(),
            u'Cobertura' : forms.CoberturaForm(),
            u'FloraYFauna' : forms.FloraYFaunaForm(),
            u'PMEcosistemas' : forms.PMEcosistemasForm(),
            u'Amenazas' : forms.AmenazasForm(),
            u'Riesgos' : forms.RiesgosForm(),
            u'seActoresSoc' : forms.seActoresSocForm(),
            u'seEstrParticip' : forms.seEstrParticipForm(),
            u'seParticComuEtnicas' : forms.seParticComuEtnicasForm(),
            u'seDiagSocioEconom' : forms.seDiagSocioEconomForm(),
            u'seCaractCultural' : forms.seCaractCulturalForm(),
            u'seValorServicEcos' : forms.seValorServicEcosForm(),
            u'seRelaFuncUrbaRegio' : forms.seRelaFuncUrbaRegioForm(),
        }
        form = formlist[subcompo] 
        return render(request, 'forms.html', {
            'form': form,
            'title' : GetName(), 
            'shared_id' : shared_id,
            'subcompo' : subcompo,
            'watersheed': GetUserWatersheed(GetUserCorpo(request.user), shared_id),
            #'compo' : GetCompo(),
        })