Example #1
0
 def encode(self, incoming_msg, **kwargs):
     answer, cmd = incoming_msg.process()
     if answer and cmd:
         if cmd.command.account.customer.user_ptr == incoming_msg.access.account_set.all()[0].customer.user_ptr:
             id = Message.create_one(answer, incoming_msg.mobile, datetime.datetime.now(), cmd.command.account)
             if id < 0:
                 log.error("Error while trying to create a msg response: info = %s", kwargs)
             else:
                 log.debug("Response mesage %s to %s: %s", id, incoming_msg.mobile[1:], answer)
         else:
             log.error("% user cannot receive msgs from %s access", cmd.command.account.customer.user_ptr, incoming_msg.access)
     else:
         log.error(cmd)
Example #2
0
def lista_contactos(request):
    rc = RequestContext(request)
    context = {'profile': request.session['profile'] }
    context['crumbs'] = ( ( _('Home') , reverse('root') ),
                          ( _('Contact list') , reverse('contacto_listar') ),
                        )
    info(request, 'lista_contactos', 'Listing contacts')
    setLeftMenu(request, contactMenu(request), _(u'Summary'))
    context['object_list'] = request.user.contacto_set.all()
    if request.POST:
        data = request.POST
        msg = Message.easy_create(data['text'], adapt_mobile(data['mobile']), request.user)
        context['msg'] = msg
    return render_to_response('addressbook/listar_contactos.html',context, rc)
Example #3
0
def send_sms(username, password, account, phoneNumber, text, activationDate = None):
    """
        Send a text msg to a phone over an account given
    """
    try:
        account = Customer.check_customer_and_credit(username, password, account)
    except OutOfCredit:
        return ACCOUNT_NO_CREDIT 
    if account < 0:
        return account
    if not activationDate:
        activationDate = datetime.datetime.now()
    phoneNumber = check_mobile(phoneNumber)
    if phoneNumber < 0:
        return phoneNumber
    return Message.create_one(text, phoneNumber, activationDate, account)
Example #4
0
def send_sms_many(username, password, account, phoneList, text, activationDate = None):
    """
        Send a text msg to a many phones over an account given
    """
    try:
        account = Customer.check_customer_and_credit (username, password, account, len(phoneList))
    except OutOfCredit:
        return [ACCOUNT_NO_CREDIT]
    if account < 0:
        return [account]
    activationDate = datetime.datetime.now ()
    idlist = []
    for phone in phoneList:
        if check_mobile(phone) < 0:
            return [-50] # FIXME: cambiar esto por MobileErrorException cuando se implemente
    for phone in phoneList:
        phone = phone.strip()
        idlist.append(Message.create_one (text, phone, activationDate, account))
    return idlist
Example #5
0
 def doInfo(self, mobile, *args):
     body_id = self.command.defaultAnswer.id        
     # Channel means body_id. Would be wise to change it.
     Message.create_one('', mobile, datetime.datetime.now(), self.command.account, body_id=body_id)
     # create_one doesnt return any values.
     return _("INFO %s") % self.channel.name
Example #6
0
 def test_put_in_the_queue (self):
     self.assertEqual(0, SMSQueue.objects.all().count())
     id = Message.create_one (self.text, self.phoneNumber, self.now, self.OKaccount)
     m = Message.objects.get (id = id)
     m.put_in_the_queue ()
     self.assertEqual (1, SMSQueue.objects.all().count())
Example #7
0
 def test_create_one_ok (self):
     Message.create_one (self.text, self.phoneNumber, self.now, self.OKaccount)
     self.assertEqual (3, Message.objects.all().count())