• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python utils.make_response函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中utils.make_response函数的典型用法代码示例。如果您正苦于以下问题:Python make_response函数的具体用法?Python make_response怎么用?Python make_response使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了make_response函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: web_create_project

def web_create_project(request):
    """ Create a new project
    """

    result = {'user': None}
    #if True:
    try:

        user, token = check_auth(request)

        name = request.POST['name']
        description = request.POST['description']

        project = create_new_project(
            user= user, 
            name = name,
            description = description,
        )
        
        result['project_id'] = project.id
        
        result['success'] = True

    except:
        pass

    return make_response(result)
开发者ID:thequbit,项目名称:bits,代码行数:27,代码来源:views.py


示例2: web_authenticate

def web_authenticate(request):

    """ End-point to authenticate user, and return a login token
    """

    result = {'user': None}
    result['success'] = False
    #if True:
    try:
        try:
            email = request.GET['email']
            password = request.GET['password']
        except:
            result['error_text'] = 'Missing Field'
            result['error_code'] = 1
            raise Exception('error')

        user, token = do_login(email, password)

        if user == None or token == None:
            result['error_text'] = 'Invalid Credentials'
            result['error_code'] = 2
            raise Exception('error')

        result['token'] = token
        result['user'] = user

        result['success'] = True

    except:
        pass

    return make_response(result)
开发者ID:PeterSulcs,项目名称:bits,代码行数:33,代码来源:views.py


示例3: web_update_ticket_contents

def web_update_ticket_contents(request):

    result = {'success': False}

    #if True:
    try:

        user, token = check_auth(request)

        ticket_id = request.POST['ticket_id']
        contents = request.POST['contents']

        update_ticket_contents(
            user_id = user.id,
            ticket_id = ticket_id,
            contents = contents,
        )

        result['ticket_id'] = ticket_id

        result['success'] = True

    except:
        pass

    return make_response(result)
开发者ID:thequbit,项目名称:bits,代码行数:26,代码来源:views.py


示例4: admin_get_languages

def admin_get_languages(request):

    result = {'success': False}

    #try:
    if True:

        token = None
        valid_token = False
        valid, user = check_token(request)
        if valid == False:
            result['error_text'] = "Missing or invalid 'token' field in request."
            raise Exception('invalid/missing token')

        languages = Languages.get_all(DBSession)

        ret_languages = []
        for language_code, name in languages:
            ret_languages.append({
                'name': name,
                'code': language_code,
            })

        result['languages'] = ret_languages
        result['success'] = True

    #except:
    #    pass

    admin_log("HTTP: admin/get_languages.json => {0}".format(json.dumps(result)))

    return make_response(result)
开发者ID:Nolski,项目名称:yellr,代码行数:32,代码来源:admin_views.py


示例5: web_assign_user_to_ticket

def web_assign_user_to_ticket(request):

    result = {'success': False}
    
    #if True:
    try:
    
        user, token = check_auth(request)
    
        ticket_id = request.POST['ticket_id']
        email = request.POST['email']
        
        unassign = False
        try:
            unassign = str2bool(request.POST['unassign'])
        except:
            pass
            
        assign_user_to_ticket(
            user = user,
            ticket_id = ticket_id,
            email = email,
            unassign = unassign,
        )
    
        result['ticket_id'] = ticket_id
    
        result['success'] = True
    
    except:
        pass

    return make_response(result)
开发者ID:thequbit,项目名称:bits,代码行数:33,代码来源:views.py


示例6: admin_get_question_types

def admin_get_question_types(request):

    result = {'success': False}

    #try:
    if True:

        token = None
        valid_token = False
        valid, user = check_token(request)
        if valid == False:
            result['error_text'] = "Missing or invalid 'token' field in request."
            raise Exception('invalid/missing token')

        question_types = QuestionTypes.get_all(DBSession)

        ret_question_types = []
        for question_type_id, question_type_text, question_type_description \
                in question_types:
            ret_question_types.append({
                'question_type_id': question_type_id,
                'question_type_text': question_type_text,
                'question_type_description': question_type_description,
            })

        result['question_types'] = ret_question_types
        result['success'] = True

    #except:
    #    pass

    admin_log("HTTP: admin/get_question_types.json => {0}".format(json.dumps(result)))

    return make_response(result)
开发者ID:Nolski,项目名称:yellr,代码行数:34,代码来源:admin_views.py


示例7: web_close_ticket

def web_close_ticket(request):

    """ Create a new ticket
    """

    result = {'user': None}
    result['success'] = False

    #if True:
    try:

        user, token = check_auth(request)

        ticket_id = request.POST['ticket_id']
        
        ticket = close_ticket(user, ticket_id);

        result['ticket_id'] = ticket.id

        result['success'] = True

    except:
        pass

    return make_response(result)
开发者ID:thequbit,项目名称:bits,代码行数:25,代码来源:views.py


示例8: web_add_user

def web_add_user(request):

    result = {'success': False}
    #if True:
    try:
    
        user, token = check_auth(request)
        
        organization_id = request.POST['organization_id']
        user_type_id = request.POST['user_type_id']
        first = request.POST['first']
        last = request.POST['last']
        email = request.POST['email']
        password = request.POST['password']

        
        new_user = add_user(
            user = user,
            organization_id = organization_id,
            user_type_id = user_type_id,
            first = first,
            last = last,
            email = email,
            password = password,
        )
        
        result['new_user_id'] = new_user.id
        
        result['success'] = True
        
    except:
        pass
        
    return make_response(result)
开发者ID:thequbit,项目名称:bits,代码行数:34,代码来源:views.py


示例9: web_complete_task

def web_complete_task(request):

    """ Complete a task
    """

    result = {'user': None}
    result['success'] = False

    #if True:
    try:

        user, token = check_auth(request)

        task_id = request.POST['task_id']
        
        task = complete_task(user, task_id);

        result['task_id'] = task.id

        result['success'] = True

    except:
       pass

    return make_response(result)
开发者ID:thequbit,项目名称:bits,代码行数:25,代码来源:views.py


示例10: web_create_task

def web_create_task(request):
    """ Get all of the organizations that the user has access to
    """
    
    result = {'user': None}
    result['success'] = False

    #if True:
    try:

        user, token = check_auth(request)

        project_id = request.POST['project_id']
        title = request.POST['title']
        contents = request.POST['contents']
        assigned_id = request.POST['assigned_id']
        due = request.POST['due']

        task = create_new_task(
            user = user,
            project_id = project_id,
            title = title,
            contents = contents,
            assigned_id = assigned_id,
            due = due,
        )
        
        result['task_id'] = task.id;
        
        result['success'] = True

    except:
        pass

    return make_response(result)
开发者ID:thequbit,项目名称:bits,代码行数:35,代码来源:views.py


示例11: web_update_ticket_title

def web_update_ticket_title(request):

    result = {'success': False}

    #if True:
    try:

        user, token = check_auth(request)

        ticket_id = request.POST['ticket_id']
        title = request.POST['title']

        update_ticket_title(
            user = user,
            ticket_id = ticket_id,
            title = title,
        )

        result['ticket_id'] = ticket_id

        result['success'] = True

    except:
        pass

    return make_response(result)
开发者ID:thequbit,项目名称:bits,代码行数:26,代码来源:views.py


示例12: web_assign_user_to_project

def web_assign_user_to_project(request):
    """ Assign a user to a project
    """

    result = {}
    #if True:
    try:

        user, token = check_auth(request)
        
        project_id = int(request.POST['project_id'])
        email = request.POST['email']

        target_user, assignment = assign_user_to_project(
            user = user,
            project_id = project_id,
            email = email,
        )
    
        if assignment != None:
            result['assignment_id'] = assignment.id
        else:
            result['assignment_id'] = -1;
            
        result['project_id'] =  project_id
        result['user_id'] = target_user.id
    
        result['success'] = True

    except:
        pass

    return make_response(result)
开发者ID:thequbit,项目名称:bits,代码行数:33,代码来源:views.py


示例13: admin_publish_story

def admin_publish_story(request):

    result = {'success': False}

    ##try:
    if True:

        token = None
        valid_token = False
        valid, user = check_token(request)
        if valid == False:
            result['error_text'] = "Missing or invalid 'token' field in request."
            raise Exception('invalid/missing token')

        try:
            title = request.POST['title']
            tags = request.POST['tags']
            top_text = request.POST['top_text']
            banner_media_id = request.POST['banner_media_id']
            contents = request.POST['contents'].encode('UTF-8')
            top_left_lat = float(request.POST['top_left_lat'])
            top_left_lng = float(request.POST['top_left_lng'])
            bottom_right_lat = float(request.POST['bottom_right_lat'])
            bottom_right_lng = float(request.POST['bottom_right_lng'])
            language_code = request.POST['language_code']
            #use_fense = request.POST['use_fense']
        except:
            result['error_text'] = """\
One or more of the following fields is missing or invalid: title, tags, \
top_text, banner_media_id, contents, top_left_lat, top_left_lng, \
bottom_right_lat, bottom_right_lng, language_code. \
"""
            raise Exception('invalid/missing field')

        story = Stories.create_from_http(
            session = DBSession,
            token = user.token,
            title = title,
            tags = tags,
            top_text = top_text,
            media_id = banner_media_id,
            contents = contents,
            top_left_lat = top_left_lat,
            top_left_lng = top_left_lng,
            bottom_right_lat = bottom_right_lat,
            bottom_right_lng = bottom_right_lng,
            #use_fence = use_fense,
            language_code = language_code,
        )

        result['story_unique_id'] = story.story_unique_id
        result['success'] = True

    ##except:
    ##    pass

    admin_log("HTTP: admin/publish_story.json => {0}".format(json.dumps(result)))

    return make_response(result)
开发者ID:Nolski,项目名称:yellr,代码行数:59,代码来源:admin_views.py


示例14: admin_update_question

def admin_update_question(request):

    result = {'success': False}

    if True:
    #try:

        token = None
        valid_token = False
        valid, user = check_token(request)
        if valid == False:
            result['error_text'] = "Missing or invalid 'token' field in request."
            raise Exception('invalid/missing token')

        if True:
        #try:
            language_code = request.POST['language_code']
            question_text = request.POST['question_text']
            description = request.POST['description']
            question_type = request.POST['question_type']
        #except:
            result['error_text'] = """\
One or more of the following fields is missing or invalid: language_code, \
question_text, description, question_type. \
"""
            raise Exception('missing field')

        # answers is a json array of strings
        answers = []
        #try:
        if True:
            answers = json.loads(request.POST['answers'])
        #except:
        #    pass
        # back fill with empty strings
        for i in range(len(answers),10):
            answers.append('')

        question = Questions.update_from_http(
            session = DBSession,
            token = user.token,
            language_code = language_code,
            question_text = question_text,
            description = description,
            question_type = question_type,
            answers = answers,
        )

        result['question_id'] = question.question_id
        result['success'] = True

    #except:
    #    pass

    admin_log("HTTP: admin/updatequestion.json => {0}".format(json.dumps(result)))

    return make_response(result)
开发者ID:Nolski,项目名称:yellr,代码行数:57,代码来源:admin_views.py


示例15: dictionary

def dictionary():
    if(request.method == 'GET'):
        key = request.args.get('key')
        try:
            result = dict[key]
        except KeyError:
            abort(404)
        return make_response(result)
    elif(request.method == 'POST'):
        data = json.loads(request.data)
        try:
           key = data['key']
           value = data['value']
        except KeyError:
            abort(400)
        if(dict.get(key) != None):
            abort(409)
        else:
            dict.update({key : value})
            return make_response(value)
    elif(request.method == 'PUT'):
        data = json.loads(request.data)
        try:
           key = data['key']
           value = data['value']
        except KeyError:
            abort(400)
        if(dict.get(key) == None):
            abort(404)
        else:
            dict[key] = value
            return make_response(value)
    elif(request.method == 'DELETE'):
        data = json.loads(request.data)
        try:
            key = data['key']
        except KeyError:
            abort(404)
        if(dict.get(key) != None):
            dict.pop(key)
        return make_response(None)
开发者ID:allavlasova,项目名称:task1,代码行数:41,代码来源:app.py


示例16: admin_create_user

def admin_create_user(request):

    result = {'success': False}

    ##try:
    if True:

        token = None
        valid_token = False
        valid, user = check_token(request)
        if valid == False:
            result['error_text'] = "Missing or invalid 'token' field in request."
            raise Exception('invalid/missing token')

        #try:
            user_type_text = request.POST['user_type']
            user_name = request.POST['user_name']
        #    password = request.POST['password']
            first_name = request.POST['first_name']
            last_name = request.POST['last_name']
            email = request.POST['email']
            organization = request.POST['organization']
        #except:
            result['error_text'] = """\
One or more of the following fields is missing or invalid: user_type, \
user_name, password, first_name, last_name, email, organization. \
"""
            raise Exception('invalid/missing field')

        user_type = UserTypes.get_from_name(DBSession, user_type_text)
        user = Users.create_new_user(
            session = DBSession,
            user_type_id = user_type.user_type_id,
            client_id = str(uuid.uuid4()),
        )

        user = Users.verify_user(
            session = DBSession,
            client_id = user.client_id,
            user_name = user_name,
        #    password = password,
            first_name = first_name,
            last_name = last_name,
            email = email,
        )

        result['user_id'] = user.user_id
        result['success'] = True

    ##except:
    ##    pass

    return make_response(result)
开发者ID:Nolski,项目名称:yellr,代码行数:53,代码来源:admin_views.py


示例17: admin_update_assignment

def admin_update_assignment(request):

    result = {'success': False}

    #try:
    if True:

        token = None
        valid_token = False
        valid, user = check_token(request)
        if valid == False:
            result['error_text'] = "Missing or invalid 'token' field in request."
            raise Exception('invalid/missing token')

        if True:
        #try:
            assignment_id = request.POST['assignment_id']
            #client_id = request.POST['client_id']
            life_time = int(request.POST['life_time'])
            #questions = json.loads(request.POST['questions'])
            top_left_lat = float(request.POST['top_left_lat'])
            top_left_lng = float(request.POST['top_left_lng'])
            bottom_right_lat = float(request.POST['bottom_right_lat'])
            bottom_right_lng = float(request.POST['bottom_right_lng'])
            #use_fence = boolean(request.POST['use_fence'])
        #except:
            result['error_text'] = """\
One or more of the following fields is missing or invalid: life_time, \
top_left_lat, top_left_lng, bottom_right_lat, bottom_right_lng. \
"""
            raise Exception('invalid/missing field')

        # create assignment
        assignment = Assignments.update_assignment(
            session = DBSession,
            assignment_id = assignment_id,
            life_time = life_time,
            top_left_lat = top_left_lat,
            top_left_lng = top_left_lng,
            bottom_right_lat = bottom_right_lat,
            bottom_right_lng = bottom_right_lng,
            #use_fence = use_fence,
        )

        result['assignment_id'] = assignment.assignment_id
        result['success'] = True

    #except:
    #    pass

    admin_log("HTTP: admin/update_assignment.json => {0}".format(json.dumps(result)))

    return make_response(result)
开发者ID:Nolski,项目名称:yellr,代码行数:53,代码来源:admin_views.py


示例18: admin_get_my_collection

def admin_get_my_collection(request):

    result = {'success': False}

    ##try:
    if True:

        token = None
        valid_token = False
        valid, user = check_token(request)
        if valid == False:
            result['error_text'] = "Missing or invalid 'token' field in request."
            raise Exception('invalid/missing token')

#        #try:
#        if True:
#            name = request.POST['name']
#            description = request.POST['description']
#            tags = request.POST['tags']
#        #except:
#            result['error_text'] = """\
#One or more of the following fields is missing or invalid: name, \
#description, tags. \
#"""
#            raise Exception('Missing or invalid field.')

        collections = Collections.get_all_from_http(
           session = DBSession,
           token = user.token,
        )

        ret_collections = []
        for collection_id, user_id, collection_datetime, name, description, \
                tags, enabled in collections:
            ret_collections.append({
                'collection_id': collection_id,
                'collection_datetime': str(collection_datetime),
                'name': name,
                'decription': description,
                'tags': tags,
                'enabled': enabled,
            })

        result['collections'] = ret_collections
        result['success'] = True

    ##except:
    ##    pass

    admin_log("HTTP: admin/get_my_collections.json => {0}".format(json.dumps(result)))

    return make_response(result)
开发者ID:Nolski,项目名称:yellr,代码行数:52,代码来源:admin_views.py


示例19: get_messages

def get_messages(request):

    result = {'success': False}

#    try:

    if True:

        client_id = None
        try:
            client_id = request.GET['client_id']
        except:
            result['error_text'] = "Missing or invalid field."
            raise Exception("missing/invalid field")

        messages = Messages.get_messages_from_client_id(DBSession, client_id)
        ret_messages = []
        for message_id, from_user_id,to_user_id,message_datetime, \
                parent_message_id,subject,text, was_read,from_organization, \
                from_first_name,from_last_name in messages:
            ret_messages.append({
                'message_id': message_id,
                'from_user_id': from_user_id,
                'to_user_id': to_user_id,
                'from_organization': from_organization,
                'from_first_name': from_first_name,
                'from_last_name': from_last_name,
                'message_datetime': str(message_datetime),
                'parent_message_id': parent_message_id,
                'subject': subject,
                'text': text,
                'was_read': was_read,
            })

        result['messages'] = ret_messages
        result['success'] = True

#    except:
#        pass

    event_type = 'http_request'
    event_details = {
        'client_id': client_id,
        'method': 'get_messages.json',
        'message_count': len(ret_messages),
        'result': result,
    }
    client_log = EventLogs.log(DBSession,client_id,event_type,json.dumps(event_details))

    return make_response(result)
开发者ID:geowa4,项目名称:yellr,代码行数:50,代码来源:client_views.py


示例20: get_local_posts

def get_local_posts(request):

    result = {'success': False}
    status_code = 200

    #try:
    if True:
        success, error_text, language_code, lat, lng, \
            client = client_utils.register_client(request)
        if success == False:
            raise Exception(error_text)

        try:
            start = 0
            if 'start' in request.GET:
                start = int(float(request.GET['start']))
            count = 75
            if 'count' in request.GET:
                count = int(float(request.GET['count']))
        except:
            status_code = 403
            raise Exception("Invalid input.")

        posts = client_utils.get_approved_posts(
            client_id = client.client_id,
            language_code = language_code,
            lat = lat,
            lng = lng,
            start = start,
            count = count,
        )

        result['posts'] = posts
        result['success'] = True

    #except Exception, e:
    #    status_code = 400
    #    result['error_text'] = str(e)

    client_utils.log_client_action(
        client = client,
        url = 'get_approved_posts.json',
        lat = lat,
        lng = lng,
        request = request,
        result = result,
        success = success,
    )

    return utils.make_response(result, status_code)
开发者ID:Nolski,项目名称:yellr-server,代码行数:50,代码来源:ep_client_post.py



注:本文中的utils.make_response函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.makedirs函数代码示例发布时间:2022-05-26
下一篇:
Python utils.make_object函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap