diff --git a/kive/container/forms.py b/kive/container/forms.py index e8e5367a1..95bebdacb 100644 --- a/kive/container/forms.py +++ b/kive/container/forms.py @@ -26,7 +26,7 @@ class Meta(object): widgets = dict(description=forms.Textarea(attrs=dict(cols=50, rows=10))) -class ContainerForm(PermissionsForm): +class ContainerUpdateForm(PermissionsForm): parent = forms.ModelChoiceField( help_text=Container.parent.field.help_text, queryset=Container.objects.filter(file_type=Container.SIMG), @@ -34,9 +34,17 @@ class ContainerForm(PermissionsForm): class Meta(object): model = Container - fields = ['file', 'parent', 'tag', 'description', 'permissions'] + fields = ['parent', 'tag', 'description', 'permissions'] widgets = dict(description=forms.Textarea(attrs=dict(cols=50, rows=10))) + +class ContainerForm(ContainerUpdateForm): + """ + Form for creation of a Container. + """ + class Meta(ContainerUpdateForm.Meta): + fields = ['file'] + ContainerUpdateForm.Meta.fields + def __init__(self, *args, **kwargs): super(ContainerForm, self).__init__(*args, **kwargs) self.file_type_detected = None @@ -91,13 +99,6 @@ def clean(self): self.instance.file_type = file_type return self.cleaned_data - -class ContainerUpdateForm(ContainerForm): - def __init__(self, *args, **kwargs): - super(ContainerUpdateForm, self).__init__(*args, **kwargs) - self.fields.pop('file') - - class ContainerAppForm(forms.ModelForm): inputs = forms.CharField( widget=TextInput(attrs=dict(size=50)), diff --git a/kive/container/views.py b/kive/container/views.py index 55f0de2ef..3afdfe05b 100644 --- a/kive/container/views.py +++ b/kive/container/views.py @@ -86,22 +86,6 @@ def form_valid(self, form): form.instance.family = ContainerFamily.objects.get(pk=self.kwargs['family_id']) form.instance.set_md5() - # We need to get a file object to validate. We might have a path or we - # might have to read the data out of memory. - # container_file = form.files['file'] - # if hasattr(container_file, 'temporary_file_path'): - # with open(container_file.temporary_file_path()) as f: - # md5 = compute_md5(f) - # else: - # if hasattr(container_file, 'read'): - # - # f = BytesIO(container_file.read()) - # else: - # f = BytesIO(container_file['content']) - # md5 = compute_md5(f) - # if hasattr(container_file, 'seek') and callable(container_file.seek): - # container_file.seek(0) - response = super(ContainerCreate, self).form_valid(form) with transaction.atomic(): self.object.grant_from_json(form.cleaned_data["permissions"])