Exemple #1
0
 def post(self):
     q_id = int(self.request.get('q_id'))
     q = QueueEntry.get_by_id(q_id)
     twilio_settings = TwilioSettings.all().get()
     schedule = SMSSchedule.all().get()
     tclient = TwilioRestClient(twilio_settings.account_sid, twilio_settings.auth_token)
     if q and q.status == 'P':
         employees = Employee.all()
         for employee in employees:
             entry = ReportingEntry.all().filter('reporting_date = ', q.report_date).filter('mobile_number =', employee.mobile_number).get()
             if not entry:
                 entry = ReportingEntry(name = employee.name, 
                            mobile_number = employee.mobile_number,
                            email = employee.email,
                            reporting_date = q.report_date,
                            reporting_location = "NOT REPORTED",
                            reporting_time = None,
                            employee = employee)
                 entry.put() 
             if schedule.status=='Active':                
                 tclient.sms.messages.create(to = employee.mobile_number, from_ = twilio_settings.twilio_number, body = schedule.message[:160])
                 smslog = SMSLog(message = schedule.message[:160],
                                 from_number = twilio_settings.twilio_number,
                                 to_number = employee.mobile_number,
                                 direction = 'outgoing-scheduled',
                                 employee_name = employee.name)
                 smslog.put()
         q.status = 'S'
         q.save()
Exemple #2
0
 def get(self):
     page = int(self.request.get('page',0))
     next_page = page +1
     logs = SMSLog.all().order('-created').fetch(PAGE_SIZE, PAGE_SIZE * page)
     next_count = len(SMSLog.all().order('-created').fetch(PAGE_SIZE, next_page*PAGE_SIZE))
     has_next = next_count > 0
     has_previous = page > 0
     context = {'logs':logs,'page':page,'next_page':next_page,'has_next':has_next,'has_previous':has_previous}
     self.response.headers['Content-Type'] = 'text/html'
     self.render_response('logs.html',**context)
Exemple #3
0
 def get(self):
     fromNumber = self.request.get('From')
     to = self.request.get('To')
     body = self.request.get('Body')
     if fromNumber != '':
         fromNumber =  fromNumber[-10:]
     smslog_incoming = SMSLog(message = body,
                     from_number = fromNumber,
                     to_number = to,
                     direction = 'incoming',
                     employee_name = '** NOT AN EMPLOYEE')
     
     employee = Employee.all().filter('mobile_number =', fromNumber).get()
     utc = timezone.UTC()
     est = timezone.Eastern_tzinfo()
     now = datetime.now()
     in_est = now.replace(tzinfo=utc).astimezone(est)
     schedule = SMSSchedule.all().get()
     if employee:
         smslog_incoming.employee_name = employee.name
         smslog_incoming.put()
         entry = ReportingEntry.all().filter('reporting_date = ', in_est.date()).filter('mobile_number =', employee.mobile_number).get()
         if not entry:
             entry = ReportingEntry(name = employee.name, 
                            mobile_number = employee.mobile_number,
                            email = employee.email,
                            reporting_date = in_est.date(),
                            reporting_location = body,
                            employee = employee)
             entry.put()
         else:
             entry.reporting_location = body
             entry.save()           
         logging.debug(" From: %s"%fromNumber)
         if schedule and schedule.auto_reply_enabled=='Y' and schedule.auto_reply!=None and schedule.auto_reply!='':
             r = twiml.Response()
             r.sms(schedule.auto_reply[:160])
             smslog = SMSLog(message = schedule.auto_reply[:160],
                     from_number = to,
                     to_number = fromNumber,
                     direction = 'outgoing-reply',
                     employee_name = employee.name)
             smslog.put()
             self.response.out.write(r)