~widelands-dev/widelands-website/django_staticfiles

« back to all changes in this revision

Viewing changes to wlimages/forms.py

  • Committer: franku
  • Date: 2016-04-18 13:29:23 UTC
  • mto: This revision was merged to the branch mainline in revision 409.
  • Revision ID: somal@arcor.de-20160418132923-bfzkb5mvdr7l8mz4
added migrations to each app

Show diffs side-by-side

added added

removed removed

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