예제 #1
0
    def post(self):
        from sosbeacon.responde_sms import Responder
        from sosbeacon.event.message import Message
        from sosbeacon.event.contact_marker import mark_as_acknowledged

        from_number = self.request.get('From', None)
        from_body = self.request.get('Body', None)

        responder_sms_list = Responder.query(Responder.contact_number == from_number)
        responder_sms_filter = responder_sms_list.order(Responder.added).fetch()
        responder_sms = responder_sms_filter[-1]

        if responder_sms.is_admin == True:
            message = {
                'event': responder_sms.event,
                'type': 'c',
                'is_student': False,
                'user_name': responder_sms.contact_first_name + " " + responder_sms.contact_last_name + " - " + str(from_number),
                'message': {'body': from_body},
                'longitude': '',
                'latitude': '',
            }
            entity = Message.from_dict(message)
            entity.is_admin = True
            entity.user = None
            entity.put()
            return

        mark_as_acknowledged(responder_sms.event, responder_sms.contact_marker)

        message = {
            'event': responder_sms.event,
            'type': 'c',
            'is_student': False,
            'user_name': responder_sms.contact_first_name + " " + responder_sms.contact_last_name + " - " + str(from_number),
            'message': {'body': from_body},
            'longitude': '',
            'latitude': '',
        }
        entity = Message.from_dict(message)
        entity.is_admin = False
        entity.user = None
        entity.put()
예제 #2
0
    def test_from_dict_email_call_payload(self, message_alloc_ids_mock, queue_add_mock):
        """Ensure email call message with correct payload and type works."""
        from sosbeacon.event.event import Event
        from sosbeacon.event.message import Message

        message_alloc_ids_mock.return_value = 1, 1

        event = Event(title="test")
        event_key = Mock()
        event_key.get.return_value = event

        message_dict = {"event": event_key, "type": "ec", "message": {"sms": "", "email": "The email message here."}}

        message = Message.from_dict(message_dict)

        self.assertEqual("ec", message.message_type)
        self.assertEqual(message_dict["message"]["email"], message.message["email"])
예제 #3
0
    def test_from_dict_comment_payload(self, message_alloc_ids_mock):
        """Ensure message with comment payload and type works OK."""
        from google.appengine.api import namespace_manager

        from sosbeacon.event.event import Event
        from sosbeacon.event.message import Message

        message_alloc_ids_mock.return_value = 1, 1

        event = Event()
        event_key = Mock()
        event_key.get.return_value = event

        message_dict = {"event": event_key, "type": "c", "message": {"body": "A Comment here."}}

        message = Message.from_dict(message_dict)

        self.assertEqual("c", message.message_type)
        self.assertEqual(message_dict["message"]["body"], message.message["body"])
예제 #4
0
    def test_from_dict_broadcast_payload(self, message_alloc_ids_mock, queue_add_mock):
        """Ensure broadcast message with correct payload and type works."""
        from google.appengine.api import namespace_manager

        from sosbeacon.event.event import Event
        from sosbeacon.event.message import Message

        message_alloc_ids_mock.return_value = 1, 1

        event = Event(title="test")
        event_key = Mock()
        event_key.get.return_value = event

        message_dict = {
            "event": event_key,
            "type": "b",
            "message": {"sms": "Your SMS message here.", "email": "The email message here."},
        }

        message = Message.from_dict(message_dict)

        self.assertEqual("b", message.message_type)
        self.assertEqual(message_dict["message"]["sms"], message.message["sms"])
        self.assertEqual(message_dict["message"]["email"], message.message["email"])
예제 #5
0
    def get(self, event_id, number, *args, **kwargs):
        import sendgrid
        import settings
        from datetime import datetime
        from sosbeacon.event.message import Message
        from sosbeacon.event.student_marker import StudentMarker

        session_store = sessions.get_store()
        session = session_store.get_session()
        user_urlsafe = session.get('u')

        user_key = ndb.Key(urlsafe = user_urlsafe).get()
        event_key = ndb.Key(urlsafe = event_id)
        query_messages = Message.query(Message.event == event_key).fetch()

        body = ""

        for i in number:
        #           list comment message
            if i == "1":
                list_comment = Message.query(Message.event == event_key,
                    Message.message_type == 'c')
                title       = "Responder messages"
                body += str(self.responder_messages(user_key, title, list_comment))

            #           list student marker Responders
            if i == "2":
                query_response = StudentMarker.query(StudentMarker.event == event_key,
                    StudentMarker.is_direct == True,
                    StudentMarker.acknowledged == True)
                student_markers = query_response.fetch()
                title = "Responder List"
                body += str(self.email_student_marker(student_markers, title))

            #           list student marker Non Responders
            if i == "3":
                query_response = StudentMarker.query(StudentMarker.event == event_key,
                    StudentMarker.acknowledged == False, StudentMarker.is_direct == True)
                student_markers = query_response.fetch()
                title = "No Responder List"
                body += str(self.email_student_marker(student_markers, title))

            #           list message email
            if i == "4":
                title = "Alert Messages"
                body += str(self.email_broadcast_message(user_key, title, query_messages))

        today       = datetime.today()
        today       = today.strftime('%Y-%m-%d %H:%M')
        subject     = "Download data sent from SOSbeacon Message Center %s" % today
        email       = user_key.email

        s = sendgrid.Sendgrid(settings.SENDGRID_ACCOUNT,
            settings.SENDGRID_PASSWORD,
            secure=True)

        message = sendgrid.Message(
            settings.SENDGRID_SENDER,
            subject,
            body, body)

        message.add_to(str(email))
        try:
            s.web.send(message)
        except:
            error = "Can not download email."
            create_error_log(error, 'ERR')
예제 #6
0
    def get(self, event_id, number, *args, **kwargs):
        import sendgrid
        import settings
        from datetime import datetime
        from sosbeacon.event.message import Message
        from sosbeacon.event.student_marker import StudentMarker

        session_store = sessions.get_store()
        session = session_store.get_session()
        user_urlsafe = session.get('u')

        user_key = ndb.Key(urlsafe=user_urlsafe).get()
        event_key = ndb.Key(urlsafe=event_id)
        query_messages = Message.query(Message.event == event_key).fetch()

        body = ""

        for i in number:
            #           list comment message
            if i == "1":
                list_comment = Message.query(Message.event == event_key,
                                             Message.message_type == 'c')
                title = "Responder messages"
                body += str(
                    self.responder_messages(user_key, title, list_comment))

            #           list student marker Responders
            if i == "2":
                query_response = StudentMarker.query(
                    StudentMarker.event == event_key,
                    StudentMarker.is_direct == True,
                    StudentMarker.acknowledged == True)
                student_markers = query_response.fetch()
                title = "Responder List"
                body += str(self.email_student_marker(student_markers, title))

            #           list student marker Non Responders
            if i == "3":
                query_response = StudentMarker.query(
                    StudentMarker.event == event_key,
                    StudentMarker.acknowledged == False,
                    StudentMarker.is_direct == True)
                student_markers = query_response.fetch()
                title = "No Responder List"
                body += str(self.email_student_marker(student_markers, title))

            #           list message email
            if i == "4":
                title = "Alert Messages"
                body += str(
                    self.email_broadcast_message(user_key, title,
                                                 query_messages))

        today = datetime.today()
        today = today.strftime('%Y-%m-%d %H:%M')
        subject = "Download data sent from SOSbeacon Message Center %s" % today
        email = user_key.email

        s = sendgrid.Sendgrid(settings.SENDGRID_ACCOUNT,
                              settings.SENDGRID_PASSWORD,
                              secure=True)

        message = sendgrid.Message(settings.SENDGRID_SENDER, subject, body,
                                   body)

        message.add_to(str(email))
        try:
            s.web.send(message)
        except:
            error = "Can not download email."
            create_error_log(error, 'ERR')
예제 #7
0
    def post(self):
        from sosbeacon.responde_sms import Responder
        from sosbeacon.event.message import Message
        from sosbeacon.event.contact_marker import mark_as_acknowledged

        from_number = self.request.get('From', None)
        from_body = self.request.get('Body', None)

        responder_sms_list = Responder.query(
            Responder.contact_number == from_number)
        responder_sms_filter = responder_sms_list.order(
            Responder.added).fetch()
        responder_sms = responder_sms_filter[-1]

        if responder_sms.is_admin == True:
            message = {
                'event':
                responder_sms.event,
                'type':
                'c',
                'is_student':
                False,
                'user_name':
                responder_sms.contact_first_name + " " +
                responder_sms.contact_last_name + " - " + str(from_number),
                'message': {
                    'body': from_body
                },
                'longitude':
                '',
                'latitude':
                '',
            }
            entity = Message.from_dict(message)
            entity.is_admin = True
            entity.user = None
            entity.put()
            return

        mark_as_acknowledged(responder_sms.event, responder_sms.contact_marker)

        message = {
            'event':
            responder_sms.event,
            'type':
            'c',
            'is_student':
            False,
            'user_name':
            responder_sms.contact_first_name + " " +
            responder_sms.contact_last_name + " - " + str(from_number),
            'message': {
                'body': from_body
            },
            'longitude':
            '',
            'latitude':
            '',
        }
        entity = Message.from_dict(message)
        entity.is_admin = False
        entity.user = None
        entity.put()