本文整理汇总了Python中util.get_code函数的典型用法代码示例。如果您正苦于以下问题:Python get_code函数的具体用法?Python get_code怎么用?Python get_code使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_code函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: get_runlist_for_runner
def get_runlist_for_runner( self, username, no_refresh=False ):
key = self.get_runlist_for_runner_memkey( username )
runlist = memcache.get( key )
if runlist is None and not no_refresh:
# Not in memcache, so construct the runlist and store in memcache.
runlist = [ ]
q = runs.Runs.all( )
q.ancestor( runs.key() )
q.filter( 'username =', username )
q.order( '-date' )
q.order( '-datetime_created' )
for run in q.run( limit = 1000 ):
runlist.append( dict( run_id = str( run.key().id() ),
game = run.game,
game_code = util.get_code( run.game ),
category = run.category,
category_code = util.get_code(
run.category ),
time = util.
seconds_to_timestr( run.seconds ),
date = run.date,
datetime_created = run.datetime_created,
video = run.video,
version = run.version,
notes = run.notes ) )
if memcache.set( key, runlist ):
logging.debug( "Set " + key + " in memcache" )
else:
logging.warning( "Failed to set " + key + " in memcache" )
elif runlist is not None:
logging.debug( "Got " + key + " from memcache" )
return runlist
开发者ID:Pafi,项目名称:pb-tracker,代码行数:33,代码来源:handler.py
示例2: get_runlist_for_runner
def get_runlist_for_runner( self, username, page_num ):
key = self.get_runlist_for_runner_memkey( username )
cached_runlists = memcache.get( key )
if cached_runlists is None:
cached_runlists = dict( )
res = cached_runlists.get( page_num )
if res is None:
# Not in memcache, so construct the runlist and store in memcache.
res = dict( page_num=page_num,
has_next=True )
runlist = [ ]
try:
q = runs.Runs.all( )
q.ancestor( runs.key() )
q.filter( 'username =', username )
q.order( '-date' )
q.order( '-datetime_created' )
c = memcache.get( self.get_runlist_for_runner_cursor_memkey(
username, page_num ) )
if c:
try:
q.with_cursor( start_cursor=c )
except BadRequestError:
res['page_num'] = 1
else:
res['page_num'] = 1
for run in q.run( limit = self.RUNLIST_PAGE_LIMIT ):
runlist.append( dict(
run_id = str( run.key().id() ),
game = run.game,
game_code = util.get_code( run.game ),
category = run.category,
category_code = util.get_code( run.category ),
time = util.
seconds_to_timestr( run.seconds ),
date = run.date,
datetime_created = run.datetime_created,
video = run.video,
version = run.version,
notes = run.notes ) )
c = q.cursor( )
cursor_key = self.get_runlist_for_runner_cursor_memkey(
username, res['page_num'] + 1 )
if memcache.set( cursor_key, c ):
logging.debug( "Set " + cursor_key + " in memcache" )
else:
logging.warning( "Failed to set new " + cursor_key
+ " in memcache" )
if len( runlist ) < self.RUNLIST_PAGE_LIMIT:
res['has_next'] = False
except apiproxy_errors.OverQuotaError, msg:
logging.error( msg )
return self.OVER_QUOTA_ERROR
res['runlist'] = runlist
cached_runlists[ res['page_num'] ] = res
if memcache.set( key, cached_runlists ):
logging.debug( "Set " + key + " in memcache" )
else:
logging.warning( "Failed to set " + key + " in memcache" )
开发者ID:rggibson,项目名称:pb-tracker,代码行数:60,代码来源:handler.py
示例3: get_gamepage
def get_gamepage(self, game, no_refresh=False):
key = self.get_gamepage_memkey(game)
gamepage = memcache.get(key)
if gamepage is None and not no_refresh:
# Not in memcache, so construct the gamepage and store it in
# memcache.
# Gamepage is a list of dictionaries. These dictionaries have up
# to 5 keys, 'category', 'bk_runner', 'bk_time', 'bk_video' and
# 'infolist'.
gamepage = []
# Grab the game model
game_model = self.get_game_model(util.get_code(game))
if game_model is None:
logging.error("Could not create " + key + " due to no " + "game model")
return None
gameinfolist = json.loads(game_model.info)
# Use a projection query to get all of the unique
# username, category pairs
q = db.Query(runs.Runs, projection=("username", "category"), distinct=True)
q.ancestor(runs.key())
q.filter("game =", game)
q.order("category")
cur_category = None
for run in q.run(limit=1000):
if run.category != cur_category:
# New category
d = dict(category=run.category, category_code=util.get_code(run.category), infolist=[])
gamepage.append(d)
cur_category = run.category
# Check for a best known time for this category
for gameinfo in gameinfolist:
if gameinfo["category"] == run.category:
d["bk_runner"] = gameinfo.get("bk_runner")
d["bk_time"] = util.seconds_to_timestr(gameinfo.get("bk_seconds"))
d["bk_date"] = util.datestr_to_date(gameinfo.get("bk_datestr"))[0]
d["bk_video"] = gameinfo.get("bk_video")
break
# Add the info to the gamepage
info = self.get_runinfo(run.username, game, run.category)
d["infolist"].append(info)
# For each category, sort the runlist by seconds, breaking ties
# by date
for runlist in gamepage:
runlist["infolist"].sort(key=lambda x: util.get_valid_date(x["pb_date"]))
runlist["infolist"].sort(key=itemgetter("pb_seconds"))
# Sort the categories by number of runners
gamepage.sort(key=lambda x: len(x["infolist"]), reverse=True)
if memcache.set(key, gamepage):
logging.debug("Set " + key + " in memcache")
else:
logging.warning("Failed to set " + key + " in memcache")
elif gamepage is not None:
logging.debug("Got " + key + " from memcache")
return gamepage
开发者ID:WeegeeZV,项目名称:pb-tracker,代码行数:60,代码来源:handler.py
示例4: get
def get( self, run_id ):
user = self.get_user( )
if not user:
self.redirect( "/" )
return
elif user == self.OVER_QUOTA_ERROR:
self.error( 403 )
self.render( "403.html" )
return
# Get the run
run = self.get_run_by_id( run_id )
if run == self.OVER_QUOTA_ERROR:
self.error( 403 )
self.render( "403.html", user=user )
return
if( not run or
( not user.is_mod and run.username != user.username ) ):
self.error( 404 )
self.render( "404.html", user=user )
return
self.render( "deleterun.html", user=user, run=run,
game_code=util.get_code( run.game ),
username_code=util.get_code( user.username ),
time=util.seconds_to_timestr( run.seconds ) )
开发者ID:rggibson,项目名称:pb-tracker,代码行数:26,代码来源:deleterun.py
示例5: get
def get( self, game_code ):
user = self.get_user( )
return_url = self.request.get( 'from' )
if not return_url:
return_url = "/"
# Get the category
category_code = self.request.get( 'c' )
if user is None or not category_code:
self.error( 404 )
self.render( "404.html", user=user )
return
# Have to take the code of the category code because of percent
# encoded plusses
category_code = util.get_code( category_code )
# Check to make sure that the user has run this game
game_model = self.get_game_model( game_code )
user_has_run = self.get_user_has_run( user.username, game_model.game )
if not user_has_run and not user.is_mod:
self.error( 404 )
self.render( "404.html", user=user )
return
# Find the corresponding gameinfo for this category
gameinfolist = json.loads( game_model.info )
gameinfo = None
for g in gameinfolist:
if util.get_code( g['category'] ) == category_code:
gameinfo = g
break
if gameinfo is None:
self.error( 404 )
self.render( "404.html", user=user )
return
params = dict( user=user, game=game_model.game, game_code=game_code,
category=gameinfo['category'], return_url=return_url )
params['username'] = gameinfo.get( 'bk_runner' )
if params['username'] is None:
params['username'] = ''
params['time'] = ''
params['datestr'] = ''
params['video'] = ''
params['updating'] = False
else:
params['time'] = util.seconds_to_timestr(
gameinfo.get( 'bk_seconds' ) )
params['datestr'] = gameinfo.get( 'bk_datestr' )
params['video'] = gameinfo.get( 'bk_video' )
params['updating'] = True
if return_url[ 0 : len( '/runner/' ) ] == '/runner/':
params['from_runnerpage'] = True
else:
params['from_runnerpage'] = False
self.render( "updatebkt.html", **params )
开发者ID:Alko-SDA,项目名称:pb-tracker,代码行数:59,代码来源:updatebkt.py
示例6: get_runinfo
def get_runinfo( self, username, game, category, no_refresh=False ):
key = self.get_runinfo_memkey( username, game, category )
runinfo = memcache.get( key )
if runinfo is None and not no_refresh:
# Not in memcache, so constrcut the runinfo dictionary
pb_run = None
avg_seconds = 0
num_runs = 0
try:
q = db.Query( runs.Runs,
projection=('seconds', 'date', 'video',
'version') )
q.ancestor( runs.key() )
q.filter('username =', username)
q.filter('game =', game)
q.filter('category =', category)
q.order('-date') # Cut off old runs
for run in q.run( limit = 100000 ):
num_runs += 1
avg_seconds += ( 1.0 / num_runs ) * (
run.seconds - avg_seconds )
if( pb_run is None or run.seconds <= pb_run.seconds ):
pb_run = run
runinfo = dict( username = username,
username_code = util.get_code( username ),
category = category,
category_code = util.get_code( category ),
pb_seconds = None,
pb_time = None,
pb_date = None,
num_runs = num_runs,
avg_seconds = avg_seconds,
avg_time = util.seconds_to_timestr(
avg_seconds, dec_places=0),
video = None )
except apiproxy_errors.OverQuotaError, msg:
logging.error( msg )
return self.OVER_QUOTA_ERROR
# Set the pb time
if pb_run:
runinfo['pb_seconds'] = pb_run.seconds
runinfo['pb_time'] = util.seconds_to_timestr( pb_run.seconds )
runinfo['pb_date'] = pb_run.date
runinfo['video'] = pb_run.video
runinfo['version'] = pb_run.version
if memcache.set( key, runinfo ):
logging.debug( "Set " + key + " in memcache" )
else:
logging.warning( "Failed to set " + key + " in memcache" )
开发者ID:stevensmedia,项目名称:pb-tracker,代码行数:51,代码来源:handler.py
示例7: get_runinfo
def get_runinfo(self, username, game, category, no_refresh=False):
key = self.get_runinfo_memkey(username, game, category)
runinfo = memcache.get(key)
if runinfo is None and not no_refresh:
# Not in memcache, so constrcut the runinfo dictionary
q = db.Query(runs.Runs, projection=("seconds", "date", "video", "version"))
q.ancestor(runs.key())
q.filter("username =", username)
q.filter("game =", game)
q.filter("category =", category)
q.order("-date") # Cut off old runs
pb_run = None
avg_seconds = 0
num_runs = 0
for run in q.run(limit=100000):
num_runs += 1
avg_seconds += (1.0 / num_runs) * (run.seconds - avg_seconds)
if pb_run is None or run.seconds <= pb_run.seconds:
pb_run = run
runinfo = dict(
username=username,
username_code=util.get_code(username),
category=category,
category_code=util.get_code(category),
pb_seconds=None,
pb_time=None,
pb_date=None,
num_runs=num_runs,
avg_seconds=avg_seconds,
avg_time=util.seconds_to_timestr(avg_seconds),
video=None,
)
# Set the pb time
if pb_run:
runinfo["pb_seconds"] = pb_run.seconds
runinfo["pb_time"] = util.seconds_to_timestr(pb_run.seconds)
runinfo["pb_date"] = pb_run.date
runinfo["video"] = pb_run.video
runinfo["version"] = pb_run.version
if memcache.set(key, runinfo):
logging.debug("Set " + key + " in memcache")
else:
logging.warning("Failed to set " + key + " in memcache")
elif runinfo is not None:
logging.debug("Got " + key + " from memcache")
return runinfo
开发者ID:WeegeeZV,项目名称:pb-tracker,代码行数:48,代码来源:handler.py
示例8: update_runlist_for_runner_put
def update_runlist_for_runner_put( self, params ):
user = params[ 'user' ]
game = params[ 'game' ]
game_code = params[ 'game_code' ]
category = params[ 'category' ]
time = params[ 'time' ]
video = params[ 'video' ]
version = params[ 'version' ]
notes = params[ 'notes' ]
date = params[ 'date' ]
datetime_created = params[ 'datetime_created' ]
run_id = params[ 'run_id' ]
# Update runlist for runner in memcache
runlist = self.get_runlist_for_runner( user.username,
no_refresh=True )
if runlist is not None:
runlist.insert( 0, dict( run_id = run_id,
game = game,
game_code = game_code,
category = category,
category_code = util.get_code( category ),
time = time,
date = date,
datetime_created = datetime_created,
video = video,
version = version,
notes = notes ) )
runlist.sort( key=lambda x: util.get_valid_date( x['date'] ),
reverse=True )
self.update_cache_runlist_for_runner( user.username, runlist )
开发者ID:Alko-SDA,项目名称:pb-tracker,代码行数:31,代码来源:runhandler.py
示例9: get_gamelist
def get_gamelist(self, no_refresh=False):
key = self.get_gamelist_memkey()
gamelist = memcache.get(key)
if gamelist is None and not no_refresh:
# Build the gamelist, which is a list of dictionaries where each
# dict gives the game, game_code and number of pbs for that game.
# The list is sorted by numbers of pbs for the game
gamelist = []
q = db.Query(games.Games, projection=("game", "num_pbs"))
q.ancestor(games.key())
q.order("-num_pbs")
q.order("game")
for game_model in q.run(limit=10000):
if game_model.num_pbs <= 0:
break
gamelist.append(
dict(game=game_model.game, game_code=util.get_code(game_model.game), num_pbs=game_model.num_pbs)
)
if memcache.set(key, gamelist):
logging.debug("Set gamelist in memcache")
else:
logging.warning("Failed to set new gamelist in memcache")
elif gamelist is not None:
logging.debug("Got gamelist from memcache")
return gamelist
开发者ID:WeegeeZV,项目名称:pb-tracker,代码行数:25,代码来源:handler.py
示例10: get_runnerlist
def get_runnerlist(self, no_refresh=False):
key = self.get_runnerlist_memkey()
runnerlist = memcache.get(key)
if runnerlist is None and not no_refresh:
# Build the runnerlist, which is a list of dictionaries where each
# dict gives the username and number of pbs for that user.
# The list is sorted by numbers of pbs for the user.
runnerlist = []
q = db.Query(runners.Runners, projection=("username", "gravatar", "num_pbs"))
q.ancestor(runners.key())
q.order("-num_pbs")
q.order("username")
for runner in q.run(limit=100000):
runnerlist.append(
dict(
username=runner.username,
username_code=util.get_code(runner.username),
num_pbs=runner.num_pbs,
gravatar_url=util.get_gravatar_url(runner.gravatar),
)
)
if memcache.set(key, runnerlist):
logging.debug("Set runnerlist in memcache")
else:
logging.warning("Failed to set new runnerlist in memcache")
elif runnerlist is not None:
logging.debug("Got runnerlist from memcache")
return runnerlist
开发者ID:WeegeeZV,项目名称:pb-tracker,代码行数:28,代码来源:handler.py
示例11: get
def get( self, username_code ):
user = self.get_user( )
# Make sure this is the correct user
if user is None:
self.error( 404 )
self.render( "404.html", user=user )
return
elif user == self.OVER_QUOTA_ERROR:
self.error( 403 )
self.render( "403.html" )
return
elif util.get_code( user.username ) != username_code:
self.error( 404 )
self.render( "404.html", user=user )
return
# Get the stored visible columns, or get the default ones
if user.visible_columns:
visible_columns = json.loads( user.visible_columns )
else:
visible_columns = util.get_default_visible_columns( )
self.render( "edit_table.html", user=user, username_code=username_code,
visible_columns=visible_columns )
开发者ID:albinohat,项目名称:pb-tracker,代码行数:25,代码来源:edit_table.py
示例12: get_runnerlist
def get_runnerlist( self, no_refresh=False ):
key = self.get_runnerlist_memkey( )
runnerlist = memcache.get( key )
if runnerlist is None and not no_refresh:
# Build the runnerlist, which is a list of dictionaries where each
# dict gives the username and number of pbs for that user.
# The list is sorted by numbers of pbs for the user.
runnerlist = [ ]
try:
q = db.Query( runners.Runners,
projection=('username', 'gravatar', 'num_pbs') )
q.ancestor( runners.key() )
q.order( '-num_pbs' )
q.order( 'username' )
for runner in q.run( limit=100000 ):
runnerlist.append(
dict( username = runner.username,
username_code = util.get_code( runner.username ),
num_pbs = runner.num_pbs,
gravatar_url = util.get_gravatar_url(
runner.gravatar ) ) )
except apiproxy_errors.OverQuotaError, msg:
logging.error( msg )
return self.OVER_QUOTA_ERROR
if memcache.set( key, runnerlist ):
logging.debug( "Set runnerlist in memcache" )
else:
logging.warning( "Failed to set new runnerlist in memcache" )
开发者ID:stevensmedia,项目名称:pb-tracker,代码行数:29,代码来源:handler.py
示例13: get_gamelist
def get_gamelist( self, no_refresh=False, get_num_pbs=True ):
key = self.get_gamelist_memkey( get_num_pbs )
gamelist = memcache.get( key )
if gamelist is None and not no_refresh:
# Build the gamelist, which is a list of dictionaries where each
# dict gives the game, game_code and number of pbs for that game.
# The list is sorted by numbers of pbs for the game
gamelist = [ ]
projection = [ 'game' ]
if get_num_pbs:
projection.append( 'num_pbs' )
try:
q = db.Query( games.Games, projection=projection )
q.ancestor( games.key() )
if get_num_pbs:
q.order( '-num_pbs' )
q.order( 'game' )
for game_model in q.run( limit=10000 ):
if get_num_pbs and game_model.num_pbs <= 0:
break
if get_num_pbs:
d = dict( game = game_model.game,
game_code = util.get_code( game_model.game ),
num_pbs = game_model.num_pbs )
gamelist.append( d )
else:
gamelist.append( str( game_model.game ) )
except apiproxy_errors.OverQuotaError, msg:
logging.error( msg )
return self.OVER_QUOTA_ERROR
if memcache.set( key, gamelist ):
logging.debug( "Set " + key + " in memcache" )
else:
logging.warning( "Failed to set new " + key + " in memcache" )
开发者ID:stevensmedia,项目名称:pb-tracker,代码行数:35,代码来源:handler.py
示例14: post
def post( self, username_code ):
user = self.get_user( )
# Make sure this is the correct user
if user is None:
self.error( 404 )
self.render( "404.html", user=user )
return
elif user == self.OVER_QUOTA_ERROR:
self.error( 403 )
self.render( "403.html" )
return
elif util.get_code( user.username ) != username_code:
self.error( 404 )
self.render( "404.html", user=user )
return
# Get the visible columns
visible_columns = util.get_default_visible_columns( )
for key in visible_columns:
checked = self.request.get( key + '_visible', default_value="no" )
if checked == "yes":
visible_columns[ key ] = True
else:
visible_columns[ key ] = False
# Store
user.visible_columns = json.dumps( visible_columns )
user.put( )
# Update memcache
self.update_cache_runner( username_code, user )
# That's all
self.redirect( "/runner/" + username_code )
开发者ID:albinohat,项目名称:pb-tracker,代码行数:35,代码来源:edit_table.py
示例15: get
def get( self, game_code ):
user = self.get_user( )
# Make sure this game exists
game_model = self.get_game_model( game_code )
if not game_model:
self.error( 404 )
self.render( "404.html", user=user )
return
# Find out if this user has run this game
if user is not None:
user_has_run = self.get_user_has_run( user.username,
game_model.game )
else:
user_has_run = False
gamepage = self.get_gamepage( game_model.game )
# Add gravatar images to the gamepage
for d in gamepage:
for run in d['infolist']:
runner = self.get_runner( util.get_code( run['username'] ) )
if runner is not None:
run['gravatar_url'] = util.get_gravatar_url(
runner.gravatar, size=20 )
if self.format == 'html':
self.render( "gamepage.html", user=user, game=game_model.game,
game_code=game_code, gamepage=gamepage,
user_has_run=user_has_run )
elif self.format == 'json':
self.render_json( gamepage )
开发者ID:Seckswrecks,项目名称:pb-tracker,代码行数:33,代码来源:gamepage.py
示例16: cleanup_games
def cleanup_games(self):
# Grab all of the categories, indexed by game
categories = self.get_categories()
categories_modified = False
games_to_delete = []
for game, categorylist in categories.iteritems():
# Grab the game model
game_code = util.get_code(game)
game_model = self.get_game_model(game_code)
gameinfolist = json.loads(game_model.info)
game_model_modified = False
glist = [(i, gameinfo) for i, gameinfo in enumerate(gameinfolist)]
for i, gameinfo in reversed(glist):
# Leave it if the category is marked as a base category
if (
gameinfo.get("is_base_category")
and game != "Luigi's Mansion"
and game != "Super Mario Bros.: The Lost Levels"
and game != "The Legend of Zelda: A Link to the Past"
):
continue
# Check if there is a run for this game and category
q = db.Query(runs.Runs, keys_only=True)
q.ancestor(runs.key())
q.filter("game =", game)
q.filter("category =", gameinfo["category"])
num_runs = q.count(limit=1)
if num_runs == 0:
# Remove this category
del gameinfolist[i]
logging.info("Removed " + gameinfo["category"] + " from " + game)
game_model_modified = True
# Remove this category in memcache too
for j, category in enumerate(categorylist):
if category == gameinfo["category"]:
del categorylist[j]
categories_modified = True
break
else:
logging.error("ERROR: Could not find in categories")
# Remove the game if no more categories exist
if len(gameinfolist) == 0:
game_model.delete()
games_to_delete.append(game)
logging.info(game + " deleted")
self.update_cache_game_model(game_code, None)
# Update database and memcache if necessary
elif game_model_modified:
game_model.info = json.dumps(gameinfolist)
game_model.put()
self.update_cache_game_model(game_code, game_model)
# Finally, update categories in memcache if necessary
if categories_modified:
for game in games_to_delete:
del categories[game]
self.update_cache_categories(categories)
开发者ID:WingedZyre,项目名称:pb-tracker,代码行数:58,代码来源:cleanup_games_base.py
示例17: get_gamelist
def get_gamelist( self, page_num ):
key = self.get_gamelist_memkey( )
data = memcache.get( key )
if data is None:
data = dict( )
res = data.get( page_num )
if res is None:
# Build the gamelist, which is a list of dictionaries where each
# dict gives the game, game_code and number of pbs for that game.
# The list is sorted by numbers of pbs for the game
res = dict( page_num=page_num )
gamelist = [ ]
projection = [ 'game', 'num_pbs' ]
try:
q = db.Query( games.Games, projection=projection )
q.ancestor( games.key() )
q.order( '-num_pbs' )
q.order( 'game' )
c = memcache.get( self.get_gamelist_cursor_memkey( page_num ) )
if c:
try:
q.with_cursor( start_cursor=c )
except BadRequestError:
res['page_num'] = 1
else:
# Send the user back to the first page
res['page_num'] = 1
for game_model in q.run( limit=self.PAGE_LIMIT ):
if game_model.num_pbs <= 0:
break
d = dict( game = game_model.game,
game_code = util.get_code( game_model.game ),
num_pbs = game_model.num_pbs )
gamelist.append( d )
c = q.cursor( )
cursor_key = self.get_gamelist_cursor_memkey(
res['page_num'] + 1 )
if memcache.set( cursor_key, c ):
logging.debug( "Set " + cursor_key + " in memcache" )
else:
logging.warning( "Failed to set new " + cursor_key
+ " in memcache" )
if len( gamelist ) >= self.PAGE_LIMIT:
res['has_next'] = True
else:
res['has_next'] = False
res['gamelist'] = gamelist
except apiproxy_errors.OverQuotaError, msg:
logging.error( msg )
return self.OVER_QUOTA_ERROR
data[ res['page_num'] ] = res
if memcache.set( key, data ):
logging.debug( "Set " + key + " in memcache" )
else:
logging.warning( "Failed to set new " + key + " in memcache" )
开发者ID:rggibson,项目名称:pb-tracker,代码行数:56,代码来源:handler.py
示例18: is_valid_login
def is_valid_login( self, username, password ):
username_code = util.get_code( username )
# Find the user in the database
try:
user = runners.Runners.get_by_key_name( username_code,
parent=runners.key() )
except apiproxy_errors.OverQuotaError, msg:
logging.error( msg )
return False, dict( user_error="Over quota error" )
开发者ID:rggibson,项目名称:pb-tracker,代码行数:10,代码来源:handler.py
示例19: get
def get( self ):
# Grab all of the categories, indexed by game
categories = self.get_categories( )
categories_modified = False
games_to_delete = [ ]
for game, categorylist in categories.iteritems( ):
# Grab the game model
game_code = util.get_code( game )
game_model = self.get_game_model( game_code )
gameinfolist = json.loads( game_model.info )
game_model_modified = False
glist = [ ( i, gameinfo )
for i, gameinfo in enumerate( gameinfolist ) ]
for i, gameinfo in reversed( glist ):
# Leave it if the category is marked as a base category
if gameinfo.get( 'is_base_category' ):
continue
# Check if there is a run for this game and category
q = db.Query( runs.Runs, keys_only=True )
q.ancestor( runs.key() )
q.filter( 'game =', game )
q.filter( 'category =', gameinfo['category'] )
num_runs = q.count( limit=1 )
if num_runs == 0:
# Remove this category
del gameinfolist[ i ]
logging.debug( "Removed " + gameinfo['category']
+ " from " + game )
game_model_modified = True
# Remove this category in memcache too
for j, category in enumerate( categorylist ):
if category == gameinfo['category']:
del categorylist[ j ]
categories_modified = True
break
else:
logging.debug( "ERROR: Could not find in categories" )
# Remove the game if no more categories exist
if len( gameinfolist ) == 0:
game_model.delete( )
games_to_delete.append( game )
logging.debug( game + " deleted" )
self.update_cache_game_model( game_code, None )
# Update database and memcache if necessary
elif game_model_modified:
game_model.info = json.dumps( gameinfolist )
game_model.put( )
self.update_cache_game_model( game_code, game_model )
# Finally, update categories in memcache if necessary
if categories_modified:
for game in games_to_delete:
del categories[ game ]
self.update_cache_categories( categories )
开发者ID:Pafi,项目名称:pb-tracker,代码行数:55,代码来源:cleanup_games.py
示例20: get_runnerlist
def get_runnerlist( self, page_num ):
key = self.get_runnerlist_memkey( )
data = memcache.get( key )
if data is None:
data = dict( )
res = data.get( page_num )
if res is None:
# Build the runnerlist, which is a list of dictionaries where each
# dict gives the username and number of pbs for that user.
# The list is sorted by numbers of pbs for the user.
res = dict( page_num=page_num,
runnerlist=[ ],
has_next=True )
try:
q = db.Query( runners.Runners,
projection=['username', 'gravatar', 'num_pbs'] )
q.ancestor( runners.key() )
q.order( '-num_pbs' )
q.order( 'username' )
c = memcache.get( self.get_runnerlist_cursor_memkey(
page_num ) )
if c:
try:
q.with_cursor( start_cursor=c )
except BadRequestError:
res['page_num'] = 1
else:
res['page_num'] = 1
for runner in q.run( limit=self.PAGE_LIMIT ):
res['runnerlist'].append(
dict( username = runner.username,
username_code = util.get_code( runner.username ),
num_pbs = runner.num_pbs,
gravatar_url = util.get_gravatar_url(
runner.gravatar ) ) )
c = q.cursor( )
cursor_key = self.get_runnerlist_cursor_memkey(
res['page_num'] + 1 )
if memcache.set( cursor_key, c ):
|
请发表评论