Exemplo n.º 1
0
    def save(self, commit=False):
        def grab(s):
            return self.cleaned_data[s]

        game = Game.nearest_game()
        player = Player.user_to_player(self.user, game)

        self.thread = Thread(
            game=game,
            team=grab('team'),
            title=grab('title'),
            slug=slugify(grab('title')),
        )

        self.thread.save()

        post = Post(
            author=player,
            thread=self.thread,
            body=grab('post_body'),
            created=settings.NOW(),
        )

        if commit:
            post.save()

        return self.thread
Exemplo n.º 2
0
 def __init__(self, *args, **kwargs):
     self.user = kwargs['user']
     del kwargs['user']
     super(ThreadCreateForm, self).__init__(*args, **kwargs)
     self.fields["team"] = forms.ChoiceField(
         choices=Thread.legal_teams(self.user)
     )
Exemplo n.º 3
0
class ThreadCreateForm(forms.Form):
    title = forms.CharField(required=True)

    post_body = forms.CharField(
        widget=forms.Textarea(),
        required=True
    )

    def __init__(self, *args, **kwargs):
        self.user = kwargs['user']
        del kwargs['user']
        super(ThreadCreateForm, self).__init__(*args, **kwargs)
        self.fields["team"] = forms.ChoiceField(
            choices=Thread.legal_teams(self.user)
        )

    def clean(self):
        return super(ThreadCreateForm, self).clean()

    def save(self, commit=False):
        def grab(s):
            return self.cleaned_data[s]

        game = Game.nearest_game()
        player = Player.user_to_player(self.user, game)

        self.thread = Thread(
            game=game,
            team=grab('team'),
            title=grab('title'),
            slug=slugify(grab('title')),
        )

        self.thread.save()

        post = Post(
            author=player,
            thread=self.thread,
            body=grab('post_body'),
            created=settings.NOW(),
        )

        if commit:
            post.save()

        return self.thread
Exemplo n.º 4
0
    def test_illegal_posting(self):
        game = Game.objects.get()
        human_thread = Thread(
            game=game,
            title="Humans Only",
            slug="humans-only",
            team="H"
        )

        human_thread.full_clean()
        human_thread.save()

        zombie = Player.objects.get(team='Z')

        self.assertEqual(Post.objects.count(), 0)

        post = Post(
            thread=human_thread,
            author=zombie,
            created=settings.NOW(),
            body="H4%0R3D"
        )

        self.assertRaises(ValidationError, post.full_clean)
Exemplo n.º 5
0
    def test_illegal_posting(self):
        game = Game.objects.get()
        human_thread = Thread(game=game,
                              title="Humans Only",
                              slug="humans-only",
                              team="H")

        human_thread.full_clean()
        human_thread.save()

        zombie = Player.objects.get(team='Z')

        self.assertEqual(Post.objects.count(), 0)

        post = Post(thread=human_thread,
                    author=zombie,
                    created=settings.NOW(),
                    body="H4%0R3D")

        self.assertRaises(ValidationError, post.full_clean)