本文整理汇总了Python中models.User.User.select_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python User.select_by_id方法的具体用法?Python User.select_by_id怎么用?Python User.select_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.User.User
的用法示例。
在下文中一共展示了User.select_by_id方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: contribution_requests_refuse
# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import select_by_id [as 别名]
def contribution_requests_refuse():
contribution_request_id = request.form.get('contribution_request_id', -1)
contribution_request = Contribution_Request.select_by_id(contribution_request_id, 1)
if len(contribution_request) is not 0:
contribution_request = contribution_request[0]
tale = Tale.select_by_id(contribution_request['tale_id'], 1)[0]
if tale['creator_id'] is session.get('user_logged_id', None):
Contribution_Request.update_was_accepted(contribution_request['id'], False)
Tale.update_contribution_request_count(contribution_request['tale_id'], -1)
creator = User.select_by_id(tale['creator_id'], 1)[0]
contributor = User.select_by_id(contribution_request['user_id'], 1)[0]
email_object = strings.construct_contribution_request_refused_email_object(
session.get('language', 'en'),
tale,
creator,
contributor,
contribution_request['id']
)
aux.send_email_to_followers(tale['id'], email_object['title'], email_object['body'])
return redirect('/tale/' + str(contribution_request['tale_id']) + '/0')
else:
return redirect('/404')
else:
return redirect('/404')
示例2: collaborations
# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import select_by_id [as 别名]
def collaborations(tale_id):
tale = aux.is_visible_tale(tale_id, session.get('user_logged_id', None))
if tale:
chapters = Chapter.select_by_tale_id_order_by_date(tale_id)
chapters_dict = dict()
for chapter in chapters:
date = aux.beautify_datetime(chapter['date'])
if date not in chapters_dict:
chapters_dict[date] = list()
chapter['contributor_username'] = User.select_by_id(chapter['user_id'], 1)[0]['username']
chapters_dict[date].append(chapter)
keys = list(chapters_dict.keys())
keys.sort(reverse = True)
return aux.return_rendered_tale_template(
tale,
'collaborations.html',
contributions_object = {
'keys': keys,
'content': chapters_dict
}
)
else:
return redirect('/404')
示例3: tale_delete
# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import select_by_id [as 别名]
def tale_delete(tale_id):
tale = Tale.select_by_id(tale_id, 1)
if request.is_xhr and len(tale) is not 0 and session.get('user_logged_id', None) is tale[0]['creator_id']:
tale = tale[0]
creator = User.select_by_id(tale['creator_id'], 1)[0]
email_object = strings.construct_delete_tale_email_object(
session.get('language', 'en'),
tale,
creator
)
aux.send_email_to_followers(tale['id'], email_object['title'], email_object['body'])
Chapter.delete_by_tale_id(tale['id'])
Contribution_Request.delete_by_tale_id(tale['id'])
Follow.delete_by_tale_id(tale['id'])
Invitation.delete_by_tale_id(tale['id'])
Star.delete_by_tale_id(tale['id'])
Tale_Genre.delete_by_tale_id(tale['id'])
Tale.delete(tale['id'])
return jsonify(url = '/profile/' + creator['username'])
else:
redirect('/404')
示例4: tale
# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import select_by_id [as 别名]
def tale(tale_id, chapter_id):
tale = aux.is_visible_tale(tale_id, session.get('user_logged_id', None))
if tale:
if chapter_id is 0:
chapter = Chapter.select_by_tale_id_and_previous_chapter_id(tale['id'], -1, 1)
else:
chapter = Chapter.select_by_id(chapter_id, 1)
# no chapter with this ID
if len(chapter) is 0:
if chapter_id is 0:
chapter = None
else:
return redirect('/404')
else:
chapter = chapter[0]
next_chapters = Chapter.select_by_tale_id_and_previous_chapter_id(tale['id'], chapter['id'])
chapter['datetime'] = aux.beautify_datetime(chapter['date'])
chapter['contributor_username'] = User.select_by_id(chapter['user_id'], 1)[0]['username']
chapter['next_chapters'] = next_chapters
chapter['is_editable'] = tale['creator_id'] is session.get('user_logged_id', None)
tale['chapter'] = chapter
return aux.return_rendered_tale_template(tale, 'tale.html')
else:
return redirect('/404')
示例5: change_password_post
# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import select_by_id [as 别名]
def change_password_post():
random_token = request.form.get('change-password-random-token', '')
p_c_r = Password_Change_Requests.select_by_id(random_token, 1)
if request.is_xhr and len(p_c_r) is not 0 and Password_Change_Requests.is_valid_random_token(p_c_r[0]['datetime']):
p_c_r = p_c_r[0]
new_password = request.form.get('change-password-new-password', '')
confirm_new_password = request.form.get('change-password-confirm-new-password', '')
language = session.get('language', 'en')
error_list = list()
if not User.is_password_valid(new_password):
error_list.append(strings.STRINGS[language]['INVALID_PASSWORD'])
if new_password != confirm_new_password:
error_list.append(strings.STRINGS[language]['PASSWORD_NO_MATCH'])
if len(error_list) is not 0:
return make_response(jsonify(error_list = error_list), 400)
else:
User.update_password(p_c_r['user_id'], new_password)
Password_Change_Requests.delete(p_c_r['user_id'])
session['user_logged_id'] = p_c_r['user_id']
username = User.select_by_id(p_c_r['user_id'], 1)[0]['username']
return jsonify(url = '/profile/' + username)
else:
return redirect('/404')
示例6: join
# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import select_by_id [as 别名]
def join():
if 'user_logged_id' in session:
user = User.select_by_id(session['user_logged_id'], 1)[0]
return redirect('/profile/' + user['username'])
else:
return render_template('join.html', redirect_url = request.args.get('redirect', ''))
示例7: invite_post
# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import select_by_id [as 别名]
def invite_post(tale_id):
username = request.form.get('invite-username', '')
user = User.select_by_email(username, 1)
tale = Tale.select_by_id(tale_id, 1)
if len(user) is 0:
user = User.select_by_full_username(username, 1)
if len(user) is not 0 and len(tale) is not 0 and session.get('user_logged_id', None) is tale[0]['creator_id']:
user = user[0]
tale = tale[0]
new_invitation = Invitation(session['user_logged_id'], user['id'], tale_id)
new_invitation.insert()
creator = User.select_by_id(tale['creator_id'], 1)[0]
email_object = strings.construct_tale_invitation_email_object(
session.get('language', 'en'),
user,
tale,
creator
)
aux.send_email(email_object['title'], user['email'], email_object['body'])
return redirect('/tale/' + str(tale_id) + '/0')
示例8: search_tales
# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import select_by_id [as 别名]
def search_tales():
content = request.args.get('c', '')
genre_id = int(request.args.get('g', -1))
if len(content) < 3 and genre_id is -1:
return render_template('bad_search.html', search_page = 'tales')
sort_value = int(request.args.get('s', 1))
user_logged_id = session.get('user_logged_id', None)
tales = Tale.select_viewable_by_title_and_creator_id(
content, user_logged_id
) if genre_id is -1 else Tale.select_viewable_by_title_creator_id_and_genre_id(
content, user_logged_id, genre_id
)
tales_per_genre = dict()
tales_list = list()
for tale in tales:
tale_genres = Tale_Genre.select_by_tale_id(tale['id'])
tale_genres_list = list()
for tale_genre in tale_genres:
genre = Genre.select_by_id(tale_genre[1], 1)[0]
tale_genres_list.append(genre)
if genre['type'] in tales_per_genre:
tales_per_genre[genre['type']]['count'] += 1
else:
tales_per_genre[genre['type']] = {'count': 1, 'id': genre['id']}
last_update = Tale.select_last_update(tale['id'], 1)[0][0]
tale['genres'] = tale_genres_list
tale['creator_username'] = User.select_by_id(tale['creator_id'], 1)[0]['username']
tale['last_update'] = False if last_update is None else aux.beautify_datetime(last_update)
tale['ugly_last_update'] = datetime(1, 1, 1, 15, 11) if last_update is None else last_update
tales_list.append(tale)
if sort_value is 2:
tales_list = sorted(tales_list, key = lambda tale: tale['stars'], reverse = True)
elif sort_value is 3:
tales_list = sorted(tales_list, key = lambda tale: tale['stars'])
elif sort_value is 4:
tales_list = sorted(tales_list, key = lambda tale: tale['ugly_last_update'], reverse = True)
elif sort_value is 5:
tales_list = sorted(tales_list, key = lambda tale: tale['ugly_last_update'])
return render_template(
'search_tales.html',
content = content,
tales = tales_list,
amount_of_tales = len(tales_list),
tales_per_genre = tales_per_genre,
sort_value = sort_value,
genre_id = genre_id,
)
示例9: contribution_requests
# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import select_by_id [as 别名]
def contribution_requests(tale_id):
tale = aux.is_visible_tale(tale_id, session.get('user_logged_id', None))
if tale:
o_c_r = Contribution_Request.select_open_by_tale_id_order_by_datetime(tale_id)
for contribution_request in o_c_r:
contribution_request['user_username'] = User.select_by_id(contribution_request['user_id'], 1)[0]['username']
contribution_request['datetime'] = aux.beautify_datetime(contribution_request['datetime'])
c_c_r = Contribution_Request.select_closed_by_tale_id_order_by_datetime(tale_id)
for contribution_request in c_c_r:
contribution_request['user_username'] = User.select_by_id(contribution_request['user_id'], 1)[0]['username']
contribution_request['datetime'] = aux.beautify_datetime(contribution_request['datetime'])
return aux.return_rendered_tale_template(
tale,
'contribution_requests.html',
open_contribution_requests_list = o_c_r,
closed_contribution_requests_list = c_c_r
)
else:
return redirect('/404')
示例10: contributors
# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import select_by_id [as 别名]
def contributors(tale_id):
tale = aux.is_visible_tale(tale_id, session.get('user_logged_id', None))
if tale:
contributors = Chapter.select_by_tale_id(tale_id)
contributors_dict = dict()
creator = User.select_by_id(tale['creator_id'], 1)[0]
contributors_dict[creator['id']] = {'username': creator['username'], 'count': 0}
for c in contributors:
contributor = User.select_by_id(c['user_id'], 1)[0]
if contributor['id'] not in contributors_dict:
contributors_dict[contributor['id']] = {'username': contributor['username'], 'count': 0}
contributors_dict[contributor['id']]['count'] += 1
return aux.return_rendered_tale_template(
tale, 'contributors.html', contributors_object = contributors_dict
)
else:
return redirect('/404')
示例11: inject_data
# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import select_by_id [as 别名]
def inject_data():
language_url = 'https://www.anaddventure.com'
if not request.is_xhr and request.method != 'POST':
matches = re.findall(r'(https?://)(\w+)(\.anaddventure\.com.*)', request.base_url)[0]
if matches[1] == 'pt':
language = 'pt'
language_url = matches[0] + 'www'
else:
language = 'en'
language_url = matches[0] + 'pt'
language_url += matches[2] + '?' + ''.join(list(map(
lambda key: key + '=' + request.args.get(key) + '&', request.args
)))
language_url = language_url[:len(language_url) - 1]
if session.get('language', None) != language:
session['language'] = language
language = session.get('language', 'en')
def generate_csrf_token():
if '_csrf_token' not in session:
session['_csrf_token'] = aux.generate_random_token()
return session['_csrf_token']
if 'user_logged_id' in session:
user_is_logged = True
user_logged_id = session['user_logged_id']
user_logged_username = User.select_by_id(user_logged_id, 1)[0]['username']
else:
user_is_logged = None
user_logged_id = None
user_logged_username = None
return {
'language': language,
'_csrf_token': generate_csrf_token,
'user_logged_id': user_logged_id,
'user_is_logged': user_is_logged,
'user_logged_username': user_logged_username,
'_': lambda token: strings.STRINGS[language][token],
'conf_production': app.config['CONF_PRODUCTION'],
'language_url': language_url,
}
示例12: collaboration
# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import select_by_id [as 别名]
def collaboration(contribution_request_id):
contribution_request = Contribution_Request.select_by_id(contribution_request_id, 1)
if len(contribution_request) is not 0:
contribution_request = contribution_request[0]
tale = aux.is_visible_tale(contribution_request['tale_id'], session.get('user_logged_id', None))
if tale:
contribution_request['user_username'] = User.select_by_id(
contribution_request['user_id'],
1
)[0]['username']
contribution_request['datetime'] = aux.beautify_datetime(contribution_request['datetime'])
return aux.return_rendered_tale_template(tale, 'collaboration.html', contribution = contribution_request)
else:
return redirect('/404')
else:
return redirect('/404')
示例13: login
# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import select_by_id [as 别名]
def login():
if request.is_xhr and 'user_logged_id' not in session:
username = request.form.get('login-username', '')
password = request.form.get('login-password', '')
user_id = User.is_valid_user(username, password)
if user_id is not None:
session['user_logged_id'] = user_id
username = User.select_by_id(user_id, 1)[0]['username']
return jsonify(url = request.args.get('redirect', '/profile/' + username))
else:
language = session.get('language', 'en')
return make_response(
jsonify(error_list = ([strings.STRINGS[language]['INVALID_USER']])),
400
)
else:
return redirect('/404')
示例14: branches
# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import select_by_id [as 别名]
def branches(tale_id):
tale = aux.is_visible_tale(tale_id, session.get('user_logged_id', None))
if tale:
chapters = Chapter.select_by_tale_id(tale_id)
number_bundle = dict()
for chapter in chapters:
number = chapter['number']
if number not in number_bundle:
number_bundle[number] = {'number': number, 'contributions': list()}
chapter['date'] = aux.beautify_datetime(chapter['date'])
chapter['contributor_username'] = User.select_by_id(chapter['user_id'], 1)[0]['username']
number_bundle[number]['contributions'].append(chapter)
return aux.return_rendered_tale_template(tale, 'branches.html', branches_object = number_bundle)
else:
return redirect('/404')
示例15: collaboration_add_post
# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import select_by_id [as 别名]
def collaboration_add_post(tale_id, chapter_id):
tale = aux.is_visible_tale(tale_id, session.get('user_logged_id', None))
chapter = Chapter.select_by_id(chapter_id, 1)
if request.is_xhr and tale and 'user_logged_id' in session and (
((len(chapter) is not 0 and int(chapter[0]['tale_id']) is tale_id)) or
(chapter_id is 0 and len(Chapter.select_by_tale_id_and_previous_chapter_id(tale_id, -1)) is 0)):
creator = tale['creator_id']
user_id = session['user_logged_id']
title = request.form.get('collaboration-add-title', '')
content = request.form.get('collaboration-add-content', '')
language = session.get('language', 'en')
error_list = list()
if not Contribution_Request.is_title_valid(title):
error_list.append(strings.STRINGS[language]['INVALID_TITLE'])
if not Contribution_Request.is_content_valid(content):
error_list.append(strings.STRINGS[language]['INVALID_CONTENT'])
if len(error_list) is not 0:
return make_response(jsonify(error_list = error_list), 400)
else:
email_object = {}
creator_username = User.select_by_id(user_id, 1)[0]['username']
if creator is user_id:
if chapter_id is 0:
new_chapter = Chapter(
user_id,
tale_id,
1,
title,
content,
aux.get_current_datetime_as_string(),
-1
)
new_chapter.insert()
email_object = strings.construct_new_chapter_email_object(
language,
tale,
creator_username,
1,
0
)
else:
chapter = Chapter.select_by_id(chapter_id, 1)[0]
date = aux.get_current_datetime_as_string()
new_chapter = Chapter(
user_id,
tale_id,
chapter['number'] + 1,
title,
content,
date,
chapter['id']
)
new_chapter.insert()
new_chapter_id = Chapter.select_by_date(date, 1)[0]['id']
email_object = strings.construct_new_chapter_email_object(
language,
tale,
creator_username,
chapter['number'] + 1,
new_chapter_id
)
else:
chapter = Chapter.select_by_id(chapter_id, 1)[0]
new_contribution_request = Contribution_Request(
user_id,
tale_id,
chapter['number'] + 1,
title,
content,
aux.get_current_datetime_as_string(),
chapter['id']
)
new_contribution_request.insert()
Tale.update_contribution_request_count(tale_id, 1)
email_object = strings.construct_new_contribution_request_email_object(
language,
tale,
creator_username
)
aux.send_email_to_followers(tale_id, email_object['title'], email_object['body'])
return jsonify(url = '/tale/' + str(tale_id) + '/' + str(chapter_id))
else:
return redirect('/404')