コード例 #1
0
ファイル: views.py プロジェクト: dcaulton/thermal
def generic_update_view(item_id='', document_type=''):
    try:
        item_dict = get_document_with_exception(item_id, document_type)
        if request.headers['Content-Type'] == 'application/json':
            for k in request.json.keys():
                if doc_attribute_can_be_set(k):
                    item_dict[k] = request.json[k]
            update_generic(item_dict, document_type)
            return Response(json.dumps(item_dict), status=200, mimetype='application/json')
        error_msg = 'problem with update: content type is not application/json'
        return Response(json.dumps(error_msg), status=409, mimetype='application/json')
    except Exception as e:
        return Response(json.dumps(e.message), status=e.status_code, mimetype='application/json')
コード例 #2
0
ファイル: views.py プロジェクト: dcaulton/thermal
def update_group(group_id):
    '''
    Updates group record
    '''
    try:
        group_dict = get_group_document(group_id)
        if request.headers['Content-Type'] == 'application/json':
            for k in request.json.keys():
                if doc_attribute_can_be_set(k):
                    group_dict[k] = request.json[k]
            update_generic(group_dict, 'group')
            return Response(json.dumps(group_dict), status=200, mimetype='application/json')
        return Response(json.dumps('problem with request data'), status=409, mimetype='application/json')
    except Exception as e:
        return Response(json.dumps(e.message), status=e.status_code, mimetype='application/json')
コード例 #3
0
ファイル: views.py プロジェクト: dcaulton/thermal
def update_settings():
    '''
    Updates the settings document
    '''
    try:
        settings = get_settings_document()
        if request.headers['Content-Type'] == 'application/json':
            for k in request.json.keys():
                if doc_attribute_can_be_set(k):
                    settings[k] = request.json[k]
            update_generic(settings, 'settings')
            return Response(json.dumps(settings), status=200, mimetype='application/json')
        err_msg = 'no valid settings parameters supplied'
        return Response(json.dumps(err_msg), status=409, mimetype='application/json')
    except Exception as e:
        return Response(json.dumps(e.message), status=e.status_code, mimetype='application/json')
コード例 #4
0
def generic_update_view(item_id='', document_type=''):
    try:
        item_dict = get_document_with_exception(item_id, document_type)
        if request.headers['Content-Type'] == 'application/json':
            for k in request.json.keys():
                if doc_attribute_can_be_set(k):
                    item_dict[k] = request.json[k]
            update_generic(item_dict, document_type)
            return Response(json.dumps(item_dict),
                            status=200,
                            mimetype='application/json')
        error_msg = 'problem with update: content type is not application/json'
        return Response(json.dumps(error_msg),
                        status=409,
                        mimetype='application/json')
    except Exception as e:
        return Response(json.dumps(e.message),
                        status=e.status_code,
                        mimetype='application/json')
コード例 #5
0
def update_group(group_id):
    '''
    Updates group record
    '''
    try:
        group_dict = get_group_document(group_id)
        if request.headers['Content-Type'] == 'application/json':
            for k in request.json.keys():
                if doc_attribute_can_be_set(k):
                    group_dict[k] = request.json[k]
            update_generic(group_dict, 'group')
            return Response(json.dumps(group_dict),
                            status=200,
                            mimetype='application/json')
        return Response(json.dumps('problem with request data'),
                        status=409,
                        mimetype='application/json')
    except Exception as e:
        return Response(json.dumps(e.message),
                        status=e.status_code,
                        mimetype='application/json')
コード例 #6
0
def update_settings():
    '''
    Updates the settings document
    '''
    try:
        settings = get_settings_document()
        if request.headers['Content-Type'] == 'application/json':
            for k in request.json.keys():
                if doc_attribute_can_be_set(k):
                    settings[k] = request.json[k]
            update_generic(settings, 'settings')
            return Response(json.dumps(settings),
                            status=200,
                            mimetype='application/json')
        err_msg = 'no valid settings parameters supplied'
        return Response(json.dumps(err_msg),
                        status=409,
                        mimetype='application/json')
    except Exception as e:
        return Response(json.dumps(e.message),
                        status=e.status_code,
                        mimetype='application/json')
コード例 #7
0
 def test_doc_attribute_can_be_set_works_for_normal_and_forbidden_keys(
         self):
     assert tu.doc_attribute_can_be_set('lester')
     assert not tu.doc_attribute_can_be_set('_id')
     assert not tu.doc_attribute_can_be_set('_rev')
コード例 #8
0
ファイル: test_utils.py プロジェクト: dcaulton/thermal
 def test_doc_attribute_can_be_set_works_for_normal_and_forbidden_keys(self):
     assert tu.doc_attribute_can_be_set('lester')
     assert not tu.doc_attribute_can_be_set('_id')
     assert not tu.doc_attribute_can_be_set('_rev')