Beispiel #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()
Beispiel #2
0
 def get(self):
     self.response.headers['Content-Type'] = 'text/html'
     utc = timezone.UTC()
     est = timezone.Eastern_tzinfo()
     now = datetime.now()
     in_est = now.replace(tzinfo=utc).astimezone(est)
     entries = ReportingEntry.all().filter('reporting_date =', in_est.date())
     context = {'entries':entries,'reporting_date':in_est.date()}
     self.render_response('index.html', **context)
Beispiel #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)
Beispiel #4
0
 def post(self):
     try:
         key = self.request.get('key')
         entityType = self.request.get('type')
         if entityType == 'employee':
             emp = db.get(key)
             try:
                 db.delete(emp.entries.filter('reporting_date = ', current_reportng_date()))
             except:
                 pass
             try:
                 db.delete(ReportingEntry.all()
                       .filter('reporting_date =', current_reportng_date())
                       .filter('mobile_number =', emp.mobile_number))
             except:
                 pass
         db.delete(key)
         result_dict = {'success':True}
     except:
         result_dict = {'success':False}
         raise
     self.response.headers['Content-Type'] = 'application/json'
     self.response.out.write(json.dumps(result_dict))