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()