Hi,
I'm developing a fantast league application but I'm having an issue
with the league issuing positions both in the oveall rankings and in
the private rankings and I'm not sure of the best way to do this.
At the minute I have this for sorting overall:
class SortOverall(webapp.RequestHandler):
def post(self):
weekend = int(self.request.get("weekend"))
## print weekend
## print '<br>'
teams_query = UserTeams.all().filter("nextsort =",weekend
+1).order('-position')
teams = teams_query.fetch(1)
a = len(teams)
if a == 0:
pos = 0
else:
pos = teams[0].position
## print pos
## print '<br>'
teams_query = UserTeams.all().filter("nextsort =",weekend).order('-
points')
teams = teams_query.fetch(500)
for p in teams:
key = p.key()
po = db.get(key)
pos = pos + 1
po.lastposition = p.position
po.position = pos
po.nextsort = weekend + 1
## print po.teamname
## print ' - '
## print po.position
## print '<br>'
db.put(po)
self.redirect('/results')
If you leave in the print actions you can see that its finding the
right entries and ordering them correctly put its not putting the
resulting number into the database, although it will do it
intermittantly (maybe 30% of the time).
For sorting in the private leagues I have this:
class SortLeague(webapp.RequestHandler):
def post(self):
weekend = int(self.request.get("weekend"))
league_query = League.all().filter("nextsort =",weekend)
league = league_query.fetch(500)
for p in league:
team_query = LeagueTeams.all().filter("league =",str(p.key()))
teams = team_query.fetch(500)
for q in teams:
## print q.player
## print '<br>'
a = db.get(q.team)
points = a.points
## print points
## print'<br>'
b = db.get(q.key())
## print b
## print '<br>'
b.points = points
db.put(b)
## print b
## print '<br>'
team_query = LeagueTeams.all().filter("league
=",str(p.key())).order("-points")
teams = team_query.fetch(500)
a = 0
## print 'stage 2'
for q in teams:
a = a+1
b = db.get(q.key())
## print q.leaguename
## print '<br>'
b.lastposition = q.position
b.position = a
db.put(b)
key = p.key()
po = db.get(key)
po.nextsort = weekend + 1
db.put(po)
## print
po.name
## print '<br>'
self.redirect('/results')
but it produces the same results - the print bits seem to indicate its
working but no data is being inserted into the datastore, although it
does, again, work intermittanly, although maybe only 10% of the time.
Does anyone know how to fix this, or a better way of doing this in the
first place?
Any help would be appreciated,
Paul