Example #1
0
 def save(self, commit=True):
     instance = super(singleAdminCommandForm, self).save(commit=False)
     instance.type = ADMIN
     ans = Body(plainTxt = self.cleaned_data['answer'])
     ans.save()
     instance.defaultAnswer = ans
     # Getting a translation if available
     try:
         index = int(self.cleaned_data['action'])            
         actionName = getNameFromTuple(ADMIN_COMMAND_LIST_CHOICES, index)
         translatedCommandType = ADMIN_COMMAND_TRANSLATION[self.language][actionName]
     except KeyError:
         translatedCommandType = actionName
          
     channel = Channel.objects.get(pk=self.cleaned_data['channel'])
     instance.pattern = translatedCommandType + ASCII_SPACE + channel.name                
     if commit:
         # Already existing commands are deleted
         try:
             oldcommand = Command.objects.get(pattern=instance.pattern)
             oldcommand.delete()
         except Command.DoesNotExist:
             pass            
         instance.save()            
         adminInstance = AdminCommand()
         adminInstance.command = instance
         adminInstance.channel = channel
         adminInstance.action = self.cleaned_data['action']
         adminInstance.save()            
     return instance
Example #2
0
 def create_one (mobile, text, date, account, body = None):
     """
         Create one message and left it waiting to be processed by the daemon
     """
     if not body:
         body = Body(plainTxt=text, mms=False, encodedMsg=text)
         body.save ()
     m = IncomingMessage(body=body, mobile=mobile, account=account, receivedDate = date, creationDate = datetime.datetime.now())
     m.save()
     return m
Example #3
0
 def save(self, commit=True):
     try:
         itemCommand = Command.objects.get(pattern = self.cleaned_data['pattern'])
         if itemCommand.activationDate > self.cleaned_data['activationDate']:
             itemCommand.activationdate = self.cleaned_data['activationDate']
         if itemCommand.deactivationDate < self.cleaned_data['deactivationDate']:
             itemCommand.deactivationDate = self.cleaned_data['deactivationDate']
     except Command.DoesNotExist:
         itemCommand = super(forms.ModelForm, self).save(commit=False)
     itemCommand.type = REPLY    #type: ReplyCommand
     itemCommand.defaultAnswer = None
     if commit:
         itemCommand.save()
         itemTxt = Body(plainTxt=self.cleaned_data['answer'], mms=False)
         itemTxt.save()
         itemReplyCommand = ReplyCommand(command=itemCommand, startTime=self.cleaned_data['activationDate'], 
                                         endTime=self.cleaned_data['deactivationDate'], answer=itemTxt)
         itemReplyCommand.save()
     return itemCommand
    def setUp(self):
        self.admin_name = 'proveedorBase'
        self.admin_pass = '******'
        
        self.customer_name = 'clienteBase'
        self.customer_pass = '******'
        
        self.account_name = 'cuentaBase'
        self.account_name2 = 'cuentaNoPurchase'
        self.account_name3 = 'cuentaVariosPurchase'
        
        self.purchase_id = 1        

        acc = Account.objects.get(name = self.account_name)
       
        cmd = Command(pattern = 'CANDELARIA AVISO', type = REPLY, active = True,
                      account = acc, priority = 0)
        cmd.save()
        body = Body(plainTxt = 'DUMMY ENCODE')
        body.save()
        rep = ReplyCommand(command = cmd, answer = body)
        rep.save()
Example #5
0
 def clean(self, text):        
     if text is u'':
         return None
     itemTxt = Body(plainTxt=text, mms=False)
     itemTxt.save()
     return itemTxt