Skip to content

Instantly share code, notes, and snippets.

@freakboy3742
Created September 8, 2015 19:31
Show Gist options
  • Save freakboy3742/e9cace36f2d3cd11449d to your computer and use it in GitHub Desktop.
Save freakboy3742/e9cace36f2d3cd11449d to your computer and use it in GitHub Desktop.
Patch to get django-mailer working
diff --git a/django/contrib/admin/checks.py b/django/contrib/admin/checks.py
index d8f7fe5..7a7c651 100644
--- a/django/contrib/admin/checks.py
+++ b/django/contrib/admin/checks.py
@@ -560,9 +560,10 @@ class ModelAdminChecks(BaseModelAdminChecks):
id='admin.E105',
)
]
- elif not issubclass(inline.model, models.Model):
- return must_be('a Model', option='%s.model' % inline_label,
- obj=cls, id='admin.E106')
+ # Strict check on django.db.models.Model. We could potentially remove this?
+ #elif not issubclass(inline.model, models.Model):
+ #return must_be('a Model', option='%s.model' % inline_label,
+ #obj=cls, id='admin.E106')
else:
return inline.check(model)
@@ -897,6 +898,7 @@ class InlineModelAdminChecks(BaseModelAdminChecks):
try:
_get_foreign_key(parent_model, cls.model, fk_name=cls.fk_name)
except ValueError as e:
+ _get_foreign_key(parent_model, cls.model, fk_name=cls.fk_name)
return [checks.Error(e.args[0], hint=None, obj=cls, id='admin.E202')]
else:
return []
diff --git a/django/db/models/options.py b/django/db/models/options.py
index 4a2ab10..76d5b4c 100644
--- a/django/db/models/options.py
+++ b/django/db/models/options.py
@@ -82,9 +82,110 @@ def normalize_together(option_together):
def make_immutable_fields_list(name, data):
return ImmutableList(data, warning=IMMUTABLE_WARNING % name)
+class CachedPropertiesMixin(object):
+
+ @cached_property
+ def fields(self):
+ """
+ Returns a list of all forward fields on the model and its parents,
+ excluding ManyToManyFields.
+
+ Private API intended only to be used by Django itself; get_fields()
+ combined with filtering of field properties is the public API for
+ obtaining this field list.
+ """
+ # For legacy reasons, the fields property should only contain forward
+ # fields that are not virtual or with a m2m cardinality. Therefore we
+ # pass these three filters as filters to the generator.
+ # The third lambda is a longwinded way of checking f.related_model - we don't
+ # use that property directly because related_model is a cached property,
+ # and all the models may not have been loaded yet; we don't want to cache
+ # the string reference to the related_model.
+ is_not_an_m2m_field = lambda f: not (f.is_relation and f.many_to_many)
+ is_not_a_generic_relation = lambda f: not (f.is_relation and f.one_to_many)
+ is_not_a_generic_foreign_key = lambda f: not (
+ f.is_relation and f.many_to_one and not (hasattr(f.rel, 'to') and f.rel.to)
+ )
+ return make_immutable_fields_list(
+ "fields",
+ (f for f in self._get_fields(reverse=False) if
+ is_not_an_m2m_field(f) and is_not_a_generic_relation(f)
+ and is_not_a_generic_foreign_key(f))
+ )
+
+ @cached_property
+ def concrete_fields(self):
+ """
+ Returns a list of all concrete fields on the model and its parents.
+
+ Private API intended only to be used by Django itself; get_fields()
+ combined with filtering of field properties is the public API for
+ obtaining this field list.
+ """
+ try:
+ return make_immutable_fields_list(
+ "concrete_fields", (f for f in self.fields if f.concrete)
+ )
+ except AttributeError:
+ import ipdb; ipdb.set_trace()
+
+ @cached_property
+ def local_concrete_fields(self):
+ """
+ Returns a list of all concrete fields on the model.
+
+ Private API intended only to be used by Django itself; get_fields()
+ combined with filtering of field properties is the public API for
+ obtaining this field list.
+ """
+ return make_immutable_fields_list(
+ "local_concrete_fields", (f for f in self.local_fields if f.concrete)
+ )
+
+ @raise_deprecation(suggested_alternative="get_fields()")
+ def get_fields_with_model(self):
+ return [self._map_model(f) for f in self.get_fields()]
+
+ @raise_deprecation(suggested_alternative="get_fields()")
+ def get_concrete_fields_with_model(self):
+ return [self._map_model(f) for f in self.concrete_fields]
+
+ @cached_property
+ def many_to_many(self):
+ """
+ Returns a list of all many to many fields on the model and its parents.
+
+ Private API intended only to be used by Django itself; get_fields()
+ combined with filtering of field properties is the public API for
+ obtaining this list.
+ """
+ return make_immutable_fields_list(
+ "many_to_many",
+ (f for f in self._get_fields(reverse=False)
+ if f.is_relation and f.many_to_many)
+ )
+
+ @cached_property
+ def related_objects(self):
+ """
+ Returns all related objects pointing to the current model. The related
+ objects can come from a one-to-one, one-to-many, or many-to-many field
+ relation type.
+
+ Private API intended only to be used by Django itself; get_fields()
+ combined with filtering of field properties is the public API for
+ obtaining this field list.
+ """
+ all_related_fields = self._get_fields(forward=False, reverse=True, include_hidden=True)
+ return make_immutable_fields_list(
+ "related_objects",
+ (obj for obj in all_related_fields
+ if not obj.hidden or obj.field.many_to_many)
+ )
+
@python_2_unicode_compatible
-class Options(object):
+class Options(CachedPropertiesMixin):
FORWARD_PROPERTIES = ('fields', 'many_to_many', 'concrete_fields',
'local_concrete_fields', '_forward_fields_map')
REVERSE_PROPERTIES = ('related_objects', 'fields_map', '_relation_tree')
@@ -373,102 +474,6 @@ class Options(object):
return swapped_for
return None
- @cached_property
- def fields(self):
- """
- Returns a list of all forward fields on the model and its parents,
- excluding ManyToManyFields.
-
- Private API intended only to be used by Django itself; get_fields()
- combined with filtering of field properties is the public API for
- obtaining this field list.
- """
- # For legacy reasons, the fields property should only contain forward
- # fields that are not virtual or with a m2m cardinality. Therefore we
- # pass these three filters as filters to the generator.
- # The third lambda is a longwinded way of checking f.related_model - we don't
- # use that property directly because related_model is a cached property,
- # and all the models may not have been loaded yet; we don't want to cache
- # the string reference to the related_model.
- is_not_an_m2m_field = lambda f: not (f.is_relation and f.many_to_many)
- is_not_a_generic_relation = lambda f: not (f.is_relation and f.one_to_many)
- is_not_a_generic_foreign_key = lambda f: not (
- f.is_relation and f.many_to_one and not (hasattr(f.rel, 'to') and f.rel.to)
- )
- return make_immutable_fields_list(
- "fields",
- (f for f in self._get_fields(reverse=False) if
- is_not_an_m2m_field(f) and is_not_a_generic_relation(f)
- and is_not_a_generic_foreign_key(f))
- )
-
- @cached_property
- def concrete_fields(self):
- """
- Returns a list of all concrete fields on the model and its parents.
-
- Private API intended only to be used by Django itself; get_fields()
- combined with filtering of field properties is the public API for
- obtaining this field list.
- """
- return make_immutable_fields_list(
- "concrete_fields", (f for f in self.fields if f.concrete)
- )
-
- @cached_property
- def local_concrete_fields(self):
- """
- Returns a list of all concrete fields on the model.
-
- Private API intended only to be used by Django itself; get_fields()
- combined with filtering of field properties is the public API for
- obtaining this field list.
- """
- return make_immutable_fields_list(
- "local_concrete_fields", (f for f in self.local_fields if f.concrete)
- )
-
- @raise_deprecation(suggested_alternative="get_fields()")
- def get_fields_with_model(self):
- return [self._map_model(f) for f in self.get_fields()]
-
- @raise_deprecation(suggested_alternative="get_fields()")
- def get_concrete_fields_with_model(self):
- return [self._map_model(f) for f in self.concrete_fields]
-
- @cached_property
- def many_to_many(self):
- """
- Returns a list of all many to many fields on the model and its parents.
-
- Private API intended only to be used by Django itself; get_fields()
- combined with filtering of field properties is the public API for
- obtaining this list.
- """
- return make_immutable_fields_list(
- "many_to_many",
- (f for f in self._get_fields(reverse=False)
- if f.is_relation and f.many_to_many)
- )
-
- @cached_property
- def related_objects(self):
- """
- Returns all related objects pointing to the current model. The related
- objects can come from a one-to-one, one-to-many, or many-to-many field
- relation type.
-
- Private API intended only to be used by Django itself; get_fields()
- combined with filtering of field properties is the public API for
- obtaining this field list.
- """
- all_related_fields = self._get_fields(forward=False, reverse=True, include_hidden=True)
- return make_immutable_fields_list(
- "related_objects",
- (obj for obj in all_related_fields
- if not obj.hidden or obj.field.many_to_many)
- )
-
@raise_deprecation(suggested_alternative="get_fields()")
def get_m2m_with_model(self):
return [self._map_model(f) for f in self.many_to_many]
diff --git a/django/forms/fields.py b/django/forms/fields.py
index 57d6a75..26422b7 100644
--- a/django/forms/fields.py
+++ b/django/forms/fields.py
@@ -135,8 +135,11 @@ class Field(six.with_metaclass(RenameFieldMethods, object)):
return value
def validate(self, value):
- if value in self.empty_values and self.required:
- raise ValidationError(self.error_messages['required'], code='required')
+ try:
+ if value in self.empty_values and self.required:
+ raise ValidationError(self.error_messages['required'], code='required')
+ except TypeError:
+ import ipdb; ipdb.set_trace()
def run_validators(self, value):
if value in self.empty_values:
diff --git a/django/utils/encoding.py b/django/utils/encoding.py
index 99c9da8..2d60a77 100644
--- a/django/utils/encoding.py
+++ b/django/utils/encoding.py
@@ -98,6 +98,7 @@ def force_text(s, encoding='utf-8', strings_only=False, errors='strict'):
# SafeText at the end.
s = s.decode(encoding, errors)
except UnicodeDecodeError as e:
+ import ipdb; ipdb.set_trace()
if not isinstance(s, Exception):
raise DjangoUnicodeDecodeError(s, *e.args)
else:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment