def notifications():
        form = SendMessageForm()
        if request.method == 'POST' and form.validate_on_submit():
            subscribers = Subscriber.query.filter(Subscriber.subscribed).all()
            if len(subscribers) > 0:
                flash('Messages on their way!')
                twilio_services = TwilioServices()
                for s in subscribers:
                    twilio_services.send_message(s.phone_number, form.message.data, form.imageUrl.data)
            else:
                flash('No subscribers found!')

            form.reset()
            return view('notifications', form)

        return view('notifications', form)
예제 #2
0
    def notifications():
        form = SendMessageForm()
        if request.method == 'POST' and form.validate_on_submit():
            subscribers = Subscriber.query.filter(Subscriber.subscribed).all()
            if len(subscribers) > 0:
                flash('Messages on their way!')
                twilio_services = TwilioServices()
                for s in subscribers:
                    twilio_services.send_message(s.phone_number,
                                                 form.message.data,
                                                 form.imageUrl.data)
            else:
                flash('No subscribers found!')

            form.reset()
            return view('notifications', form)

        return view('notifications', form)
예제 #3
0
    def notifications():
        form = SendMessageForm()
        if request.method == 'POST' and form.validate():
            flash(form.language.data)
            flash(form.zipCode.data)
            for zip in form.zipCode.data:
                flash(zip.strip('u'))
            flash(form.interest.data)
            for i in form.interest.data:
                flash(i.strip('u'))
            flash(form.childAge.data)
            temp1 = set()
            subscribers = []
            flash(form.message.data)
            for zips in form.zipCode.data:
                if zips != "All":
                    tempzip = int(zips)
                    temp1.update(
                        Subscriber.query.filter(
                            Subscriber.zipcode == tempzip).all())
                else:
                    temp1.update(
                        Subscriber.query.filter(Subscriber.subscribed).all())
            if (form.language.data) == "Spanish":
                temp1.intersection_update(
                    Subscriber.query.filter(Subscriber.spanish).all())
            for i in (form.interest.data):
                if i == "All":
                    temp1.intersection_update(
                        Subscriber.query.filter(
                            Subscriber.interests == 4).all())
                elif i == "Science/Tech":
                    temp1.intersection_update(
                        Subscriber.query.filter(
                            Subscriber.interests == 1).all())
                elif i == "Arts":
                    temp1.intersection_update(
                        Subscriber.query.filter(
                            Subscriber.interests == 2).all())
                else:
                    temp1.intersection_update(
                        Subscriber.query.filter(
                            Subscriber.interests == 3).all())
            if form.childAge.data != "":
                ages = (form.childAge.data.split(" "))
                for age in ages:
                    if len(temp1) > 0:
                        for subs in temp1:
                            subages = subs.age.split(" ")
                            for subage in subages:
                                if subage == age:
                                    subscribers.append(subs)
            else:
                subscribers = temp1

            #temp2 = Subscriber.query.filter(Subscriber.age == form.childAge.data).all()
            #stemp2 = set(temp2)

            #subscribers= Subscriber.query.filter(Subscriber.subscribed).all()
            if len(subscribers) > 0:
                flash('Messages on their way!')
                twilio_services = TwilioServices()
                for s in subscribers:
                    twilio_services.send_message(s.phone_number,
                                                 form.message.data)
            else:
                flash('No subscribers found!')

            form.reset()
            return view('notifications', form)

        return render_template('notifications.html', form=form)
 def test_view_renders_the_same_template_as_render_template(self):
     # assert
     assert view('notifications') == render_template('notifications.html')