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)
def tile_view_pre(request, tile_id, template_name="kinger/revision/axis_tile_view_pre.html"): user = request.user data = json.dumps({'status':"error"}) ty = request.GET.get('ty') cid = request.GET.get('cid') if ty == 'theme' and tile_id == '0': if cid != '0': tiles = Tile.objects.filter(new_category_id=cid)[:1] else: tiles = Tile.objects.filter(new_category_id__gt=2400,new_category_id__lte=2412)[:1] if tiles.count(): tile = tiles[0] else: return HttpResponse(data) else: try: tile = Tile.objects.get(pk=tile_id) except: return HttpResponse(data) is_last_page = True if tile.n_comments > 0: comments = Comment.objects.for_model(tile).select_related('user')\ .order_by("-submit_date").filter(is_public=True).filter(is_removed=False) if comments.count() > 5: comments = comments[0:5] is_last_page = False else: comments = None ctx = {} ctx.update({"tile": tile,"comments": comments,"is_last_page":is_last_page}) data = render(request, template_name,ctx) con=data.content return ajax_ok('成功',con)
def unread_list(request): user = request.user if request.user.is_authenticated(): con = unread_count(request) return helpers.ajax_ok('成功',con) else: return helpers.ajax_error('失败','')
def cancle_track(request,): contact_id = request.GET['contact_id'] try: track = Track.objects.get(message_contact=contact_id) except ObjectDoesNotExist: return ajax_error('取消失败') track.is_track = False track.save() return ajax_ok('已取消跟踪')
def add_track(request,): contact_id = request.GET['contact_id'] try: track = Track.objects.get(message_contact=contact_id) except ObjectDoesNotExist: message_contact = MessageContact.objects.get(id=contact_id) track = Track(message_contact=message_contact,is_track=True,user=request.user) track.save() track.is_track = True track.save() return ajax_ok('添加跟踪成功')
def photo_detail(request,template_name="oa/school_photo_detail.html"): """照片详情""" photo_id = int(request.POST.get('photo_id')) schools = get_schools(request.user) photo = get_object_or_404(Photo,id=photo_id,album__site__school__in=schools) form = PhotoForm(instance=photo) album = photo.album ctx = {'album':album,'form':form,'photo':photo} data = render(request, template_name,ctx) con=data.content return ajax_ok('成功',con)
def pwd_back_mobile_get_vcode(request): """ 得到用户手机号码,并生成验证码 """ mobile = request.GET.get('mobile') if mobile: message, code, extra = verify_sms_helper.get_vcode(mobile) return helpers.ajax_ok(message,con=extra,code=code) return helpers.ajax_error('请先填写你的手机号码。', code=100)
def get_approvalers(request, template_name="oa/document_approvalers.html"): """ 设置审批人 """ schools = get_schools(request.user) school_id = int(request.POST.get("sid",0)) try: school = get_object_or_404(School,pk=school_id) except: school = schools[0] teacher_all = Teacher.objects.filter(school=school) #老师按照职位分组 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_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}) 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,\ {'teacher_all':teacher_all,\ 'teacher_position_list':teacher_position_list,\ 'teacher_word_list':teacher_word_list,\ 'global_workgroup_list':global_workgroup_list,\ 'school':school,'schools':schools}) con=data.content return ajax_ok('成功',con)
def source_list(request,group_id,template_name="growth/source_list.html"): print group_id,'(?P<group_id>\d+)/' group = get_object_or_404(Group,pk=group_id) tiles = Tile.objects.filter(group=group,is_tips=0,is_public=0,new_type_id=1) try: tiles = tiles[0:10] except: pass ctx = {"tiles":tiles} data = render(request, template_name,ctx) con=data.content return ajax_ok('成功',con)
def daily_record(request, template_name="kinger/revision/axis_daily_record.html"): """日常记录详情页 """ if not is_vip(request.user): return render(request, "403.html") date = request.POST.get('date') type = int(request.POST.get('ty','0')) tiles = Tile.objects.get_tiles_baby(request.user) category = NewTileCategory.objects.filter(is_tips=0, parent__pk=1130) date = datetime.datetime.strptime(date,"%Y-%m-%d") dates = get_group_date(request) group_date = [d for d in dates if d[0].date() <= date.date()] content_type = ContentType.objects.get_for_model(Tile) new_visitor = DailyRecordVisitor() new_visitor.visitor = request.user new_visitor.target_content_type = content_type new_visitor.save() effective_date = [str(x[0].date()) for x in dates] current_date = datetime.datetime.now().date() effective_date.append(str(current_date)) page = int(request.POST.get("page", '1')) start = (page - 1) * 5 end = page * 5 is_last_page = False if end >= len(group_date): is_last_page = True is_first = {"year":0,"month":0} record_list = [] for day in group_date[start:end]: record_dict = {} record_dict['day'] = day[0] record_dict['is_first'] = False #判断当年当月的首条记录 if is_first['year'] != day[0].year or is_first['month'] != day[0].month: record_dict['is_first'] = True is_first['year'] = day[0].year is_first['month'] = day[0].month daily_record = get_daily_category_tiles(tiles, category, day[0]) if daily_record: record_dict['data'] = daily_record record_list.append(record_dict) ctx = {"channel":"baby", "record_list":record_list,"group_date":group_date,\ 'effective_date':effective_date,'type':type,'page':page,'date':date,'is_last_page':is_last_page} data = render(request, template_name,ctx) con=data.content return ajax_ok('成功',con)
def reback_record(request, record_id,template_name="supply/supply_reback.html"): ty = request.GET.get('ty','') schools = get_schools(request.user) 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) else: records = SupplyRecord.objects.filter(id=record_id,school__in=schools,parent_id__gt=0) ctx = {"records":records} data = render(request,template_name,ctx) con=data.content return ajax_ok('成功',con)
def get_cookbook_date(request,): """ 获得某天食谱 """ try: # 初始化数据 user = request.user schools = user.manageSchools.all() if schools.count() > 0: school = schools[0] else: messages.error(request, "你没有可管理的学校") return redirect("manage") cur_date = datetime.date.today() cookbook_day = None cookbook_type = "school" # 食谱类型,默认是学校的 # 取得参数 date_param = request.GET.get("date") school_param = request.GET.get("school") group_param = request.GET.get("group") # 日期初始化,空日期代表当前月份 if date_param: try: the_date = datetime.datetime.strptime(date_param, "%Y-%m-%d") except ValueError: the_date = cur_date else: the_date = cur_date # 只有学校为空,班级不为空,才是班级类型,其它都是学校 if not school_param and group_param: cookbook_type = "group" if cookbook_type == "school": cookbook_day = Cookbook.objects.get_cookbook_date(school=school, date=the_date) else: group_param = int(group_param) group = Group.objects.get(pk=group_param) cookbook_day = Cookbook.objects.get_cookbook_date(school=school, group=group, date=the_date) return helpers.ajax_ok("成功", con=cookbook_day) except: return helpers.ajax_error("失败")
def tile_page(request, tile_id, template_name="kinger/revision/axis_tile_page.html"): """ 瓦片详情页,底部分页""" tile = get_object_or_404(Tile, pk=tile_id) user = request.user channel = request.GET.get("channel") tpage = int(request.GET.get("tpage",1)) is_ajax = request.GET.get("is_ajax",False) is_ajax = True if is_ajax == "True" else False if channel == "edu": tiles = Tile.objects.get_tiles_edu(user) elif channel == "life": tiles = Tile.objects.get_tiles_life(user) else: tiles = Tile.objects.get_tiles_baby(user).exclude(new_category_id=9) # 禁止访问其它用户的记录 if tile.creator != user: try: tiles.get(pk=tile_id) except ObjectDoesNotExist: if not tile.is_public: return render(request, "403.html") tiles = tiles.exclude(new_category__parent_id=1130).order_by("-microsecond") ctx = {} tile_all = [t for t in tiles] tile_order = tile_all.index(tile) # if tpage == (tile_order / 10) + 1: # order = (tile_order + 1) % 10 # else: # order = None order = (tile_order) % 10 # if tpage == 1: # tpage = (tile_order / 10) + 1 start = (tpage - 1) * 10 end = tpage * 10 is_last_tpage = True if end >= len(tile_all) else False tiles = tile_all[start:end] print tpage,'tttttttttttttttt' ctx.update({"tpage":tpage,"tiles": tiles,"order":order,"tile":tile,"is_last_tpage":is_last_tpage,"channel":channel,"is_ajax":is_ajax}) data = render(request, template_name,ctx) con=data.content return ajax_ok('成功',con)
def get_daily_baby_tiles(request,template_name = "kinger/revision/baby_axis_extra_container.html"): date = request.POST.get('date') page = int(request.POST.get('num',1)) is_all = False category = NewTileCategory.objects.all() category = category.filter(is_tips=0) category = NewTileCategory.objects.filter(is_tips=0) today_tiles = Tile.objects.get_tiles_baby(request.user).filter(new_category__in=category,start_time__startswith=date)\ .exclude(new_category__parent_id=1130).exclude(new_category_id=9).order_by("-microsecond") start = (page - 1) * 20 + 8 end = page * 20 + 8 tiles = today_tiles[start:end] if end >= today_tiles.count(): is_all = True data = render(request, template_name,{'tiles':tiles,'page':page+1,'is_all':is_all,'tile_date':date}) con=data.content return ajax_ok('成功',con)
def document_applies(request,template_name="supply/document_applies.html"): pk = request.GET.get('pk','') did = request.GET.get('did','') if pk: applies = MaterialApply.objects.filter(id=pk) if did: applies = MaterialApply.objects.filter(document_id=did) try: doc = applies[0].document school = applies[0].school type = applies[0].document.type except: type = 0 doc = None school = None print type,'yyyyyyyyyyyyyyyyyyyyyyyyy' data = render(request, template_name, {'applies':applies,'ty':type,'doc':doc,'school':school}) con=data.content return ajax_ok('成功',con)
def get_extra_form(request,template_name="oa/extra_form.html"): """公文类别附加表单""" order = int(request.POST.get('order')) formset = formset_factory(DocumentCategoryForm, extra=order + 1) form = formset() pid = request.POST.get('parent_id',0) parent = None if pid: parent_list = [] parent = get_object_or_404(DocumentCategory,id=pid) for i in range(order): parent_list.append({'name':'','parent':parent}) form = formset(initial=parent_list) form = form[order] ctx = {'form':form,'order':order,'parent':parent} data = render(request,template_name,ctx) con=data.content return ajax_ok('成功',con)
def save_message(request,): if request.is_ajax(): if request.method == 'POST': try: parent_id = request.POST['parent_id'] mentor_id = request.POST['mentor_id'] body = request.POST['body'] parent = get_object_or_404(User,id=parent_id) mentor = get_object_or_404(User,id=mentor_id) #验证工作 #添加会话 mes = Message.objects.send_message(mentor,[parent],body) #运营记录 om = OperatorsMessage(user=request.user,message=mes) om.save() return ajax_ok('消息发送成功') except: return ajax_error('消息发送失败')
def save_message(request,): if request.is_ajax(): if request.method == 'POST': try: parent_id = request.POST['parent_id'] waiter_id = request.POST['waiter_id'] body = request.POST['body'] parent = get_object_or_404(User,id=parent_id) waiter = get_object_or_404(User,id=waiter_id) #验证工作 #添加会话 mes = Message.objects.send_message(waiter,[parent],body) #客服记录 wm = WaiterMessage(user=request.user,message=mes) wm.save() return ajax_ok('消息发送成功') except: return ajax_error('消息发送失败')
def update_unread_message(request,): try: userid = request.GET['userid'] recipientid = request.GET['recipientid'] user = get_object_or_404(User,pk=userid) recipient = get_object_or_404(User,pk=recipientid) # 找到 user 发给 recipient 的消息。 queryset = Message.objects.filter(Q(sender=user, recipients=recipient, messagerecipient__deleted_at__isnull=True)) message_pks = [m.pk for m in queryset] # 更新 user 发给 recipient 的未读消息 unread_list = MessageRecipient.objects.filter(message__in=message_pks, user=recipient, read_at__isnull=True) now = get_datetime_now() unread_list.update(read_at=now) return ajax_ok('消息发送成功') except: return ajax_error('消息发送失败')
def more_comment(request, tile_id,template_name="kinger/revision/includes/comments_show.html"): """ 加载更多评论 """ tile = get_object_or_404(Tile, pk=tile_id) cpage = int(request.GET.get("cpage",1)) is_last_page = True if tile.n_comments > 0: comments = Comment.objects.for_model(tile).select_related('user')\ .order_by("-submit_date").filter(is_public=True).filter(is_removed=False) else: comments = None start = (cpage - 1) * 10 + 5 # start = 0 end = cpage * 10 + 5 if end < comments.count(): is_last_page = False comments = comments[start:end] data = render(request, template_name,{"tile": tile,'comments':comments,"cpage":cpage,"is_last_page":is_last_page}) con=data.content return ajax_ok('成功',con)
def delete_comment(request, comment_id,template_name="kinger/revision/includes/comments_show.html"): """ 评论删除后,减少对应*瓦片*的评论数(冗余字段), 并跳转且作出提示 """ comment = get_object_or_404(Comment, pk=comment_id, site__pk=settings.SITE_ID) if request.user == comment.user: perform_delete(request, comment) comment.content_object.after_del_comments() # messages.success(request, _("Comment deleted success")) else: # messages.error(request, _("You can't delete this comment")) pass tile = comment.content_object is_last_page = True if tile.n_comments > 0: comments = Comment.objects.for_model(tile).select_related('user')\ .order_by("-submit_date").filter(is_public=True).filter(is_removed=False) if comments.count() > 5: is_last_page = False else: comments = None data = render(request, template_name,{"tile": tile,'comments':comments,"is_last_page":is_last_page}) con=data.content # print con,'ccccccccccc' return ajax_ok('成功',con)
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)
def save_cookbook(request,): """ 保存某天,班或学校食谱 """ # 取得参数 # 初始化数据 user = request.user schools = get_schools(request.user) school_id = int(request.POST.get('sid',0)) try: if user.teacher.school.parent_id == 0: school = School.objects.get(id=school_id) if not school in schools: raise else: school = schools[0] except: messages.error(request,'你没有可管理的学校') return redirect('oa_cookbook') cookbook_type = 'school' # 食谱类型,默认是学校的 items = Cookbook.objects.get_items() come_items = {} show_list = {} # 取得参数 date_param = request.POST.get('date') school_param = request.POST.get('school') group_param = request.POST.get('group') print school_param,group_param,'----------------------------***************************' action_type = request.POST.get('ty') the_date = datetime.datetime.strptime(date_param, "%Y-%m-%d") # 只有学校为空,班级不为空,才是班级类型,其它都是学校 if group_param and group_param != '0': cookbook_type = 'group' is_empty = 0 for i in items: come_items[i] = request.POST.get(i) is_empty = is_empty + 1 if come_items[i] else is_empty if not is_empty and action_type != 'clear': return helpers.ajax_error('请添加食谱内容',type='') school_cookbook = Cookbook.objects.filter(school=school,date=the_date) if cookbook_type == 'school': if school_cookbook.count() > 0: school_cookbook = school_cookbook[0] for i in items: setattr(school_cookbook,i,come_items[i]) school_cookbook.save() else: school_cookbook = Cookbook(creator=user,school=school,date=the_date,breakfast=come_items['breakfast'],light_breakfast=come_items['light_breakfast'], lunch=come_items['lunch'], light_lunch=come_items['light_lunch'], dinner=come_items['dinner'], light_dinner=come_items['light_dinner']) school_cookbook.save() for i in items: school_item = getattr(school_cookbook, i) show_list[i] = True if school_item != '' else False elif cookbook_type == 'group': group_pk = int(group_param) group_cookbook = Cookbook.objects.filter(group=group_pk,date=the_date) school_pub = True if school_cookbook.count() > 0 else False group_pub = True if group_cookbook.count() > 0 else False # 保存继承,若来自学校内容,则保存为空(代表继承) # if school_pub: # school_cookbook_items = school_cookbook[0] # for i in items: # if getattr(school_cookbook_items, i) == come_items[i]: # come_items[i] = '' # 需要继承保存判断 if group_pub: group_cookbook = group_cookbook[0] for i in items: setattr(group_cookbook,i,come_items[i]) group_cookbook.save() else: group = Group.objects.get(pk=group_pk) group_cookbook = Cookbook(creator=user,group=group,date=the_date,breakfast=come_items['breakfast'],light_breakfast=come_items['light_breakfast'], lunch=come_items['lunch'], light_lunch=come_items['light_lunch'], dinner=come_items['dinner'], light_dinner=come_items['light_dinner']) group_cookbook.save() # 返回 是否为空选项,用于前端显示 for i in items: group_item = getattr(group_cookbook, i) school_item = getattr(school_cookbook[0], i) if school_pub else '' if group_item != '': show_list[i] = True elif school_item !='': show_list[i] = True else: show_list[i] = False cookbook_set_items = CookbookSet.objects.get_set(school=school) for i in items: if not cookbook_set_items[i]['is_show']: del show_list[i] return helpers.ajax_ok('成功',con=show_list)
def save_cookbook(request,): """ 保存某天,班或学校食谱 """ # 取得参数 # 初始化数据 user = request.user schools = user.manageSchools.all() if schools.count() > 0: school = schools[0] else: messages.error(request, "你没有可管理的学校") return redirect("manage") cookbook_type = "school" # 食谱类型,默认是学校的 items = Cookbook.objects.get_items() come_items = {} show_list = {} # 取得参数 date_param = request.POST.get("date") school_param = request.POST.get("school") group_param = request.POST.get("group") action_type = request.POST.get("ty") the_date = datetime.datetime.strptime(date_param, "%Y-%m-%d") # 只有学校为空,班级不为空,才是班级类型,其它都是学校 if not school_param and group_param: cookbook_type = "group" is_empty = 0 for i in items: come_items[i] = request.POST.get(i) is_empty = is_empty + 1 if come_items[i] else is_empty if not is_empty and action_type != "clear": return helpers.ajax_error("请添加食谱内容", type="") # print dinner school_cookbook = Cookbook.objects.filter(school=school, date=the_date) if cookbook_type == "school": if school_cookbook.count() > 0: school_cookbook = school_cookbook[0] for i in items: setattr(school_cookbook, i, come_items[i]) school_cookbook.save() else: school_cookbook = Cookbook( creator=user, school=school, date=the_date, breakfast=come_items["breakfast"], light_breakfast=come_items["light_breakfast"], lunch=come_items["lunch"], light_lunch=come_items["light_lunch"], dinner=come_items["dinner"], light_dinner=come_items["light_dinner"], ) school_cookbook.save() for i in items: school_item = getattr(school_cookbook, i) show_list[i] = True if school_item != "" else False elif cookbook_type == "group": group_pk = int(group_param) group_cookbook = Cookbook.objects.filter(group=group_pk, date=the_date) school_pub = True if school_cookbook.count() > 0 else False group_pub = True if group_cookbook.count() > 0 else False # 保存继承,若来自学校内容,则保存为空(代表继承) if school_pub: school_cookbook_items = school_cookbook[0] for i in items: if getattr(school_cookbook_items, i) == come_items[i]: come_items[i] = "" # 需要继承保存判断 if group_pub: group_cookbook = group_cookbook[0] for i in items: setattr(group_cookbook, i, come_items[i]) group_cookbook.save() else: group = Group.objects.get(pk=group_pk) group_cookbook = Cookbook( creator=user, group=group, date=the_date, breakfast=come_items["breakfast"], light_breakfast=come_items["light_breakfast"], lunch=come_items["lunch"], light_lunch=come_items["light_lunch"], dinner=come_items["dinner"], light_dinner=come_items["light_dinner"], ) group_cookbook.save() # 返回 是否为空选项,用于前端显示 for i in items: group_item = getattr(group_cookbook, i) school_item = getattr(school_cookbook[0], i) if school_pub else "" if group_item != "": show_list[i] = True elif school_item != "": show_list[i] = True else: show_list[i] = False cookbook_set_items = CookbookSet.objects.get_set(school=school) for i in items: if not cookbook_set_items[i]["is_show"]: del show_list[i] return helpers.ajax_ok("成功", con=show_list)
user_role_pks = '' schools = helpers.get_schools(request.user) q = request.POST.get("q", "") s = int(request.POST.get("s", 0)) roles = Role.objects.filter(school__in=schools) if s: roles = roles.filter(school_id=s) if q: roles = roles.filter(name__contains=q) ctx = {'roles':roles,'query':q,'schools':schools,'s':s,'user':user,\ 'user_roles':user_roles,'user_role_pks':user_role_pks} data = render(request,template_name,ctx) con=data.content return ajax_ok('成功',con) def change_status(request): tid = int(request.POST.get('tid')) p = PostJob.objects.get(teacher_id=tid) s = p.status if s == 0: p.status = 1 p.save() if s == 1: p.status = 0 p.save() data = json.dumps({'status':p.status}) return HttpResponse(data)
def get_cookbook_date(request,): """ 获得某天食谱 """ user = request.user schools = get_schools(request.user) school_pks = [s.id for s in schools] school_id = int(request.GET.get('school',0)) if school_id != 0: try: school =School.objects.get(id=school_id,id__in=school_pks) except: messages.error(request,'你没有可管理的学校') return redirect('oa_home') else: if schools: school = schools[0] else: messages.error(request,'你没有可管理的学校') return redirect('oa_home') print school,school.id try: #初始化数据 cur_date = datetime.date.today() cookbook_day = None cookbook_type = 'school' # 食谱类型,默认是学校的 # 取得参数 date_param = request.GET.get('date') school_param = request.GET.get('school') group_param = request.GET.get('group') print group_param,'group_param-----------------------------' # 日期初始化,空日期代表当前月份 if date_param: try: the_date = datetime.datetime.strptime(date_param, "%Y-%m-%d") except ValueError: the_date = cur_date else: the_date = cur_date # 只有学校为空,班级不为空,才是班级类型,其它都是学校 if group_param and group_param != '0': cookbook_type = 'group' print cookbook_type,'ttttttttttttttttttttttttttttttttttttttttttttttttttttt' if cookbook_type == 'school': cookbook_day = Cookbook.objects.get_cookbook_date(school=school,date=the_date) else: group_param = int(group_param) group = Group.objects.get(pk=group_param) cookbook_day = Cookbook.objects.get_cookbook_date(school=school,group=group,date=the_date) print school,group,the_date print cookbook_day,'ccccccccccccccccccccccc' return helpers.ajax_ok('成功',con=cookbook_day) except: return helpers.ajax_error('失败')
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)
image = '' about_me = '' user_name = user.username url = media_path(image) # 消息对话链接 talk_link = reverse('user_umessages_history',kwargs={'uid':user.id}) show_talk = True if user.id != request.user.id else False info = { "about_me":about_me, "user_name":user_name, "avatar":url, "talk_link":talk_link, "show_talk":show_talk } return helpers.ajax_ok('成功',con=info) @login_required def vcar(request, template_name="kinger/includes/vcar.html"): """ 鼠标移动到头像,显示用户详情信息 """ uid = request.GET.get('uid') if not uid: return helpers.ajax_error('失败') uid = int(uid) try: user = User.objects.get(pk=uid) except Exception, e: return helpers.ajax_error('失败') is_mentor = False try:
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)
def get_extra_form(request,template_name="oa/extra_guardian_form.html"): order = int(request.POST.get('order')) ctx = {'order':order - 1} data = render(request,template_name,ctx) con=data.content return ajax_ok('成功',con)