Core - Player

The user profile class is a Django-specific way to extend the User class. In WoUSO, we use this to store login information, basic level and title information, group membership, and also the artifact inventory. Moreover, each game may extend this class in order to store user-game specific data.

Extensions

Example

# games/qotd/models.py:
class QotdUser(Player):
    last_answered = models.DateTimeField()
    last_answer = models.IntegerField()

    @property
    def has_answered(self):
        """ Check if last_answered was today """
        if self.last_answered is None:
            return False
        else:
            return (datetime.now() - self.last_answered) < timedelta (days = 1)

# games/qotd/views.py
@login_required
def index(request):
    profile = request.user.get_profile()
    qotd_user = profile.get_extension(QotdUser)

    if qotd_user.has_answered:
        return HttpResponseRedirect('/done/')

wouso.core.user.models

class wouso.core.user.models.Player(*args, **kwargs)

Base class for the game user. This is extended by game specific player models.

get_extension(cls)

Search for an extension of this object, with the type cls Create instance if there isn’t any.

Using an workaround, while: http://code.djangoproject.com/ticket/7623 gets fixed. Also see: http://code.djangoproject.com/ticket/11618

group

Return the core game group, if any

level

Return an artifact object for the current level_no. Ask God about the right artifact object, given the player instance. In the future, God may check players race and give specific artifacts.

level_progress()

Return a dictionary with: points_gained, points_left, next_level

proximate_group

Return the group with minimum class, for which the user is a member of, or None.

series

Return the group with class == 1, for which the user is a member of, or None.

TODO: get rid of old gclass=1 series, we now have race.

class wouso.core.user.models.PlayerGroup(*args, **kwargs)

Group players together

children

All groups with parent set to this group, cached

live_points

Calculate sum of user points dynamically

sisters

All groups with the same parent as this group or of the same class, if parent is not set.

class wouso.core.user.models.Race(*args, **kwargs)

Groups a large set of players together and it’s used extensively for ‘can_play’ checks.

points

Sum of race members points

wouso.core.user.templatetags.user

wouso.core.user.templatetags.user.player(user)

Render player name and level image with link to player’s profile

wouso.core.user.templatetags.user.player_avatar(player_obj)

Return avatar’s URL using the gravatar service

wouso.core.user.templatetags.user.player_group(group)

Render group with link to group’s profile page

wouso.core.user.templatetags.user.player_race(race)

Render group with link to group’s profile page

wouso.core.user.templatetags.user.player_simple(user)

Render only the player name with link to player’s profile

wouso.core.user.templatetags.user.player_simple2(user, user2)

Render name as You if player is the same as to user argument

Table Of Contents

Previous topic

Core - Scoring

Next topic

Interface

This Page