def get_user_info(request): """ 鼠标移动到头像,显示用户详情信息 """ 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('失败')
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('失败')
def user_role(request, template_name="oa/teacher_user_role.html"): """ 分配用户角色 """ uid = request.POST.get('user_id') if not uid: return ajax_error('失败') uid = int(uid) try: user = User.objects.get(pk=uid) except Exception, e: return ajax_error('失败')
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 role_detail(request, template_name="oa/role_detail.html"): """ 角色详情 """ rid = request.POST.get('role_id') if not rid: return ajax_error('失败') rid = int(rid) try: role = Role.objects.get(pk=rid) except Exception, e: return helpers.ajax_error('失败')
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_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 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 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)
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 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)