Skip to content

Commit

Permalink
Removed functools32; smaller fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
vthorsteinsson committed Apr 20, 2015
1 parent 54776cb commit 1adb118
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 16 deletions.
5 changes: 0 additions & 5 deletions dawgdictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@
import time
import cPickle as pickle

from functools32 import lru_cache

from languages import Alphabet


Expand Down Expand Up @@ -161,9 +159,6 @@ def num_nodes(self):
""" Return a count of unique nodes in the DAWG """
return 0 if self._nodes is None else len(self._nodes)

# This is a very common code path.
# Use LRU caching from functools32 to speed up lookups of common words
@lru_cache(maxsize = 1024)
def find(self, word):
""" Look for a word in the graph, returning True if it is found or False if not """
nav = FindNavigator(word)
Expand Down
9 changes: 6 additions & 3 deletions netskrafl.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

app = Flask(__name__)

running_local = os.environ.get('SERVER_SOFTWARE','').startswith('Development')
running_local = os.environ.get('SERVER_SOFTWARE', '').startswith('Development')

if running_local:
logging.info(u"Netskrafl app running with DEBUG set to True")
Expand Down Expand Up @@ -1190,6 +1190,9 @@ def store(self, usr):
uf = UserForm()
err = dict()

# The URL to go back to, if not main.html
from_url = request.args.get("from", None)

if request.method == 'GET':
# Entering the form for the first time: load the user data
uf.init_from_user(user)
Expand All @@ -1200,10 +1203,10 @@ def store(self, usr):
if not err:
# All is fine: store the data back in the user entity
uf.store(user)
return redirect(url_for("main"))
return redirect(from_url or url_for("main"))

# Render the form with the current data and error messages, if any
return render_template("userprefs.html", uf = uf, err = err)
return render_template("userprefs.html", uf = uf, err = err, from_url = from_url)


@app.route("/wait")
Expand Down
9 changes: 6 additions & 3 deletions skrafldb.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,20 +332,23 @@ def game_callback(gm):
human_elo_adj = human_elo_adj,
prefs = gm.prefs)

k = ndb.Key(UserModel, user_id)

# Run the query in two parts as experience suggests that
# AppEngine is not efficient with ndb.OR between two distinct values
# This also means that the returned list may be twice max_len

k = ndb.Key(UserModel, user_id)

q = cls.query(GameModel.over == True) \
.filter(GameModel.player0 == k)
.filter(GameModel.player0 == k) \
.order(-GameModel.ts_last_move)

for gm in q.fetch(max_len):
yield game_callback(gm)

q = cls.query(GameModel.over == True) \
.filter(GameModel.player1 == k)
.filter(GameModel.player1 == k) \
.order(-GameModel.ts_last_move)

for gm in q.fetch(max_len):
yield game_callback(gm)
Expand Down
2 changes: 1 addition & 1 deletion templates/board.html
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ <h2 id="usr-info-fullname"></h2>

function navToUserprefs() {
/* Show the user preferences page */
window.location.href = "{{ url_for('userprefs') | safe }}";
window.location.href = "{{ url_for('userprefs', from = url_for('board', game = game.id())) | safe }}";
}

function fbShare() {
Expand Down
2 changes: 1 addition & 1 deletion templates/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<span class="caption"></span>Skemmtilegt | skerpandi | ókeypis
</div>
<div class="welcome">
<span class="caption"></span>Netskrafl er vettvangur yfir 7.000 íslenskra skraflara á netinu.
<span class="caption"></span>Netskrafl er vettvangur yfir 8.000 íslenskra skraflara á netinu.
</div>
<div class="welcome">
<span class="caption"></span>Netskrafl notar Google Accounts innskráningu, þá
Expand Down
10 changes: 7 additions & 3 deletions templates/userprefs.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

<div class="loginhdr"><span class='glyphicon glyphicon-user'></span> Upplýsingar um leikmann</div>
<div>
<form name="frm1" id="frm1" action="{{ url_for('userprefs') }}" method="post">
<form name="frm1" id="frm1" action="{{ url_for('userprefs', from = from_url) | safe }}" method="post">

<div class="dialog-spacer"><span class="caption">Einkenni:</span>
<input type="text" name="nickname" id="nickname" tabindex="1"
Expand Down Expand Up @@ -141,13 +141,17 @@

<!-- Cancel button -->
<div class="modal-close" id="user-cancel" title="Hætta við" tabindex="9"
onclick="location.href='{{ url_for('main') }}'"
{% if from_url %}
onclick="location.href='{{ from_url | safe }}'"
{% else %}
onclick="location.href='{{ url_for('main') | safe }}'"
{% endif %}
onmouseover="buttonOver(this)"
onmouseout="buttonOut(this)"><span class="glyphicon glyphicon-remove"></span></div>

<!-- Logout button -->
<div class="modal-close" id="user-logout" title="Skrá mig út" tabindex="10"
onclick="location.href='{{ uf.logout_url }}'"
onclick="location.href='{{ uf.logout_url | safe }}'"
onmouseover="buttonOver(this)"
onmouseout="buttonOut(this)"><span class="glyphicon glyphicon-log-out"></span> Skrá mig út</div>

Expand Down

0 comments on commit 1adb118

Please sign in to comment.