def get_prep_lookup(self, lookup_type, value): if lookup_type not in ["in", "isnull"]: # Users really shouldn't do "isnull" lookups, again: the ORM can, # you can't. raise ValueError("You can't do lookups other than \"in\" on Tags: " "__%s=%s" % (lookup_type, value)) if hasattr(value, 'prepare'): return value.prepare() if hasattr(value, '_prepare'): return value._prepare() if lookup_type == "in": if all(isinstance(v, Tag) for v in value): value = self.through.objects.filter(tag__in=value) elif all(isinstance(v, basestring) for v in value): value = self.through.objects.filter(tag__name__in=value) elif all(isinstance(v, (int, long)) for v in value): # This one is really ackward, just don't do it. The ORM does # it for deletes, but no one else gets to. return value else: # F*****g flip-floppers. raise ValueError("You can't combine Tag objects and strings. '%s' " "was provided." % value) if hasattr(models.Field, "get_prep_lookup"): return models.Field().get_prep_lookup(lookup_type, value) return models.Field().get_db_prep_lookup(lookup_type, value)
def connections_support_transactions(): """ Returns True if all connections support transactions. This is messy because 2.4 doesn't support any or all. """ return all(conn.features.supports_transactions for conn in connections.all())
def connections_support_transactions(): """ Returns True if all connections support transactions. This is messy because 2.4 doesn't support any or all. """ return all(conn.settings_dict['SUPPORTS_TRANSACTIONS'] for conn in connections.all())
def dependency_ordered(test_databases, dependencies): """Reorder test_databases into an order that honors the dependencies described in TEST_DEPENDENCIES. """ ordered_test_databases = [] resolved_databases = set() while test_databases: changed = False deferred = [] while test_databases: signature, (db_name, aliases) = test_databases.pop() dependencies_satisfied = True for alias in aliases: if alias in dependencies: if all(a in resolved_databases for a in dependencies[alias]): # all dependencies for this alias are satisfied dependencies.pop(alias) resolved_databases.add(alias) else: dependencies_satisfied = False else: resolved_databases.add(alias) if dependencies_satisfied: ordered_test_databases.append((signature, (db_name, aliases))) changed = True else: deferred.append((signature, (db_name, aliases))) if not changed: raise ImproperlyConfigured("Circular dependency in TEST_DEPENDENCIES") test_databases = deferred return ordered_test_databases
def get_prep_lookup(self, lookup_type, value): if lookup_type != "in": raise ValueError("You can't do lookups other than \"in\" on Tags") if all(isinstance(v, Tag) for v in value): qs = self.through.objects.filter(tag__in=value) elif all(isinstance(v, basestring) for v in value): qs = self.through.objects.filter(tag__name__in=value) elif all(isinstance(v, (int, long)) for v in value): # This one is really ackward, just don't do it. The ORM does it # for deletes, but no one else gets to. return value else: # F*****g flip-floppers. raise ValueError("You can't combine Tag objects and strings. '%s' was provided." % value) if hasattr(models.Field, "get_prep_lookup"): return models.Field().get_prep_lookup(lookup_type, qs) return models.Field().get_db_prep_lookup(lookup_type, qs)
def get_prep_lookup(self, lookup_type, value): if lookup_type != "in": raise ValueError("You can't do lookups other than \"in\" on Tags") if all(isinstance(v, Tag) for v in value): qs = self.through.objects.filter(tag__in=value) elif all(isinstance(v, basestring) for v in value): qs = self.through.objects.filter(tag__name__in=value) elif all(isinstance(v, (int, long)) for v in value): # This one is really ackward, just don't do it. The ORM does it # for deletes, but no one else gets to. return value else: # F*****g flip-floppers. raise ValueError( "You can't combine Tag objects and strings. '%s' was provided." % value) if hasattr(models.Field, "get_prep_lookup"): return models.Field().get_prep_lookup(lookup_type, qs) return models.Field().get_db_prep_lookup(lookup_type, qs)
def get_all_related_objects_with_model(self, local_only=False, include_hidden=False): """ Returns a list of (related-object, model) pairs. Similar to get_fields_with_model(). """ try: self._related_objects_cache except AttributeError: self._fill_related_objects_cache() predicates = [] if local_only: predicates.append(lambda k, v: not v) if not include_hidden: predicates.append(lambda k, v: not k.field.rel.is_hidden()) return filter(lambda t: all([p(*t) for p in predicates]), self._related_objects_cache.items())
def dependency_ordered(test_databases, dependencies): """Reorder test_databases into an order that honors the dependencies described in TEST_DEPENDENCIES. """ ordered_test_databases = [] resolved_databases = set() while test_databases: changed = False deferred = [] while test_databases: signature, (db_name, aliases) = test_databases.pop() dependencies_satisfied = True for alias in aliases: if alias in dependencies: if all(a in resolved_databases for a in dependencies[alias]): # all dependencies for this alias are satisfied dependencies.pop(alias) resolved_databases.add(alias) else: dependencies_satisfied = False else: resolved_databases.add(alias) if dependencies_satisfied: ordered_test_databases.append((signature, (db_name, aliases))) changed = True else: deferred.append((signature, (db_name, aliases))) if not changed: raise ImproperlyConfigured( "Circular dependency in TEST_DEPENDENCIES") test_databases = deferred return ordered_test_databases