Example #1
0
        def _route_db(self, model, **hints):
            from landlord import landlord

            hints.update({settings.LANDLORD_DEFAULT_NAMESPACE_KEY: landlord.get_current_namespace()})

            chosen_db = None
            for router in self.routers:
                try:
                    method = getattr(router, action)
                except AttributeError:
                    # If the router doesn't have a method, skip to the next one.
                    pass
                else:
                    chosen_db = method(model, **hints)
                    if chosen_db:
                        return chosen_db
            try:
                return hints["instance"]._state.db or DEFAULT_DB_ALIAS
            except KeyError:
                return DEFAULT_DB_ALIAS
Example #2
0
 def test_basic(self):
     random_str = randomStr(24)
     landlord.push(random_str)
     self.assertEqual(landlord.get_current_namespace(), random_str)
     landlord.pop()
     self.assertEqual(landlord.get_current_namespace(), None)
def landlord(request):
    return {"landlord": {"current": landlord.get_current_namespace()}}