Games - Challenge

wouso.games.challenge.models

class wouso.games.challenge.models.Challenge(*args, **kwargs)

Challenge(id, user_from_id, user_to_id, date, status, winner_id)

can_play(user)

Check if user can play this challenge

static create(user_from, user_to, ignore_questions=False)

Assigns questions, and returns the number of assigned q

classmethod exist_last_day(today, user_from, user_to)

Return true if there are any challenges between the two users in the last day

extraInfo(user_won, user_lost)

returns a string with extra info for a string such as User 1 finished the challenge in $SECONDS seconds (or $MINUTES minutes and seconds) and scored X points)

static get_expired(today)

Return all expired candidate challenges at given date.

is_expired(participant)

This function assumes that seconds_took has been set. If the user didn’t submit the challenge, this will return False which might be incorrect. TODO: fix this to first check if user has submitted, and if not, verify with datetime.now - participant.start.

is_expired_for_user(user)

Check if the challenge has expired for the user

is_started_for_user(user)

Check if the challenge has already started for the given user

played()

Both players have played, save and score Notice the fact this is the only function where the scoring is affected

set_played(user, responses)

Set user’s results. If both users have played, also update self and activity.

set_start(user)

Update user.start and set playing time to now This is called when one of the participants sees the challenge for the first time. After this call, challenge will be visible to him for 5 minutes TODO: check it hasn’t been already started in the past

class wouso.games.challenge.models.ChallengeGame(*args, **kwargs)

Each game must extend Game

static get_active(user)

Return a list of active (runnable) challenges for a user

static get_expired(user)

Return a list of status != L/A challenges, where played = False

classmethod get_formulas(kls)

Returns a list of formulas used by qotd

classmethod get_modifiers(kls)

Challenge game modifiers

static get_played(user)

Return a list of played (scored TODO) challenges for a user

class wouso.games.challenge.models.ChallengeUser(*args, **kwargs)

Extension of the userprofile, customized for challenge

can_challenge(user)

Check if the target user is available.

can_launch()

Check if 1 challenge per day restriction apply

has_enough_points()

Check if the user has 30 points to challenge

class wouso.games.challenge.models.Participant(*args, **kwargs)

Participant(id, user_id, start, seconds_took, played, responses, score)

wouso.games.challenge.models.challenge_post_delete(sender, instance, **kwargs)

For some reason, this is called twice. Needs investigantion Also, in django devele, on_delete=cascade will fix this hack

wouso.games.challenge.views

wouso.games.challenge.views.challenge(request, *args, **kwargs)

Displays a challenge, only if status = accepted This is play

wouso.games.challenge.views.index(request, *args, **kwargs)

Shows all challenges related to the current user

wouso.games.challenge.views.setplayed(request, *args, **kwargs)

Set challenge as played for the other user. Only superuser can do this. Useful for debugging

Table Of Contents

Previous topic

Middleware

Next topic

Games - Question of the Day

This Page