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 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 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 __init__(self, *args, **kwargs): user = kwargs.pop('user') if kwargs else None super(DepartmentForm, self).__init__(*args, **kwargs) instance = getattr(self, 'instance', None) self.fields['name'].required = True if user and helpers.get_schools(user): manage_school_pks = [_school.id for _school in helpers.get_schools(user)] self.fields['charger'].queryset = Teacher.objects.filter(school__pk__in=manage_school_pks)
def __init__(self, *args, **kwargs): user = kwargs.pop('user') if kwargs else None super(ClassForm, self).__init__(*args, **kwargs) instance = getattr(self, 'instance', None) if user and helpers.get_schools(user): manage_school_pks = [_school.id for _school in helpers.get_schools(user) if not _school.parent_id==0] print manage_school_pks,'pppppppppppp' self.fields['headteacher'].queryset = Teacher.objects.filter(school__pk__in=manage_school_pks)
def provider_index(request, template_name="supply/provider_index.html"): """供应商列表""" schools = get_schools(request.user) school_id = int(request.GET.get("sid",0)) if school_id == 0: school = None if is_agency_user(request.user) else schools[0] else: school = School.objects.get(id=school_id) school = school if school in schools else None query = request.GET.get("n", "") qs = Q(school=school) if school else Q(school__in=schools) qn = Q(name__contains=query) if query else Q() q = qs & qn providers = Provider.objects.filter(q) #删除供应商 if request.method == 'POST': try: provider_pks = request.POST.getlist("provider_pks") providers = providers.filter(id__in=provider_pks) for p in providers: p.delete() messages.success(request, u"操作成功") except: messages.success(request, u"操作失败") redirect_url = reverse('oa_provider_index') + "?sid=" + str(school_id) + "&n=" + query return redirect(redirect_url) ctx = {'schools':schools,'school':school,'providers':providers,'sid':school_id,'query':query} return render(request, template_name, ctx)
def update_role(request,role_id,template_name="oa/role_form.html"): """更新角色""" ctx = {} schools = helpers.get_schools(request.user) role = get_object_or_404(Role, id=role_id,school__in=schools) agency_pks = [r.id for r in role.accesses.filter(level=0)] school_pks = [r.id for r in role.accesses.filter(level=1)] agency_par_accesses = Access.objects.filter(parent__pk=0,level=0).exclude(pk=5) school_par_accesses = Access.objects.filter(parent__pk=0,level=1) agency_sub_accesses = Access.objects.filter(level=0).exclude(parent__pk=0).exclude(parent__pk=5) school_sub_accesses = Access.objects.filter(level=1).exclude(parent__pk=0) if request.method == 'POST': form = RoleForm(request.POST,instance=role) if form.is_valid(): access_pks = request.POST.getlist('user') form.save() access_list = [a for a in Access.objects.filter(pk__in=access_pks)] if access_list: role.accesses = access_list messages.success(request, u"角色 %s 已成功创建" % role.name) return redirect("oa_permission_role_list") else: form = RoleForm(instance=role) ctx.update({'agency_par_accesses':agency_par_accesses,'school_par_accesses':school_par_accesses,\ 'agency_sub_accesses':agency_sub_accesses,'school_sub_accesses':school_sub_accesses,\ 'form':form,'agency_pks':agency_pks,'school_pks':school_pks,'role':role}) 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 teacher_index(request, template_name="oa/schedule/teacher_index.html"): """周课表列表页""" user = request.user schools = helpers.get_schools(user) school_id = int(request.GET.get("sid",-1)) group_id = int(request.GET.get("gid",-1)) try: school = get_object_or_404(School, pk=school_id) except: school = None is_admin = helpers.is_school_admin(request.user) if is_admin: groups = Group.objects.filter(school_id=school_id).exclude(type=3) else: group_pks = [g.group_id for g in GroupTeacher.objects.filter(teacher=user.teacher)] groups = Group.objects.filter(pk__in=group_pks) group_count = groups.count() schedules = Schedule.objects.all() try: group = Group.objects.get(pk=group_id) except: group = None schedules = Schedule.objects.filter(user=user) if school: schedules = schedules.filter(group__school=school) if group: schedules = schedules.filter(group=group) ctx = {"schedules":schedules,"group":group,"groups":groups,\ "schools":schools,"school":school,'group_count':group_count} 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 check_import(request, template_name="oa/teacher_import.html"): schools = helpers.get_schools(request.user) roles_xls = request.FILES.get('teachers') error_list = [] num = 0 try: school_id = request.POST['school'] school = get_object_or_404(School, pk=school_id) except: school = schools[0] if not roles_xls: messages.error(request, _("Files Missing")) return render(request, template_name, {'schools':schools,'school':school}) try: wb = xlrd.open_workbook(file_contents=roles_xls.read()) s = wb.sheet_by_index(0) except xlrd.biffh.XLRDError: messages.error(request, _("Unsupported format, or corrupt file")) return render(request, template_name, {'schools':schools,'school':school}) try: trans_map = { "name": s.cell(0, 0).value, "mobile": s.cell(0, 1).value } except: trans_map = None xls_cache = [] for row in range(s.nrows)[1:]: num = num + 1 try: mobile = mobile = str(int(s.cell(row, 1).value)).strip() except: mobile = '' try: name = s.cell(row, 0).value.strip() except Exception, e: print e messages.error(request, u"导入的 Excel 文件缺少需要的列, 或者该列数据为空.") return redirect('oa_teacher_batch_import') try: teacher = Teacher.objects.get(name=name, user__profile__mobile=mobile,school=school) if teacher and teacher.user.profile.mobile: error_list.append({'name':name,'mobile':mobile,'row':row,'msg':"姓名和手机已存在"}) continue except: pass initial_data = {"name": name, "mobile": mobile} form = TeacherForm(initial_data) if not form.is_valid(): error_list.append({'name':name,'mobile':mobile,'row':row,'msg':form.errors}) continue print name,mobile xls_cache.append({'name':name,'mobile':mobile})
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 wrapped_f(request, *args, **kwargs): # print self.arg1,'aaaaaaaaaaaaaaaaaaaa' user = request.user path = request.build_absolute_uri() # 用户登录 if not user.is_authenticated(): messages.error(request, "您尚未登录。") return redirect_to_login(path) # 老师用户 try: school = helpers.get_schools(request.user)[0] # print school,'ssssssss' if not school: return f(request, *args, **kwargs) except: messages.error(request, "您的权限不足无法访问。") return redirect(reverse("userena_signin") + "?lack_perm=lack&next=" + str(path)) # return redirect_to_login(path) # 权限判断 code_list = [c.code for c in helpers.user_access_list(user)] # print code_list,'cccccccccc' if self.arg1 in code_list: # print 'in' return f(request, *args, **kwargs) elif user.is_authenticated(): # print 'out' messages.error(request, "您的权限不足无法访问。") return redirect(reverse("userena_signin") + "?lack_perm=lack&next=" + str(path)) # return redirect_to_login(path) else: return redirect_to_login(path)
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 __init__(self, *args, **kwargs): try: category = kwargs.pop('category') except: category = None try: user = kwargs.pop('user') except: user = None super(PartForm, self).__init__(*args, **kwargs) instance = getattr(self, 'instance', None) self.fields['video_type'].required = False if user: manage_school_pks = [_school.id for _school in helpers.get_schools(user)] self.fields['creator'].queryset = Teacher.objects.filter(school__pk__in=manage_school_pks) if instance and instance.id: self.fields['video'].widget.template_with_initial = u'%(input)s' self.fields['attachment'].widget.template_with_initial = u'%(input)s' if category and category.id == 12: self.fields['content'].required = False else: self.fields['content'].required = True self.fields['creator'].required = False self.fields['type'].required = False if category and category.id == 4: self.fields['title'].required = True # self.fields['creator'].required = True if category and category.id == 19: self.fields['title'].required = True
def create_provider(request,template_name="supply/provider_form.html"): """创建供应商""" ctx = {} school_id = request.GET.get("sid",0) if request.method == 'POST': school_id = int(request.POST.get("school",0)) form = ProviderForm(request.POST) if form.is_valid(): provider = form.save(commit=False) provider.creator = request.user provider.save() ctx.update({"school":provider.school}) if provider.id: messages.success(request, u'已成功创建供应商%s ' % provider.name) redirect_url = reverse('oa_provider_index') + "?sid=" + str(provider.school.id) return redirect(redirect_url) else: form = ProviderForm() try: school = School.objects.get(id=school_id) except: school = None schools = get_schools(request.user) ctx.update({"school":school,"schools":schools}) ctx.update({'form':form}) return render(request, template_name, ctx)
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)
def delete_record(request, record_id): """delete a record""" ty = request.GET.get('ty','') schools = get_schools(request.user) data = {'status':0} if ty == "bach": records = SupplyRecord.objects.filter(school__in=schools,parent_id=record_id) ids = request.GET.get('ids','') if ids: pks = ids.split(',') records = records.filter(id__in=pks) for record in records: r = edit_apply(record) if r: record.status = 1 record.save() data = {'status':1} else: record = get_object_or_404(SupplyRecord,id=record_id,school__in=schools,parent_id__gt=0) r = edit_apply(record) if r: record.status = 1 record.save() data = {'status':1} return HttpResponse(json.dumps(data))
def delete(request,school_id): """删除学园""" 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.delete() messages.success(request, u'学园 %s 已删除' % school.name) return redirect("oa_school_list")
def personal(request,template_name="oa/workgroup_list.html"): school = get_schools(request.user)[0] workgroups = school.workgroup_set.all() workgroups = workgroups.filter(type=1) workgroups = workgroups.filter(user=request.user) ctx = {'workgroups':workgroups,'ty':True} return render(request, template_name, ctx)
def template(request,site_id,template_name="oa/template_list.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) templates = Template.objects.filter(site=site) ctx = {'templates':templates,'site':site} return render(request, template_name, ctx)
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)
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 delete(request, teacher_id): """delete a teacher""" schools = helpers.get_schools(request.user) teacher = get_object_or_404(Teacher, pk=teacher_id, school__in=schools) teacher.delete() messages.success(request, _('Teacher deleted')) return redirect("manage_teacher_list")
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 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)
def create_role(request,template_name="oa/role_form.html"): """创建角色""" school = helpers.get_schools(request.user)[0] ctx = {} agency_par_accesses = Access.objects.filter(parent__pk=0,level=0).exclude(pk=5) agency_sub_accesses = Access.objects.filter(level=0).exclude(parent__pk=0).exclude(parent__pk=5) if request.method == 'POST': form = RoleForm(request.POST) if form.is_valid(): access_pks = request.POST.getlist('user') role = form.save(commit=False) role.school = school role.save() access_list = [a for a in Access.objects.filter(pk__in=access_pks)] if access_list: role.accesses = access_list messages.success(request, u"角色 %s 已成功创建" % role.name) return redirect("oa_permission_role_list") else: form = RoleForm() ctx.update({'agency_par_accesses':agency_par_accesses,'agency_sub_accesses':agency_sub_accesses,'form':form}) return render(request, template_name, ctx)
def create(request,template_name="oa/schedule/add_form.html"): """添加周课表""" user = request.user schools = helpers.get_schools(user) is_admin = helpers.is_school_admin(request.user) if is_admin: school_id = schools[0].id groups = Group.objects.filter(school_id=school_id).exclude(type=3) else: group_pks = [g.group_id for g in GroupTeacher.objects.filter(teacher=user.teacher)] groups = Group.objects.filter(pk__in=group_pks) group_count = groups.count() group_id = int(request.GET.get("class_id",-1)) ctx = {'schools':schools,'groups':groups,'group_count':group_count} if request.method == 'POST': form = ScheduleForm(request.POST,request.FILES) group_id = request.POST.get("group","") if form.is_valid(): schedule = form.save(commit=False) schedule.save() group = schedule.group messages.success(request, u'课表 %s 上传成功' % schedule.name) return redirect(request.get_full_path() + '?class_id=' + str(group.id)) else: form = ScheduleForm() ctx.update({'form':form,"group_id":group_id}) return render(request, template_name, ctx)
def check_teachers(request, template_name="oa/class_check_teachers.html"): """ """ schools = get_schools(request.user) school_id = request.POST.get("sid",None) group_id = request.POST.get("gid") try: group = get_object_or_404(Group, pk=group_id) except: group = None try: school = get_object_or_404(School,id=school_id) except: school = None teachers = school.teacher_set.all() if school else None class_teachers = teachers channel = request.POST.get("channel","school") if teachers and channel == "group": group_teacher_ids = [t.teacher_id for t in GroupTeacher.objects.filter(type_id=1)] class_teachers = teachers.exclude(pk__in=group_teacher_ids) data = render(request, template_name, {'class_teachers':class_teachers,\ 'group':group,'teachers':teachers,'channel':channel}) con=data.content return ajax_ok('成功',con)