Exemple #1
0
def dailysend():

    now = timezone.now()
    #today = now.replace(hour=0,minute=0,second=0,microsecond=0)
    today = now.date()

    #Fetch active subscriptions and loop
    subs = Subscription.objects.filter(active=True)
    for S in subs:

        #First, quit if today is invalid for the subscription
        if not S.check_today(): continue

        #Second, look for a dailySend record for today
        dS = None
        [dS, new] = dailySend.objects.get_or_create(subscription=S,
                                                    next_send_date=today)

        #Create a new dailySend record if one doesn't exist
        if new:
            msg = do.next_message(S)
            dS.message = msg
            dS.save()
            set_send_time(S, dS)

            #If the dailySend is new, create sentMessages for all activeSubscriptions
            activeSubs = activeSubscription.objects.filter(subscription=S,
                                                           active=True)
            for aS in activeSubs:
                [sM, new
                 ] = sentMessage.objects.get_or_create(active_subscription=aS,
                                                       message=msg,
                                                       next_send_date=today,
                                                       daily_send=dS)
                if new:
                    sM.next_send = get_send_time(dS, aS)
                    sM.save()

    #Now try to send any eligible sentMessage records
    sentMessages = []
    toSend = sentMessage.objects.filter(next_send_date=today,
                                        next_send__lt=now,
                                        attempted__lt=2)
    for sM in toSend:
        if sM.active_subscription.active == False: continue
        if sM.active_subscription.subscription.active == False: continue
        sentMessages.append(sM)
    if sentMessages != []: do.send_to_all(sentMessages)

    return (None)
Exemple #2
0
def dailysend():

    now = timezone.now()
    #today = now.replace(hour=0,minute=0,second=0,microsecond=0)
    today = now.date()

    #Fetch active subscriptions and loop
    subs = Subscription.objects.filter(active=True)
    for S in subs:

        #First, quit if today is invalid for the subscription
        if not S.check_today(): continue

        #Second, look for a dailySend record for today
        dS = None
        [dS,new] = dailySend.objects.get_or_create(subscription=S,next_send_date=today)

        #Create a new dailySend record if one doesn't exist
        if new:
            msg = do.next_message(S)
            dS.message = msg
            dS.save()
            set_send_time(S,dS)

            #If the dailySend is new, create sentMessages for all activeSubscriptions
            activeSubs = activeSubscription.objects.filter(subscription=S,active=True)
            for aS in activeSubs:
                [sM,new] = sentMessage.objects.get_or_create(active_subscription=aS,message=msg,next_send_date=today,daily_send=dS)
                if new:
                    sM.next_send = get_send_time(dS,aS)
                    sM.save()

    #Now try to send any eligible sentMessage records
    sentMessages = []
    toSend = sentMessage.objects.filter(next_send_date=today,next_send__lt=now,attempted__lt=2)
    for sM in toSend:
        if sM.active_subscription.active == False: continue
        if sM.active_subscription.subscription.active == False: continue
        sentMessages.append(sM)
    if sentMessages != []: do.send_to_all(sentMessages)

    return(None)
Exemple #3
0
def send(request):
    if request.method == 'POST':
        form = sendForm(request.POST, request.FILES)
        if form.is_valid():
            cd = form.cleaned_data
            sub = cd['subscription']
            msg = cd['message']
            if msg != None:
                if msg.subscription != sub:
                    return HttpResponse("Fail. Be sure to select a message that is for the selected subscription")
            res = send_to_all(sub, msgObj=msg)
            return render_to_response('send_results.html', res)
        return HttpResponse("Fail" + str(form.errors))
    else:
        form = sendForm
    out = {'form': form}
    out.update(csrf(request))
    return render_to_response('send.html', out)
Exemple #4
0
def send(request):
    if request.method == 'POST':
        form = sendForm(request.POST, request.FILES)
        if form.is_valid():
            cd = form.cleaned_data
            sub = cd['subscription']
            msg = cd['message']
            if msg != None:
                if msg.subscription != sub:
                    return HttpResponse(
                        "Fail. Be sure to select a message that is for the selected subscription"
                    )
            res = send_to_all(sub, msgObj=msg)
            return render_to_response('send_results.html', res)
        return HttpResponse("Fail" + str(form.errors))
    else:
        form = sendForm
    out = {'form': form}
    out.update(csrf(request))
    return render_to_response('send.html', out)