Skip to content

Commit

Permalink
Reworked ContainerForm and ContainerUpdateForm to fix updating Contai…
Browse files Browse the repository at this point in the history
…ners.
  • Loading branch information
Richard Liang committed Feb 11, 2019
1 parent 78ea6e0 commit b13ee4a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 25 deletions.
19 changes: 10 additions & 9 deletions kive/container/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,25 @@ 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),
required=False)

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
Expand Down Expand Up @@ -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)),
Expand Down
16 changes: 0 additions & 16 deletions kive/container/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down

0 comments on commit b13ee4a

Please sign in to comment.