Ejemplo n.º 1
0
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))
Ejemplo n.º 2
0
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))
Ejemplo n.º 3
0
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))
Ejemplo n.º 4
0
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))
Ejemplo n.º 5
0
def route_community_guild(id):
    guild = Guild.query.filter(Guild.id == id).first()
    members = GuildMembership.query.filter(
        GuildMembership.guild_id == guild.id).all()
    invites = GuildInvite.query.filter(GuildInvite.guild_id == guild.id).all()
    wars = GuildWar.query.filter(
        or_(GuildWar.guild1 == id, GuildWar.guild2 == id)).filter(
            GuildWar.status == GuildWar.Active).all()

    user = current_user()
    if user:
        ids = []
        for player in user.players:
            ids.append(player.id)

        for invite in invites:
            if invite.player_id in ids:
                invite.own = True

        for member in members:
            if member.player_id in ids:
                member.own = True

    return render_template('community/guilds/view.htm',
                           guild=guild,
                           members=members,
                           invites=invites,
                           leader=is_guild_leader(id),
                           vice=is_guild_vice(id),
                           wars=wars)
Ejemplo n.º 6
0
def route_community_guild_ranks(id):
    if not is_guild_leader(id):
        return redirect(url_for('route_community_guild', id=id))

    ranks = GuildRank.query.filter(GuildRank.guild_id == id).all()
    if not ranks:
        return redirect(url_for('route_community_guild', id=id))

    return render_template('community/guilds/ranks.htm', id=id, ranks=ranks)
Ejemplo n.º 7
0
def route_community_guild_motd(id):
	if not is_guild_leader(id):
		return redirect(url_for('route_community_guild', id=id))

	guild = Guild.query.filter(Guild.id == id).first()
	if not guild:
		return redirect(url_for('route_community_guild', id=id))

	return render_template('community/guilds/motd.htm', id=id, motd=guild.motd)
Ejemplo n.º 8
0
def route_community_guild_motd(id):
    if not is_guild_leader(id):
        return redirect(url_for('route_community_guild', id=id))

    guild = Guild.query.filter(Guild.id == id).first()
    if not guild:
        return redirect(url_for('route_community_guild', id=id))

    return render_template('community/guilds/motd.htm', id=id, motd=guild.motd)
Ejemplo n.º 9
0
def route_community_guild_ranks(id):
	if not is_guild_leader(id):
		return redirect(url_for('route_community_guild', id=id))

	ranks = GuildRank.query.filter(GuildRank.guild_id == id).all()
	if not ranks:
		return redirect(url_for('route_community_guild', id=id))

	return render_template('community/guilds/ranks.htm', id=id, ranks=ranks)
Ejemplo n.º 10
0
def route_community_guild_disband_post(id):
	if not is_guild_leader(id):
		return redirect(url_for('route_community_guild', id=id))

	guild = Guild.query.filter(Guild.id == id).first()
	db.session().delete(guild)
	db.session().commit()

	logo = os.path.join(UPLOAD_PATH, '{}.png'.format(id))
	if os.path.isfile(logo):
		os.remove(logo)

	return redirect(url_for('route_community_guilds'))
Ejemplo n.º 11
0
def route_community_guild_disband_post(id):
    if not is_guild_leader(id):
        return redirect(url_for('route_community_guild', id=id))

    guild = Guild.query.filter(Guild.id == id).first()
    db.session().delete(guild)
    db.session().commit()

    logo = os.path.join(UPLOAD_PATH, '{}.png'.format(id))
    if os.path.isfile(logo):
        os.remove(logo)

    return redirect(url_for('route_community_guilds'))
Ejemplo n.º 12
0
def route_community_guild_motd_post(id):
    if not is_guild_leader(id):
        return redirect(url_for('route_community_guild', id=id))

    guild = Guild.query.filter(Guild.id == id).first()
    if not guild:
        return redirect(url_for('route_community_guild', id=id))

    motd = request.form.get('motd', '', type=str)
    guild.motd = motd

    db.session().commit()
    flash('The guild description has been changed.', 'success')

    return redirect(url_for('route_community_guild', id=id))
Ejemplo n.º 13
0
def route_community_guild_motd_post(id):
	if not is_guild_leader(id):
		return redirect(url_for('route_community_guild', id=id))

	guild = Guild.query.filter(Guild.id == id).first()
	if not guild:
		return redirect(url_for('route_community_guild', id=id))

	motd = request.form.get('motd', '', type=str)
	guild.motd = motd

	db.session().commit()
	flash('The guild description has been changed.', 'success')

	return redirect(url_for('route_community_guild', id=id))
Ejemplo n.º 14
0
def route_community_guild_logo_post(id):
    if not is_guild_leader(id):
        return redirect(url_for('route_community_guild', id=id))

    file = request.files.get('logo')
    error = False

    if file:
        name = secure_filename(file.filename)
        if len(name) == 0 or not '.' in name and not name.rsplit(
                '.', 1)[1] in ['png', 'gif', 'jpg', 'jpeg']:
            flash('The file extension is not allowed.', 'error')
            error = True

        if file.content_length > 3 * 1024 * 1024:
            flash('The file size exceeds the limit of 3 MB.', 'error')
            error = True

        if file.content_type not in ['image/png', 'image/gif', 'image/jpeg']:
            flash('The file format is not allowed.', 'error')
            error = True

        if not error:
            name = os.path.join(UPLOAD_PATH, '{}.png'.format(id))
            file.save(name)

            try:
                image = Image.open(name)
                image.convert('RGBA')
                image.thumbnail((128, 128), Image.ANTIALIAS)
                image.save(name)
            except Exception as e:
                flash('Failed to upload the file.', 'error')
                os.remove(name)
                error = True
    else:
        flash('Failed to upload the file.', 'error')
        error = True

    if not error:
        flash(
            'The guild logo has been changed. If you still see the old logo, try using CTRL+F5, which should erase the previously cached image.',
            'success')

    return redirect(url_for('route_community_guild', id=id))
Ejemplo n.º 15
0
def route_community_guild_rank(id):
	if not is_guild_leader(id):
		return redirect(url_for('route_community_guild', id=id))

	ranks = []
	for rank in db.session().query(GuildRank.id).filter(GuildRank.guild_id == id).filter(GuildRank.level < 3).all():
		ranks.append(rank.id)

	membership = db.session().query(GuildMembership.player_id, GuildMembership.rank_id)
	membership = membership.filter(GuildMembership.guild_id == id)
	membership = membership.filter(GuildMembership.rank_id.in_(ranks)).all()

	members = []
	for entry in membership:
		player = db.session().query(Player.id, Player.name).filter(Player.id == entry.player_id).first()
		if player:
			members.append(player)

	return render_template('community/guilds/rank.htm', id=id, members=members)
Ejemplo n.º 16
0
def route_community_guild_logo_post(id):
	if not is_guild_leader(id):
		return redirect(url_for('route_community_guild', id=id))

	file = request.files.get('logo')
	error = False

	if file:
		name = secure_filename(file.filename)
		if len(name) == 0 or not '.' in name and not name.rsplit('.', 1)[1] in ['png', 'gif', 'jpg', 'jpeg']:
			flash('The file extension is not allowed.', 'error')
			error = True

		if file.content_length > 3 * 1024 * 1024:
			flash('The file size exceeds the limit of 3 MB.', 'error')
			error = True

		if file.content_type not in ['image/png', 'image/gif', 'image/jpeg']:
			flash('The file format is not allowed.', 'error')
			error = True

		if not error:
			name = os.path.join(UPLOAD_PATH, '{}.png'.format(id))
			file.save(name)

			try:
				image = Image.open(name)
				image.convert('RGBA')
				image.thumbnail((128, 128), Image.ANTIALIAS)
				image.save(name)
			except Exception as e:
				flash('Failed to upload the file.', 'error')
				os.remove(name)
				error = True
	else:
		flash('Failed to upload the file.', 'error')
		error = True

	if not error:
		flash('The guild logo has been changed. If you still see the old logo, try using CTRL+F5, which should erase the previously cached image.', 'success')

	return redirect(url_for('route_community_guild', id=id))
Ejemplo n.º 17
0
def route_community_guild_rank(id):
    if not is_guild_leader(id):
        return redirect(url_for('route_community_guild', id=id))

    ranks = []
    for rank in db.session().query(GuildRank.id).filter(
            GuildRank.guild_id == id).filter(GuildRank.level < 3).all():
        ranks.append(rank.id)

    membership = db.session().query(GuildMembership.player_id,
                                    GuildMembership.rank_id)
    membership = membership.filter(GuildMembership.guild_id == id)
    membership = membership.filter(GuildMembership.rank_id.in_(ranks)).all()

    members = []
    for entry in membership:
        player = db.session().query(
            Player.id,
            Player.name).filter(Player.id == entry.player_id).first()
        if player:
            members.append(player)

    return render_template('community/guilds/rank.htm', id=id, members=members)
Ejemplo n.º 18
0
def route_community_guild(id):
	guild = Guild.query.filter(Guild.id == id).first()
	members = GuildMembership.query.filter(GuildMembership.guild_id == guild.id).all()
	invites = GuildInvite.query.filter(GuildInvite.guild_id == guild.id).all()
	wars = GuildWar.query.filter(or_(GuildWar.guild1 == id, GuildWar.guild2 == id)).filter(GuildWar.status == GuildWar.Active).all()

	user = current_user()
	if user:
		ids = []
		for player in user.players:
			ids.append(player.id)

		for invite in invites:
			if invite.player_id in ids:
				invite.own = True

		for member in members:
			if member.player_id in ids:
				member.own = True

	return render_template(
		'community/guilds/view.htm', guild=guild, members=members, invites=invites,
		leader=is_guild_leader(id), vice=is_guild_vice(id), wars=wars
	)
Ejemplo n.º 19
0
def route_community_guild_disband(id):
    if not is_guild_leader(id):
        return redirect(url_for('route_community_guild', id=id))

    return render_template('community/guilds/disband.htm', id=id)
Ejemplo n.º 20
0
def route_community_guild_disband(id):
	if not is_guild_leader(id):
		return redirect(url_for('route_community_guild', id=id))

	return render_template('community/guilds/disband.htm', id=id)