Пример #1
0
        inactive_quizzes = [t for t in through if t.quiz.is_inactive() and t.quiz.is_public()]
        return inactive_quizzes

    @property
    def expired_quizzes(self):
        through = UserToQuiz.objects.filter(user=self)
        expired_quizzes = [t for t in through if t.quiz.is_expired()]
        return expired_quizzes

    @property
    def played_quizzes(self):
        through = UserToQuiz.objects.filter(user=self, state='P')
        return through


Player.register_extension('quiz', QuizUser)

register_category(QuizGame.QPOOL_CATEGORY, QuizGame)


class UserToQuiz(models.Model):
    """
     Used as a link between each user and each quiz
    """
    CHOICES = {
        ('P', 'PLAYED'),
        ('R', 'RUNNING'),
        ('N', 'NOT RUNNING')
    }

    user = models.ForeignKey(QuizUser)
Пример #2
0
        inactive_quizzes = [t for t in through if t.quiz.is_inactive() and t.quiz.is_public()]
        return inactive_quizzes

    @property
    def expired_quizzes(self):
        through = UserToQuiz.objects.filter(user=self)
        expired_quizzes = [t for t in through if t.quiz.is_expired()]
        return expired_quizzes

    @property
    def played_quizzes(self):
        through = UserToQuiz.objects.filter(user=self, state="P")
        return through


Player.register_extension("quiz", QuizUser)

register_category(QuizGame.QPOOL_CATEGORY, QuizGame)


class UserToQuiz(models.Model):
    """
     Used as a link between each user and each quiz
    """

    CHOICES = {("P", "PLAYED"), ("R", "RUNNING"), ("N", "NOT RUNNING")}

    user = models.ForeignKey(QuizUser)
    quiz = models.ForeignKey(Quiz)
    questions = models.ManyToManyField(Question)
    state = models.CharField(max_length=1, choices=CHOICES, default="N")
Пример #3
0
        """ :return: list of pairs (index, position) for the last week """
        if relative_to is None:
            hs = self.history()
        else:
            hs = self.history().filter(relative_to=relative_to).order_by('-date')[:7]
        tot = len(hs)
        return [(tot - i, h.position) for (i, h) in enumerate(hs)]

    def week_points_evolution(self):
        """ :return: list of pairs (index, points) for the last week """
        hs = self.history()
        tot = len(hs)
        return [(tot - i, h.points) for (i, h) in enumerate(hs)]


Player.register_extension('top', TopUser)


class NewHistory(models.Model):
    TYPES = (('u', 'user'), ('r', 'race'), ('g', 'group'), ('c', 'coin'))

    object = models.IntegerField(help_text='Object id, user, race, group')
    object_type = models.CharField(max_length=1, choices=TYPES, default='u')
    relative_to = models.IntegerField(help_text='Relative to id, race or group', blank=True, null=True)
    relative_to_type = models.CharField(max_length=1, choices=TYPES, default=None, blank=True, null=True)

    position = models.IntegerField(default=0)
    points = models.FloatField(default=0)
    date = models.DateField()

    @classmethod
Пример #4
0
        if relative_to is None:
            hs = self.history()
        else:
            hs = self.history().filter(
                relative_to=relative_to).order_by('-date')[:7]
        tot = len(hs)
        return [(tot - i, h.position) for (i, h) in enumerate(hs)]

    def week_points_evolution(self):
        """ :return: list of pairs (index, points) for the last week """
        hs = self.history()
        tot = len(hs)
        return [(tot - i, h.points) for (i, h) in enumerate(hs)]


Player.register_extension('top', TopUser)


class NewHistory(models.Model):
    TYPES = (('u', 'user'), ('r', 'race'), ('g', 'group'), ('c', 'coin'))

    object = models.IntegerField(help_text='Object id, user, race, group')
    object_type = models.CharField(max_length=1, choices=TYPES, default='u')
    relative_to = models.IntegerField(
        help_text='Relative to id, race or group', blank=True, null=True)
    relative_to_type = models.CharField(max_length=1,
                                        choices=TYPES,
                                        default=None,
                                        blank=True,
                                        null=True)
Пример #5
0
 def __init__(self, **kwargs):
     super(AGForm, self).__init__(**kwargs)
     self.fields['assistant'].queryset = Player.get_by_permission(
         'change_semigroup')
Пример #6
0
 def __init__(self, **kwargs):
     super(AGForm, self).__init__(**kwargs)
     self.fields['assistant'].queryset = Player.get_by_permission('change_semigroup')
Пример #7
0
        self.last_launched = value
        self.save()

    def get_all_challenges(self):
        chall_total = Challenge.objects.exclude(status=u'L').filter(
            Q(user_from__user=self) | Q(user_to__user=self))
        return chall_total

    def get_won_challenges(self):
        return self.get_all_challenges().filter(winner=self)

    def get_lost_challenges(self):
        return self.get_all_challenges().exclude(winner=self)


Player.register_extension('challenge', ChallengeUser)


class Participant(models.Model):
    user = models.ForeignKey(ChallengeUser)
    start = models.DateTimeField(null=True, blank=True)
    seconds_took = models.IntegerField(null=True, blank=True)
    played = models.BooleanField(default=False)
    responses = models.TextField(default='', blank=True, null=True)
    #score = models.FloatField(null=True, blank=True)
    score = models.IntegerField(null=True, blank=True)

    @property
    def challenge(self):
        try:
            return Challenge.objects.get(Q(user_from=self) | Q(user_to=self))
Пример #8
0
        if average_time is None:
            average_time = 0
        if average_score is None:
            average_score = 0

        win_percentage = self.get_win_percentage()

        stats = dict(n_chall_played=n_chall_played, n_chall_won=n_chall_won,
                     n_chall_sent=n_chall_sent, n_chall_rec=n_chall_rec,
                     n_chall_ref=n_chall_ref, current_player=self,
                     average_time=average_time, average_score=average_score,
                     win_percentage=win_percentage, opponents=result)
        return stats


Player.register_extension('challenge', ChallengeUser)


class Participant(models.Model):
    user = models.ForeignKey(ChallengeUser)
    start = models.DateTimeField(null=True, blank=True)
    seconds_took = models.IntegerField(null=True, blank=True)
    played = models.BooleanField(default=False)
    responses = models.TextField(default='', blank=True, null=True)
    # score = models.FloatField(null=True, blank=True)
    score = models.IntegerField(null=True, blank=True)

    @property
    def challenge(self):
        try:
            return Challenge.objects.get(Q(user_from=self) | Q(user_to=self))
Пример #9
0
 def get_context_data(self, **kwargs):
     context = super(HistoryView, self).get_context_data(**kwargs)
     context.update({'gods': Player.get_quest_gods()})
     return context
Пример #10
0
from ckeditor.fields import RichTextField
from django.db import models
from wouso.core.user.models import Player


class ForumUser(Player):
    def __unicode__(self):
        super(ForumUser, self).__init__()


Player.register_extension('top', ForumUser)


class Category(models.Model):
    name = models.CharField(max_length=255, unique=True)

    def __unicode__(self):
        return self.name


class Forum(models.Model):
    category = models.ForeignKey('Category', related_name='forums')
    name = models.CharField(blank=True, max_length=255)
    position = models.IntegerField(default=0)
    description = models.TextField(blank=True)
    is_closed = models.BooleanField(default=False)

    def get_latest_topic(self):
        if self.topics.count() > 0:
            return self.topics.all()[0]
Пример #11
0
        if t.quiz.is_inactive() and t.quiz.is_public()]
        return inactive_quizzes

    @property
    def expired_quizzes(self):
        through = UserToQuiz.objects.filter(user=self)
        expired_quizzes = [t for t in through if t.quiz.is_expired()]
        return expired_quizzes

    @property
    def played_quizzes(self):
        through = UserToQuiz.objects.filter(user=self, state='P')
        return through


Player.register_extension('quiz', QuizUser)

register_category(QuizGame.QPOOL_CATEGORY, QuizGame)


class UserToQuiz(models.Model):
    """
     Used as a link between each user and each quiz
    """
    CHOICES = {('P', 'PLAYED'), ('R', 'RUNNING'), ('N', 'NOT RUNNING')}

    user = models.ForeignKey(QuizUser)
    quiz = models.ForeignKey(Quiz)
    questions = models.ManyToManyField(Question)
    state = models.CharField(max_length=1, choices=CHOICES, default='N')
    start = models.DateTimeField(blank=True, null=True)
Пример #12
0
        stats = dict(
            n_chall_played=n_chall_played,
            n_chall_won=n_chall_won,
            n_chall_sent=n_chall_sent,
            n_chall_rec=n_chall_rec,
            n_chall_ref=n_chall_ref,
            current_player=self,
            average_time=average_time,
            average_score=average_score,
            win_percentage=win_percentage,
            opponents=result,
        )
        return stats


Player.register_extension("challenge", ChallengeUser)


class Participant(models.Model):
    user = models.ForeignKey(ChallengeUser)
    start = models.DateTimeField(null=True, blank=True)
    seconds_took = models.IntegerField(null=True, blank=True)
    played = models.BooleanField(default=False)
    responses = models.TextField(default="", blank=True, null=True)
    # score = models.FloatField(null=True, blank=True)
    score = models.IntegerField(null=True, blank=True)

    @property
    def challenge(self):
        try:
            return Challenge.objects.get(Q(user_from=self) | Q(user_to=self))