diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-01-16 20:09:34 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-01-16 20:09:34 +0100 |
commit | 701e27958d98542b24e4e0bbd3f9604650bd0f8c (patch) | |
tree | 75b2bf05b5896ce960165a28b9b23b4f18a593c0 | |
parent | f250dc4ee10f722876c09246c8acc3f5ff213ee4 (diff) | |
download | Ishtar-701e27958d98542b24e4e0bbd3f9604650bd0f8c.tar.bz2 Ishtar-701e27958d98542b24e4e0bbd3f9604650bd0f8c.zip |
Indication of the maximum file size in help for file fields
-rw-r--r-- | example_project/settings.py | 2 | ||||
-rwxr-xr-x | install/ishtar-prepare-instance | 27 | ||||
-rw-r--r-- | install/local_settings.py.sample | 4 | ||||
-rw-r--r-- | install/nginx.conf.template | 4 | ||||
-rw-r--r-- | ishtar_common/forms_common.py | 15 | ||||
-rw-r--r-- | ishtar_common/models.py | 18 | ||||
-rw-r--r-- | ishtar_common/models_imports.py | 25 | ||||
-rw-r--r-- | ishtar_common/utils.py | 7 |
8 files changed, 74 insertions, 28 deletions
diff --git a/example_project/settings.py b/example_project/settings.py index 89df18c2a..0fb4a22da 100644 --- a/example_project/settings.py +++ b/example_project/settings.py @@ -260,6 +260,8 @@ ISHTAR_DPTS = [] MAX_ATTEMPTS = 1 # django background tasks +MAX_UPLOAD_SIZE = 100 # in Mo + # if you want to generate relation graph provide the path to the "dot" program DOT_BINARY = "" diff --git a/install/ishtar-prepare-instance b/install/ishtar-prepare-instance index d9467247b..fec08b119 100755 --- a/install/ishtar-prepare-instance +++ b/install/ishtar-prepare-instance @@ -134,6 +134,31 @@ EOF done fi + if [ ! -z '$MAX_UPLOAD_SIZE' ]; then + MAX_UPLOAD_SIZE='' + cat >&2 <<-'EOF' + +------------------------------------------------------------------------------- + A maximum size for file upload is set. By default, the limit is set to 100 + Mo. Consider raising or lowering this value to fit to your needs. + Note: to change this value after the installation change client_max_body_size + it in the nginx configuration file and MAX_UPLOAD_SIZE in local_settings. + +EOF + re_number='^[0-9]+$' + while ! [[ "$MAX_UPLOAD_SIZE" =~ $re_number ]] + do + cecho y "* Max upload size in Mo (default: 100)? " + read choice + MAX_UPLOAD_SIZE=$choice + if [ "$MAX_UPLOAD_SIZE" == '' ]; then + MAX_UPLOAD_SIZE=100 + fi + done + fi + + + DEST=$ISHTAR_PATH cat >&2 <<-'EOF' @@ -242,6 +267,7 @@ EOF s|#DB_NAME#|$DB_NAME|g;\ s|#DB_PORT#|$DB_PORT|g;\ s|#DB_PASSWORD#|$DB_PASSWORD|g;\ + s|#MAX_UPLOAD_SIZE#|$MAX_UPLOAD_SIZE|g;\ s|#URL#|$URL|g;\ s|#APP_DIR#|$APP_DIR|g;\ s|#SECRET_KEY#|$SECRET_KEY|g;" \ @@ -272,6 +298,7 @@ EOF s|#UWSGI_PORT#|$UWSGI_PORT|g;\ s|#NGINX_PORT#|$NGINX_PORT|g;\ s|#INSTALL_PATH#|$INSTALL_PATH|g;\ + s|#MAX_UPLOAD_SIZE#|$MAX_UPLOAD_SIZE|g;\ s|#URL#|$URL|g;" \ "install/nginx.conf.template" > \ "$INSTANCE/nginx.conf" diff --git a/install/local_settings.py.sample b/install/local_settings.py.sample index dbe4e7e62..93ccdc01a 100644 --- a/install/local_settings.py.sample +++ b/install/local_settings.py.sample @@ -13,6 +13,10 @@ LOGFILE = "/var/log/django/ishtar-#APP_NAME#.log" MEDIA_ROOT = "#APP_DIR#/media/" +# if you change this parameter do not forget to change it in your nginx +# configuration +MAX_UPLOAD_SIZE = #MAX_UPLOAD_SIZE# # in Mo + ODT_TEMPLATE = "#INSTALL_PATH#/ishtar_common/static/template.odt" ALLOWED_HOSTS = ["#URL#"] diff --git a/install/nginx.conf.template b/install/nginx.conf.template index 15333393b..cf28553a8 100644 --- a/install/nginx.conf.template +++ b/install/nginx.conf.template @@ -4,7 +4,9 @@ server { root #INSTALL_PATH#; access_log /var/log/django/#APP_NAME#-access.log; error_log /var/log/django/#APP_NAME#-error.log; - client_max_body_size 20M; + # if you change client_max_body_size do not forget to change it also + # to your corresponding local_settings.py file + client_max_body_size #MAX_UPLOAD_SIZE#M; location /static/ { # STATIC_URL alias #INSTALL_PATH#/#APP_NAME#/static/; # STATIC_ROOT diff --git a/ishtar_common/forms_common.py b/ishtar_common/forms_common.py index b461d6266..47a282ab7 100644 --- a/ishtar_common/forms_common.py +++ b/ishtar_common/forms_common.py @@ -44,7 +44,8 @@ from ishtar_common.templatetags.link_to_window import simple_link_to_window from forms import FinalForm, FormSet, reverse_lazy, name_validator, \ TableSelect, ManageOldType, CustomForm, FieldType, FormHeader, \ FormSetWithDeleteSwitches, IshtarForm, get_data_from_formset -from ishtar_common.utils import is_downloadable, clean_session_cache +from ishtar_common.utils import is_downloadable, clean_session_cache, \ + max_size_help from archaeological_operations.models import Operation from archaeological_context_records.models import ContextRecord @@ -1072,11 +1073,13 @@ class MergeOrganizationForm(MergeForm): 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>") \ + return max_size_help() + return unicode( + _(u"Heavy images are resized to: %(width)dx%(height)d " + u"(ratio is preserved).") \ % {'width': settings.IMAGE_MAX_SIZE[0], - 'height': settings.IMAGE_MAX_SIZE[1]} + 'height': settings.IMAGE_MAX_SIZE[1]}) + " " + unicode( + max_size_help()) ####################### @@ -1108,7 +1111,7 @@ class DocumentForm(forms.ModelForm, CustomForm, ManageOldType): max_length=255, required=False, widget=widgets.ImageFileInput()) associated_file = forms.FileField( label=pgettext(u"Not directory", u"File"), max_length=255, - required=False) + required=False, help_text=max_size_help()) reference = forms.CharField( label=_(u"Reference"), validators=[validators.MaxLengthValidator(100)], required=False) diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 71868cb63..73366e35a 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -27,7 +27,6 @@ from importlib import import_module from jinja2 import TemplateSyntaxError import logging import os -import pytz import re import shutil import tempfile @@ -56,7 +55,6 @@ from django.db.utils import DatabaseError from django.template.defaultfilters import slugify from django.utils.functional import lazy from django.utils.safestring import SafeUnicode, mark_safe -#from django.utils.timezone import now, timedelta from django.utils.translation import ugettext_lazy as _, ugettext, \ pgettext_lazy, activate, deactivate from secretary import Renderer as SecretaryRenderer @@ -73,7 +71,7 @@ from ishtar_common.models_imports import ImporterModel, ImporterType, \ Import, TargetKeyGroup from ishtar_common.utils import get_cache, disable_for_loaddata, create_slug, \ get_all_field_names, merge_tsvectors, cached_label_changed, \ - generate_relation_graph + generate_relation_graph, max_size_help __all__ = [ 'ImporterModel', 'ImporterType', 'ImporterDefault', 'ImporterDefaultValues', @@ -992,9 +990,10 @@ def get_image_path(instance, filename): class ImageModel(models.Model): image = models.ImageField(upload_to=get_image_path, blank=True, null=True, - max_length=255) - thumbnail = models.ImageField(upload_to=get_image_path, blank=True, - null=True, max_length=255) + max_length=255, help_text=max_size_help()) + thumbnail = models.ImageField( + upload_to=get_image_path, blank=True, null=True, max_length=255, + help_text=max_size_help()) IMAGE_MAX_SIZE = settings.IMAGE_MAX_SIZE THUMB_MAX_SIZE = settings.THUMB_MAX_SIZE IMAGE_PREFIX = '' @@ -1115,7 +1114,7 @@ class RelationItem(models.Model): """ relation_image = models.FileField( _(u"Generated relation image (SVG)"), null=True, blank=True, - upload_to=get_image_path + upload_to=get_image_path, help_text=max_size_help() ) class Meta: @@ -2538,7 +2537,7 @@ class DocumentTemplate(models.Model): slug = models.SlugField(_(u"Slug"), blank=True, null=True, max_length=100, unique=True) template = models.FileField( - _(u"Template"), upload_to="templates/%Y/") + _(u"Template"), upload_to="templates/%Y/", help_text=max_size_help()) associated_object_name = models.CharField( _(u"Associated object"), max_length=100, choices=CLASSNAMES) available = models.BooleanField(_(u"Available"), default=True) @@ -3896,7 +3895,8 @@ class Document(OwnPerms, ImageModel, FullSearch, Imported): title = models.TextField(_(u"Title"), blank=True, default='') associated_file = models.FileField( - upload_to=get_image_path, blank=True, null=True, max_length=255) + upload_to=get_image_path, blank=True, null=True, max_length=255, + help_text=max_size_help()) index = models.IntegerField(verbose_name=_(u"Index"), blank=True, null=True) external_id = models.TextField(_(u"External ID"), null=True, blank=True) diff --git a/ishtar_common/models_imports.py b/ishtar_common/models_imports.py index b5ce3323d..e9f0e5d9e 100644 --- a/ishtar_common/models_imports.py +++ b/ishtar_common/models_imports.py @@ -41,7 +41,7 @@ from django.utils.translation import ugettext_lazy as _, pgettext_lazy from ishtar_common.utils import create_slug, \ get_all_related_m2m_objects_with_model, put_session_message, \ - put_session_var, get_session_var, num2col + put_session_var, get_session_var, num2col, max_size_help from ishtar_common.data_importer import Importer, ImportFormater, \ IntegerFormater, FloatFormater, UnicodeFormater, DateFormater, \ TypeFormater, YearFormater, StrToBoolean, FileFormater, InseeFormater, \ @@ -828,10 +828,11 @@ class Import(models.Model): name = models.CharField(_(u"Name"), max_length=500, null=True) importer_type = models.ForeignKey(ImporterType) imported_file = models.FileField( - _(u"Imported file"), upload_to="upload/imports/%Y/%m/", max_length=220) + _(u"Imported file"), upload_to="upload/imports/%Y/%m/", max_length=220, + help_text=max_size_help()) imported_images = models.FileField( _(u"Associated images (zip file)"), upload_to="upload/imports/%Y/%m/", - blank=True, null=True, max_length=220) + blank=True, null=True, max_length=220, help_text=max_size_help()) associated_group = models.ForeignKey( TargetKeyGroup, blank=True, null=True, help_text=_(u"If a group is selected, target key saved in this group " @@ -842,15 +843,15 @@ class Import(models.Model): skip_lines = models.IntegerField( _(u"Skip lines"), default=1, help_text=_(u"Number of header lines in your file (can be 0).")) - error_file = models.FileField(_(u"Error file"), - upload_to="upload/imports/%Y/%m/", - blank=True, null=True, max_length=255) - result_file = models.FileField(_(u"Result file"), - upload_to="upload/imports/%Y/%m/", - blank=True, null=True, max_length=255) - match_file = models.FileField(_(u"Match file"), - upload_to="upload/imports/%Y/%m/", - blank=True, null=True, max_length=255) + error_file = models.FileField( + _(u"Error file"), upload_to="upload/imports/%Y/%m/", + blank=True, null=True, max_length=255, help_text=max_size_help()) + result_file = models.FileField( + _(u"Result file"), upload_to="upload/imports/%Y/%m/", + blank=True, null=True, max_length=255, help_text=max_size_help()) + match_file = models.FileField( + _(u"Match file"), upload_to="upload/imports/%Y/%m/", blank=True, + null=True, max_length=255, help_text=max_size_help()) state = models.CharField(_(u"State"), max_length=2, choices=IMPORT_STATE, default=u'C') conservative_import = models.BooleanField( diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py index cbc7d069d..562992bdb 100644 --- a/ishtar_common/utils.py +++ b/ishtar_common/utils.py @@ -958,3 +958,10 @@ def m2m_historization_changed(sender, **kwargs): elif not obj.history_modifier: obj.skip_history_when_saving = True obj.save() + + +def max_size_help(): + msg = unicode(_(u"The maximum supported file size is {} Mo.")).format( + settings.MAX_UPLOAD_SIZE + ) + return msg |