Exemple #1
0
def send_unread_cookbook(): 
    count = 0
    time_limit = datetime.datetime.now() + datetime.timedelta(seconds = -1800)
    has_send = Sms.objects.filter(type_id=3,send_time__gt=time_limit).count()
    if has_send:
        print '30分钟内已发送过短信'
        return '30分钟内已发送过短信'
    c_day = datetime.datetime.now() + datetime.timedelta(days = 1)
    date = c_day.date()
    cookbooks = Cookbook.objects.filter(date=date,is_send=False).exclude(breakfast='',light_breakfast='',
                lunch='',light_lunch='',dinner='',light_dinner='')
    
    school_cookbooks = cookbooks.filter(school__isnull=False)
    group_cookbooks = cookbooks.filter(group__isnull=False)
    group_pks = []
    if group_cookbooks:
        for gc in group_cookbooks:
            content = helpers.set_cookbook_content(gc)
            g_user = [s.user for s in gc.get_student()]
            group_pks.append(gc.group_id)
            for gu in g_user:
                if helpers.send_user_cookbook(gu,gc,content):
                    count = count + 1
                    
            gc.is_send = True
            gc.save()
                
    if school_cookbooks: 
        for sc in school_cookbooks:
            school_user =[]
            content = helpers.set_cookbook_content(sc)
            students = Student.objects.filter(school_id=sc.school_id).exclude(group_id__in=group_pks)
            school_user = [s.user for s in students]

            for su in school_user:
                if helpers.send_user_cookbook(su,sc,content):
                    count = count + 1
            
            sc.is_send = True
            sc.save()
            
    result = "send_unread_cookbook:"+str(count)
    return result
Exemple #2
0
def send_unread_cookbook(request): 
    count = 0
    c_day = datetime.datetime.now() + datetime.timedelta(days = 1)
    date = c_day.date()
    cookbooks = Cookbook.objects.filter(date=date,is_send=False).exclude(breakfast='',light_breakfast='',
                lunch='',light_lunch='',dinner='',light_dinner='')
    
    school_cookbooks = cookbooks.filter(school__isnull=False)
    group_cookbooks = cookbooks.filter(group__isnull=False)
    group_pks = []
    if group_cookbooks:
        for gc in group_cookbooks:
            content = helpers.set_cookbook_content(gc)
            g_user = [s.user for s in gc.get_student()]
            group_pks.append(gc.group_id)
            for gu in g_user:
                if helpers.send_user_cookbook(gu,gc,content):
                    count = count + 1
                    
            gc.is_send = True
            gc.save()
                
    if school_cookbooks: 
        for sc in school_cookbooks:
            school_user =[]
            content = helpers.set_cookbook_content(sc)
            students = Student.objects.filter(school_id=sc.school_id).exclude(group_id__in=group_pks)
            school_user = [s.user for s in students]

            for su in school_user:
                if helpers.send_user_cookbook(su,sc,content):
                    count = count + 1
            
            sc.is_send = True
            sc.save()
            
    result = "total push cookbooks:"+str(count)
    return HttpResponse(result)