示例#1
0
def razredi_dijaki_dijak_uredi(request, razred, dijak):
    profesor = request.user_profile
    razred = get_object_or_404(profesor.razredi, id=razred)
    dijak = get_object_or_404(razred.dijaki_cached, id=dijak)
    
    data = request.POST if request.method == 'POST' else None
    
    user_form = UserForm(instance=dijak.uporabnik, data=data, prefix='user')
    dijak_form = DijakForm(instance=dijak, data=data, prefix='dijak')
    sp_form = NaslovForm(instance=dijak.stalno_prebivalisce, data=data, prefix='sp')
    zp_form = NaslovForm(instance=dijak.zacasno_prebivalisce, data=data, prefix='zp')
    
    valid = True
    
    if user_form.is_valid() and dijak_form.is_valid():
        user = user_form.save(commit=False)
        dijak = dijak_form.save(commit=False)
        
        sp = None
        zp = None
        
        if not form_data_empty(sp_form):
            if sp_form.is_valid():
                sp = sp_form.save(commit=False)
            else:
                valid = False
        
        if not form_data_empty(zp_form):
            if zp_form.is_valid():
                zp = zp_form.save(commit=False)
            else:
                valid = False
        
        if valid:
            if sp:
                sp.save()
            
            if zp:
                zp.save()
            
            dijak.stalno_prebivalisce = sp
            dijak.zacasno_prebivalisce = zp
            
            user.save()
            dijak.save()
        
    else:
        valid = False
            
    if valid:
        messages.info(request, u'Podatki o dijaku so shranjeni.')
        
        return HttpResponseRedirect(reverse('profesor_razredi_dijaki_podatki', args=[razred.id, dijak.id]))
    
    return locals()
示例#2
0
def razredi_dijaki_mati_uredi(request, razred, dijak):
    profesor = request.user_profile
    razred = get_object_or_404(profesor.razredi, id=razred)
    dijak = get_object_or_404(razred.dijaki_cached, id=dijak)
    
    stars = dijak.mati
    
    data = request.POST if request.method == 'POST' else None
    
    user_form = UserForm(instance=stars.uporabnik if stars else None, data=data, prefix='user')
    stars_form = StarsForm(instance=stars, data=data, prefix='stars')
    p_form = NaslovForm(instance=stars.prebivalisce if stars else None, data=data, prefix='p')
    
    valid = True
    
    if user_form.is_valid() and stars_form.is_valid():
        user = user_form.save(commit=False)
        stars = stars_form.save(commit=False)
        
        p = None
        
        if not form_data_empty(p_form):
            if p_form.is_valid():
                p = p_form.save(commit=False)
            else:
                valid = False
        
        if valid:
            if p:
                p.save()
            
            stars.prebivalisce = p
            
            if not user.id:
                user.gen_username()
                user.set_unusable_password()
            
            user.save()
            
            stars.uporabnik = user
            stars.save()
            
            dijak.mati = stars
            dijak.save()
        
    else:
        valid = False
            
    if valid:
        messages.info(request, u'Podatki o materi so shranjeni.')
        
        return HttpResponseRedirect(reverse('profesor_razredi_dijaki_podatki', args=[razred.id, dijak.id]))
    
    return locals()