Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
0
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
Ejemplo n.º 5
0
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
Ejemplo n.º 6
0
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
Ejemplo n.º 7
0
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)