All pastes #251734 Raw Edit

Miscellany

public text v1 · immutable
#251734 ·published 2006-11-18 15:31 UTC
rendered paste body
def get_game_list(site_id, strict=False):
	from cursesite.portals.models import RelatedObject
	cfilter = None
	related_objects = cache.get('site_related_objects_%s' % site_id)
	if not related_objects:
		related_objects = RelatedObject.objects.filter(site=site_id).select_related()
		cache.set('site_related_objects_%s' % site_id, related_objects)
	games = cache.get('site_games_%s' % site_id)
	if not games:
		ids = []
		for obj in related_objects:
			if obj.content_type.model_class() == Game:
				ids.append(str(obj.object_id))
		games = Game.objects
		if len(ids) > 0:
			games = games.filter(id__in=ids).order_by('name')
		elif not strict:
			games = games.all().order_by('name')
		else:
			games = []
		cache.set('site_games_%s' % site_id, games)
	return games