class SymbolForm(FileFormMixin, forms.ModelForm): METHODS = ( (0, "Suggested path"), (1, "Upload linux packages"), (2, "Upload symbol"), ) method = forms.IntegerField(label="Method", widget=forms.Select(choices=METHODS)) path = SimpleArrayField(forms.CharField(required=False)) packages = MultipleUploadedFileField(required=False) symbol = UploadedFileField(required=False) def __init__(self, *args, **kwargs): super(SymbolForm, self).__init__(*args, **kwargs) self.fields["banner"].widget.attrs["readonly"] = True class Meta: model = Dump fields = ( "index", "operating_system", "banner", "method", "path", "packages", "symbol", ) widgets = { "index": forms.HiddenInput(), "operating_system": forms.HiddenInput(), }
class ExampleMultipleModelForm(FileFormMixin, ModelForm): class Meta: model = Example2 fields = ("title", ) input_file = MultipleUploadedFileField() prefix = "example"
class RuleForm(FileFormMixin, forms.Form): rules = MultipleUploadedFileField(required=False) def __init__(self, *args, **kwargs): super(RuleForm, self).__init__(*args, **kwargs) class Meta: fields = ("rules", )
class PlaceholderS3ExampleForm(BaseForm): prefix = "example" input_file = MultipleUploadedFileField() other_input_file = UploadedFileField() s3_upload_dir = "s3_placeholder_example" def save(self): self.delete_temporary_files()
class MultipleFileExampleForm(BaseForm): input_file = MultipleUploadedFileField() def save(self): example = Example2.objects.create(title=self.cleaned_data['title']) for f in self.cleaned_data['input_file']: ExampleFile.objects.create(example=example, input_file=f) self.delete_temporary_files()
class MultipleFileExampleForm(BaseForm): prefix = "example" input_file = MultipleUploadedFileField() def save(self): example = Example2.objects.create(title=self.cleaned_data["title"]) for f in self.cleaned_data["input_file"]: try: ExampleFile.objects.create(example=example, input_file=f) finally: f.close() self.delete_temporary_files()
class PlaceholderExampleForm(BaseForm): prefix = "example" input_file = MultipleUploadedFileField() other_input_file = UploadedFileField() def save(self): example = Example2.objects.create(title=self.cleaned_data["title"]) for f in self.cleaned_data["input_file"]: if f.is_placeholder: continue try: ExampleFile.objects.create(example=example, input_file=f) finally: f.close() self.delete_temporary_files()
class PlaceholderExampleForm(BaseForm): prefix = 'example' input_file = MultipleUploadedFileField() def save(self): example = Example2.objects.create( title=self.cleaned_data['title'] ) for f in self.cleaned_data['input_file']: if f.is_placeholder: continue ExampleFile.objects.create( example=example, input_file=f ) f.close() self.delete_temporary_files()
def __init__(self, *args, **kwargs): super(NewSiteForm, self).__init__(*args, **kwargs) self.fields['name'] = forms.CharField(max_length=128, label=_('Name')) self.fields['undefined'] = forms.BooleanField( required=False, label=_('Dating is undefined')) self.fields['literature'] = forms.CharField(required=False, widget=forms.Textarea, max_length=2048, label=_('Literature')) self.create_filter_fields() # create image fields for i, choice in ImageType.choices: field = None # limit site profile picture to one if i == ImageType.general: field = UploadedFileField(required=False, label=_(choice)) else: field = MultipleUploadedFileField(required=False, label=_(choice)) self.fields[choice.lower()] = field
class S3ExampleForm(BaseForm): prefix = "example" input_file = MultipleUploadedFileField() s3_upload_dir = "s3_example" def save(self): example = Example2.objects.create(title=self.cleaned_data["title"]) for f in self.cleaned_data["input_file"]: try: assert f.is_s3direct # FILE_FORM_UPLOAD_DIR/s3_upload_dir/basename_RANDOM.ext basename = os.path.splitext(os.path.basename(f.name))[0] # basename.ext original_basename = os.path.splitext(f.original_name)[0] assert basename.startswith(original_basename) # download from S3 example_file = ExampleFile(example=example) example_file.input_file.save(original_basename, f) example_file.save() finally: f.close()
class WithAcceptExampleForm(BaseForm): prefix = "example" input_file = MultipleUploadedFileField(accept="image/*")
class UploadFilesForm(FileFormMixin, forms.Form): input_files = MultipleUploadedFileField()
class MultipleInputFileForm(FileFormMixin, forms.Form): input_file = MultipleUploadedFileField()