def __init__(self, *args, **kwargs): self.legend = kwargs.pop('legend', 'Entry') self.compo = kwargs.pop('compo', None) self.editing = kwargs.pop('editing', False) # Max sizes for filefields self.max_source_size = self.compo.source_sizelimit self.max_entry_size = self.compo.entry_sizelimit # Layout for uni-form ext. self.helper = FormHelper() self.helper.layout = Layout( Fieldset(self.legend, 'name', 'creator', 'description', 'entryfile', 'sourcefile', 'imagefile_original', ButtonHolder(Submit('submit', 'Tallenna')))) # Create the fields super(EntryForm, self).__init__(*args, **kwargs) # Give the entryfile and sourcefile fields a nicer help_text if self.compo: self.fields[ 'entryfile'].help_text = u"Tuotospaketti. Sallitut tiedostoformaatit: " + self.compo.readable_entry_formats( ) + u'. Tiedoston maksimikoko on ' + sizeformat( self.max_entry_size) + '.' self.fields[ 'sourcefile'].help_text = u"Lähdekoodipaketti. Sallitut tiedostoformaatit: " + self.compo.readable_source_formats( ) + u'. Tiedoston maksimikoko on ' + sizeformat( self.max_source_size) + '.' # If we are editing, then entryfile field is not required if self.editing: self.fields['entryfile'].required = False
def __init__(self, *args, **kwargs): self.compo = kwargs.pop('compo', None) # Max sizes for filefields self.max_source_size = self.compo.source_sizelimit self.max_entry_size = self.compo.entry_sizelimit self.show_thumbnail_field = (self.compo.thumbnail_pref == 0 or self.compo.thumbnail_pref == 2) self.max_image_size = 6 * 1024 * 1024 # Layout for uni-form ext. self.helper = FormHelper() # Fill the fieldset with the required fields fs = Fieldset('Entry') fs.fields.extend( ['name', 'creator', 'description', 'entryfile', 'sourcefile']) # Add thumbnail field if necessary if self.show_thumbnail_field: fs.fields.append('imagefile_original') # Add submitbutton fs.fields.append(ButtonHolder(Submit('submit', 'Tallenna'))) # Add fieldset to layout self.helper.layout = Layout(fs) # Create the fields super(EntryForm, self).__init__(*args, **kwargs) # Give the entryfile and sourcefile fields a nicer help_text if self.compo: # Description for entryfile self.fields['entryfile'].help_text = \ "Tuotospaketti. Sallitut tiedostoformaatit: {}. Tiedoston maksimikoko on {}.".format( self.compo.readable_entry_formats, sizeformat(self.max_entry_size)) # Description for sourcefile self.fields['sourcefile'].help_text = \ "Lähdekoodipaketti. Sallitut tiedostoformaatit: {}. Tiedoston maksimikoko on {}.".format( self.compo.readable_source_formats, sizeformat(self.max_source_size)) # If we want to show thumbnail field, set description etc. # Otherwise delete field from form. if self.show_thumbnail_field: # Set thumbnail "field required" flag if self.compo.thumbnail_pref == 0: self.fields['imagefile_original'].required = True else: self.fields['imagefile_original'].required = False # Description for imagefile self.fields['imagefile_original'].help_text = \ "Kuva teokselle. Tätä käytetään mm. arkistossa ja kompomaatin äänestysvaiheessa. Sallitut " \ "kuvaformaatit: {}. Tiedoston maksimikoko on {}.".format(self.compo.readable_image_formats, sizeformat(self.max_image_size)) else: del self.fields['imagefile_original']
def __init__(self, *args, **kwargs): self.legend = kwargs.pop("legend", "Entry") self.compo = kwargs.pop("compo", None) self.editing = kwargs.pop("editing", False) # Max sizes for filefields self.max_source_size = self.compo.source_sizelimit self.max_entry_size = self.compo.entry_sizelimit # Layout for uni-form ext. self.helper = FormHelper() self.helper.layout = Layout( Fieldset( self.legend, "name", "creator", "description", "entryfile", "sourcefile", "imagefile_original", ButtonHolder(Submit("submit", "Tallenna")), ) ) # Create the fields super(EntryForm, self).__init__(*args, **kwargs) # Give the entryfile and sourcefile fields a nicer help_text if self.compo: self.fields["entryfile"].help_text = ( u"Tuotospaketti. Sallitut tiedostoformaatit: " + self.compo.readable_entry_formats() + u". Tiedoston maksimikoko on " + sizeformat(self.max_entry_size) + "." ) self.fields["sourcefile"].help_text = ( u"Lähdekoodipaketti. Sallitut tiedostoformaatit: " + self.compo.readable_source_formats() + u". Tiedoston maksimikoko on " + sizeformat(self.max_source_size) + "." ) # If we are editing, then entryfile field is not required if self.editing: self.fields["entryfile"].required = False
def clean_sourcefile(self): if not self.field_size_ok("sourcefile", self.max_source_size): raise ValidationError( u"Tiedoston koko on liian suuri! Suurin sallittu koko on " + sizeformat(self.max_source_size) + "." ) if not self.field_format_ok("sourcefile", self.compo.source_formats): raise ValidationError( u"Tiedostotyyppi ei ole sallittu. Sallitut formaatit: " + self.compo.readable_source_formats() + "." ) return self.cleaned_data["sourcefile"]
def clean_sourcefile(self): if not self.field_size_ok("sourcefile", self.max_source_size): raise ValidationError( u'Tiedoston koko on liian suuri! Suurin sallittu koko on ' + sizeformat(self.max_source_size) + '.') if not self.field_format_ok("sourcefile", self.compo.source_formats): raise ValidationError( u'Tiedostotyyppi ei ole sallittu. Sallitut formaatit: ' + self.compo.readable_source_formats() + '.') return self.cleaned_data['sourcefile']
def clean_imagefile_original(self): # Check if imagefile_original is set if not self.cleaned_data['imagefile_original']: return None # Check image size if not self.field_size_ok("imagefile_original", self.max_image_size): raise ValidationError('Tiedoston koko on liian suuri! Suurin sallittu koko on {}.' .format(sizeformat(self.max_image_size))) # Check image format if not self.field_format_ok("imagefile_original", self.compo.image_format_list): raise ValidationError('Tiedostotyyppi ei ole sallittu. Sallitut formaatit: {}.' .format(self.compo.readable_image_formats)) # Done return self.cleaned_data['imagefile_original']
def clean_sourcefile(self): # Check if sourcefile is set if not self.cleaned_data['sourcefile']: return None # Check source file size if not self.field_size_ok("sourcefile", self.max_source_size): raise ValidationError('Tiedoston koko on liian suuri! Suurin sallittu koko on {}.' .format(sizeformat(self.max_source_size))) # Check source file format if not self.field_format_ok("sourcefile", self.compo.source_format_list): raise ValidationError('Tiedostotyyppi ei ole sallittu. Sallitut formaatit: {}.' .format(self.compo.readable_source_formats)) # All done. return self.cleaned_data['sourcefile']
def clean_imagefile_original(self): # Check if imagefile_original is set if not self.cleaned_data['imagefile_original']: return None # Check image size if not self.field_size_ok("imagefile_original", self.max_image_size): raise ValidationError('Tiedoston koko on liian suuri! Suurin sallittu koko on {}.' .format(sizeformat(self.max_image_size))) # Check image format if not self.field_format_ok("imagefile_original", self.compo.image_formats): raise ValidationError('Tiedostotyyppi ei ole sallittu. Sallitut formaatit: {}.' .format(self.compo.readable_image_formats)) # Done return self.cleaned_data['imagefile_original']
def clean_sourcefile(self): # Check if sourcefile is set if not self.cleaned_data['sourcefile']: return None # Check source file size if not self.field_size_ok("sourcefile", self.max_source_size): raise ValidationError('Tiedoston koko on liian suuri! Suurin sallittu koko on {}.' .format(sizeformat(self.max_source_size))) # Check source file format if not self.field_format_ok("sourcefile", self.compo.source_formats): raise ValidationError('Tiedostotyyppi ei ole sallittu. Sallitut formaatit: {}.' .format(self.compo.readable_source_formats)) # All done. return self.cleaned_data['sourcefile']
def readable_max_source_size(self): return sizeformat.sizeformat(self.max_source_size)
def clean_entryfile(self): # Check if entryfile is set if self.cleaned_data['entryfile'] == None: return None # Check entry file size if not self.field_size_ok("entryfile", self.max_entry_size): raise ValidationError(u'Tiedoston koko on liian suuri! Suurin sallittu koko on ' + sizeformat(self.max_entry_size) + '.') # Check entry file format if not self.field_format_ok("entryfile", self.compo.formats): raise ValidationError(u'Tiedostotyyppi ei ole sallittu. Sallitut formaatit: ' + self.compo.readable_entry_formats() + '.') # All done. return self.cleaned_data['entryfile']
def __init__(self, *args, **kwargs): self.compo = kwargs.pop('compo', None) # Max sizes for filefields self.max_source_size = self.compo.source_sizelimit self.max_entry_size = self.compo.entry_sizelimit self.show_thumbnail_field = (self.compo.thumbnail_pref == 0 or self.compo.thumbnail_pref == 2) self.max_image_size = 6 * 1024 * 1024 # Layout for uni-form ext. self.helper = FormHelper() # Fill the fieldset with the required fields fs = Fieldset(u'Entry') fs.fields.extend([ 'name', 'creator', 'description', 'entryfile', 'sourcefile' ]) # Add thumbnail field if necessary if self.show_thumbnail_field: fs.fields.append('imagefile_original') # Add submitbutton fs.fields.append(ButtonHolder(Submit('submit', u'Tallenna'))) # Add fieldset to layout self.helper.layout = Layout(fs) # Create the fields super(EntryForm, self).__init__(*args, **kwargs) # Give the entryfile and sourcefile fields a nicer help_text if self.compo: # Description for entryfile self.fields['entryfile'].help_text = \ u"Tuotospaketti. Sallitut tiedostoformaatit: " \ + self.compo.readable_entry_formats() \ + u'. Tiedoston maksimikoko on ' \ + sizeformat(self.max_entry_size) + '.' # Description for sourcefile self.fields['sourcefile'].help_text = \ u"Lähdekoodipaketti. Sallitut tiedostoformaatit: " \ + self.compo.readable_source_formats() \ + u'. Tiedoston maksimikoko on ' \ + sizeformat(self.max_source_size) + '.' # If we want to show thumbnail field, set description etc. # Otherwise delete field from form. if self.show_thumbnail_field: # Set thumbnail "field required" flag if self.compo.thumbnail_pref == 0: self.fields['imagefile_original'].required = True else: self.fields['imagefile_original'].required = False # Description for imagefile self.fields['imagefile_original'].help_text = \ u"Kuva teokselle. Tätä käytetään mm. arkistossa ja kompomaatin äänestysvaiheessa. Sallitut kuvaformaatit: " \ + self.compo.readable_image_formats() \ + u'. Tiedoston maksimikoko on ' \ + sizeformat(self.max_image_size) + '.' else: del self.fields['imagefile_original']
def readable_max_entry_size(self): return sizeformat.sizeformat(self.max_entry_size)
def readable_max_image_size(self): return sizeformat.sizeformat(self.max_image_size)