def get_connections(reporter):
    connections = None
    try:
        connections = Connection.objects.filter(
            identity=reporter.telephone_moh)

    except Exception, e:
        contact, created = Contact.objects.get_or_create(
            name=reporter.national_id)
        if reporter.language: contact.language = reporter.language.lower()
        else: contact.language = 'rw'

        backends = Backend.objects.all()
        for b in backends:
            try:
                identity = reporter.telephone_moh if b.name != 'message_tester' else reporter.telephone_moh.replace(
                    '+', '')
                connection, created = Connection.objects.get_or_create(
                    contact=contact, backend=b, identity=identity)

                connection.save()
            except:
                continue

        contact.save()
        connections = Connection.objects.filter(contact=contact)
def get_connections(reporter):
    connections = None
    try:
        connections = Connection.objects.filter(identity = reporter.telephone_moh)
        
    except Exception, e:
        contact, created = Contact.objects.get_or_create(name = reporter.national_id)
        if reporter.language:    contact.language = reporter.language.lower()
        else:   contact.language = 'rw'

        backends = Backend.objects.all()
        for b in backends:
            try:
                identity = reporter.telephone_moh if b.name != 'message_tester' else reporter.telephone_moh.replace('+','')
                connection, created = Connection.objects.get_or_create(contact = contact, backend = b, identity = identity)

                connection.save()
            except:
                continue
        
        contact.save()
        connections = Connection.objects.filter(contact = contact)
Example #3
0
def get_connection(telephone_moh, reporter=None):
    try:
        connection = old_registry.PersistantConnection.objects.filter(identity=telephone_moh)[0]
        if connection.reporter:
            return connection
        else:
            connection.reporter = reporter
            connection.save()
            return connection
    except Exception, e:
        try:
            if reporter:

                backend = old_registry.PersistantBackend.objects.get(title="kannel")
                connection = old_registry.PersistantConnection(
                    backend=backend, identity=telephone_moh, reporter=reporter, last_seen=datetime.datetime.now()
                )
                connection.save()
                return connection
            else:
                return None
        except Exception, e:
            return None
Example #4
0
def get_connection(telephone_moh, reporter=None):
    try:
        connection = old_registry.PersistantConnection.objects.filter(
            identity=telephone_moh)[0]
        if connection.reporter: return connection
        else:
            connection.reporter = reporter
            connection.save()
            return connection
    except Exception, e:
        try:
            if reporter:

                backend = old_registry.PersistantBackend.objects.get(
                    title="kannel")
                connection = old_registry.PersistantConnection(backend = backend, identity = telephone_moh, \
                                                                                        reporter = reporter, last_seen = datetime.datetime.now())
                connection.save()
                return connection
            else:
                return None
        except Exception, e:
            return None