本文整理汇总了Python中utils.make_response函数的典型用法代码示例。如果您正苦于以下问题:Python make_response函数的具体用法?Python make_response怎么用?Python make_response使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了make_response函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)