X-Git-Url: https://git.mdrn.pl/edumed.git/blobdiff_plain/1084f388829b560079274b78214a6fda41f8ef23..f3e40709f5b8ebcdf42bbfd705cf8043759d9e64:/contact/forms.py diff --git a/contact/forms.py b/contact/forms.py index a9e3366..059f9e8 100644 --- a/contact/forms.py +++ b/contact/forms.py @@ -1,4 +1,6 @@ # -*- coding: utf-8 -*- +import os + from django.contrib.sites.models import Site from django.core.exceptions import ValidationError from django.core.files.uploadedfile import UploadedFile @@ -66,6 +68,7 @@ class ContactForm(forms.Form): super(ContactForm, self).__init__(data, files, *args, **kwargs) if not self.is_bound and self.instance: self.fields['contact'].initial = self.instance.contact + self.fields['contact'].widget = forms.HiddenInput() body = self.instance.body for field, value in body.iteritems(): if field in self.fields: @@ -137,11 +140,12 @@ class ContactForm(forms.Form): contact=self.cleaned_data['contact'], form_tag=self.form_tag) contact.generate_key() - contact.save() email_changed = True for name, value in self.cleaned_data.items(): if isinstance(value, UploadedFile): - Attachment.objects.filter(contact=contact, tag=name).delete() # delete files? + for attachment in Attachment.objects.filter(contact=contact, tag=name): + os.remove(attachment.file.path) + attachment.delete() attachment = Attachment(contact=contact, tag=name) attachment.file.save(value.name, value) attachment.save()