def create(request,template_name="oa/school_form.html"): """创建学园""" ctx = {} schools = helpers.get_schools(request.user) try: agency = schools[0].parent except: agency = schools[0] if request.method == 'POST': form = SchoolForm(request.POST) if request.is_ajax(): return helpers.ajax_validate_form(form) if form.is_valid(): school = form.save(commit=False) school.creator = request.user school.parent = agency # admins = [u for u in agency.admins.all()] school.save() if school.id: # school.admins = admins messages.success(request, u'已成功创建学园 %s ' % school.name) return redirect("oa_school_list") else: form = SchoolForm() ctx.update({'form':form}) return render(request, template_name, ctx)
def create(request,template_name="oa/website_form.html"): school = get_schools(request.user)[0] schools = get_schools(request.user) domain_string = helpers.get_parent_domain_string(request) if request.method == 'POST': form = WebSiteForm(request.POST) print form.errors if request.is_ajax(): return helpers.ajax_validate_form(form) if form.is_valid(): school_id = request.POST.get("school", '') if school_id: school = School.objects.get(pk=school_id) print school,'sssssss' # type = form.cleaned_data['type'] # print type,'tttttttttt' website = form.save(commit=False) website.creator = request.user # if not type: # website.domain = website.domain + '.' + domain_string website.school = school website.save() if website.id: messages.success(request, u'已成功创建网站%s ' % website.name) return redirect("oa_website_list") else: form = WebSiteForm() ctx = {'form':form,'schools':schools,'school':school,'domain_string':domain_string} return render(request, template_name, ctx)
def create(request,template_name="oa/class_form.html"): """创建班级""" ctx = {} schools = get_schools(request.user) schools = [s for s in schools if not s.parent_id==0] if request.method == 'POST': form = ClassForm(request.POST,user=request.user) if request.is_ajax(): return helpers.ajax_validate_form(form) if form.is_valid(): group = form.save(commit=False) group.creator = request.user group.save() ctx.update({"school":group.school}) if group.id: class_teacher = request.POST.getlist('class_teacher') set_class_teacher(group,class_teacher) guide_teacher = request.POST.getlist('guide_teacher') set_guide_teacher(group,guide_teacher) messages.success(request, u'已成功创建班级 %s ' % group.name) redirect_url = reverse('oa_class_list') + "?sid=" + str(group.school.id) return redirect(redirect_url) else: form = ClassForm(user=request.user) ctx.update({'form':form,'schools':schools}) return render(request, template_name, ctx)
def create(request,template_name="oa/position_form.html"): """创建职务""" ctx = {} school_id = request.GET.get("sid",0) if request.method == 'POST': form = PositionForm(request.POST) school_id = int(request.POST.get('school')) if request.is_ajax(): return helpers.ajax_validate_form(form) if form.is_valid(): position = form.save(commit=False) position.creator = request.user position.save() ctx.update({"school":position.school}) if position.id: messages.success(request, u'已成功创建职务 %s ' % position.name) # redirect_url = reverse('oa_position_list') + "?sid=" + str(position.school.id) return redirect('oa_position_list') else: form = PositionForm() try: school = get_object_or_404(School,id=school_id) except: school = None schools = helpers.get_schools(request.user) ctx.update({"school":school,"schools":schools}) ctx.update({'form':form}) return render(request, template_name, ctx)
def update(request, group_id, template_name="oa/class_form.html"): """更新班级""" ctx = {} schools = get_schools(request.user) group = get_object_or_404(Group,pk=group_id,school__in=schools) if request.method == 'POST': form = ClassForm(request.POST, instance=group, user=request.user) if request.is_ajax(): return helpers.ajax_validate_form(form) if form.is_valid(): group = form.save(commit=False) group.save() class_teacher = request.POST.getlist('class_teacher') set_class_teacher(group,class_teacher) guide_teacher = request.POST.getlist('guide_teacher') set_guide_teacher(group,guide_teacher) messages.success(request, u"已成功更新班级: %s " % group.name) redirect_url = reverse('oa_class_list') + "?sid=" + str(group.school.id) return redirect(redirect_url) else: school = group.school form = ClassForm(instance=group, user=request.user) teachers = school.teacher_set.all() class_teachers = teachers ctx.update({'teachers':teachers,'class_teachers':class_teachers}) schools = get_schools(request.user) schools = [s for s in schools if not s.parent_id==0] ctx.update({"form": form, "group": group,"school":school,"schools":schools}) return render(request, template_name, ctx)
def tips_create(request,site_id,template_name="oa/tips_form.html"): schools = get_schools(request.user) site = get_object_or_404(WebSite,id=site_id,school__in=schools) helpers.set_website_visit(request.user,site) try: category = get_object_or_404(PartCategory,id=11) except: category = None try: part = Part.objects.get(site=site,category=category) except: part =None school = get_schools(request.user)[0] if request.method == 'POST': form = PartForm(request.POST,category=category,user=request.user,instance=part) if request.is_ajax(): return helpers.ajax_validate_form(form) if form.is_valid(): part = form.save(commit=False) if not form.cleaned_data['creator']: part.creator = request.user.teacher part.school = school part.category = category part.site = site part.type = 0 part.save() if part.id: messages.success(request, u'已成功修改%s ' % part.category) return redirect(reverse('oa_part_con_tips_create',kwargs={'site_id':site.id})) else: form = PartForm(category=category,user=request.user,instance=part) ctx = {'form':form,'category':category,'site':site} return render(request, template_name, ctx)
def mailbox(request,template_name="oa/site/email.html",domain="domain"): site = get_site(request) if not site: return render(request, "404.html") school = site.school 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': form = MailBoxForm(request.POST) print form.errors,'eeeeeeeeeeeeeeeeeee' if request.is_ajax(): return helpers.ajax_validate_form(form) if form.is_valid(): human = True mail = form.save(commit=False) # mail.user = school.header mail.site = site mail.save() if mail.id: messages.success(request, u'已成功发送%s ' % mail.title) return redirect(request.get_full_path()) else: form = MailBoxForm() ctx = {'form':form,'class':'startes','site':site} return render(request, template_name, ctx)
def announcement_create(request,site_id,template_name="oa/announcement_form.html"): schools = get_schools(request.user) site = get_object_or_404(WebSite,id=site_id,school__in=schools) helpers.set_website_visit(request.user,site) category = get_object_or_404(PartCategory,id=9) school = get_schools(request.user)[0] if request.method == 'POST': form = PartForm(request.POST,user=request.user,category=category) if request.is_ajax(): return helpers.ajax_validate_form(form) if form.is_valid(): part = form.save(commit=False) if not form.cleaned_data['creator']: part.creator = request.user.teacher part.school = school part.category = category part.site = site part.save() if part.id: messages.success(request, u'已成功创建%s ' % part.category) return redirect(reverse('oa_part_con_anc_list',kwargs={'site_id':site.id})) else: form = PartForm(category=category,user=request.user) ctx = {'form':form,'category':category,'site':site} return render(request, template_name, ctx)
def update_part(request,part_id,template_name="oa/part_form.html"): schools = get_schools(request.user) part = get_object_or_404(Part,id=part_id,site__school__in=schools) site = part.site helpers.set_website_visit(request.user,site) category = part.category cid = int(request.GET.get("cid", 5)) categorys = PartCategory.objects.filter(parent_id=part.category.parent_id).exclude(parent_id=0) school = site.school if request.method == 'POST': form = PartForm(request.POST,category=category,user=request.user,instance=part) if request.is_ajax(): return helpers.ajax_validate_form(form) if form.is_valid(): cid = int(request.POST.get("cid")) category = get_object_or_404(PartCategory,id=cid) part = form.save(commit=False) if not form.cleaned_data['creator']: part.creator = request.user.teacher part.save() if part.id: messages.success(request, u'已成功创建%s ' % part.category) # return redirect("oa_website_list") else: form = PartForm(category=category,user=request.user,instance=part) ctx = {'form':form,'category':category,'categorys':categorys,'site':site} return render(request, template_name, ctx)
def create(request,template_name="oa/department_form.html"): """创建部门""" ctx = {} school_id = request.GET.get("sid",0) if request.method == 'POST': school_id = int(request.POST.get("school",0)) form = DepartmentForm(request.POST,user=request.user) if request.is_ajax(): return helpers.ajax_validate_form(form) if form.is_valid(): department = form.save(commit=False) department.creator = request.user department.save() ctx.update({"school":department.school}) if department.id: messages.success(request, u'已成功创建部门 %s ' % department.name) redirect_url = reverse('oa_department_list') + "?sid=" + str(department.school.id) return redirect(redirect_url) else: form = DepartmentForm(user=request.user) try: school = get_object_or_404(School,id=school_id) except: school = None schools = helpers.get_schools(request.user) ctx.update({"school":school,"schools":schools}) ctx.update({'form':form}) return render(request, template_name, ctx)
def star_figure_detail(request,site_id,user_id,template_name="oa/start_form.html"): user = get_object_or_404(User,id=user_id) schools = get_schools(request.user) site = get_object_or_404(WebSite,id=site_id,school__in=schools) helpers.set_website_visit(request.user,site) if is_teacher(user): next = reverse('oa_star_figure_teacher',kwargs={'site_id':site_id}) else: next = reverse('oa_star_figure_student',kwargs={'site_id':site_id}) try: figure = user.figure except: figure = StarFigure(user=user).save() if request.method == 'POST': form = StarFigureForm(request.POST,instance=figure) if request.is_ajax(): return helpers.ajax_validate_form(form) if form.is_valid(): part = form.save() messages.success(request, u'已成功修改%s ' % user.profile.realname) return redirect(next) else: form = StarFigureForm(instance=figure) ctx = {'form':form,'user':user,'next':next,'site':site} return render(request, template_name, ctx)
def create_part(request,site_id,template_name="oa/part_form.html"): schools = get_schools(request.user) site = get_object_or_404(WebSite,id=site_id,school__in=schools) helpers.set_website_visit(request.user,site) cid = int(request.GET.get("cid", 5)) try: category = get_object_or_404(PartCategory,id=cid) except: category = None try: if category.id == 4: part = None else: part = Part.objects.get(site=site,category=category) except: part =None categorys = [] if category and category.parent_id == 1: categorys = PartCategory.objects.filter(parent=category.parent) school = site.school if request.method == 'POST': form = PartForm(request.POST,category=category,user=request.user,instance=part) if request.is_ajax(): return helpers.ajax_validate_form(form) if form.is_valid(): cid = int(request.POST.get("cid",0)) category = get_object_or_404(PartCategory,id=cid) part = form.save(commit=False) if not form.cleaned_data['creator']: part.creator = request.user.teacher part.school = school part.category = category part.site = site # part.video_type = 0 # part.type = 0 print category,'ccccccccccc' part.save() if part.id: messages.success(request, u'已成功修改%s ' % part.category) if part.category_id == 4: return redirect(reverse('oa_part_teache',kwargs={'site_id':site.id})) else: form = PartForm(category=category,user=request.user,instance=part) ctx = {'form':form,'category':category,'categorys':categorys,'site':site,'school':school} return render(request, template_name, ctx)
def update_website(request,site_id,template_name="oa/website_detail.html"): schools = get_schools(request.user) site = get_object_or_404(WebSite,id=site_id,school__in=schools) helpers.set_website_visit(request.user,site) if request.method == 'POST': form = WebSiteForm(request.POST,request.FILES,instance=site) if request.is_ajax(): return helpers.ajax_validate_form(form) print form.errors,'eeeeeeeeee' if form.is_valid(): site = form.save(commit=False) site.save() messages.success(request, u'已成功修改网站%s ' % site.name) return redirect(request.get_full_path()) else: form = WebSiteForm(instance=site) ctx = {'form':form,'site':site} return render(request, template_name, ctx)
def update(request, school_id, template_name="oa/school_form.html"): """更新学园""" school_pks = [s.id for s in helpers.get_schools(request.user)] school = get_object_or_404(School,pk=school_id,pk__in=school_pks) # school = get_object_or_404(School, pk=school_id) if request.method == 'POST': form = SchoolForm(request.POST, instance=school) if request.is_ajax(): return helpers.ajax_validate_form(form) if form.is_valid(): form.save() messages.success(request, u"已成功更新学园: %s " % school.name) return redirect("oa_school_list") else: form = SchoolForm(instance=school) ctx = {"form": form, "school": school} return render(request, template_name, ctx)
def update(request, department_id, template_name="oa/department_form.html"): """更新部门""" schools = helpers.get_schools(request.user) department = get_object_or_404(Department,pk=department_id,school__in=schools) school = department.school if request.method == 'POST': form = DepartmentForm(request.POST, instance=department, user=request.user) if request.is_ajax(): return helpers.ajax_validate_form(form) if form.is_valid(): department = form.save(commit=False) department.save() messages.success(request, u"已成功更新部门: %s " % department.name) redirect_url = reverse('oa_department_list') + "?sid=" + str(department.school.id) return redirect(redirect_url) else: form = DepartmentForm(instance=department,user=request.user) ctx = {"form": form, "department": department,"school":school,"schools":schools} return render(request, template_name, ctx)
def update(request, position_id, template_name="oa/position_form.html"): """更新职务""" schools = helpers.get_schools(request.user) position = get_object_or_404(Position,pk=position_id,school__in=schools) school = position.school if request.method == 'POST': form = PositionForm(request.POST, instance=position) if request.is_ajax(): return helpers.ajax_validate_form(form) if form.is_valid(): position = form.save(commit=False) position.save() messages.success(request, u"已成功更新职务: %s " % position.name) redirect_url = reverse('oa_position_list') + "?sid=" + str(position.school.id) return redirect(redirect_url) else: form = PositionForm(instance=position) ctx = {"form": form, "position": position,"school":school,"schools":schools} return render(request, template_name, ctx)
def update_news(request,part_id,template_name="oa/news_form.html"): schools = get_schools(request.user) part = get_object_or_404(Part,id=part_id,site__school__in=schools) site = part.site helpers.set_website_visit(request.user,site) category = part.category if request.method == 'POST': form = PartForm(request.POST,category=category,user=request.user,instance=part) if request.is_ajax(): return helpers.ajax_validate_form(form) if form.is_valid(): part = form.save(commit=False) if not form.cleaned_data['creator']: part.creator = request.user.teacher part.save() if part.id: messages.success(request, u'已成功修改%s ' % part.category) return redirect(reverse('oa_part_con_news_list',kwargs={'site_id':site.id})) else: form = PartForm(category=category,user=request.user,instance=part) ctx = {'form':form,'category':category,'site':site} return render(request, template_name, ctx)
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)
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)
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)