Exemple #1
0
def regist_detail(request,regist_id,template_name="oa/onlineRegistration_form.html"):
    """在线报名详情及更新"""
    schools = get_schools(request.user)
    regist = get_object_or_404(Registration,id=regist_id,school__in=schools)
    if request.method == 'POST':
        human = True
        form = RegistrationForm(request.POST,instance=regist)
        if form.is_valid():
            r = form.save(commit=False)
            r.save()
            try:
                mobile = r.guardians.exclude(name='').exclude(mobile='').exclude(unit='')[0].mobile
            except:
                mobile = None
            if r.send_msg and r.msg_body and mobile:
                msg = Sms()
                msg.sender_id = request.user.id
                msg.receiver_id = -1
                msg.mobile = mobile
                msg.type_id = 6
                msg.content = r.msg_body + '/' + request.user.teacher.name
                msg.save()
            messages.success(request, '操作成功')
            
            return redirect('oa_regist_apply_list')
    else:
        form = RegistrationForm(instance=regist)
    guardians = regist.guardians.exclude(relation='').exclude(name='').exclude(mobile='').exclude(unit='')
    guardians_count = guardians.count()
    ctx = {'regist':regist,'form':form,'guardians':guardians,'range':range(4),'guardians_count':guardians_count}
    return render(request, template_name, ctx)
Exemple #2
0
def regist(request,template_name="oa/site/registration.html",domain="huaban"):
    ctx = {'channel':'site_regist'}
    site = get_site(request)
    if not site:
        return render(request, "404.html")
    school = site.school
    
    extra = int(request.GET.get("extra", 4))
    if request.GET.get('newsn')=='1':
        csn=CaptchaStore.generate_key()
        cimageurl= captcha_image_url(csn)
        parent_domain = helpers.get_parent_domain(request)
        return HttpResponse(parent_domain + cimageurl)
    
    if request.method == 'POST':
        form1 = RegistrationForm(request.POST)
        extra = request.POST['form-TOTAL_FORMS']
        formset = formset_factory(RegistGuardianForm,formset=RequiredFormSet,extra=extra)
        form2 = formset(request.POST)
        print form1.errors,'11111'
        print form2[0].errors,'222222222'
        print form2[0].is_valid(),'vvvvv'
        
        if request.is_ajax():
            form2_error_list = []
            for fo in form2:
                form2_error_list = form2_error_list + fo.errors.items()
            error_list = form1.errors.items() + form2_error_list
            return helpers.ajax_validate_form_error_list(error_list)
        
        if form1.is_valid() and form2[0].is_valid():
            human = True
            reg = form1.save(commit=False)
            reg.school = school
            reg.status = 0
            reg.save()
            for f in form2:
                print f.errors
                if f.is_valid():
                    guardian = f.save(commit=False)
                    if guardian.relation and guardian.name and guardian.mobile and guardian.unit:
                        guardian.regist = reg
                        guardian.save()
            messages.success(request, u"报名表%s 保存成功" % reg.name)
            return redirect(request.get_full_path())
    else:
        form1 = RegistrationForm()
        form2 = formset_factory(RegistGuardianForm,formset=RequiredFormSet,extra=extra)
    ctx = {'form1':form1,'form2':form2,'class':'startes','site':site}
    return render(request, template_name, ctx)