Beispiel #1
0
def get_manager(request, uid):
    manager = Manager.get_by_id(uid)
    if not manager:
        data = {'api_success': False,
                'api_msg': 'Manager %s not found' % uid}
        return render_json_response(data, status=404)

    if request.method == 'GET':
        return render_json_response(manager.to_json())

    if request.method == 'DELETE':
        manager.key.delete()
        data = {'api_success': True, 'api_msg': 'Manager %s deleted' % uid}
        return render_json_response(data)

    if request.method == 'PUT':
        model = simplejson.loads(request.data)
        manager.communication = Communication.from_json(model.get('communication', {}))
        manager.telephone = Telephone.from_json(model.get('telephone', {}))
        manager.address = Address.from_json(model.get('address', {}))
        manager.name = model.get('name', '')
        manager.last_name = model.get('last_name', '')
        manager.is_display = model.get('is_display', False)
        manager.put()
        data = {'api_success': True, 'api_msg': 'Manager %s updated' % uid}
        data.update(manager.to_json())
        return render_json_response(data)
Beispiel #2
0
def new_manager(request):
    model = simplejson.loads(request.data)
    try:
        communication = Communication.from_json(model.get('communications', {}))
        telephone = Telephone.from_json(model.get('telephone', {}))
        address = Address.from_json(model.get('address', {}))
        is_display = model.get('is_display', False)

        manager = Manager(
            name=model['name'],
            last_name=model['last_name'],
            communication=communication,
            telephone=telephone,
            address=address,
            is_display=is_display)
        manager.put()
    except Exception, e:
        data = {'api_success': False, 'api_msg': str(e)}
        return render_json_response(data, status=400)