コード例 #1
0
ファイル: forms.py プロジェクト: garanews/orochi
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(),
        }
コード例 #2
0
class ExampleMultipleModelForm(FileFormMixin, ModelForm):
    class Meta:
        model = Example2
        fields = ("title", )

    input_file = MultipleUploadedFileField()
    prefix = "example"
コード例 #3
0
ファイル: forms.py プロジェクト: Blue-infosec/orochi
class RuleForm(FileFormMixin, forms.Form):
    rules = MultipleUploadedFileField(required=False)

    def __init__(self, *args, **kwargs):
        super(RuleForm, self).__init__(*args, **kwargs)

    class Meta:
        fields = ("rules", )
コード例 #4
0
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()
コード例 #5
0
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()
コード例 #6
0
ファイル: forms.py プロジェクト: jucajuca/django-file-form
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()
コード例 #7
0
ファイル: forms.py プロジェクト: jucajuca/django-file-form
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()
コード例 #8
0
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()
コード例 #9
0
ファイル: forms.py プロジェクト: biletboh/archaeologyapp
    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
コード例 #10
0
ファイル: forms.py プロジェクト: jucajuca/django-file-form
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()
コード例 #11
0
ファイル: forms.py プロジェクト: jucajuca/django-file-form
class WithAcceptExampleForm(BaseForm):
    prefix = "example"
    input_file = MultipleUploadedFileField(accept="image/*")
コード例 #12
0
ファイル: forms.py プロジェクト: susejreina/dating
class UploadFilesForm(FileFormMixin, forms.Form):
    input_files = MultipleUploadedFileField()
コード例 #13
0
ファイル: forms.py プロジェクト: ngaurav/bootcamp
class MultipleInputFileForm(FileFormMixin, forms.Form):
    input_file = MultipleUploadedFileField()