Ticket #12844: lazy.patch

File lazy.patch, 12.3 KB (added by Waldemar Kornewald, 15 years ago)

patch against r12411

  • django/core/context_processors.py

    diff -r 30ac4352ae9b django/core/context_processors.py
    a b  
    88"""
    99
    1010from django.conf import settings
    11 from django.middleware.csrf import get_token
    1211from django.utils.functional import lazy, memoize, SimpleLazyObject
    13 from django.contrib import messages
    1412
    1513def auth(request):
    1614    """
     
    3634            from django.contrib.auth.models import AnonymousUser
    3735            return AnonymousUser()
    3836
     37    from django.contrib import messages
    3938    return {
    4039        'user': SimpleLazyObject(get_user),
    4140        'messages': messages.get_messages(request),
     
    4847    it has not been provided by either a view decorator or the middleware
    4948    """
    5049    def _get_val():
     50        from django.middleware.csrf import get_token
    5151        token = get_token(request)
    5252        if token is None:
    5353            # In order to be able to provide debugging info in the
  • django/core/files/storage.py

    diff -r 30ac4352ae9b django/core/files/storage.py
    a b  
    44
    55from django.conf import settings
    66from django.core.exceptions import ImproperlyConfigured, SuspiciousOperation
    7 from django.core.files import locks, File
    8 from django.core.files.move import file_move_safe
     7from django.core.files import File
    98from django.utils.encoding import force_unicode, smart_str
    109from django.utils.functional import LazyObject
    1110from django.utils.importlib import import_module
     
    153152            try:
    154153                # This file has a file path that we can move.
    155154                if hasattr(content, 'temporary_file_path'):
     155                    from django.core.files.move import file_move_safe
    156156                    file_move_safe(content.temporary_file_path(), full_path)
    157157                    content.close()
    158158
     
    161161                    # This fun binary flag incantation makes os.open throw an
    162162                    # OSError if the file already exists before we open it.
    163163                    fd = os.open(full_path, os.O_WRONLY | os.O_CREAT | os.O_EXCL | getattr(os, 'O_BINARY', 0))
     164                    from django.core.files import locks
    164165                    try:
    165166                        locks.lock(fd, locks.LOCK_EX)
    166167                        for chunk in content.chunks():
  • django/core/files/uploadedfile.py

    diff -r 30ac4352ae9b django/core/files/uploadedfile.py
    a b  
    1010
    1111from django.conf import settings
    1212from django.core.files.base import File
    13 from django.core.files import temp as tempfile
    1413from django.utils.encoding import smart_str
    1514
    1615__all__ = ('UploadedFile', 'TemporaryUploadedFile', 'InMemoryUploadedFile',
     
    5958    A file uploaded to a temporary location (i.e. stream-to-disk).
    6059    """
    6160    def __init__(self, name, content_type, size, charset):
     61        from django.core.files import temp as tempfile
    6262        if settings.FILE_UPLOAD_TEMP_DIR:
    6363            file = tempfile.NamedTemporaryFile(suffix='.upload',
    6464                dir=settings.FILE_UPLOAD_TEMP_DIR)
  • django/db/backends/creation.py

    diff -r 30ac4352ae9b django/db/backends/creation.py
    a b  
    77    from sets import Set as set
    88
    99from django.conf import settings
    10 from django.core.management import call_command
    1110
    1211# The prefix to put on the default database name when creating
    1312# the test database.
     
    355354        can_rollback = self._rollback_works()
    356355        self.connection.settings_dict["SUPPORTS_TRANSACTIONS"] = can_rollback
    357356
     357        from django.core.management import call_command
    358358        call_command('syncdb', verbosity=verbosity, interactive=False, database=self.connection.alias)
    359359
    360360        if settings.CACHE_BACKEND.startswith('db://'):
  • django/db/models/fields/__init__.py

    diff -r 30ac4352ae9b django/db/models/fields/__init__.py
    a b  
    99from django.db.models.fields.subclassing import LegacyConnection
    1010from django.db.models.query_utils import QueryWrapper
    1111from django.conf import settings
    12 from django import forms
    1312from django.core import exceptions, validators
    1413from django.utils.datastructures import DictWrapper
    1514from django.utils.functional import curry
     
    441440    def save_form_data(self, instance, data):
    442441        setattr(instance, self.name, data)
    443442
    444     def formfield(self, form_class=forms.CharField, **kwargs):
     443    def formfield(self, form_class=None, **kwargs):
     444        from django import forms
     445        if form_class is None:
     446            form_class = forms.CharField
    445447        "Returns a django.forms.Field instance for this database Field."
    446         defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text}
     448        defaults = {
     449            'required': not self.blank,
     450            'label': capfirst(self.verbose_name),
     451            'help_text': self.help_text
     452        }
    447453        if self.has_default():
    448454            defaults['initial'] = self.get_default()
    449455            if callable(self.default):
     
    550556            include_blank = self.null or not (self.has_default() or 'initial' in kwargs)
    551557            defaults = {'choices': self.get_choices(include_blank=include_blank)}
    552558        else:
     559            from django import forms
    553560            defaults = {'form_class': forms.BooleanField}
    554561        defaults.update(kwargs)
    555562        return super(BooleanField, self).formfield(**defaults)
     
    677684        return data
    678685
    679686    def formfield(self, **kwargs):
     687        from django import forms
    680688        defaults = {'form_class': forms.DateField}
    681689        defaults.update(kwargs)
    682690        return super(DateField, self).formfield(**defaults)
     
    744752        return data
    745753
    746754    def formfield(self, **kwargs):
     755        from django import forms
    747756        defaults = {'form_class': forms.DateTimeField}
    748757        defaults.update(kwargs)
    749758        return super(DateTimeField, self).formfield(**defaults)
     
    798807        return self.to_python(value)
    799808
    800809    def formfield(self, **kwargs):
     810        from django import forms
    801811        defaults = {
    802812            'max_digits': self.max_digits,
    803813            'decimal_places': self.decimal_places,
     
    823833        Field.__init__(self, verbose_name, name, **kwargs)
    824834
    825835    def formfield(self, **kwargs):
     836        from django import forms
    826837        defaults = {
    827838            'path': self.path,
    828839            'match': self.match,
     
    859870            raise exceptions.ValidationError(self.error_messages['invalid'])
    860871
    861872    def formfield(self, **kwargs):
     873        from django import forms
    862874        defaults = {'form_class': forms.FloatField}
    863875        defaults.update(kwargs)
    864876        return super(FloatField, self).formfield(**defaults)
     
    887899            raise exceptions.ValidationError(self.error_messages['invalid'])
    888900
    889901    def formfield(self, **kwargs):
     902        from django import forms
    890903        defaults = {'form_class': forms.IntegerField}
    891904        defaults.update(kwargs)
    892905        return super(IntegerField, self).formfield(**defaults)
     
    915928        return "IPAddressField"
    916929
    917930    def formfield(self, **kwargs):
     931        from django import forms
    918932        defaults = {'form_class': forms.IPAddressField}
    919933        defaults.update(kwargs)
    920934        return super(IPAddressField, self).formfield(**defaults)
     
    955969        return bool(value)
    956970
    957971    def formfield(self, **kwargs):
     972        from django import forms
    958973        defaults = {
    959974            'form_class': forms.NullBooleanField,
    960975            'required': not self.blank,
     
    9971012        return "SlugField"
    9981013
    9991014    def formfield(self, **kwargs):
     1015        from django import forms
    10001016        defaults = {'form_class': forms.SlugField}
    10011017        defaults.update(kwargs)
    10021018        return super(SlugField, self).formfield(**defaults)
     
    10191035        return smart_unicode(value)
    10201036
    10211037    def formfield(self, **kwargs):
     1038        from django import forms
    10221039        defaults = {'widget': forms.Textarea}
    10231040        defaults.update(kwargs)
    10241041        return super(TextField, self).formfield(**defaults)
     
    10991116        return data
    11001117
    11011118    def formfield(self, **kwargs):
     1119        from django import forms
    11021120        defaults = {'form_class': forms.TimeField}
    11031121        defaults.update(kwargs)
    11041122        return super(TimeField, self).formfield(**defaults)
  • django/db/models/fields/files.py

    diff -r 30ac4352ae9b django/db/models/fields/files.py
    a b  
    66from django.conf import settings
    77from django.db.models.fields import Field
    88from django.core.files.base import File, ContentFile
    9 from django.core.files.storage import default_storage
    109from django.core.files.images import ImageFile, get_image_dimensions
    1110from django.core.files.uploadedfile import UploadedFile
    1211from django.utils.functional import curry
    1312from django.db.models import signals
    1413from django.utils.encoding import force_unicode, smart_str
    1514from django.utils.translation import ugettext_lazy, ugettext as _
    16 from django import forms
    1715from django.db.models.loading import cache
    1816
    1917class FieldFile(File):
     
    224222            if arg in kwargs:
    225223                raise TypeError("'%s' is not a valid argument for %s." % (arg, self.__class__))
    226224
    227         self.storage = storage or default_storage
     225        if not storage:
     226            from django.core.files.storage import default_storage as storage
     227        self.storage = storage
    228228        self.upload_to = upload_to
    229229        if callable(upload_to):
    230230            self.generate_filename = upload_to
     
    286286            setattr(instance, self.name, data)
    287287
    288288    def formfield(self, **kwargs):
     289        from django import forms
    289290        defaults = {'form_class': forms.FileField, 'max_length': self.max_length}
    290291        # If a file has been provided previously, then the form doesn't require
    291292        # that a new file is provided this time.
     
    398399            setattr(instance, self.height_field, height)
    399400
    400401    def formfield(self, **kwargs):
     402        from django import forms
    401403        defaults = {'form_class': forms.ImageField}
    402404        defaults.update(kwargs)
    403405        return super(ImageField, self).formfield(**defaults)
  • django/db/models/fields/related.py

    diff -r 30ac4352ae9b django/db/models/fields/related.py
    a b  
    1111from django.utils.translation import ugettext_lazy as _, string_concat, ungettext, ugettext
    1212from django.utils.functional import curry
    1313from django.core import exceptions
    14 from django import forms
    1514
    1615
    1716RECURSIVE_RELATIONSHIP_CONSTANT = 'self'
     
    845844            self.rel.field_name = cls._meta.pk.name
    846845
    847846    def formfield(self, **kwargs):
     847        from django import forms
    848848        db = kwargs.pop('using', None)
    849849        defaults = {
    850850            'form_class': forms.ModelChoiceField,
     
    10991099        setattr(instance, self.attname, data)
    11001100
    11011101    def formfield(self, **kwargs):
     1102        from django import forms
    11021103        db = kwargs.pop('using', None)
    11031104        defaults = {
    11041105            'form_class': forms.ModelMultipleChoiceField,
  • django/http/__init__.py

    diff -r 30ac4352ae9b django/http/__init__.py
    a b  
    1212
    1313from django.utils.datastructures import MultiValueDict, ImmutableList
    1414from django.utils.encoding import smart_str, iri_to_uri, force_unicode
    15 from django.http.multipartparser import MultiPartParser
    1615from django.conf import settings
    1716from django.core.files import uploadhandler
    1817from utils import *
     
    120119            self.upload_handlers,
    121120            warning = "You cannot alter upload handlers after the upload has been processed."
    122121        )
     122        from django.http.multipartparser import MultiPartParser
    123123        parser = MultiPartParser(META, post_data, self.upload_handlers, self.encoding)
    124124        return parser.parse()
    125125
Back to Top