original_docstring: A way to trim down the list of objects by company
docstring: A way to trim down the list of objects by company
docstring_tokens: A way to trim down the list of objects by company
code: def filter_certifications_by_user(self, user, **kwargs):
          """A way to trim down the list of objects by company"""
  
          name = kwargs.pop("name", None)
          names = [name] if name else []
          if not len(names):
              EEPProgram = apps.get_model("eep_program", "EEPProgram")
              names = EEPProgram.objects.filter_by_user(user).values_list("name", flat=True)
              names = ["EEP {} Certifications".format(name) for name in names]
  
          if user.is_superuser:
              return self.filter(metric__name__in=names, **kwargs)
          company = user.company
          if company.company_type in ["rater", "hvac", "qa", "provider"]:
              return self.filter(metric__company=company, metric__name__in=names, **kwargs)
  
          # Everyone else should only see data for companies in which we have mutual relationships.
          Relationship = apps.get_model("relationship", "Relationship")
          comps = Relationship.objects.get_reversed_companies(company, ids_only=True)
          # Who do I have a relationship with
          rels = company.relationships.get_companies(ids_only=True)
          # The intersection of these is what matters..
          ints = list(set(rels).intersection(set(comps)))
          data = self.filter(
              Q(metric__company=company) | Q(metric__company__in=ints),
              metric__name__in=names,
              **kwargs,
          )
          return data
code_tokens: def filter_certifications_by_user ( self , user , ** kwargs ) : name = kwargs . pop ( "name" , None ) names = [ name ] if name else [ ] if not len ( names ) : EEPProgram = apps . get_model ( "eep_program" , "EEPProgram" ) names = EEPProgram . objects . filter_by_user ( user ) . values_list ( "name" , flat = True ) names = [ "EEP {} Certifications" . format ( name ) for name in names ] if user . is_superuser : return self . filter ( metric__name__in = names , ** kwargs ) company = user . company if company . company_type in [ "rater" , "hvac" , "qa" , "provider" ] : return self . filter ( metric__company = company , metric__name__in = names , ** kwargs ) Relationship = apps . get_model ( "relationship" , "Relationship" ) comps = Relationship . objects . get_reversed_companies ( company , ids_only = True ) rels = company . relationships . get_companies ( ids_only = True ) ints = list ( set ( rels ) . intersection ( set ( comps ) ) ) data = self . filter ( Q ( metric__company = company ) | Q ( metric__company__in = ints ) , metric__name__in = names , ** kwargs , ) return data
short_docstring: A way to trim down the list of objects by company
short_docstring_tokens: A way to trim down the list of objects by company
comment: """A way to trim down the list of objects by company"""$SEP$# Everyone else should only see data for companies in which we have mutual relationships.$SEP$# Who do I have a relationship with$SEP$# The intersection of these is what matters..