diff --git a/pyfsw/__init__.py b/pyfsw/__init__.py index 09ccf5c..ef7e7df 100644 --- a/pyfsw/__init__.py +++ b/pyfsw/__init__.py @@ -49,5 +49,5 @@ def init_globals(): from pyfsw.helpers import * from pyfsw.views import news, forum, account, community, community_guilds, library, shop -from pyfsw.views import error, captcha, outfit, paypal, zaypay +from pyfsw.views import error, captcha, messages, outfit, paypal, zaypay from pyfsw.views.admin import dashboard, news, forum, community, shop diff --git a/pyfsw/static/js/custom.js b/pyfsw/static/js/custom.js new file mode 100644 index 0000000..c4d9340 --- /dev/null +++ b/pyfsw/static/js/custom.js @@ -0,0 +1,8 @@ +$(function() { + $.get('/messages', function(data) { + if(!data.length) return; + + $('#messages').show(); + $('#messages').append(data); + }); +}); diff --git a/pyfsw/templates/messages.htm b/pyfsw/templates/messages.htm new file mode 100644 index 0000000..d595fc4 --- /dev/null +++ b/pyfsw/templates/messages.htm @@ -0,0 +1,24 @@ +{% with messages = get_flashed_messages(category_filter=['error']) %} +{% if messages %} +
+ Error + +
+{% endif %} +{% endwith %} +{% with messages = get_flashed_messages(category_filter=['success']) %} +{% if messages %} +
+ Success + +
+ {% endif %} +{% endwith %} diff --git a/pyfsw/templates/template.htm b/pyfsw/templates/template.htm index 9ee3cb4..750e258 100644 --- a/pyfsw/templates/template.htm +++ b/pyfsw/templates/template.htm @@ -88,31 +88,7 @@
- {% with messages = get_flashed_messages(category_filter=['error']) %} - {% if messages %} -
- Error - -
- {% endif %} - {% endwith %} - - {% with messages = get_flashed_messages(category_filter=['success']) %} - {% if messages %} -
- Success - -
- {% endif %} - {% endwith %} +
{% block body %} {% endblock %} @@ -130,5 +106,6 @@
+ diff --git a/pyfsw/views/community.py b/pyfsw/views/community.py index 5536af8..4d52812 100644 --- a/pyfsw/views/community.py +++ b/pyfsw/views/community.py @@ -27,7 +27,7 @@ def route_community_player_get(): return render_template('community/player_search.htm') @app.route('/community/player/') -@cache.cached(timeout=CACHE_TIME) +@cache.memoize(timeout=CACHE_TIME) def route_community_player_get_name(name): player = Player.query.filter(Player.name == name).first() @@ -61,7 +61,7 @@ def route_community_player_get_name(name): ) @app.route('/community/player', methods=['POST']) -@cache.cached(timeout=CACHE_TIME) +@cache.memoize(timeout=CACHE_TIME) def route_community_player_post(): name = request.form.get('name', '', type=str) player = Player.query.filter(Player.name == name).first() @@ -96,7 +96,7 @@ def route_community_player_post(): ) @app.route('/community/highscores//') -@cache.cached(timeout=CACHE_TIME) +@cache.memoize(timeout=CACHE_TIME) def route_community_highscores(type, page): current = HS_TYPES.get(type) if not current: @@ -131,7 +131,7 @@ def route_community_highscores(type, page): ) @app.route('/community/houses/') -@cache.cached(timeout=CACHE_TIME) +@cache.memoize(timeout=CACHE_TIME) def route_community_houses(town_id): houses = House.query.order_by(House.id) @@ -148,7 +148,7 @@ def route_community_houses(town_id): return render_template('community/houses.htm', towns=TOWNS, town_id=town_id, price=HOUSE_PRICE, houses=houses) @app.route('/community/staff') -@cache.cached(timeout=CACHE_TIME) +@cache.memoize(timeout=CACHE_TIME) def route_community_staff(): staff = db.session().query( Player.name, Player.lastlogin, Player.lastlogout, Player.group_id, @@ -158,7 +158,7 @@ def route_community_staff(): return render_template('community/staff.htm', staff=staff) @app.route('/community/deaths') -@cache.cached(timeout=CACHE_TIME) +@cache.memoize(timeout=CACHE_TIME) def route_community_deaths(): deaths = PlayerDeath.query.limit(25).all() for death in deaths: @@ -171,7 +171,7 @@ def route_community_deaths(): return render_template('community/deaths.htm', deaths=deaths) @app.route('/community/online') -@cache.cached(timeout=CACHE_TIME) +@cache.memoize(timeout=CACHE_TIME) def route_community_online(): ids = [] for entry in PlayerOnline.query.all(): @@ -190,7 +190,7 @@ def route_community_online(): return render_template('community/online.htm', online=online) @app.route('/community/market') -@cache.cached(timeout=CACHE_TIME) +@cache.memoize(timeout=CACHE_TIME) def route_community_market(): sell = MarketOffer.query.filter(MarketOffer.sale == 1).all() for offer in sell: @@ -210,7 +210,7 @@ def route_community_market(): return render_template('community/market.htm', sell=sell, buy=buy, history=history) @app.route('/community/wars') -@cache.cached(timeout=CACHE_TIME) +@cache.memoize(timeout=CACHE_TIME) def route_community_wars(): active = GuildWar.query.filter(GuildWar.status == GuildWar.Active).all() pending = GuildWar.query.filter(GuildWar.status == GuildWar.Pending).all() @@ -219,7 +219,7 @@ def route_community_wars(): return render_template('community/wars.htm', active=active, pending=pending, ended=ended) @app.route('/community/war/') -@cache.cached(timeout=CACHE_TIME) +@cache.memoize(timeout=CACHE_TIME) def route_community_war(id): war = db.session().query(GuildWar.id, GuildWar.guild1, GuildWar.guild2).filter(GuildWar.id == id).first() if not war: diff --git a/pyfsw/views/community_guilds.py b/pyfsw/views/community_guilds.py index fa31238..557504f 100644 --- a/pyfsw/views/community_guilds.py +++ b/pyfsw/views/community_guilds.py @@ -17,13 +17,13 @@ GUILD_NAME_EXPR = re.compile('^([a-zA-Z ]+)$') @app.route('/community/guilds') -@cache.cached(timeout=CACHE_TIME) +@cache.memoize(timeout=CACHE_TIME) def route_community_guilds(): guilds = Guild.query.order_by(Guild.name).all() return render_template('community/guilds/list.htm', guilds=guilds, user=current_user()) @app.route('/community/guild/') -@cache.cached(timeout=CACHE_TIME) +@cache.memoize(timeout=CACHE_TIME) def route_community_guild(id): guild = Guild.query.filter(Guild.id == id).first() members = GuildMembership.query.filter(GuildMembership.guild_id == guild.id).all() diff --git a/pyfsw/views/messages.py b/pyfsw/views/messages.py new file mode 100644 index 0000000..2fee9d0 --- /dev/null +++ b/pyfsw/views/messages.py @@ -0,0 +1,7 @@ +from flask import render_template + +from pyfsw import app + +@app.route('/messages') +def route_messages(): + return render_template('messages.htm')