def test_init_creates_layout(self): form = TalkCommentForm(instance=mock.MagicMock(pk=1)) self.assertIsInstance(form.helper.layout, Layout) layout_fields = [ name for [_, name] in form.helper.layout.get_field_names() ] self.assertListEqual(['comment', 'is_visible'], layout_fields) self.assertEqual(len(form.helper.layout.get_layout_objects(Submit)), 1)
def get_context_data(self, **kwargs): context = super(CommitteeTalkDetails, self).get_context_data(**kwargs) talk = context["talk"] try: user_vote = talk.vote_set.get(voter=self.request.user) user_score = user_vote.score except Vote.DoesNotExist: user_score = None context.update( { "comment_form": TalkCommentForm(instance=talk), "user_vote": user_score, "average_votes": talk.average_score, "comments": talk.talkcomment_set.select_related("commenter") .order_by("-modified") .all(), } ) return context
def get_context_data(self, **kwargs): context = super(CommitteeTalkDetails, self).get_context_data(**kwargs) talk = context['talk'] try: user_vote = talk.vote_set.get(voter=self.request.user) user_score = user_vote.score except Vote.DoesNotExist: user_score = None context.update({ 'comment_form': TalkCommentForm(instance=talk), 'user_vote': user_score, 'average_votes': talk.average_score, 'comments': talk.talkcomment_set.select_related('commenter').order_by( '-modified').all() }) return context
def test_init_creates_form_helper(self): form = TalkCommentForm(instance=mock.MagicMock(pk=1)) self.assertIsInstance(form.helper, DevDayFormHelper) self.assertEqual(form.fields['comment'].widget.attrs['rows'], 2) self.assertEqual(form.helper.form_action, '/committee/talks/1/comment/')
def test_fields(self): form = TalkCommentForm(instance=mock.MagicMock(pk=1)) self.assertListEqual(['comment', 'is_visible'], list(form.fields))