예제 #1
0
 def get_fieldsets(self, request, obj=None):
     fieldsets = super(OrgUserAdmin, self).get_fieldsets(request, obj)
     if get_tenant_from_request() is not None:
         fields = list(fieldsets[0][1]['fields'])
         tenant_fields = auth_model_tenant_fields()
         for field_to_remove in [f for f in tenant_fields if f in fields]:
             fields.remove(field_to_remove)
         fieldsets[0][1]['fields'] = tuple(fields)
     return fieldsets
예제 #2
0
def _new_get_query_set_method(self):
    """
    Replacement query set that forces the default manager of a model to restrict itself to the
    user's tenant from the request (no restriction if the user doesn't have a tenant).

    NOTE: Monkey patched in via the @tenant_restricted decorator.
    """
    qs = self.old_get_query_set_method()
    tenant = get_tenant_from_request()
    if tenant:
        tenant_model = get_tenant_model()
        for tenant_field in tenant_model._get_tenant_fields_in(self.model):
            qs = qs.filter(**{tenant_field: tenant})
    return qs