Opened 12 months ago
Closed 11 months ago
#227 closed defect (worksforme)
Avatar image upload upon replacement.
| Reported by: | lehins | Owned by: | somebody |
|---|---|---|---|
| Priority: | major | Milestone: | 1.0 |
| Component: | Uncategorized | Version: | devel |
| Keywords: | Cc: | ||
| Blocked By: | Blocking: |
Description
Avatar image uploading works fine, same with replacement of the image if the file was selected.
There is an exception:
'ImageFieldFile' object has no attribute 'content_type'
when clicked on upload button without selecting a new file, but only after initial upload.
The reason is that when no file selected
djangobb_forum.fields.ExtendedImageField.save_form_data()
gets an argument 'data' of type ImageFieldFile? instead of InMemoryUploadedFile?.
The way I fixed it was just to check for the instance type:
def save_form_data(self, instance, data):
if data and self.width and self.height and isinstance(data, InMemoryUploadedFile):
content = self.resize_image(data.read(), width=self.width, height=self.height)
salt = sha1(str(random.random())).hexdigest()[:5]
fname = sha1(salt + crowdsite.settings.SECRET_KEY).hexdigest() + '.png'
data = SimpleUploadedFile(fname, content, data.content_type)
super(ExtendedImageField, self).save_form_data(instance, data)
I hope the fix will be applied in future, or other solution to the bug implemented. Thanks, and thank you for the fine forum.
Change History (2)
comment:1 Changed 12 months ago by slav0nic
comment:2 Changed 11 months ago by slav0nic
- Resolution set to worksforme
- Status changed from new to closed
Note: See
TracTickets for help on using
tickets.

did u got this in latest tip?
http://djangobb.org/browser/djangobb_forum/fields.py#L43
same bug was fixed 1 month ago
i set content_type='image/png' becouse we always converted images to png, maybe this field will be replaced to sorl later, but i don't like 100500 dependence :)