Пример #1
0
 def save(self, *args, **kwargs):
     if self.pk is None:
         game = get_game()
         length = game.auth_string_length
         alphabet = string.lowercase + string.digits
         random_letters = [random.choice(alphabet) for _ in xrange(length)]
         self.auth_string = "".join(random_letters)
         self.created_at = timezone.now()
     return super(Team, self).save(*args, **kwargs)
Пример #2
0
 def save(self, *args, **kwargs):
     if self.pk is None:
         game = get_game()
         length = game.auth_string_length
         alphabet = string.lowercase + string.digits
         random_letters = [random.choice(alphabet) for _ in xrange(length)]
         self.auth_string = ''.join(random_letters)
         self.created_at = timezone.now()
     return super(Team, self).save(*args, **kwargs)
Пример #3
0
    def get_context_data(self, *args, **kwargs):
        context = super(IndexView, self).get_context_data(*args, **kwargs)
        country_list = list()
        for code, name in countries.countries.iteritems():
            country_list.append((code, unicode(name)))
        country_list.sort(lambda x, y: cmp(x[1], y[1]))

        context["countries"] = country_list
        context["game"] = get_game()
        if hasattr(self.request.user, "member"):
            context["member"] = self.request.user.member
        else:
            context["member"] = None
        return context
Пример #4
0
    def get_context_data(self, *args, **kwargs):
        context = super(IndexView, self).get_context_data(*args, **kwargs)
        country_list = list()
        for code, name in countries.countries.iteritems():
            country_list.append((code, unicode(name)))
        country_list.sort(lambda x, y: cmp(x[1], y[1]))

        context['countries'] = country_list
        context['game'] = get_game()
        if hasattr(self.request.user, 'member'):
            context['member'] = self.request.user.member
        else:
            context['member'] = None
        return context
Пример #5
0
def welcome_team(sender, instance, **kwargs):
    game = get_game(raise_exception=False)
    if game is None or not game.send_emails:
        return
    if kwargs['created']:
        recipients = [instance.leader_email]
        if instance.teacher_email:
            recipients.append(instance.teacher_email)
        subject_template = _('Welcome to School CTF Spring 2015, {team_name}!')
        send_mail(subject_template.format(team_name=instance.name),
                  render_to_string('welcome-team-email.txt',
                                   {'auth_string': instance.auth_string}),
                  'School CTF Jury <%s>' % settings.EMAIL_HOST_USER,
                  recipients,
                  fail_silently=True)
Пример #6
0
def welcome_team(sender, instance, **kwargs):
    game = get_game(raise_exception=False)
    if game is None or not game.send_emails:
        return
    if kwargs["created"]:
        recipients = [instance.leader_email]
        if instance.teacher_email:
            recipients.append(instance.teacher_email)
        subject_template = _("Welcome to School CTF Spring 2015, {team_name}!")
        send_mail(
            subject_template.format(team_name=instance.name),
            render_to_string("welcome-team-email.txt", {"auth_string": instance.auth_string}),
            "School CTF Jury <%s>" % settings.EMAIL_HOST_USER,
            recipients,
            fail_silently=True,
        )
Пример #7
0
def welcome_participant(sender, instance, **kwargs):
    game = get_game(raise_exception=False)
    if game is None or not game.send_emails:
        return
    if kwargs["created"]:
        recipients = [instance.team.leader_email]
        if instance.team.teacher_email:
            recipients.append(instance.team.teacher_email)
        subject_template = _("Participant {full_name} joined team {team_name}")
        send_mail(
            subject_template.format(full_name=instance.user.first_name, team_name=instance.team.name),
            render_to_string(
                "welcome-participant-email.txt",
                {"full_name": instance.user.first_name, "team_name": instance.team.name},
            ),
            "School CTF Jury <%s>" % settings.EMAIL_HOST_USER,
            recipients,
            fail_silently=True,
        )
Пример #8
0
def welcome_participant(sender, instance, **kwargs):
    game = get_game(raise_exception=False)
    if game is None or not game.send_emails:
        return
    if kwargs['created']:
        recipients = [instance.team.leader_email]
        if instance.team.teacher_email:
            recipients.append(instance.team.teacher_email)
        subject_template = _('Participant {full_name} joined team {team_name}')
        send_mail(subject_template.format(full_name=instance.user.first_name,
                                          team_name=instance.team.name),
                  render_to_string(
                      'welcome-participant-email.txt', {
                          'full_name': instance.user.first_name,
                          'team_name': instance.team.name
                      }),
                  'School CTF Jury <%s>' % settings.EMAIL_HOST_USER,
                  recipients,
                  fail_silently=True)
Пример #9
0
    def validate(self, data):
        game = get_game()
        error_dict = {}

        if 'is_school' in data and data['is_school']:
            if 'school_name' not in data or not data['school_name'].strip():
                error_dict['school_name'] = [_('The field is required for school teams')]
            if 'teacher_name' not in data or not data['teacher_name'].strip():
                error_dict['teacher_name'] = [_('The field is required for school teams')]
            if game.send_emails \
                    and ('teacher_email' not in data \
                         or not data['teacher_email'].strip()):
                error_dict['teacher_email'] = [_('The field is required for school teams')]
            if 'address' not in data or not data['address'].strip():
                error_dict['address'] = [_('The field is required for school teams')]

        if game.send_emails \
                and ('leader_email' not in data \
                     or not data['leader_email'].strip()):
            error_dict['leader_email'] = [_('The field is required for the game')]

        if len(error_dict) > 0:
            raise ValidationError(error_dict)
        return data