This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/django/contrib/admin/widgets.py b/django/contrib/admin/widgets.py | |
index 2103788..14b46f1 100644 | |
--- a/django/contrib/admin/widgets.py | |
+++ b/django/contrib/admin/widgets.py | |
@@ -255,7 +255,6 @@ class RelatedFieldWidgetWrapper(forms.Widget): | |
can_change_related=False, can_delete_related=False): | |
self.needs_multipart_form = widget.needs_multipart_form | |
self.attrs = widget.attrs | |
- self.choices = widget.choices | |
self.widget = widget |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6855871 function calls (6855838 primitive calls) in 12.051 seconds | |
Ordered by: internal time | |
ncalls tottime percall cumtime percall filename:lineno(function) | |
346704 1.364 0.000 1.364 0.000 {method 'astype' of 'numpy.generic' objects} | |
12 1.049 0.087 1.864 0.155 encoder.py:204(iterencode) | |
2 1.031 0.516 1.031 0.516 decoder.py:345(raw_decode) | |
35488 0.542 0.000 3.842 0.000 properties.py:809(properties_with_values) | |
115516 0.509 0.000 0.509 0.000 {built-in method numpy.core.multiarray.array} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# See: https://stackoverflow.com/questions/27720254/django-allowed-hosts-with-elb-healthcheck | |
def get_ELB_hostname(): | |
import urllib.request | |
import urllib.error | |
try: | |
fileobj = urllib.request.urlopen('http://169.254.169.254/latest/meta-data/local-ipv4', timeout=0.1) | |
return fileobj.read().decode('ascii') | |
except urllib.error.URLError: | |
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.conf import settings | |
from django.urls import is_valid_path | |
from django.middleware.common import CommonMiddleware | |
class RemoveSlashCommonMiddleware(CommonMiddleware): | |
"""REMOVE_SLASH works like APPEND_SLASH, but reversed.""" | |
def process_request(self, request): | |
# Check if a slash should be removed | |
if self.should_redirect_with_no_slash(request): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.conf import settings | |
try: | |
from django.utils.deprecation import MiddlewareMixin | |
except ImportError: | |
class MiddlewareMixin(object): | |
""" | |
If this middleware doesn't exist, this is an older version of django | |
and we don't need it. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.core.mail.message import make_msgid | |
class FastMailBackendMixin: | |
"""Work around slow development email backend due to slow socket.getfqdn() call. | |
This simply uses "example.com" instead of your local machine's hostname. | |
""" | |
def send_messages(self, messages): | |
for message in messages: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('img[data-original]') | |
.lazyload() | |
.each(function (_, e) { | |
// Empty placeholder image so that page does not "jump" while real images are being loaded | |
e = $(e) | |
if (!e.loaded) { | |
const w = e.attr('data-width') | |
const h = e.attr('data-height') | |
if (w && h) { | |
e.attr('src', `data:image/svg+xml;charset=utf-8,%3Csvg width%3D'${w}' height%3D'${h}' xmlns%3D'http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg' %2F%3E`) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CustomManagerMixin: | |
"""Hack to override the manager used by the admin interface. | |
Set ``model_manager`` in subclasses to specify a custom manager. | |
""" | |
def get_queryset(self, *args, **kwargs): | |
default_manager = self.model._meta.default_manager | |
try: | |
self.model._meta.default_manager = self.model_manager |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class suppress_exceptions_in_production: | |
"""Allow exceptions in production; propagate exceptions during development. | |
Usage: | |
with suppress_exceptions_in_production() as result: | |
... | |
Exceptions that happen in the ... block are suppressed but logged using the | |
``logger`` given (or a default logger if none is given). Exceptions are |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import django.contrib.auth | |
import django.core.exceptions | |
from django import forms | |
from django.utils.translation import ugettext_lazy as _ | |
class RequiresPasswordMixin(forms.Form): | |
error_messages = { | |
'password_incorrect': _("Your old password was entered incorrectly. Please enter it again."), | |
} |