Ejemplo n.º 1
0
    def _create_credentials(self, raw_user, league_id=None, inviter_id=None):
        """ Create a new User and Player from raw user credentials. """

        # TODO: there are a lot of open questions here:
        # 1/ maybe fix this parameter list...it's ridiculous!
        # 2/ what about when we want to create a Person who isn't a Player?
        # 3/ when other credentialing options exist, it might not be good to
        #    assume exclusively.
        # 4/ is it more sensible to keep these methods separate if it turns out
        #    we can't easily generalize across other Person subclasses?
        (user, player) = User.create_user_and_player(
            PROPERTY_VALUE.EMPTY,
            PROPERTY_VALUE.EMPTY,
            None,
            PROPERTY_VALUE.EMPTY,
            PROPERTY_VALUE.EMPTY,
            {THIRD_PARTY.FACEBOOK: raw_user},
            inviter_id,
            self._ip,
            self._locale,
        )

        # TODO: uncomment TAGGED SqEdge type and pass optional third argument.
        if league_id is not None:
            Person.join_league(player.id, league_id)

        return (user, player)
Ejemplo n.º 2
0
 def _update_credentials(self, raw_user, user):
     """ Update an existing User with new raw user credentials. """
     # TODO: implement update and use it here!
     # return User.update_user_and_player(user, raw_user)
     return (user, Person.load_leagues(user.get_default_person_id()))
Ejemplo n.º 3
0
    def load(self):
        """ Populate context, aggregations, objects, and opponents. """

        # TODO: we should be able to do all this in one or two queries. given
        # player id, traverse to a league. from there get games and opponents
        # for those games. the only tricky thing is just getting one league. it
        # shouldn't be tricky to avoid manually loading opponents.

        person = Person.load_leagues(self.session.person_id)

        league = None
        if self._league_id is None:
            # if no league was requested than get the first league
            league = person.get_leagues().values()[0]
        else:
            league = person.get_leagues().get(self._league_id)
        # TODO: if league is None than throw some 'request invalid league
        # error'

        # TODO: we don't need to load Games from League when they can be loaded
        # from Opponents [or the vice-versa] all at the same time. we should
        # never be calling set_opponents() and set_games() outside the api.

        # RANKINGS LOAD
        opponents_list = League.load_opponents(league.id).get_opponents()
        league.set_opponents({o.id: o for o in opponents_list})

        # GAMES LOAD (WITH OPPONENTS AND COMMENTERS)
        games_list = League.load_games(league.id).get_games()

        # TODO: iterating through this list is only temporary becaue the
        # multiload should have happened in the api.
        game_ids = [g.id for g in games_list]

        # load opponents and commenters and creator for each game {g_id: Game}
        games_dict = Game.multiload_important_persons(game_ids)

        # load league with opponents and games into generic context
        league.set_games(games_dict)
        self._context = league

        # league's opponents by Win Count
        # store the list because the league has a dict, and sort returns None
        opponents = self._context.get_opponents()
        opponents.sort(
                key=lambda x: x.win_count,
                reverse=True)
        self._aggregations["standings"] = opponents
        self._aggregations["activity"] = None

        # store opponents loaded games in reverse order (so it's new first)
        games = games_dict.values()
        # sort returns None as it's in-place
        games.sort(
                key=lambda x: x.created_ts,
                reverse=True)
        self._objects = games

        # load opponents into rivals as well
        self._rivals = self._context.get_opponents()

        # load the list of sports
        self._sports = SPORT.ALL