equal
deleted
inserted
replaced
1 import copy |
|
2 import datetime |
1 import datetime |
3 import os |
2 import os |
|
3 |
|
4 import django.utils.copycompat as copy |
4 |
5 |
5 from django.conf import settings |
6 from django.conf import settings |
6 from django.db.models.fields import Field |
7 from django.db.models.fields import Field |
7 from django.core.files.base import File, ContentFile |
8 from django.core.files.base import File, ContentFile |
8 from django.core.files.storage import default_storage |
9 from django.core.files.storage import default_storage |
214 attr_class = FieldFile |
215 attr_class = FieldFile |
215 |
216 |
216 # The descriptor to use for accessing the attribute off of the class. |
217 # The descriptor to use for accessing the attribute off of the class. |
217 descriptor_class = FileDescriptor |
218 descriptor_class = FileDescriptor |
218 |
219 |
|
220 description = ugettext_lazy("File path") |
|
221 |
219 def __init__(self, verbose_name=None, name=None, upload_to='', storage=None, **kwargs): |
222 def __init__(self, verbose_name=None, name=None, upload_to='', storage=None, **kwargs): |
220 for arg in ('primary_key', 'unique'): |
223 for arg in ('primary_key', 'unique'): |
221 if arg in kwargs: |
224 if arg in kwargs: |
222 raise TypeError("'%s' is not a valid argument for %s." % (arg, self.__class__)) |
225 raise TypeError("'%s' is not a valid argument for %s." % (arg, self.__class__)) |
223 |
226 |
230 super(FileField, self).__init__(verbose_name, name, **kwargs) |
233 super(FileField, self).__init__(verbose_name, name, **kwargs) |
231 |
234 |
232 def get_internal_type(self): |
235 def get_internal_type(self): |
233 return "FileField" |
236 return "FileField" |
234 |
237 |
235 def get_db_prep_lookup(self, lookup_type, value): |
238 def get_prep_lookup(self, lookup_type, value): |
236 if hasattr(value, 'name'): |
239 if hasattr(value, 'name'): |
237 value = value.name |
240 value = value.name |
238 return super(FileField, self).get_db_prep_lookup(lookup_type, value) |
241 return super(FileField, self).get_prep_lookup(lookup_type, value) |
239 |
242 |
240 def get_db_prep_value(self, value): |
243 def get_prep_value(self, value): |
241 "Returns field's value prepared for saving into a database." |
244 "Returns field's value prepared for saving into a database." |
242 # Need to convert File objects provided via a form to unicode for database insertion |
245 # Need to convert File objects provided via a form to unicode for database insertion |
243 if value is None: |
246 if value is None: |
244 return None |
247 return None |
245 return unicode(value) |
248 return unicode(value) |
323 super(ImageFieldFile, self).delete(save) |
326 super(ImageFieldFile, self).delete(save) |
324 |
327 |
325 class ImageField(FileField): |
328 class ImageField(FileField): |
326 attr_class = ImageFieldFile |
329 attr_class = ImageFieldFile |
327 descriptor_class = ImageFileDescriptor |
330 descriptor_class = ImageFileDescriptor |
|
331 description = ugettext_lazy("File path") |
328 |
332 |
329 def __init__(self, verbose_name=None, name=None, width_field=None, height_field=None, **kwargs): |
333 def __init__(self, verbose_name=None, name=None, width_field=None, height_field=None, **kwargs): |
330 self.width_field, self.height_field = width_field, height_field |
334 self.width_field, self.height_field = width_field, height_field |
331 FileField.__init__(self, verbose_name, name, **kwargs) |
335 FileField.__init__(self, verbose_name, name, **kwargs) |
332 |
336 |