

@treeio_login_required
def ajax_upload(request, object_id=None, record=None):
    try:
        object = None
        if (request.method == 'POST'):
            if request.is_ajax():
                upload = request
                is_raw = True
                try:
                    filename = request.GET['qqfile']
                    content_type = 'application/octet-stream'
                except KeyError:
                    return HttpResponseBadRequest('AJAX request not valid')
            else:
                is_raw = False
                if (len(request.FILES) == 1):
                    upload = request.FILES.values()[0]
                    content_type = upload.content_type
                else:
                    raise Http404('Bad Upload')
                filename = upload.name
            random.seed()
            filehash = str(random.getrandbits(128))
            savefile = join(getattr(settings, 'MEDIA_ROOT'), 'attachments', filehash)
            success = save_upload(upload, savefile, is_raw)
            attachment = Attachment(filename=filename, content_type=content_type, uploaded_by=request.user.profile, attached_file=filehash)
            if record:
                attachment.attached_record = record
                about = record.about.all()
                if about.count():
                    attachment.attached_object = about[0]
                    object = attachment.attached_object
            else:
                object = Object.objects.get(id=object_id)
                attachment.attached_object = object
            attachment.save()
            if object:
                object.set_last_updated()
            if success:
                ret_json = {
                    'success': success,
                    'object_id': (attachment.id if object else None),
                    'update_id': (record.id if record else None),
                }
            else:
                ret_json = {
                    'success': False,
                    'object_id': None,
                    'update_id': None,
                }
            return HttpResponse(json.dumps(ret_json))
    except:
        pass

dataset/ETHPy150Open treeio/treeio/treeio/core/views.py ajax_upload/VarMisuse@324/435 `object`->`attachment`