~widelands-dev/widelands-website/django_staticfiles

« back to all changes in this revision

Viewing changes to wlimages/forms.py

  • Committer: franku
  • Date: 2016-12-13 18:28:51 UTC
  • mto: This revision was merged to the branch mainline in revision 443.
  • Revision ID: somal@arcor.de-20161213182851-bo5ebf8pdvw5beua
run the script

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 
4
4
import os
5
5
 
 
6
 
6
7
class UploadImageForm(forms.Form):
7
8
    # max_length = 90 because the length of 'upload_to =' has to be considered
8
9
    imagename = forms.ImageField(max_length=90)
9
10
 
10
 
    def clean_imagename( self ):
 
11
    def clean_imagename(self):
11
12
        # clean_<name_of_fieldvar>() acts only for this specific field
12
 
        in_mem_img = self.cleaned_data["imagename"]
13
 
        
 
13
        in_mem_img = self.cleaned_data['imagename']
 
14
 
14
15
        if Image.objects.has_image(in_mem_img.name):
15
16
            # Get the existing image to show its properties
16
 
            exist_img = Image.objects.get(name = in_mem_img.name)
 
17
            exist_img = Image.objects.get(name=in_mem_img.name)
17
18
            raise forms.ValidationError(
18
19
                ("There is already an image with name '%(name)s' attached to %(object)s '%(obj_name)s'. \
19
20
                 Use the existing image or rename your file and upload gain."),
20
 
                params={'name': exist_img.name, 'object': exist_img.content_type, 'obj_name': exist_img.content_object}
21
 
                )
22
 
 
 
21
                params={'name': exist_img.name, 'object': exist_img.content_type,
 
22
                        'obj_name': exist_img.content_object}
 
23
            )