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 send_emergency_message_unlogin(): print 'send_emergency_message_unlogin---------------' count = 0 time_start = datetime.datetime.now() + datetime.timedelta(weeks = -1) time_end = datetime.datetime.now() sql = "select a.id,a.user_id,a.message_id,c.sender_id,c.body from umessages_messagerecipient a left join umessages_message c on a.message_id = c.id where c.type=1 and c.sent_at>'" + str(time_start) + "' and c.sent_at<'" + str(time_end) + "' and a.no_need_send=0 and a.is_send =0 and a.read_at is null limit 0,1000" cursor = connection.cursor() cursor.execute(sql) desc = cursor.description unread_list = [dict(zip([col[0] for col in desc], row)) for row in cursor.fetchall()] for m in unread_list: try: user = User.objects.get(pk=m['user_id']) times = Access_log.objects.filter(user=user).count() if times == 0: msg = Sms() msg.sender_id = m['sender_id'] msg.receiver_id = m['user_id'] msg.mobile = User.objects.get(pk=m['user_id']).get_profile().mobile msg.type_id = 5 msg.content = str(m['body']) + '/' + str(User.objects.get(pk=m['sender_id']).get_profile().chinese_name_or_username()) msg.save() unread = MessageRecipient.objects.get(pk=m['id']) unread.is_send = 1 unread.save() count = count + 1 except: pass result = "send_emergency_message:"+str(count) print result,'rrrrrrrrrrr--------------------------------------' return result
def send_emergency_message(request): count = 0 time_start = datetime.datetime.now() + datetime.timedelta(weeks = -1) time_end = datetime.datetime.now() + datetime.timedelta(seconds = -300) sql = "select a.id,a.user_id,a.message_id,c.sender_id,c.body from umessages_messagerecipient a left join umessages_message c on a.message_id = c.id where c.type=1 and c.sent_at>'" + str(time_start) + "' and c.sent_at<'" + str(time_end) + "' and a.no_need_send=0 and a.is_send =0 and a.read_at is null limit 0,1000" cursor = connection.cursor() cursor.execute(sql) desc = cursor.description unread_list = [dict(zip([col[0] for col in desc], row)) for row in cursor.fetchall()] for m in unread_list: msg = Sms() msg.sender_id = m['sender_id'] msg.receiver_id = m['user_id'] msg.mobile = User.objects.get(pk=m['user_id']).get_profile().mobile msg.type_id = 5 msg.content = m['body'] msg.save() unread = MessageRecipient.objects.get(pk=m['id']) unread.is_send = 1 unread.save() count = count + 1 result = "total push message:"+str(count) return HttpResponse(result)
def send_staff_mobile(mobile,msg): from kinger.models import Sms mes = Sms() mes.sender_id = 1 mes.receiver_id = -1 mes.mobile = mobile mes.type_id = 99 mes.content = msg mes.save() return True
def send_user_cookbook(user,cookbook,content): from kinger.models import CookbookRead,Sms c = CookbookRead.objects.set_cookbook_unread(user=user,cookbook=cookbook,ty="send") if not c: return False msg = Sms() msg.sender_id = cookbook.creator_id msg.receiver_id = user.id msg.mobile = user.get_profile().mobile msg.type_id = 3 msg.content = content msg.save() return True
def send_user_message(): count = 0 time_limit = datetime.datetime.now() + datetime.timedelta(weeks = -1) users = [s.user for s in Student.objects.all() if s.user.get_profile().last_access_time() < time_limit] for user in users: has_send = Sms.objects.filter(type_id=98,send_time__gt=time_limit,receiver_id=user.id).count() if not has_send: unread_count = Tile.objects.count_unread_tiles_for(user) if unread_count: msg = Sms() msg.sender_id = 1 msg.receiver_id = user.id msg.mobile = user.get_profile().mobile msg.type_id = 98 msg.content = "您有" + str(unread_count) + "条新内容未查看,您可以登陆网站或者安装客户端来查看,详情请登录" + str(SITE_INFO.domain) + "[" + str(SITE_INFO.name) + "]" msg.save() count = count + 1 result = "send_user_message:"+str(count) return result
def send_user_message(request): count = 0 time_limit = datetime.datetime.now() + datetime.timedelta(weeks = -1) users = [s.user for s in Student.objects.all() if s.user.get_profile().last_access_time() < time_limit] for user in users: has_send = Sms.objects.filter(type_id=98,send_time__gt=time_limit,receiver_id=user.id).count() if not has_send: unread_count = Tile.objects.count_unread_tiles_for(user) if unread_count: msg = Sms() msg.sender_id = 1 msg.receiver_id = user.id msg.mobile = user.get_profile().mobile msg.type_id = 98 msg.content = "您有" + str(unread_count) + "条新内容未查看,您可以登陆网站或者安装客户端来查看,详情请登录 http://jytn365.com/welcom [记忆童年]" msg.save() count = count + 1 result = "total push user_message:"+str(count) return HttpResponse(result)
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)
def write_document(request,template_name="supply/document_form.html"): """撰写公文""" ctx = {} school = get_schools(request.user)[0] teachers = Teacher.objects.filter(school=school) categorys = SupplyCategory.objects.filter(school=school) schools = get_schools(request.user) if request.method == 'POST': form = MaterialForm(request.POST) receiver_pks = request.POST.getlist("to") teacher_list = User.objects.filter(pk__in=receiver_pks) approvaler_pk = request.POST.get("approvaler",'') sid = request.POST.get('sid','') if sid: sup_school = get_object_or_404(School,id=sid) else: sup_school = school try: approvaler = User.objects.get(pk=approvaler_pk) except: approvaler = None ctx.update({'teacher_list':teacher_list,'approvaler':approvaler}) if form.is_valid(): doc = form.save(commit=False) doc.school = school doc.sender = request.user doc.save() print doc.type,'tttttttttttttttttttttttt' #发布对象 for t in teacher_list: receiver = MaterialReceiver() receiver.user = t receiver.document = doc receiver.save() #送审 approvaler_pk = request.POST.get("approvaler",0) if doc.is_submit and approvaler_pk: approvaler = User.objects.get(pk=approvaler_pk) appr = MaterialApproval() appr.sender = doc.sender appr.document = doc appr.remark = doc.remark appr.approvaler = approvaler appr.send_time = datetime.datetime.now() appr.save() doc.remark = '' doc.save() #发送短信 if doc.send_msg and doc.msg_body: msg = Sms() msg.sender = doc.sender msg.receiver = approvaler msg.mobile = approvaler.get_profile().mobile msg.type_id = 7 msg.content = str(doc.msg_body) + '/' + str(doc.sender.get_profile().chinese_name_or_username()) msg.save() desc = request.POST.get("applies") apply = json.loads(desc) for i in apply: supply,created = Supply.objects.get_or_create(name=apply[i]['name'],category_id=apply[i]['cat'],parent_id=0,school=sup_school) if created: supply.creator = request.user supply.is_show = False supply.save() apl = MaterialApply(supply=supply,document=doc,num=apply[i]['num'],school=sup_school) apl.save() messages.success(request, u"撰写公文成功") if doc.status == 1: return redirect('oa_supply_personal_document') else: return redirect('oa_supply_issued_document') else: form = MaterialForm() ctx.update({'form':form,'teachers':teachers,'schools':schools,'categorys':categorys}) return render(request, template_name, ctx)