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.
# 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/')
Base class for the game user. This is extended by game specific player models.
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
Return the core game group, if any
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.
Return a dictionary with: points_gained, points_left, next_level
Return the group with minimum class, for which the user is a member of, or None.
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.
Render player name and level image with link to player’s profile
Return avatar’s URL using the gravatar service
Render group with link to group’s profile page
Render group with link to group’s profile page
Render only the player name with link to player’s profile
Render name as You if player is the same as to user argument