Exemplo n.º 1
0
    def create(self, name=None, hostname=None, phonenumber=None):
        agent = Agent()
        
        if name is not None:
            agent.name = name
        if hostname is not None:
            agent.hostname = hostname
        if phonenumber is not None:
            agent.phonenumber = phonenumber

        if agent.save() > 0:
            return agent
Exemplo n.º 2
0
 def get_byphonenumber(self, phonenumber, create_if_nonexist=False):
     try:
         agent = Agent.get(Agent.phonenumber == phonenumber)
     except Agent.DoesNotExist:
         if create_if_nonexist:
             agent = self.create(phonenumber=phonenumber)
     
     return agent
Exemplo n.º 3
0
    def get_byhostname(self, hostname, create_if_nonexist=False):
        try:
            agent = Agent.get(Agent.hostname == hostname)
        except Agent.DoesNotExist:
            if create_if_nonexist:
                agent = self.create(hostname=hostname)

        return agent
Exemplo n.º 4
0
    def get_byname(self, name, create_if_nonexist=False):
        try:
            agent = Agent.get(Agent.name == name)
        except Agent.DoesNotExist:
            if create_if_nonexist:
                agent = self.create(name=name)

        return agent