Esempio n. 1
0
def update_document(request,doc_id,template_name="supply/document_form.html"):
    """更新公文"""
    ctx = {}
    doc = get_object_or_404(Material,id=doc_id)
    receivers = MaterialReceiver.objects.filter(document=doc)
    school = doc.school
    categorys = SupplyCategory.objects.filter(school=school)
    teachers = Teacher.objects.filter(school=school)
    applies = MaterialApply.objects.filter(document=doc,supply__parent_id=0)
    print applies,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
    if request.method == 'POST':
        form = MaterialForm(request.POST,instance=doc)
        print form.errors,'eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'
        if form.is_valid():
            doc = form.save(commit=False)
            doc.save()
             
            sid = request.POST.get('sid','')
            if sid:
                sup_school = get_object_or_404(School,id=sid)
            else:
                sup_school = school
            #发布对象
            receiver_pks = request.POST.getlist("to")
            teacher_list = Teacher.objects.filter(pk__in=receiver_pks)
            try:
                MaterialReceiver.objects.filter(document=doc).delete()
            except:
                pass
            for t in teacher_list:
                receiver = MaterialReceiver()
                receiver.user = t.user
                receiver.document = doc
                if not doc.is_submit and doc.status == 0:
                    receiver.is_send = True
                    receiver.send_time = datetime.datetime.now()
                    doc.is_approvaled = True
                    doc.save()
                receiver.save()
            
            #物资清单
            desc = request.POST.get("applies")  
            set_material_apply(desc,doc,request.user,sup_school)
                  
            #送审
            approvaler_pks = request.POST.get("approvaler")
            print approvaler_pks,'-----------------------------'
            if doc.is_submit and approvaler_pks:
                teacher_list = User.objects.get(pk=approvaler_pks)
                print teacher_list,'teacher_list-----------------------'
                appr = MaterialApproval()
                appr.sender = doc.sender
                appr.document = doc
                appr.remark = doc.remark
                appr.approvaler = teacher_list
                appr.send_time = doc.send_time
                appr.save()
                
                doc.remark = ''
                doc.save()
                
            
        return redirect(reverse('oa_supply_personal_document'))
    else:
        form = MaterialForm(instance=doc)
    
    schools = get_school_with_workgroup(request.user)
    ctx.update({'form':form,'teachers':teachers,'doc':doc,'categorys':categorys,\
                'receivers':receivers,'schools':schools,'applies':applies})
    return render(request, template_name, ctx)
Esempio n. 2
0
def write_document(request,template_name="supply/document_form.html"):
    """撰写公文"""
    ctx = {}
    school = get_schools(request.user)[0]
    teachers = Teacher.objects.filter(school=school)
    categorys = SupplyCategory.objects.filter(school=school)
    schools = get_schools(request.user)
    if request.method == 'POST':
        form = MaterialForm(request.POST)
        receiver_pks = request.POST.getlist("to")
        teacher_list = User.objects.filter(pk__in=receiver_pks)
        approvaler_pk = request.POST.get("approvaler",'')
        sid = request.POST.get('sid','')
        if sid:
            sup_school = get_object_or_404(School,id=sid)
        else:
            sup_school = school
        try:
            approvaler = User.objects.get(pk=approvaler_pk)
        except:
            approvaler = None
        ctx.update({'teacher_list':teacher_list,'approvaler':approvaler})    

        if form.is_valid():
            doc = form.save(commit=False)
            doc.school = school
            doc.sender = request.user
            doc.save()
            print doc.type,'tttttttttttttttttttttttt'
             
            #发布对象
            for t in teacher_list:
                receiver = MaterialReceiver()
                receiver.user = t
                receiver.document = doc
                receiver.save()
                       
            #送审
            approvaler_pk = request.POST.get("approvaler",0)
            if doc.is_submit and approvaler_pk:
                approvaler = User.objects.get(pk=approvaler_pk)
                appr = MaterialApproval()
                appr.sender = doc.sender
                appr.document = doc
                appr.remark = doc.remark
                appr.approvaler = approvaler
                appr.send_time = datetime.datetime.now()
                appr.save()
                doc.remark = ''
                doc.save()
                #发送短信
                if doc.send_msg and doc.msg_body:
                    msg = Sms()
                    msg.sender = doc.sender
                    msg.receiver = approvaler
                    msg.mobile = approvaler.get_profile().mobile
                    msg.type_id = 7
                    msg.content = str(doc.msg_body) + '/' + str(doc.sender.get_profile().chinese_name_or_username()) 
                    msg.save()
                
            desc = request.POST.get("applies")
            apply = json.loads(desc)
            for i in apply:
                supply,created = Supply.objects.get_or_create(name=apply[i]['name'],category_id=apply[i]['cat'],parent_id=0,school=sup_school)
                if created:
                    supply.creator = request.user
                    supply.is_show = False
                    supply.save()
                apl = MaterialApply(supply=supply,document=doc,num=apply[i]['num'],school=sup_school)
                apl.save()
                    
            messages.success(request, u"撰写公文成功") 
            if doc.status == 1:
                return redirect('oa_supply_personal_document')
            else:
                return redirect('oa_supply_issued_document')
    else:
        form = MaterialForm()
    
    ctx.update({'form':form,'teachers':teachers,'schools':schools,'categorys':categorys})
    return render(request, template_name, ctx)
Esempio n. 3
0
def approval_document(request,doca_id,template_name="supply/document_approval.html"):
    """审批公文"""
    doca = get_object_or_404(MaterialApproval,id=doca_id)
    document = doca.document
    print document.type,'tttt-----------------------------'
    receivers = MaterialReceiver.objects.filter(document=document)
    user_pks = [u.user_id for u in receivers]
    history = MaterialApproval.objects.filter(document=document).order_by('ctime')
    school = document.school
    categorys = SupplyCategory.objects.filter(school=school)
    teachers = Teacher.objects.filter(school=school)
    applies = MaterialApply.objects.filter(document=document,supply__parent_id=0)
    type = request.GET.get("ty", "")
    school_list = get_schools(request.user)
    if doca.status == 2:
        try:
            doca_l = MaterialApproval.objects.filter(approvaler=doca.approvaler)\
                .exclude(id=doca.id).order_by('-send_time')[0]
        except:
            doca_l = None
    else:
        doca_l = None
    
    if request.method == 'POST':
        form = MaterialForm(request.POST,instance=document)
        
        sid = request.POST.get('sid','')
        if sid:
            sup_school = get_object_or_404(School,id=sid)
        else:
            sup_school = school
            
        if form.is_valid():
            doc = form.save(commit=False)
            doc.save()
             
            #发布对象
            receiver_pks = request.POST.getlist("to")

            teacher_list = User.objects.filter(pk__in=receiver_pks)
            
            try:
                MaterialReceiver.objects.filter(document=doc).delete()
            except:
                pass
            for t in teacher_list:
                receiver = MaterialReceiver()
                receiver.user = t
                receiver.document = doc
                receiver.save()
                       
            approvaler_pks = request.POST.getlist("approvaler")
            ty = int(request.POST.get("commit_type"))
            
            #重置物资申请数据
            desc = request.POST.get("applies")  
            set_material_apply(desc,doc,request.user,sup_school)
            
            #直接发出
            if ty == 1:
                doca.remark = doc.remark
                doca.status = 1
                doca.send_time = datetime.datetime.now()
                doca.save()
                
                doc.is_approvaled = True
                doc.save()
                
                #发送信息
                receivers = MaterialReceiver.objects.filter(document=doc)
                receivers.update(is_send=True,send_time=datetime.datetime.now())
            
            #发回公文
            if ty == 2:
                doca.receiver = doca.sender
                doca.remark = doc.remark
                doca.status = 3
                doca.send_time = datetime.datetime.now()
                doca.save()
                
                doc.remark = ''
                doc.save()
                
                appr = MaterialApproval()
                appr.sender = request.user
                appr.document = doc
                appr.remark = doc.remark
                if doca_l:
                    appr.approvaler = doca_l.sender
                else:
                    appr.approvaler = doca.sender
                appr.send_time = datetime.datetime.now() + datetime.timedelta(seconds = 10)
                appr.status = 2
                appr.save()
                
            #送审公文
            if ty == 3:
                teacher_list = Teacher.objects.filter(user__pk__in=approvaler_pks)
                if doc.is_submit and approvaler_pks:
                    doca.receiver = teacher_list[0].user
                    doca.remark = doc.remark
                    doca.status = 3
                    doca.send_time = datetime.datetime.now()
                    doca.save() 
                    
                    doc.remark = ''
                    doc.save()
                    
                    appr = MaterialApproval()
                    appr.sender = request.user
                    appr.document = doc
                    appr.status = 0
                    appr.remark = doc.remark
                    appr.approvaler = teacher_list[0].user
                    appr.send_time = datetime.datetime.now() + datetime.timedelta(seconds = 10)
                    appr.save()
        
            messages.success(request, u"审批公文成功") 
            return redirect('oa_supply_document_need_approval')

    else:
        form = MaterialForm(instance=document)
    schools = get_school_with_workgroup(request.user)
    ctx = {'doca':doca,'history':history,'doc':document,'form':form,'receivers':receivers,'doca_l':doca_l,\
           'teachers':teachers,'user_pks':user_pks,'type':type,'schools':schools,'categorys':categorys,\
           'applies':applies,'school_list':school_list}
    return render(request, template_name, ctx)