Esempio n. 1
0
def update(request, workgroup_id, template_name="oa/workgroup_form.html"):
    ctx = {}
    school = get_schools(request.user)[0]
    teachers = Teacher.objects.filter(school=school)
    workgroup = get_object_or_404(WorkGroup,pk=workgroup_id)
    ty = workgroup.type
    member_pks = [m.id for m in workgroup.members.all()]
    
    if request.method == 'POST':
        form = WorkGroupForm(request.POST,instance=workgroup)
        if form.is_valid():
            workgroup = form.save(commit=False)
            workgroup.save()
            
            member_pks = request.POST.getlist('to')
            print member_pks,'mmmmmmmmmmmmm'
            members = [t for t in User.objects.filter(pk__in=member_pks)]
            workgroup.members = members
            messages.success(request, u'已成功更新 %s ' % workgroup.name)
            return redirect('oa_workgroup_list')
    else:
        form = WorkGroupForm(instance=workgroup)
        
    schools = get_school_with_workgroup(request.user)
    ctx.update({'form':form,'teachers':teachers,'member_pks':member_pks,'workgroup':workgroup,'ty':0,'schools':schools})
    return render(request, template_name, ctx)
Esempio n. 2
0
def personal_create(request,template_name="oa/workgroup_form.html"):
    ctx = {}
    school = get_schools(request.user)[0]
    teachers = Teacher.objects.filter(school=school)
    
    if request.method == 'POST':
        form = WorkGroupForm(request.POST)
        if form.is_valid():
            workgroup = form.save(commit=False)
            workgroup.school = school
            workgroup.type = 1
            workgroup.user = request.user
            workgroup.save()
            
            member_pks = request.POST.getlist('to')
            members = [t for t in User.objects.filter(pk__in=member_pks)]
            workgroup.members = members
            messages.success(request, u'已成功创建 %s ' % workgroup.name)
            return redirect('oa_workgroup_personal')
    else:
        form = WorkGroupForm()
    
    schools = get_school_with_workgroup(request.user)
    ctx.update({'form':form,'teachers':teachers,'ty':1,'schools':schools})
    return render(request, template_name, ctx)
Esempio n. 3
0
def send_message(request,template_name="oa/message_send.html"):
    """发送消息"""
    schools = get_school_with_workgroup(request.user)
    if request.method == "POST":
        recipient_pks = list(set(request.POST.getlist('to')))
        recipients = [u for u in User.objects.filter(pk__in=recipient_pks)]
        form = MessageForm(request.POST,recipients=recipients)
        if form.is_valid():
            message = form.save(User.objects.get(pk=request.user.id))
#             recipients = form.cleaned_data['to']
            return redirect(reverse('oa_message_record'))
    else:
        form = MessageForm()
        
    hour = range(8,23)
    minite = range(0,60,5)
    ctx = {'form':form,'hour':hour,'minite':minite,'schools':schools}
    return render(request,template_name,ctx)
Esempio n. 4
0
def edit_reback_document(request,doca_id,template_name="oa/document_reback_form.html"):
    """编辑发回给我的公文"""
    doca = get_object_or_404(DocumentApproval,id=doca_id)
    doc = doca.document
    if request.user != doc.sender:
        return redirect(reverse('oa_approval_document',kwargs={'doca_id':doca.id}) + "?ty=reback")
    
    files = doc.files.all()
    receivers = DocumentReceiver.objects.filter(document=doc)
    user_pks = [u.user_id for u in receivers]
    history = DocumentApproval.objects.filter(document=doc).exclude(id=doca_id)
    school = doc.school
    category_group = get_category_group(school)
    teachers = Teacher.objects.filter(school=school)
    form = DocumentForm(instance=doc)
    schools = get_school_with_workgroup(request.user)
    ctx = {'doca':doca,'history':history,'doc':doc,'form':form,'files':files,'receivers':receivers,\
           'teachers':teachers,'user_pks':user_pks,'category_group':category_group,'schools':schools}
    return render(request, template_name, ctx)
Esempio n. 5
0
def edit_reback_document(request,doca_id,template_name="supply/document_reback_form.html"):
    """编辑发回给我的公文"""
    doca = get_object_or_404(MaterialApproval,id=doca_id)
    doc = doca.document
    if request.user != doc.sender:
        return redirect(reverse('oa_supply_approval_document',kwargs={'doca_id':doca.id}) + "?ty=reback")
    
    receivers = MaterialReceiver.objects.filter(document=doc)
    user_pks = [u.user_id for u in receivers]
    history = MaterialApproval.objects.filter(document=doc).exclude(id=doca_id)
    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)
    form = MaterialForm(instance=doc)
    schools = get_school_with_workgroup(request.user)
    school_list = get_schools(request.user)
    print doc.id,'-----------------------'
    ctx = {'doca':doca,'history':history,'doc':doc,'form':form,'applies':applies,'receivers':receivers,\
           'teachers':teachers,'user_pks':user_pks,'categorys':categorys,'schools':schools,'school_list':school_list}
    return render(request, template_name, ctx)
Esempio n. 6
0
def set_receiver(request, template_name="oa/document_receiver.html"):
    """ 设置接收对象"""
#    schools = get_schools(request.user)
    schools = get_school_with_workgroup(request.user)
    school_id = request.POST.get("sid",0)
    
    data = request.POST.get('data','')
    user_pks = [int(u) for u in data.split(",") if u]
    
    doc_id = int(request.POST.get('doc_id',0))
    ty = request.POST.get('ty','')
    member_pks = []
    if doc_id and doc_id !=0:
        if ty == 'supply':
            doc = get_object_or_404(Material, pk=doc_id)
        else:
            doc = get_object_or_404(Document, pk=doc_id)
        member_pks = [r.user.id for r in doc.receivers.all()]
    
    user_pks = user_pks + member_pks
    
    member_list = [u for u in User.objects.filter(pk__in=user_pks)]
    
    try:
        school = get_object_or_404(School,pk=school_id)
    except:
        school = schools[0]
    teacher_all = Teacher.objects.filter(school=school)
    group_list = Group.objects.filter(school=school)
    teacher_group_list = []
    
    group_grades = GroupGrade.objects.all()
    for grade in group_grades:
        t_list = []
        grade_groups = group_list.filter(grade=grade)
        for g in grade_groups:
            #老师按照班级分组
            teachers = [s.user for s in Teacher.objects.filter(group=g)]
            if teachers:
                t_list.append({'id':g.id,'name':g.name,'members':teachers})
        if t_list:
            teacher_group_list.append({'id':grade.id,'name':grade.name,'groups':t_list})
    
    #老师按照职位分组
    teacher_position_list = []
    positions = Position.objects.filter(school=school)
    for p in positions:
        members = []
        for po in PostJob.objects.filter(position=p):
            try:
                members.append(po.teacher.user)
            except:
                pass
#         members = [po.teacher.user for po in PostJob.objects.filter(position=p)]
        if members:
            teacher_position_list.append({'id':p.id,'name':p.name,'members':members})
    #老师按照部门分组
    teacher_depatrment_list = []
    departments = Department.objects.filter(school=school)
    for d in departments:
        members = []
        for dp in PostJob.objects.filter(department=d):
            try:
                members.append(dp.teacher.user)
            except:
                pass
#         members = [p.teacher.user for p in PostJob.objects.filter(department=d)]
        if members:
            teacher_depatrment_list.append({'id':d.id,'name':d.name,'members':members})
    #老师按照首字母分组
    teacher_word_list = []
    words = [chr(i) for i in range(65,91)]
    for w in words:
        members = [t.user for t in teacher_all.filter(pinyin__istartswith=w)]
        if members:
            teacher_word_list.append({'id':w,'name':w,'members':members})
    #老师按照个人虚拟组分组 
    personal_workgoup_list = []     
    personal_workgroups = WorkGroup.objects.filter(type=1,user=request.user)
    for pw in personal_workgroups:
        members = [m for m in pw.members.all()]
        if members:
            personal_workgoup_list.append({'id':pw.id,'name':pw.name,'members':members})
    #老师按照全局虚拟组分组       
    global_workgroup_list = []
    try:
        if schools[0].parent_id == 0:
            global_workgroups = WorkGroup.objects.filter(school=schools[0],type=0)
        else:
            global_workgroups = WorkGroup.objects.filter(school_id=schools[0].parent_id,type=0)
    except:
        global_workgroups = []
    for gw in global_workgroups:
        members = [m for m in gw.members.all()]
        if members:
            global_workgroup_list.append({'id':gw.id,'name':gw.name,'members':members})
    print user_pks,'uuuuuuuuuuuuuuuuuuuuuuu'
    data = render(request, template_name,\
                  {'teacher_all':teacher_all,\
                   'teacher_group_list':teacher_group_list,\
                   'teacher_position_list':teacher_position_list,\
                   'teacher_depatrment_list':teacher_depatrment_list,\
                   'teacher_word_list':teacher_word_list,\
                   'personal_workgoup_list':personal_workgoup_list,\
                   'global_workgroup_list':global_workgroup_list,\
                   'school':school,'schools':schools,\
                   'member_list':member_list,'user_pks':user_pks})
    con=data.content
    return ajax_ok('成功',con)
Esempio n. 7
0
def update_document(request,doc_id,template_name="oa/document_form.html"):
    """更新公文"""
    ctx = {}
    doc = get_object_or_404(Document,id=doc_id)
    files = doc.files.all()
    category_group = get_category_group(doc.school)
    receivers = DocumentReceiver.objects.filter(document=doc)
    teachers = Teacher.objects.filter(school=doc.school)
    if request.method == 'POST':
        form = DocumentForm(request.POST,instance=doc)
        
        if request.is_ajax():
            return helpers.ajax_validate_form(form)
        
        if form.is_valid():
            doc = form.save(commit=False)
            doc.save()
             
            #发布对象
            receiver_pks = request.POST.getlist("to")
            teacher_list = Teacher.objects.filter(pk__in=receiver_pks)
            try:
                DocumentReceiver.objects.filter(document=doc).delete()
            except:
                pass
            for t in teacher_list:
                receiver = DocumentReceiver()
                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()
                       
            #送审
            approvaler_pks = request.POST.getlist("approver")
            if doc.is_submit and approvaler_pks:
                teacher_list = Teacher.objects.filter(pk__in=approvaler_pks)
                appr = DocumentApproval()
                appr.sender = doc.sender
                appr.document = doc
                appr.remark = doc.remark
                appr.approvaler = teacher_list[0].user
                appr.send_time = doc.send_time
                appr.save()
                
                doc.remark = ''
                doc.save()
                
            #附件
            for f in request.FILES.getlist('files'):
                atta = Attachment()
                atta.name = f.name.split('.')[0]
                atta.file = f
                atta.save()
                doc.files.add(atta)
        return redirect(reverse('oa_personal_document'))
    else:
        form = DocumentForm(instance=doc)
    
    schools = get_school_with_workgroup(request.user)
    ctx.update({'form':form,'teachers':teachers,'doc':doc,'category_group':category_group,\
                'receivers':receivers,'schools':schools,'files':files})
    return render(request, template_name, ctx)
Esempio n. 8
0
def approval_document(request,doca_id,template_name="oa/document_approval.html"):
    """审批公文"""
    doca = get_object_or_404(DocumentApproval,id=doca_id)
    document = doca.document
    files = document.files.all()
    receivers = DocumentReceiver.objects.filter(document=document)
    user_pks = [u.user_id for u in receivers]
    history = DocumentApproval.objects.filter(document=document).order_by('ctime')
    school = document.school
    category_group = get_category_group(school)
    teachers = Teacher.objects.filter(school=school)
    type = request.GET.get("ty", "")
    if doca.status == 2:
        try:
            doca_l = DocumentApproval.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 = DocumentForm(request.POST,instance=document)
        
        if request.is_ajax():
            return helpers.ajax_validate_form(form)
        
        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)
#             exist_user_pks = [u.user.id for u in DocumentReceiver.objects.filter(document=doc)]
#             teacher_list = teacher_list.exclude(user_id__in=exist_user_pks)
            try:
                DocumentReceiver.objects.filter(document=doc).delete()
            except:
                pass
            for t in teacher_list:
                receiver = DocumentReceiver()
                receiver.user = t
                receiver.document = doc
                receiver.save()
                       
            approvaler_pks = request.POST.getlist("approvaler")
            ty = int(request.POST.get("commit_type"))
            
            #直接发出
            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 = DocumentReceiver.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 = DocumentApproval()
                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 = DocumentApproval()
                    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()
            #附件
            for f in request.FILES.getlist('files'):
                atta = Attachment()
                atta.name = f.name.split('.')[0]
                atta.file = f
                atta.save()
                doc.files.add(atta)
        
            messages.success(request, u"审批公文成功") 
            return redirect('oa_approvaled_document')

    else:
        form = DocumentForm(instance=document)
    schools = get_school_with_workgroup(request.user)
    ctx = {'doca':doca,'history':history,'doc':document,'form':form,'files':files,'receivers':receivers,'doca_l':doca_l,\
           'teachers':teachers,'user_pks':user_pks,'category_group':category_group,'type':type,'schools':schools}
    return render(request, template_name, ctx) 
Esempio n. 9
0
def write_document(request,template_name="oa/document_form.html"):
    """撰写公文"""
    ctx = {}
    school = get_schools(request.user)[0]
    category_group = get_category_group(school)
    teachers = Teacher.objects.filter(school=school)
    
    if request.method == 'POST':
        form = DocumentForm(request.POST)
        receiver_pks = request.POST.getlist("to")
        teacher_list = User.objects.filter(pk__in=receiver_pks)
        approvaler_pk = request.POST.get("approvaler",'')
        try:
            approvaler = User.objects.get(pk=approvaler_pk)
        except:
            approvaler = None
        category_pk = int(request.POST.get("category",0))
        ctx.update({'teacher_list':teacher_list,'approvaler':approvaler,'category_pk':category_pk})    
        
        if request.is_ajax():
            return helpers.ajax_validate_form(form)
        
        if form.is_valid():
            doc = form.save(commit=False)
            doc.school = school
            doc.sender = request.user
            doc.save()
             
            #发布对象
            for t in teacher_list:
                receiver = DocumentReceiver()
                receiver.user = t
                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()
                if doc.send_msg and doc.status == 0 and doc.msg_body:
                    msg = Sms()
                    msg.sender = doc.sender
                    msg.receiver = t
                    msg.mobile = t.get_profile().mobile
                    msg.type_id = 7
                    msg.content = str(doc.msg_body) + '/' + str(doc.sender.get_profile().chinese_name_or_username()) 
                    msg.save()
                receiver.save()
                       
            #送审
            approvaler_pk = request.POST.get("approvaler",0)
            if doc.is_submit and approvaler_pk:
                approvaler = User.objects.get(pk=approvaler_pk)
                appr = DocumentApproval()
                appr.sender = doc.sender
                appr.document = doc
                appr.remark = doc.remark
                appr.approvaler = approvaler
                appr.send_time = datetime.datetime.now()
                appr.save()
#                doc.send_time = datetime.datetime.now()
                doc.remark = ''
                doc.save()
                
            #附件
            for f in request.FILES.getlist('files'):
                atta = Attachment()
                atta.name = f.name
                atta.file = f
                atta.save()
                doc.files.add(atta)
            
            messages.success(request, u"撰写公文成功") 
            if doc.status == 1:
                return redirect('oa_personal_document')
            else:
                return redirect('oa_issued_document')
    else:
        form = DocumentForm()
    
    schools = get_school_with_workgroup(request.user)
    ctx.update({'form':form,'teachers':teachers,'category_group':category_group,'schools':schools})
    return render(request, template_name, ctx)
Esempio n. 10
0
def set_workgroup(request, template_name="oa/workgroup_set.html"):
    """ 设置组成员 """
    wid = int(request.POST.get('workgroup_id',0))
    
    ty = int(request.POST.get('ty',0))
    data = request.POST.get('data','')
    user_pks = [int(u) for u in data.split(",") if u]
    
    schools = get_school_with_workgroup(request.user)
    member_pks = []
    if wid and wid !=0:
        workgroup = get_object_or_404(WorkGroup, pk=wid)
        member_pks = [u.id for u in workgroup.members.all()]
    
    user_pks = user_pks + member_pks
    
    member_list = [u for u in User.objects.filter(pk__in=user_pks)]
    
    school_id = request.POST.get('s','')
    if school_id:
        school = get_object_or_404(School, pk=school_id)
    else:
        school = get_schools(request.user)[0]
    
    if school.parent_id == 0:
        q = Q(school__in=schools)
    else:
        q = Q(school=school)
    teachers = Teacher.objects.filter(q)
    group_lists = Group.objects.filter(q)
    group_list = []
    group_grades = GroupGrade.objects.all()
    for grade in group_grades:
        t_list = []
        grade_groups = group_lists.filter(grade=grade)
        for g in grade_groups:
            #老师按照班级分组
            group_teachers = [s.user for s in Teacher.objects.filter(group=g)]
            if group_teachers:
                t_list.append({'id':g.id,'name':g.name,'members':group_teachers})
        if t_list:
            group_list.append({'id':grade.id,'name':grade.name,'groups':t_list})
    
    depatrment_list = []
    departments = Department.objects.filter(q)
    for d in departments:
        members = [p.teacher.user for p in PostJob.objects.filter(department=d)]
        if members:
            depatrment_list.append({'id':d.id,'name':d.name,'members':members})
    
    positions = Position.objects.filter(q)
    position_list = []
    for p in positions:
        members = [po.teacher.user for po in PostJob.objects.filter(position=p)]
        if members:
            position_list.append({'id':p.id,'name':p.name,'members':members})
    
    word_list = []
    words = [chr(i) for i in range(65,91)]
    for w in words:
        members = [t.user for t in teachers.filter(pinyin__istartswith=w)]
        if members:
            word_list.append({'id':w,'name':w,'members':members})
        
    
    data = render(request, template_name,{'member_list':member_list,'teachers':teachers,'depatrment_list':depatrment_list,\
                                          'position_list':position_list,'word_list':word_list,'school':school,\
                                          'group_list':group_list,'schools':schools,'user_pks':user_pks})
    con=data.content
    return ajax_ok('成功',con)
Esempio n. 11
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. 12
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) 
Esempio n. 13
0
def set_receiver(request, template_name="oa/message_receiver.html"):
    """ 设置组成员 """
#    schools = get_schools(request.user)
    schools = get_school_with_workgroup(request.user)
    school_id = int(request.POST.get("sid",0))
    data = request.POST.get('data','')
    user_pks = [int(u) for u in data.split(",") if u]
    
    try:
        school = get_object_or_404(School,id=school_id)
    except:
        school = schools[0]
    
    student_all = Student.objects.filter(school=school)
    teacher_all = Teacher.objects.filter(school=school)
    
    #全园家长群发控制
    try:
        teacher = request.user.teacher
        if teacher.is_authorize:
            group_list = Group.objects.filter(school=school).exclude(type=3)
        else:
            group_header_pks = [g.id for g in Group.objects.filter(headteacher=teacher).exclude(type=3)]
            group_teacher_pks = [gt.group_id for gt in GroupTeacher.objects.filter(teacher=teacher).exclude(type=3)]
            group_pks = group_header_pks + group_teacher_pks
            group_list = Group.objects.filter(id__in=group_pks).exclude(type=3)
    except:
        group_list = []
    print group_list,'group_list-----------------------------'
#    group_list = Group.objects.filter(school=school)

    student_group_list = []
    teacher_group_list = []
    
    group_grades = GroupGrade.objects.all()
    for grade in group_grades:
        t_list = []
        s_list = []
        grade_groups = group_list.filter(grade=grade)
#        if not request.user.teacher.is_authorize:
#            group_pks = [k.group_id for k in GroupTeacher.objects.filter(teacher=request.user.teacher)]
#            grade_groups = grade_groups.filter(id__in=group_pks)
        for g in grade_groups:
            #学生按照班级分组
            students = [s.user for s in Student.objects.filter(group=g)]
            if students:
                s_list.append({'id':g.id,'name':g.name,'members':students})
            #老师按照班级分组
            teachers = [s.user for s in Teacher.objects.filter(group=g)]
            if teachers:
                t_list.append({'id':g.id,'name':g.name,'members':teachers})
        if s_list:
            student_group_list.append({'id':grade.id,'name':grade.name,'groups':s_list})
        if t_list:
            teacher_group_list.append({'id':grade.id,'name':grade.name,'groups':t_list})
    
    #老师按照职位分组
    teacher_position_list = []
    positions = Position.objects.filter(school=school)
    for p in positions:
        print p.id,p.is_delete,'position---------------------------------'
#        members = [po.teacher.user for po in PostJob.objects.filter(position=p,teacher__is_delete=False)]
        members = []
        for po in PostJob.objects.filter(position=p):
            try:
                members.append(po.teacher.user)
            except:
                pass
        if members:
            teacher_position_list.append({'id':p.id,'name':p.name,'members':members})
    #老师按照部门分组
    teacher_depatrment_list = []
    departments = Department.objects.filter(school=school)
    for d in departments:
#        members = [p.teacher.user for p in PostJob.objects.filter(department=d)]
        members = []
        for dp in PostJob.objects.filter(department=d):
            try:
                members.append(dp.teacher.user)
            except:
                pass
        if members:
            teacher_depatrment_list.append({'id':d.id,'name':d.name,'members':members})
    #老师按照首字母分组
    teacher_word_list = []
    words = [chr(i) for i in range(65,91)]
    for w in words:
        members = [t.user for t in teacher_all.filter(pinyin__istartswith=w)]
        if members:
            teacher_word_list.append({'id':w,'name':w,'members':members})
    #老师按照个人虚拟组分组 
    personal_workgoup_list = []     
    personal_workgroups = WorkGroup.objects.filter(type=1,user=request.user)
    for pw in personal_workgroups:
        members = [m for m in pw.members.all()]
        if members:
            personal_workgoup_list.append({'id':pw.id,'name':pw.name,'members':members})
    #老师按照全局虚拟组分组       
    global_workgroup_list = []
    try:
        if schools[0].parent_id == 0:
            global_workgroups = WorkGroup.objects.filter(school=schools[0],type=0)
        else:
            global_workgroups = WorkGroup.objects.filter(school_id=schools[0].parent_id,type=0)
    except:
        global_workgroups = []
    for gw in global_workgroups:
        members = [m for m in gw.members.all()]
        if members:
            global_workgroup_list.append({'id':gw.id,'name':gw.name,'members':members})
    data = render(request, template_name,\
                  {'student_all':student_all,'teacher_all':teacher_all,\
                   'student_group_list':student_group_list,\
                   'teacher_group_list':teacher_group_list,\
                   'teacher_position_list':teacher_position_list,\
                   'teacher_depatrment_list':teacher_depatrment_list,\
                   'teacher_word_list':teacher_word_list,\
                   'personal_workgoup_list':personal_workgoup_list,\
                   'global_workgroup_list':global_workgroup_list,\
                   'school':school,'schools':schools,'user_pks':user_pks})
    con=data.content
    return ajax_ok('成功',con)