Beispiel #1
0
    def update_user(data):
        try:
            simcard = Enduser.get_or_create_simcard(data.get('telephone'))
            if not simcard: return ( 'Bad Telephone', None)
            telephone = simcard.msisdn
            old_amb = Ambulance.get_ambulance(telephone)
            ## Check ambulance registered for the telephone
            if not old_amb:
                 return ( 'Ambulance does not exist with Telephone %s' % (telephone) , None)
            else:
                data.update({"indexcol": old_amb.indexcol})
                data.update({"simcard_pk": simcard.indexcol})
                data.update({"telephone": telephone})   
                #print "UPDATE DATA: ", data 
                migrate(Ambulance._table, data)
                amb = Ambulance.get_ambulance(telephone)
                if amb:                    
                    sent = Enduser.send_message(telephone, 
                        "Twabamenyeshaga ko mumaze gukosorwa imyirondoro muri sisitemu ya RapidSMS Rwanda, nk'ukurikirana imbagukira gutabara, ikigo nderabuzima cya %(hc)s, ibitaro bya %(hd)s. Murakoze."
                                                    % { 'hc': amb.facility_name, 'hd': amb.referral_facility_name })
                    sent = Enduser.send_message(telephone, 
                        "You have been updated in RapidSMS as ambulance coordinator, in %(hc)s health centre, %(hd)s district hospital. Thanks."
                                                    % { 'hc': amb.facility_name, 'hd': amb.referral_facility_name })
                       
                    if not sent:    return ("Ambulance Updated, but SMS not sent, please contact telephone: %(phone)s."
                                        % {'phone': amb.telephone}, amb)
                    return ( 'Ambulance Updated', amb)

                else:
                    return ( 'Ambulance with telephone %s cannot be updated, contact system administrator.' % (
                                                                        old_amb.telephone) , None)
            
        except Exception, e:
            print e
            pass
Beispiel #2
0
 def get_or_create( data):
     try:
         simcard = Enduser.get_or_create_simcard(data.get('telephone'))
         if not simcard: return ( 'Bad Telephone', None)
         telephone = simcard.msisdn
         amb = Ambulance.get_ambulance(telephone)
         if not amb:
             data.update({"simcard_pk": simcard.indexcol})
             data.update({"telephone": telephone})
             #print "SAVE DATA: ", data 
             migrate(Ambulance._table, data)
             amb = Ambulance.get_ambulance(telephone)
             sent = False
             sent = Enduser.send_message(telephone, 
                 "Twabamenyeshaga ko mumaze kwandikwa muri sisitemu ya RapidSMS Rwanda, nk'ukurikirana imbagukira gutabara, ikigo nderabuzima cya %(hc)s, ibitaro bya %(hd)s. Murakoze."
                                             % { 'hc': amb.facility_name, 'hd': amb.referral_facility_name })
             sent = Enduser.send_message(telephone, 
                 "You have been registered in RapidSMS as ambulance coordinator, in %(hc)s health centre, %(hd)s district hospital. Thanks."
                                             % { 'hc': amb.facility_name, 'hd': amb.referral_facility_name })
                
             if not sent:    return ("Ambulance Created, but SMS not sent, please contact telephone: %(phone)s."
                                 % {'phone': amb.telephone}, amb)
             return ( 'Ambulance created', amb)
         return ( 'Ambulance exists', amb)
     except Exception, e:
         print e
         pass