diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-02-27 15:47:32 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-02-27 15:47:32 +0100 |
commit | 05eeada23bd7065bf750e88c4c3125676e9ace92 (patch) | |
tree | cb99bb453ae23db575810471c660dda06a98bd77 | |
parent | 96dab3e5402589d9537df776bbcd7df816ae54f2 (diff) | |
download | Ishtar-05eeada23bd7065bf750e88c4c3125676e9ace92.tar.bz2 Ishtar-05eeada23bd7065bf750e88c4c3125676e9ace92.zip |
Allow no resizing of images (by explicit parameter in settings)
-rw-r--r-- | archaeological_context_records/forms.py | 9 | ||||
-rw-r--r-- | archaeological_finds/forms.py | 9 | ||||
-rw-r--r-- | archaeological_finds/forms_treatments.py | 8 | ||||
-rw-r--r-- | archaeological_operations/forms.py | 8 | ||||
-rw-r--r-- | archaeological_warehouse/forms.py | 7 | ||||
-rw-r--r-- | example_project/settings.py | 2 | ||||
-rw-r--r-- | ishtar_common/forms_common.py | 15 | ||||
-rw-r--r-- | ishtar_common/models.py | 7 |
8 files changed, 27 insertions, 38 deletions
diff --git a/archaeological_context_records/forms.py b/archaeological_context_records/forms.py index e776f2ec7..61460ab3b 100644 --- a/archaeological_context_records/forms.py +++ b/archaeological_context_records/forms.py @@ -40,7 +40,8 @@ from archaeological_operations.widgets import OAWidget from ishtar_common.forms import FinalForm, FormSet, \ reverse_lazy, get_form_selection, TableSelect, ManageOldType, CustomForm,\ FieldType, IshtarForm -from ishtar_common.forms_common import get_town_field, SourceSelect +from ishtar_common.forms_common import get_town_field, SourceSelect, \ + get_image_help from archaeological_operations.forms import OperationSelect, ParcelField,\ RecordRelationsForm as OpeRecordRelationsForm, RecordRelationsFormSetBase @@ -181,11 +182,7 @@ class RecordFormGeneral(CustomForm, ManageOldType): label=_(u"Location"), widget=forms.Textarea, required=False, validators=[validators.MaxLengthValidator(200)]) image = forms.ImageField( - label=_(u"Image"), help_text=mark_safe( - _(u"<p>Heavy images are resized to: %(width)dx%(height)d " - u"(ratio is preserved).</p>") % { - 'width': settings.IMAGE_MAX_SIZE[0], - 'height': settings.IMAGE_MAX_SIZE[1]}), + label=_(u"Image"), help_text=mark_safe(get_image_help()), max_length=255, required=False, widget=widgets.ImageFileInput()) TYPES = [ diff --git a/archaeological_finds/forms.py b/archaeological_finds/forms.py index 26ba8350f..191c8722a 100644 --- a/archaeological_finds/forms.py +++ b/archaeological_finds/forms.py @@ -43,7 +43,8 @@ from ishtar_common.forms import FormSet, FloatField, \ get_form_selection, reverse_lazy, TableSelect, get_now, FinalForm, \ ManageOldType, FieldType, IshtarForm -from ishtar_common.forms_common import get_town_field, SourceSelect, CustomForm +from ishtar_common.forms_common import get_town_field, \ + get_image_help, SourceSelect, CustomForm from ishtar_common.utils import convert_coordinates_to_point from ishtar_common import widgets from bootstrap_datepicker.widgets import DatePicker @@ -204,11 +205,7 @@ class FindForm(CustomForm, ManageOldType): label=_(u"Comment on dating"), required=False, widget=forms.Textarea) estimated_value = FloatField(label=_(u"Estimated value"), required=False) image = forms.ImageField( - label=_(u"Image"), help_text=mark_safe( - _(u"<p>Heavy images are resized to: %(width)dx%(height)d " - u"(ratio is preserved).</p>") % { - 'width': settings.IMAGE_MAX_SIZE[0], - 'height': settings.IMAGE_MAX_SIZE[1]}), + label=_(u"Image"), help_text=mark_safe(get_image_help()), max_length=255, required=False, widget=widgets.ImageFileInput()) TYPES = [ diff --git a/archaeological_finds/forms_treatments.py b/archaeological_finds/forms_treatments.py index 6dfc028e6..86f00a834 100644 --- a/archaeological_finds/forms_treatments.py +++ b/archaeological_finds/forms_treatments.py @@ -38,7 +38,7 @@ from archaeological_operations.forms import AdministrativeActOpeForm, \ from ishtar_common.forms import reverse_lazy, TableSelect, FinalForm, \ ManageOldType, get_form_selection, CustomForm, FieldType, IshtarForm -from ishtar_common.forms_common import SourceSelect +from ishtar_common.forms_common import SourceSelect, get_image_help from ishtar_common import widgets from bootstrap_datepicker.widgets import DatePicker @@ -152,11 +152,7 @@ class BaseTreatmentForm(CustomForm, ManageOldType): insurance_cost = forms.FloatField(label=_(u"Insurance cost ({currency})"), required=False) image = forms.ImageField( - label=_(u"Image"), help_text=mark_safe( - _(u"<p>Heavy images are resized to: %(width)dx%(height)d " - u"(ratio is preserved).</p>") % { - 'width': settings.IMAGE_MAX_SIZE[0], - 'height': settings.IMAGE_MAX_SIZE[1]}), + label=_(u"Image"), help_text=mark_safe(get_image_help()), max_length=255, required=False, widget=widgets.ImageFileInput()) TYPES = [ diff --git a/archaeological_operations/forms.py b/archaeological_operations/forms.py index e0d31bef7..ae9a18862 100644 --- a/archaeological_operations/forms.py +++ b/archaeological_operations/forms.py @@ -52,7 +52,7 @@ from ishtar_common.forms import FinalForm, FormSet, get_now, \ reverse_lazy, get_form_selection, TableSelect, get_data_from_formset, \ ManageOldType, IshtarForm, CustomForm, FieldType from ishtar_common.forms_common import TownFormSet, SourceForm, SourceSelect, \ - get_town_field, TownForm + get_town_field, TownForm, get_image_help from archaeological_operations.utils import parse_parcels @@ -871,11 +871,7 @@ class OperationFormGeneral(CustomForm, ManageOldType): virtual_operation = forms.BooleanField(required=False, label=_(u"Virtual operation")) image = forms.ImageField( - label=_(u"Image"), help_text=mark_safe( - _(u"<p>Heavy images are resized to: %(width)dx%(height)d " - u"(ratio is preserved).</p>") % { - 'width': settings.IMAGE_MAX_SIZE[0], - 'height': settings.IMAGE_MAX_SIZE[1]}), + label=_(u"Image"), help_text=mark_safe(get_image_help()), max_length=255, required=False, widget=widgets.ImageFileInput()) FILE_FIELDS = [ diff --git a/archaeological_warehouse/forms.py b/archaeological_warehouse/forms.py index 5ac907deb..fc8ba056e 100644 --- a/archaeological_warehouse/forms.py +++ b/archaeological_warehouse/forms.py @@ -33,6 +33,7 @@ from bootstrap_datepicker.widgets import DatePicker from ishtar_common.forms import name_validator, reverse_lazy, \ get_form_selection, TableSelect, ManageOldType, FinalForm, FormSet, \ CustomForm, FieldType +from ishtar_common.forms_common import get_image_help from archaeological_finds.forms import FindMultipleFormSelection, \ SelectFindBasketForm @@ -188,11 +189,7 @@ class ContainerForm(CustomForm, ManageOldType, forms.Form): associated_model=models.Warehouse, new=True), validators=[valid_id(models.Warehouse)]) image = forms.ImageField( - label=_(u"Image"), help_text=mark_safe( - _(u"<p>Heavy images are resized to: %(width)dx%(height)d " - u"(ratio is preserved).</p>") % { - 'width': settings.IMAGE_MAX_SIZE[0], - 'height': settings.IMAGE_MAX_SIZE[1]}), + label=_(u"Image"), help_text=mark_safe(get_image_help()), max_length=255, required=False, widget=widgets.ImageFileInput()) comment = forms.CharField(label=_(u"Comment"), widget=forms.Textarea, required=False) diff --git a/example_project/settings.py b/example_project/settings.py index 7135f62f9..96eabacb9 100644 --- a/example_project/settings.py +++ b/example_project/settings.py @@ -15,7 +15,7 @@ TEST_VIEWS = True if "test" in sys.argv: sys.path.insert(0, '..') -IMAGE_MAX_SIZE = (1024, 768) +IMAGE_MAX_SIZE = (1024, 768) # put None if no resizing THUMB_MAX_SIZE = (300, 300) CACHE_SMALLTIMEOUT = 60 diff --git a/ishtar_common/forms_common.py b/ishtar_common/forms_common.py index f01c3e4b8..940ce99b8 100644 --- a/ishtar_common/forms_common.py +++ b/ishtar_common/forms_common.py @@ -870,6 +870,15 @@ class MergeOrganizationForm(MergeForm): TO_KEY = 'to_organization' +def get_image_help(): + if not settings.IMAGE_MAX_SIZE: + return "" + return _(u"<p>Heavy images are resized to: %(width)dx%(height)d " + u"(ratio is preserved).</p>") \ + % {'width': settings.IMAGE_MAX_SIZE[0], + 'height': settings.IMAGE_MAX_SIZE[1]} + + ###################### # Sources management # ###################### @@ -908,11 +917,7 @@ class SourceForm(CustomForm, ManageOldType): duplicate = forms.BooleanField(label=_(u"Has a duplicate"), required=False) image = forms.ImageField( - label=_(u"Image"), help_text=mark_safe( - _(u"<p>Heavy images are resized to: %(width)dx%(height)d " - u"(ratio is preserved).</p>") % { - 'width': settings.IMAGE_MAX_SIZE[0], - 'height': settings.IMAGE_MAX_SIZE[1]}), + label=_(u"Image"), help_text=mark_safe(get_image_help()), max_length=255, required=False, widget=widgets.ImageFileInput()) TYPES = [ diff --git a/ishtar_common/models.py b/ishtar_common/models.py index f482cf61d..6f8a66f3b 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -896,9 +896,10 @@ class ImageModel(models.Model): image = image.convert('RGB') # resize if necessary - self.image.save(filename, - self.create_thumb(image, self.IMAGE_MAX_SIZE), - save=False) + if self.IMAGE_MAX_SIZE: + self.image.save(filename, + self.create_thumb(image, self.IMAGE_MAX_SIZE), + save=False) if old_path != self.image.path: try: |