示例#1
0
文件: ajax.py 项目: fergalmoran/dss
def upload_mix_image(request, mix_id):
    try:
        if len(request.FILES) != 0:
            mix = Mix.objects.get(pk=mix_id)
            if mix:
                mix.mix_image = request.FILES[request.FILES.keys()[0]]
                mix.save()
                return HttpResponse(json.dumps({'status': 'OK', 'url': mix.get_image_url()}))
    except Exception, ex:
        logger.exception("Error uploading avatar: %s", ex.message)
        return HttpResponse(json.dumps({'status': 'failed', 'message': ex.message}))
示例#2
0
文件: ajax.py 项目: fergalmoran/dss
def upload_avatar_image(request):
    # TODO: [email protected]
    # Problem here that only the current user can update avatar
    # Might need to allow staff to change other's avatars?
    try:
        if len(request.FILES) != 0:
            profile = request.user.get_profile()
            if profile:
                profile.avatar_image = request.FILES[request.FILES.keys()[0]]
                profile.avatar_type = 'custom'
                profile.save()
                return HttpResponse(json.dumps({'status': 'OK', 'url': profile.get_avatar_image()}))
    except Exception, ex:
        logger.exception("Error uploading avatar: %s", ex.message)
        return HttpResponse(json.dumps({'status': 'failed', 'message': ex.message}))
示例#3
0
def post_activity(session_id, activity_url):
    payload = {
        'sessionid': session_id,
        'message': activity_url
    }
    data = json.dumps(payload)
    r = requests.post(localsettings.REALTIME_HOST + 'activity', data=data, headers=settings.REALTIME_HEADERS)
    if r.status_code == 200:
        return ""
    else:
        return r.text
示例#4
0
文件: ajax.py 项目: fergalmoran/dss
def lookup_search(request):
    query = request.GET['query'] if 'query' in request.GET else request.GET['q'] if 'q' in request.GET else ''
    if query != '':
        filter_field = Mix.get_lookup_filter_field()
        kwargs = {
        '{0}__{1}'.format(filter_field, 'icontains'): query,
        }
        rows = Mix.objects.values("title").filter(**kwargs)
        #results = serializers.serialize("json", rows, fields="title",)
        results = json.dumps(rows)
        return HttpResponse(results, mimetype='application/json')
示例#5
0
def post_notification(session_id, image, message):
    try:
        payload = {
            'sessionid': session_id,
            'image': image,
            'message': message
        }
        data = json.dumps(payload)
        r = requests.post(
            localsettings.REALTIME_HOST + 'notification',
            data=data,
            headers=HEADERS
        )
        if r.status_code == 200:
            return ""
        else:
            return r.text
    except ConnectionError:
        #should probably implement some sort of retry in here
        pass
示例#6
0
文件: ajax.py 项目: fergalmoran/dss
    return HttpResponse(_get_json("Failed"))


def upload_mix_image(request, mix_id):
    try:
        if len(request.FILES) != 0:
            mix = Mix.objects.get(pk=mix_id)
            if mix:
                mix.mix_image = request.FILES[request.FILES.keys()[0]]
                mix.save()
                return HttpResponse(json.dumps({'status': 'OK', 'url': mix.get_image_url()}))
    except Exception, ex:
        logger.exception("Error uploading avatar: %s", ex.message)
        return HttpResponse(json.dumps({'status': 'failed', 'message': ex.message}))

    return HttpResponse(json.dumps({'status': 'failed', 'message': 'No image file found'}))


def upload_avatar_image(request):
    # TODO: [email protected]
    # Problem here that only the current user can update avatar
    # Might need to allow staff to change other's avatars?
    try:
        if len(request.FILES) != 0:
            profile = request.user.get_profile()
            if profile:
                profile.avatar_image = request.FILES[request.FILES.keys()[0]]
                profile.avatar_type = 'custom'
                profile.save()
                return HttpResponse(json.dumps({'status': 'OK', 'url': profile.get_avatar_image()}))
    except Exception, ex: