示例#1
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)
示例#2
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)
示例#3
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) 
示例#4
0
def update_disk(request, disk_id, template_name="disk/disk_form.html"):
    disk = get_object_or_404(Disk,id=disk_id)
    categorys = []
    user = request.user
    school = user.teacher.school
    personal_list = disk_category_group(school,user)
    school_list = disk_category_group(school)
    form = DiskForm(instance=disk)
    ctx = {}
    file_list = disk.files
    school = user.teacher.school
    if request.method == 'POST':
        f = request.FILES.get("files")
        chunks = int(request.POST.get('chunks','1'))
        if chunks == 1 or not f:
            form = DiskForm(request.POST,instance=disk)
            if form.is_valid():
                disk = form.save(commit=False)
                disk.save()
                delete_file = request.POST.get('delete_file')
                if delete_file and not f:
                    disk.files = []
                else:
                    if f:
                        atta = Attachment()
                        atta.name = f.name
                        atta.file = f
                        atta.save()
                        file_list = []
                        file_list.append(atta)
                        disk.files = file_list
                is_share = request.POST.get('is_share') 
                if is_share:
                    disk.subdisks.all().delete()
                    pid = disk.id
                    scat = request.POST.get('scat')
                    school_disk = disk
                    school_disk.id = None
                    school_disk.category_id = scat
                    school_disk.parent_id = pid
                    school_disk.save()
                    
                if disk.id:
                    if request.is_ajax():
                        return HttpResponse(json.dumps({'status':1,'desc':"ok"}))
                    else:
                        redirect_url = reverse('oa_disk_index')
                        return redirect(redirect_url)
            return HttpResponse(json.dumps({'status':0,'desc':"error"}))
        else:
            chunk = int(request.POST.get('chunk'))
            file_id = request.POST.get('file_id')
            name = request.POST.get('name')
            
            file_path = FILE_PATH + '/temp/' + str(file_id)
            fp = open(file_path,"a+b")
            fp.write(f.read())
            fp.close()
            
            if chunk + 1  == chunks:
                filename = 'disk/' + str(file_id) + '.' +  name.split('.')[-1].lower()
                try:
                    URL('http://' + SITE_INFO.domain + reverse('cron_make_large_img')).post_async(filename=filename,file_path=file_path)
                except:
                    fr = open(file_path,"rb")
                    content = fr.read()
                    fr.close()
                    if os.path.isfile(file_path):
                        os.remove(file_path)
                    AliyunStorage(). _put_file(filename, content)
                    
                form = DiskForm(request.POST,instance=disk)
                if form.is_valid():
                    disk = form.save(commit=False)
                    disk.creator = request.user
                    disk.school = school
                    disk.save()
                    
                    atta  = Attachment(name=file_id,file=filename)
                    atta.save()
                    file_list = []
                    file_list.append(atta)
                    disk.files = file_list
                    is_share = request.POST.get('is_share') 
                    if is_share:
                        disk.subdisks.all().delete()
                        pid = disk.id
                        scat = request.POST.get('scat')
                        school_disk = disk
                        school_disk.id = None
                        school_disk.category_id = scat
                        school_disk.parent_id = pid
                        school_disk.save()
                    return HttpResponse(json.dumps({'status':1,'desc':"ok"}))
                else:
                    return HttpResponse(json.dumps({'status':0,'desc':"error"}))
            return HttpResponse(json.dumps({'status':1,'desc':"ok"}))
    schools = get_schools(request.user)
    ctx.update({'form':form,"school":school,'personal_list':personal_list,'school_list':school_list,"disk":disk})
    return render(request, template_name, ctx)