parameters: (user, ldap_user, related, opts, remove=True)
docstring: Hepler function to update m2m relationship based on LDAP group membership.
docstring_summary: Hepler function to update m2m relationship based on LDAP group membership.
docstring_tokens: Hepler function to update m2m relationship based on LDAP group membership .
function: def _update_m2m_from_groups(user, ldap_user, related, opts, remove=True):
      """
      Hepler function to update m2m relationship based on LDAP group membership.
      """
      should_add = False
      if opts is None:
          return
      elif not opts:
          pass
      elif opts is True:
          should_add = True
      else:
          if isinstance(opts, str):
              opts = [opts]
          for group_dn in opts:
              if not isinstance(group_dn, str):
                  continue
              if ldap_user._get_groups().is_member_of(group_dn):
                  should_add = True
      if should_add:
          user.save()
          related.add(user)
      elif remove and user in related.all():
          user.save()
          related.remove(user)
function_tokens: def _update_m2m_from_groups ( user , ldap_user , related , opts , remove = True ) : should_add = False if opts is None : return elif not opts : pass elif opts is True : should_add = True else : if isinstance ( opts , str ) : opts = [ opts ] for group_dn in opts : if not isinstance ( group_dn , str ) : continue if ldap_user . _get_groups ( ) . is_member_of ( group_dn ) : should_add = True if should_add : user . save ( ) related . add ( user ) elif remove and user in related . all ( ) : user . save ( ) related . remove ( user )