diff -r 30ac4352ae9b django/core/context_processors.py
a
|
b
|
|
8 | 8 | """ |
9 | 9 | |
10 | 10 | from django.conf import settings |
11 | | from django.middleware.csrf import get_token |
12 | 11 | from django.utils.functional import lazy, memoize, SimpleLazyObject |
13 | | from django.contrib import messages |
14 | 12 | |
15 | 13 | def auth(request): |
16 | 14 | """ |
… |
… |
|
36 | 34 | from django.contrib.auth.models import AnonymousUser |
37 | 35 | return AnonymousUser() |
38 | 36 | |
| 37 | from django.contrib import messages |
39 | 38 | return { |
40 | 39 | 'user': SimpleLazyObject(get_user), |
41 | 40 | 'messages': messages.get_messages(request), |
… |
… |
|
48 | 47 | it has not been provided by either a view decorator or the middleware |
49 | 48 | """ |
50 | 49 | def _get_val(): |
| 50 | from django.middleware.csrf import get_token |
51 | 51 | token = get_token(request) |
52 | 52 | if token is None: |
53 | 53 | # In order to be able to provide debugging info in the |
diff -r 30ac4352ae9b django/core/files/storage.py
a
|
b
|
|
4 | 4 | |
5 | 5 | from django.conf import settings |
6 | 6 | from django.core.exceptions import ImproperlyConfigured, SuspiciousOperation |
7 | | from django.core.files import locks, File |
8 | | from django.core.files.move import file_move_safe |
| 7 | from django.core.files import File |
9 | 8 | from django.utils.encoding import force_unicode, smart_str |
10 | 9 | from django.utils.functional import LazyObject |
11 | 10 | from django.utils.importlib import import_module |
… |
… |
|
153 | 152 | try: |
154 | 153 | # This file has a file path that we can move. |
155 | 154 | if hasattr(content, 'temporary_file_path'): |
| 155 | from django.core.files.move import file_move_safe |
156 | 156 | file_move_safe(content.temporary_file_path(), full_path) |
157 | 157 | content.close() |
158 | 158 | |
… |
… |
|
161 | 161 | # This fun binary flag incantation makes os.open throw an |
162 | 162 | # OSError if the file already exists before we open it. |
163 | 163 | 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 |
164 | 165 | try: |
165 | 166 | locks.lock(fd, locks.LOCK_EX) |
166 | 167 | for chunk in content.chunks(): |
diff -r 30ac4352ae9b django/core/files/uploadedfile.py
a
|
b
|
|
10 | 10 | |
11 | 11 | from django.conf import settings |
12 | 12 | from django.core.files.base import File |
13 | | from django.core.files import temp as tempfile |
14 | 13 | from django.utils.encoding import smart_str |
15 | 14 | |
16 | 15 | __all__ = ('UploadedFile', 'TemporaryUploadedFile', 'InMemoryUploadedFile', |
… |
… |
|
59 | 58 | A file uploaded to a temporary location (i.e. stream-to-disk). |
60 | 59 | """ |
61 | 60 | def __init__(self, name, content_type, size, charset): |
| 61 | from django.core.files import temp as tempfile |
62 | 62 | if settings.FILE_UPLOAD_TEMP_DIR: |
63 | 63 | file = tempfile.NamedTemporaryFile(suffix='.upload', |
64 | 64 | dir=settings.FILE_UPLOAD_TEMP_DIR) |
diff -r 30ac4352ae9b django/db/backends/creation.py
a
|
b
|
|
7 | 7 | from sets import Set as set |
8 | 8 | |
9 | 9 | from django.conf import settings |
10 | | from django.core.management import call_command |
11 | 10 | |
12 | 11 | # The prefix to put on the default database name when creating |
13 | 12 | # the test database. |
… |
… |
|
355 | 354 | can_rollback = self._rollback_works() |
356 | 355 | self.connection.settings_dict["SUPPORTS_TRANSACTIONS"] = can_rollback |
357 | 356 | |
| 357 | from django.core.management import call_command |
358 | 358 | call_command('syncdb', verbosity=verbosity, interactive=False, database=self.connection.alias) |
359 | 359 | |
360 | 360 | if settings.CACHE_BACKEND.startswith('db://'): |
diff -r 30ac4352ae9b django/db/models/fields/__init__.py
a
|
b
|
|
9 | 9 | from django.db.models.fields.subclassing import LegacyConnection |
10 | 10 | from django.db.models.query_utils import QueryWrapper |
11 | 11 | from django.conf import settings |
12 | | from django import forms |
13 | 12 | from django.core import exceptions, validators |
14 | 13 | from django.utils.datastructures import DictWrapper |
15 | 14 | from django.utils.functional import curry |
… |
… |
|
441 | 440 | def save_form_data(self, instance, data): |
442 | 441 | setattr(instance, self.name, data) |
443 | 442 | |
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 |
445 | 447 | "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 | } |
447 | 453 | if self.has_default(): |
448 | 454 | defaults['initial'] = self.get_default() |
449 | 455 | if callable(self.default): |
… |
… |
|
550 | 556 | include_blank = self.null or not (self.has_default() or 'initial' in kwargs) |
551 | 557 | defaults = {'choices': self.get_choices(include_blank=include_blank)} |
552 | 558 | else: |
| 559 | from django import forms |
553 | 560 | defaults = {'form_class': forms.BooleanField} |
554 | 561 | defaults.update(kwargs) |
555 | 562 | return super(BooleanField, self).formfield(**defaults) |
… |
… |
|
677 | 684 | return data |
678 | 685 | |
679 | 686 | def formfield(self, **kwargs): |
| 687 | from django import forms |
680 | 688 | defaults = {'form_class': forms.DateField} |
681 | 689 | defaults.update(kwargs) |
682 | 690 | return super(DateField, self).formfield(**defaults) |
… |
… |
|
744 | 752 | return data |
745 | 753 | |
746 | 754 | def formfield(self, **kwargs): |
| 755 | from django import forms |
747 | 756 | defaults = {'form_class': forms.DateTimeField} |
748 | 757 | defaults.update(kwargs) |
749 | 758 | return super(DateTimeField, self).formfield(**defaults) |
… |
… |
|
798 | 807 | return self.to_python(value) |
799 | 808 | |
800 | 809 | def formfield(self, **kwargs): |
| 810 | from django import forms |
801 | 811 | defaults = { |
802 | 812 | 'max_digits': self.max_digits, |
803 | 813 | 'decimal_places': self.decimal_places, |
… |
… |
|
823 | 833 | Field.__init__(self, verbose_name, name, **kwargs) |
824 | 834 | |
825 | 835 | def formfield(self, **kwargs): |
| 836 | from django import forms |
826 | 837 | defaults = { |
827 | 838 | 'path': self.path, |
828 | 839 | 'match': self.match, |
… |
… |
|
859 | 870 | raise exceptions.ValidationError(self.error_messages['invalid']) |
860 | 871 | |
861 | 872 | def formfield(self, **kwargs): |
| 873 | from django import forms |
862 | 874 | defaults = {'form_class': forms.FloatField} |
863 | 875 | defaults.update(kwargs) |
864 | 876 | return super(FloatField, self).formfield(**defaults) |
… |
… |
|
887 | 899 | raise exceptions.ValidationError(self.error_messages['invalid']) |
888 | 900 | |
889 | 901 | def formfield(self, **kwargs): |
| 902 | from django import forms |
890 | 903 | defaults = {'form_class': forms.IntegerField} |
891 | 904 | defaults.update(kwargs) |
892 | 905 | return super(IntegerField, self).formfield(**defaults) |
… |
… |
|
915 | 928 | return "IPAddressField" |
916 | 929 | |
917 | 930 | def formfield(self, **kwargs): |
| 931 | from django import forms |
918 | 932 | defaults = {'form_class': forms.IPAddressField} |
919 | 933 | defaults.update(kwargs) |
920 | 934 | return super(IPAddressField, self).formfield(**defaults) |
… |
… |
|
955 | 969 | return bool(value) |
956 | 970 | |
957 | 971 | def formfield(self, **kwargs): |
| 972 | from django import forms |
958 | 973 | defaults = { |
959 | 974 | 'form_class': forms.NullBooleanField, |
960 | 975 | 'required': not self.blank, |
… |
… |
|
997 | 1012 | return "SlugField" |
998 | 1013 | |
999 | 1014 | def formfield(self, **kwargs): |
| 1015 | from django import forms |
1000 | 1016 | defaults = {'form_class': forms.SlugField} |
1001 | 1017 | defaults.update(kwargs) |
1002 | 1018 | return super(SlugField, self).formfield(**defaults) |
… |
… |
|
1019 | 1035 | return smart_unicode(value) |
1020 | 1036 | |
1021 | 1037 | def formfield(self, **kwargs): |
| 1038 | from django import forms |
1022 | 1039 | defaults = {'widget': forms.Textarea} |
1023 | 1040 | defaults.update(kwargs) |
1024 | 1041 | return super(TextField, self).formfield(**defaults) |
… |
… |
|
1099 | 1116 | return data |
1100 | 1117 | |
1101 | 1118 | def formfield(self, **kwargs): |
| 1119 | from django import forms |
1102 | 1120 | defaults = {'form_class': forms.TimeField} |
1103 | 1121 | defaults.update(kwargs) |
1104 | 1122 | return super(TimeField, self).formfield(**defaults) |
diff -r 30ac4352ae9b django/db/models/fields/files.py
a
|
b
|
|
6 | 6 | from django.conf import settings |
7 | 7 | from django.db.models.fields import Field |
8 | 8 | from django.core.files.base import File, ContentFile |
9 | | from django.core.files.storage import default_storage |
10 | 9 | from django.core.files.images import ImageFile, get_image_dimensions |
11 | 10 | from django.core.files.uploadedfile import UploadedFile |
12 | 11 | from django.utils.functional import curry |
13 | 12 | from django.db.models import signals |
14 | 13 | from django.utils.encoding import force_unicode, smart_str |
15 | 14 | from django.utils.translation import ugettext_lazy, ugettext as _ |
16 | | from django import forms |
17 | 15 | from django.db.models.loading import cache |
18 | 16 | |
19 | 17 | class FieldFile(File): |
… |
… |
|
224 | 222 | if arg in kwargs: |
225 | 223 | raise TypeError("'%s' is not a valid argument for %s." % (arg, self.__class__)) |
226 | 224 | |
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 |
228 | 228 | self.upload_to = upload_to |
229 | 229 | if callable(upload_to): |
230 | 230 | self.generate_filename = upload_to |
… |
… |
|
286 | 286 | setattr(instance, self.name, data) |
287 | 287 | |
288 | 288 | def formfield(self, **kwargs): |
| 289 | from django import forms |
289 | 290 | defaults = {'form_class': forms.FileField, 'max_length': self.max_length} |
290 | 291 | # If a file has been provided previously, then the form doesn't require |
291 | 292 | # that a new file is provided this time. |
… |
… |
|
398 | 399 | setattr(instance, self.height_field, height) |
399 | 400 | |
400 | 401 | def formfield(self, **kwargs): |
| 402 | from django import forms |
401 | 403 | defaults = {'form_class': forms.ImageField} |
402 | 404 | defaults.update(kwargs) |
403 | 405 | return super(ImageField, self).formfield(**defaults) |
diff -r 30ac4352ae9b django/db/models/fields/related.py
a
|
b
|
|
11 | 11 | from django.utils.translation import ugettext_lazy as _, string_concat, ungettext, ugettext |
12 | 12 | from django.utils.functional import curry |
13 | 13 | from django.core import exceptions |
14 | | from django import forms |
15 | 14 | |
16 | 15 | |
17 | 16 | RECURSIVE_RELATIONSHIP_CONSTANT = 'self' |
… |
… |
|
845 | 844 | self.rel.field_name = cls._meta.pk.name |
846 | 845 | |
847 | 846 | def formfield(self, **kwargs): |
| 847 | from django import forms |
848 | 848 | db = kwargs.pop('using', None) |
849 | 849 | defaults = { |
850 | 850 | 'form_class': forms.ModelChoiceField, |
… |
… |
|
1099 | 1099 | setattr(instance, self.attname, data) |
1100 | 1100 | |
1101 | 1101 | def formfield(self, **kwargs): |
| 1102 | from django import forms |
1102 | 1103 | db = kwargs.pop('using', None) |
1103 | 1104 | defaults = { |
1104 | 1105 | 'form_class': forms.ModelMultipleChoiceField, |
diff -r 30ac4352ae9b django/http/__init__.py
a
|
b
|
|
12 | 12 | |
13 | 13 | from django.utils.datastructures import MultiValueDict, ImmutableList |
14 | 14 | from django.utils.encoding import smart_str, iri_to_uri, force_unicode |
15 | | from django.http.multipartparser import MultiPartParser |
16 | 15 | from django.conf import settings |
17 | 16 | from django.core.files import uploadhandler |
18 | 17 | from utils import * |
… |
… |
|
120 | 119 | self.upload_handlers, |
121 | 120 | warning = "You cannot alter upload handlers after the upload has been processed." |
122 | 121 | ) |
| 122 | from django.http.multipartparser import MultiPartParser |
123 | 123 | parser = MultiPartParser(META, post_data, self.upload_handlers, self.encoding) |
124 | 124 | return parser.parse() |
125 | 125 | |