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

Python db.session函数代码示例

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

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



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

示例1: route_community_guild_leave

def route_community_guild_leave(gid, pid):
	user = current_user()
	found = False

	for player in user.players:
		if player.id == pid:
			found = True
			break

	if not found:
		return redirect(url_for('route_community_guild', id=gid))

	membership = GuildMembership.query.filter(GuildMembership.guild_id == gid)
	membership = membership.filter(GuildMembership.player_id == pid).first()

	if not membership:
		return redirect(url_for('route_community_guild', id=gid))

	rank = db.session().query(GuildRank.level).filter(GuildRank.id == membership.rank_id).first()
	if not rank:
		return redirect(url_for('route_community_guild', id=gid))

	if rank.level < 3:
		db.session().delete(membership)
		db.session().commit()

		flash('You left the guild.', 'success')
	else:
		flash('Guild leaders can not leave the guild, use the disband feature instead.', 'error')

	return redirect(url_for('route_community_guild', id=gid))
开发者ID:EvulMastah,项目名称:pyfsw,代码行数:31,代码来源:community_guilds.py


示例2: route_community_guild_ranks_post

def route_community_guild_ranks_post(id):
	if not is_guild_leader(id):
		return redirect(url_for('route_community_guild', id=id))

	for level in range(1, 4):
		value = request.form.get('rank{}'.format(level), '', type=str)
		error = False

		if not GUILD_NAME_EXPR.match(value):
			flash('{} rank name may only contain latin characters (A-Z, a-z and spaces).'.format(filter_rank(level)), 'error')
			error = True

		if len(value) < 4 or len(value) > 16:
			flash('{} rank name must be between 4 and 16 characters long.'.format(filter_rank(level)), 'error')
			error = True

		if not error:
			rank = GuildRank.query.filter(GuildRank.guild_id == id).filter(GuildRank.level == level).first()
			rank.name = value

			db.session().commit()

			flash('{} rank name has been updated.'.format(filter_rank(level)), 'success')

	return redirect(url_for('route_community_guild_ranks', id=id))
开发者ID:EvulMastah,项目名称:pyfsw,代码行数:25,代码来源:community_guilds.py


示例3: route_admin_logs_login_search_post

def route_admin_logs_login_search_post():
	name = request.form.get('name', '', type=str)
	ip = request.form.get('ipAddress', '', type=str)
	history = db.session().query(
		LoginHistory.id, LoginHistory.account, LoginHistory.ip, LoginHistory.platform, 
		LoginHistory.browser, LoginHistory.status, LoginHistory.time
	).order_by(LoginHistory.time.desc())

	if name != '':
		accountName = db.session().query(Account.name).filter(Account.name == name).first()
		if not accountName:
			flash('The account name you are trying to search for does not exist.', 'error')
			return redirect(url_for('route_admin_logs_login'))

		history = history.filter(LoginHistory.account == accountName[0]).all()

		if not history:
			flash('The is no login history for this account name.', 'error')
			return redirect(url_for('route_admin_logs_login'))
	elif ip != '':
		history = history.filter(LoginHistory.ip == ip).all()

		if not history:
			flash('The submitted IP address did not match any records.', 'error')
			return redirect(url_for('route_admin_logs_login'))
	else:
		flash('You must fill out one of the search forms.', 'error')

	return render_template(
		'admin/logs/login.htm',
		history = history
	)
开发者ID:EvulMastah,项目名称:pyfsw,代码行数:32,代码来源:logs.py


示例4: route_community_guild_invite_post

def route_community_guild_invite_post(id):
	if not is_guild_vice(id):
		return redirect(url_for('route_community_guild', id=id))

	name = request.form.get('name', '', type=str)
	error = False

	player = Player.query.filter(Player.name == name).first()
	if not player:
		flash('The player you are trying to invite does not exist.', 'error')
		return redirect(url_for('route_community_guild', id=id))

	membership = GuildMembership.query.filter(GuildMembership.guild_id == id).filter(GuildMembership.player_id == player.id).first()
	if membership:
		flash('The player is already a member of your guild.', 'error')
		error = True

	invite = GuildInvite.query.filter(GuildInvite.guild_id == id).filter(GuildInvite.player_id == player.id).first()
	if invite:
		flash('The player is already invited to your guild.', 'error')
		error = True

	if not error:
		invite = GuildInvite()
		invite.player_id = player.id
		invite.guild_id = id

		db.session().add(invite)
		db.session().commit()

		flash('The player has been invited.', 'success')

	return redirect(url_for('route_community_guild', id=id))
开发者ID:EvulMastah,项目名称:pyfsw,代码行数:33,代码来源:community_guilds.py


示例5: route_forum_post_soft

def route_forum_post_soft(id):
	post = ForumPost.query.filter(ForumPost.id == id).first()
	if not post:
		return redirect(url_for('route_forum'))

	thread = ForumThread.query.filter(ForumThread.id == post.thread_id).first()
	if post.deleted:
		if thread.deleted == 0:
			character = Player.query.filter(Player.id == post.author_id).first()
			character.postcount = character.postcount + 1

		post.deleted = 0

		flash('The post has been restored.', 'success')
	else:
		if thread.deleted == 0:
			character = Player.query.filter(Player.id == post.author_id).first()
			character.postcount = character.postcount - 1

		post.deleted = 1

		flash('The post has been soft-deleted.', 'success')

	db.session().commit()

	return redirect(url_for('route_forum_thread', thread=post.thread_id, page=1))
开发者ID:EvulMastah,项目名称:pyfsw,代码行数:26,代码来源:forum.py


示例6: route_admin_forum_board_add

def route_admin_forum_board_add():
	name = request.form.get('name', '')
	description = request.form.get('description', '')
	category = request.form.get('category', 0)
	locked = request.form.get('locked', None)
	error = False

	if len(name) == 0:
		flash('Please fill the name field.', 'error')
		error = True

	if len(description) == 0:
		flash('Please fill the description field.', 'error')
		error = True

	if not error:
		board = ForumBoard()
		board.name = name
		board.description = description
		board.category_id = category
		board.locked = 0 if not locked else 1

		db.session().add(board)
		db.session().commit()

		flash('The board has beed added.', 'success')

	return redirect(url_for('route_admin_forum_boards'))
开发者ID:EvulMastah,项目名称:pyfsw,代码行数:28,代码来源:forum.py


示例7: route_admin_shop_item_add

def route_admin_shop_item_add():
	name = request.form.get('name', '')
	description = request.form.get('description', '')
	category = request.form.get('category', 0)
	type = request.form.get('type', 0)
	key = request.form.get('key', 0)
	value = request.form.get('value', 0)
	price = request.form.get('price', 0)
	image = request.form.get('image', '')
	enabled = request.form.get('enabled', None)
	error = False

	# TODO: Add verifications

	if not error:
		item = ShopItem()
		item.name = name
		item.description = description
		item.category_id = category
		item.type = type
		item.key = key
		item.value = value
		item.price = price
		item.custom_image = image
		item.enabled = 1 if enabled else 0

		db.session().add(item)
		db.session().commit()

		flash('The item has been added.', 'success')

	return redirect(url_for('route_admin_shop_items'))
开发者ID:EvulMastah,项目名称:pyfsw,代码行数:32,代码来源:shop.py


示例8: route_community_guild_rank_post

def route_community_guild_rank_post(id):
	if not is_guild_leader(id):
		return redirect(url_for('route_community_guild', id=id))

	pid = request.form.get('id', 0, type=int)
	level = request.form.get('rank', 0, type=int)

	if level not in [1, 2]:
		return redirect(url_for('route_community_guild', id=id))

	if not db.session().query(Player.id).filter(Player.id == pid).first():
		flash('The player does not exist.', 'error')
		return redirect(url_for('route_community_guild', id=id))

	rank = db.session().query(GuildRank.id).filter(GuildRank.guild_id == id)
	rank = rank.filter(GuildRank.level == level).first()
	if not rank:
		flash('The rank does not exist', 'error')
		return redirect(url_for('route_community_guild', id=id))

	membership = GuildMembership.query.filter(GuildMembership.player_id == pid).first()
	if not membership:
		return redirect(url_for('route_community_guild', id=id))

	membership.rank_id = rank.id
	db.session().commit()

	flash('The rank has been updated.', 'success')

	return redirect(url_for('route_community_guild', id=id))
开发者ID:EvulMastah,项目名称:pyfsw,代码行数:30,代码来源:community_guilds.py


示例9: route_forum_thread_soft

def route_forum_thread_soft(id):
	thread = ForumThread.query.filter(ForumThread.id == id).first()
	if not thread:
		return redirect(url_for('route_forum'))

	posts = db.session().query(ForumPost.author_id, ForumPost.deleted).filter(ForumPost.thread_id == thread.id).all()

	if thread.deleted:
		character = Player.query.filter(Player.id == thread.author_id).first()
		character.postcount = character.postcount + 1

		for post in posts:
			if post.deleted == 0:
				character = Player.query.filter(Player.id == post.author_id).first()
				character.postcount = character.postcount + 1

		thread.deleted = 0
		flash('The thread has been restored.', 'success')
	else:
		character = Player.query.filter(Player.id == thread.author_id).first()
		character.postcount = character.postcount - 1

		for post in posts:
			if post.deleted == 0:
				character = Player.query.filter(Player.id == post.author_id).first()
				character.postcount = character.postcount - 1

		thread.deleted = 1
		flash('The thread has been soft-deleted.', 'success')

	db.session().commit()
	return redirect(url_for('route_forum_thread', thread=thread.id, page=1))
开发者ID:EvulMastah,项目名称:pyfsw,代码行数:32,代码来源:forum.py


示例10: route_account_character_post

def route_account_character_post():
	name = request.form.get('name', '', type=str)
	gender = request.form.get('gender', 0, type=int)
	vocation = request.form.get('vocation', 0, type=int)
	town = request.form.get('town', 1, type=int)
	error = False

	if len(name) < 4:
		flash('The name must be at least 4 characters long.', 'error')
		error = True

	if not CHAR_NAME_EXPR.match(name):
		flash('The name may only contain latin characters (A-Z, a-z and spaces).', 'error')
		error = True

	if len(name.split(' ')) > 3:
		flash('The name may only consist of 3 words.', 'error')
		error = True

	if gender not in NEW_CHARACTER.get('genders'):
		flash('The selected gender is not valid.', 'error')
		error = True

	if vocation not in NEW_CHARACTER.get('vocations'):
		flash('The selected vocation is not valid.', 'error')
		error = True

	if town not in NEW_CHARACTER.get('towns'):
		flash('The selected town is not valid.', 'error')
		error = True

	name = string.capwords(name)
	player = db.session().query(Player.id).filter(Player.name == name).first()
	if player:
		flash('The character name is already in use.', 'error')
		error = True

	if error:
		return redirect(url_for('route_account_character'))

	player = Player()
	player.name = name
	player.sex = gender
	player.vocation = vocation
	player.town_id = town
	player.account_id = current_user().id

	player.looktype = 136 if gender == 0 else 128
	player.lookhead = NEW_CHARACTER.get('outfit')[0]
	player.lookbody = NEW_CHARACTER.get('outfit')[1]
	player.looklegs = NEW_CHARACTER.get('outfit')[2]
	player.lookfeet = NEW_CHARACTER.get('outfit')[3]

	db.session().add(player)
	db.session().commit()

	flash('The character has been created.', 'success')

	return redirect(url_for('route_account_manage'))
开发者ID:diath,项目名称:pyfsw,代码行数:59,代码来源:account.py


示例11: route_news_archive

def route_news_archive():
	news = db.session().query(News).order_by(News.id.desc()).all()
	for entry in news:
		player = db.session().query(Player.name).filter(Player.id == entry.author_id).first()
		if player:
			entry.author = player.name

	return render_template('news/archive.htm', news=news)
开发者ID:EvulMastah,项目名称:pyfsw,代码行数:8,代码来源:news.py


示例12: route_admin_shop_category_edit_post

def route_admin_shop_category_edit_post(id):
	category = ShopCategory.query.filter(ShopCategory.id == id).first()
	category.name = request.form.get('name', '')
	category.enabled = 1 if request.form.get('enabled', None) else 0

	db.session().commit()
	flash('The category has been edited.', 'success')

	return redirect(url_for('route_admin_shop_categories'))
开发者ID:EvulMastah,项目名称:pyfsw,代码行数:9,代码来源:shop.py


示例13: route_admin_shop_item_delete

def route_admin_shop_item_delete(id):
	item = ShopItem.query.filter(ShopItem.id == id).first()

	db.session().delete(item)
	db.session().commit()

	flash('The item has been deleted.', 'success')

	return redirect(url_for('route_admin_shop_items'))
开发者ID:EvulMastah,项目名称:pyfsw,代码行数:9,代码来源:shop.py


示例14: route_admin_forum_category_edit_post

def route_admin_forum_category_edit_post(id):
	category = ForumCategory.query.filter(ForumCategory.id == id).first()

	category.name = request.form.get('name', '')

	db.session().commit()
	flash('The category name has been changed.', 'success')

	return redirect(url_for('route_admin_forum_categories'))
开发者ID:EvulMastah,项目名称:pyfsw,代码行数:9,代码来源:forum.py


示例15: route_admin_forum_board_delete

def route_admin_forum_board_delete(id):
	board = ForumBoard.query.filter(ForumBoard.id == id).first()

	db.session().delete(board)
	db.session().commit()

	flash('The board has been deleted.', 'success')

	return redirect(url_for('route_admin_forum_boards'))
开发者ID:EvulMastah,项目名称:pyfsw,代码行数:9,代码来源:forum.py


示例16: route_admin_logs_zaypay_delete

def route_admin_logs_zaypay_delete(id):
	history = ZayPayHistory.query.filter(ZayPayHistory.id == id).first()

	db.session().delete(history)
	db.session().commit()

	flash('The entry has been deleted.', 'success')

	return redirect(url_for('route_admin_logs_zaypay'))
开发者ID:EvulMastah,项目名称:pyfsw,代码行数:9,代码来源:logs.py


示例17: route_admin_library_delete

def route_admin_library_delete(id):
	page = Library.query.filter(Library.id == id).first()

	db.session().delete(page)
	db.session().commit()

	flash('The library page has been deleted.', 'success')

	return redirect(url_for('route_admin_library'))
开发者ID:EvulMastah,项目名称:pyfsw,代码行数:9,代码来源:community.py


示例18: route_community_highscores

def route_community_highscores(type, page):
    current = HS_TYPES.get(type)
    if not current:
        return redirect(url_for("route_community_highscores", type="level", page=1))

    total = db.session().query(Player.id).filter(Player.group_id == 1).count()
    perpage = 50

    highscores = db.session().query(
        Player.name,
        Player.vocation,
        Player.level,
        Player.experience,
        Player.maglevel,
        Player.manaspent,
        Player.skill_fist,
        Player.skill_club,
        Player.skill_sword,
        Player.skill_axe,
        Player.skill_dist,
        Player.skill_shielding,
        Player.skill_fishing,
        Player.skill_fist_tries,
        Player.skill_club_tries,
        Player.skill_sword_tries,
        Player.skill_axe_tries,
        Player.skill_dist_tries,
        Player.skill_shielding_tries,
        Player.skill_fishing_tries,
        Player.looktype,
        Player.lookhead,
        Player.lookbody,
        Player.looklegs,
        Player.lookfeet,
        Player.lookaddons,
    )
    highscores = highscores.filter(Player.group_id == 1).order_by(current[1])
    highscores = highscores.offset((page - 1) * perpage)
    highscores = highscores.limit(perpage)
    highscores = highscores.all()

    for player in highscores:
        player.value = getattr(player, current[2])
        player.subvalue = getattr(player, current[3])

    pagination = Pagination(highscores, page, perpage, total, highscores)

    return render_template(
        "community/highscores.htm",
        type=type,
        name=current[0],
        highscores=highscores,
        suffix=current[4],
        pagination=pagination,
        perpage=perpage,
        page=page,
    )
开发者ID:EvulMastah,项目名称:pyfsw,代码行数:57,代码来源:community.py


示例19: route_admin_shop_category_delete

def route_admin_shop_category_delete(id):
	category = ShopCategory.query.filter(ShopCategory.id == id).first()

	db.session().delete(category)
	db.session().commit()

	flash('The category has been deleted.', 'success')

	return redirect(url_for('route_admin_shop_categories'))
开发者ID:EvulMastah,项目名称:pyfsw,代码行数:9,代码来源:shop.py


示例20: route_admin_news_compose_post

def route_admin_news_compose_post():
	title = request.form.get('title', '')
	content = request.form.get('content', '')
	thread_content = request.form.get('threadContent', '')
	poster_id = request.form.get('poster', 0)
	board_id = request.form.get('board', 0)
	error = False

	if len(title) == 0:
		flash('The news title cannot be empty.', 'error')
		error = True

	if len(content) == 0:
		flash('The news content cannot be empty.', 'error')
		error = True

	if len(thread_content) == 0:
		flash('The thread content cannot be empty.', 'error')
		error = True

	if not error:
		content = content.strip()
		content = ' '.join(content.split())

		timestamp = int(time())

		thread = ForumThread()
		thread.subject = title
		thread.timestamp = timestamp
		thread.board_id = board_id
		thread.locked = 0
		thread.pinned = 0
		thread.lastpost = timestamp
		thread.author_id = poster_id
		thread.content = thread_content

		db.session().add(thread)
		db.session().commit()

		news = News()
		news.timestamp = timestamp
		news.header = title
		news.content = content
		news.author_id = poster_id
		news.thread_id = thread.id

		db.session().add(news)
		db.session().commit()

		author = Player.query.filter(Player.id == poster_id).first()
		author.postcount = author.postcount + 1
		db.session().commit()

		flash('The news has been posted successfully.', 'success')

	return redirect(url_for('route_admin_news_compose'))
开发者ID:EvulMastah,项目名称:pyfsw,代码行数:56,代码来源:news.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python authorizers.DummyAuthorizer类代码示例发布时间:2022-05-25
下一篇:
Python pyfribidi.log2vis函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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