def show_attachment(request, hash): attachment = get_object_or_404(Attachment, hash=hash) if forum_settings.ATTACHMENT_EC2_SUPPORT: from djangobb_forum.attachment_storage import AttachmentStorage attachment_storage = AttachmentStorage() file_data = attachment_storage.get_attachment(attachment.path) else: file_data = file(attachment.get_absolute_path(), 'rb').read() response = HttpResponse(file_data, mimetype=attachment.content_type) response['Content-Disposition'] = 'attachment; filename="%s"' % smart_str(attachment.name) return response
def show_attachment(request, hash): attachment = get_object_or_404(Attachment, hash=hash) if forum_settings.ATTACHMENT_EC2_SUPPORT: from djangobb_forum.attachment_storage import AttachmentStorage attachment_storage = AttachmentStorage() file_data = attachment_storage.get_attachment(attachment.path) else: file_data = file(attachment.get_absolute_path(), "rb").read() response = HttpResponse(file_data, mimetype=attachment.content_type) response["Content-Disposition"] = 'attachment; filename="%s"' % smart_str(attachment.name) return response
def save_attachment(self, post, memfile): if memfile: obj = Attachment(size=memfile.size, content_type=memfile.content_type, name=memfile.name, post=post) if forum_settings.ATTACHMENT_EC2_SUPPORT: from djangobb_forum.attachment_storage import AttachmentStorage attachment_storage = AttachmentStorage() attachment_storage.add_attachment(post.id, memfile) obj.path = post.id else: dir = os.path.join(settings.MEDIA_ROOT, forum_settings.ATTACHMENT_UPLOAD_TO) fname = '%d.0' % post.id path = os.path.join(dir, fname) file(path, 'wb').write(memfile.read()) obj.path = fname obj.save()
def save_attachment(self, post, memfile): if memfile: obj = Attachment(size=memfile.size, content_type=memfile.content_type, name=memfile.name, post=post) if forum_settings.ATTACHMENT_EC2_SUPPORT: from djangobb_forum.attachment_storage import AttachmentStorage attachment_storage = AttachmentStorage() attachment_storage.add_attachment(post.id, memfile) obj.path = post.id else: dir = os.path.join(settings.MEDIA_ROOT, forum_settings.ATTACHMENT_UPLOAD_TO) fname = '%d.0' % post.id path = os.path.join(dir, fname) file(path, 'wb').write(memfile.read()) obj.path = fname obj.save()