Example #1
0
 def save(self,obj=None):
     from abon.models import Address,Person,Abonent
             
     try:
         address = Address.objects.get(pk=self.cleaned_data['address_id'])
     except Address.DoesNotExist:
         return (False,obj,'address not found')
     try:
         person = Person.objects.get(pk=self.cleaned_data['person_id'])
     except Person.DoesNotExist:
         return (False,obj,'person not found')
     
     msg=''
     if obj and obj.pk:
         pass
     else:
         try: 
             obj = Abonent.objects.get(person=person,address=address)
         except Abonent.DoesNotExist:
             pass
             obj = Abonent(disabled=True)
         else:
             msg='Абонент существует... режим редактирования включён...'            
                         
             
     obj.person = person
     obj.address = address
     #obj.activated = self.cleaned_data['activated']
     #obj.deactivated = self.cleaned_data['deactivated']
     obj.deleted = self.cleaned_data['deleted'] or False
     obj.confirmed = self.cleaned_data['confirmed'] or False
     obj.comment = self.cleaned_data['comment']
     try:
         obj.save()
     except IntegrityError as error:
         return (False,obj,error[1].decode('utf8'))
     else:
         return (True,obj,msg)
Example #2
0
    def save(self, obj=None):
        from abon.models import Address, Person, Abonent

        try:
            address = Address.objects.get(pk=self.cleaned_data["address_id"])
        except Address.DoesNotExist:
            return (False, obj, "address not found")
        try:
            person = Person.objects.get(pk=self.cleaned_data["person_id"])
        except Person.DoesNotExist:
            return (False, obj, "person not found")

        msg = ""
        if obj and obj.pk:
            pass
        else:
            try:
                obj = Abonent.objects.get(person=person, address=address)
            except Abonent.DoesNotExist:
                pass
                obj = Abonent(disabled=True)
            else:
                msg = "Абонент существует... режим редактирования включён..."

        obj.person = person
        obj.address = address
        # obj.activated = self.cleaned_data['activated']
        # obj.deactivated = self.cleaned_data['deactivated']
        obj.deleted = self.cleaned_data["deleted"] or False
        obj.confirmed = self.cleaned_data["confirmed"] or False
        obj.comment = self.cleaned_data["comment"]
        try:
            obj.save()
        except IntegrityError as error:
            return (False, obj, error[1].decode("utf8"))
        else:
            return (True, obj, msg)
Example #3
0
def hamsters_swarm(fa, fb, ts=0, tc=0, tr=0):
    from abon.models import Abonent
    Abonent.hamsters_swarm(fa, fb, ts, tc, tr)