Exemplo n.º 1
0
def jot_index(request):
    item = Item.get_or_insert('jot')
    item.title = 'jot'
    if item.body:
        return HttpResponse(item.body)
    else:
        return HttpResponse('no jot content')
Exemplo n.º 2
0
def jot(request):
    item = Item.get_or_insert('jot')
    item.title = 'jot'
    
    data = {}
    if request.raw_post_data:
        data = simplejson.loads( request.raw_post_data )
    
    if request.method == 'GET':
        if item.body:
            return json_response( flatten_obj_to_json(item) )   
        else:
            return json_response( '{}' )
    
    if request.method == 'POST':
        item.body = data['body']
        item.put()
        return json_response( flatten_obj_to_json(item) )          
    
    if request.method == 'PUT':
        request.method = 'POST'
        request.method = 'PUT'
        request.PUT = request.POST
        del request._post
        if item.body:
            item.body = data['body'] + '\n' + item.body
        else:
            item.body = data['body']
        item.put()
        return json_response( flatten_obj_to_json(item) ) 
        
    if request.method == 'DELETE':
        request.method = 'POST'
        request.method = 'PUT'
        request.DELETE = request.POST
        del request._post
        if item.is_saved():
            item.delete()
        return json_response( '{}' )
Exemplo n.º 3
0
def jot(request):
    item = Item.get_or_insert('jot')
    item.title = 'jot'

    data = {}
    if request.raw_post_data:
        data = simplejson.loads(request.raw_post_data)

    if request.method == 'GET':
        if item.body:
            return json_response(flatten_obj_to_json(item))
        else:
            return json_response('{}')

    if request.method == 'POST':
        item.body = data['body']
        item.put()
        return json_response(flatten_obj_to_json(item))

    if request.method == 'PUT':
        request.method = 'POST'
        request.method = 'PUT'
        request.PUT = request.POST
        del request._post
        if item.body:
            item.body = data['body'] + '\n' + item.body
        else:
            item.body = data['body']
        item.put()
        return json_response(flatten_obj_to_json(item))

    if request.method == 'DELETE':
        request.method = 'POST'
        request.method = 'PUT'
        request.DELETE = request.POST
        del request._post
        if item.is_saved():
            item.delete()
        return json_response('{}')
Exemplo n.º 4
0
def jot_index(request):
    item = Item.get_or_insert('jot')
    item.title = 'jot'
    if item.body:
        return HttpResponse(item.body)
    else:
        return HttpResponse('no jot content')


        #i = simplejson.loads( request.raw_post_data )
        
        # convert unicode string keys to ascii string keys.
        # this is neccessary in order to use the ** operator in the following Item constructor
        #i2 = {}
        #for k in i.keys():
        #    i2[k.encode('ascii')] = i[k]
            
        #item = Item(None, None, **i2)
        
        #item.title = i['title']
        #item.body = i['body']
        #item.tags = i['tags']

        #data = serializers.serialize("json",items)
        #return HttpResponse( data )
        #item_list = []
        #for item in items:
        #    item_list.append({'id': item.key().id(), 'title': item.title, 'body': item.body, 'tags': item.tags})
        #return HttpResponse( simplejson.dumps(item_list) )
        #item.title = item_input['title']
        #item.body = item_input['body']
        #item.encoding = item_input['encoding']
        #item.tags = item_input['tags']
        #for key in item_input.keys():
        #    item.__dict__['_' + key] = item_input[key]        
        # save new item