예제 #1
0
 def test_italic(self):
     self.assertEquals(safe_html(
             '*text*'),
             '<em>text</em>')
     self.assertEquals(safe_html(
             '_text_'),
             '<em>text</em>')
예제 #2
0
 def test_bold(self):
     self.assertEquals(safe_html(
             '**text**'),
             '<strong>text</strong>')
     self.assertEquals(safe_html(
             '__text__'),
             '<strong>text</strong>')
예제 #3
0
 def test_combined(self):
     self.assertEqual(
         safe_html("`__*text*__`"), "<tt><strong><em>text</em></strong></tt>"
     )
     self.assertEqual(
         safe_html("`**_text_**`"), "<tt><strong><em>text</em></strong></tt>"
     )
     self.assertEqual(safe_html("_*text*_"), "<em><em>text</em></em>")
예제 #4
0
 def test_combined(self):
     self.assertEquals(safe_html(
             '`__*text*__`'),
             '<tt><strong><em>text</em></strong></tt>')
     self.assertEquals(safe_html(
             '`**_text_**`'),
             '<tt><strong><em>text</em></strong></tt>')
     self.assertEquals(safe_html(
             '_*text*_'),
             '<em><em>text</em></em>')
예제 #5
0
파일: poll.py 프로젝트: josefran/jawanndenn
 def vote(self, person, votes):
     with self._lock:
         if len(self.votes) >= _MAX_VOTERS_PER_POLL:
             raise ValueError('Too many votes per poll')
         if len(votes) != len(self.options):
             raise ValueError('Malformed vote')
         self.votes.append((safe_html(person), votes))
예제 #6
0
    def create(self, validated_data):
        poll_equal_width = validated_data['equal_width']
        poll_title = safe_html(validated_data['title'])
        poll_option_names = [
            safe_html(str(option_name))
            for option_name in validated_data['options']
        ]

        with transaction.atomic():
            poll = Poll.objects.create(title=poll_title,
                                       equal_width=poll_equal_width)
            for i, option_name in enumerate(poll_option_names):
                PollOption.objects.create(poll=poll,
                                          position=i,
                                          name=option_name)

            return poll
예제 #7
0
    def from_config(config):
        poll = _Poll()

        if _KEY_OPTIONS not in config \
                or _KEY_TITLE not in config:
            raise ValueError('Malformed configuration: %s' % config)

        poll.config = {
            _KEY_EQUAL_WIDTH: bool(config.get(_KEY_EQUAL_WIDTH, False)),
            _KEY_TITLE: safe_html(config[_KEY_TITLE]),
            _KEY_DESCRIPTION: safe_html(config[_KEY_DESCRIPTION]),
            _KEY_LIMIT_DATE: config[_KEY_LIMIT_DATE],
            _KEY_OPTIONS: [],
            _KEY_PEOPLE: config[_KEY_PEOPLE],
        }
        poll.config[_KEY_OPTIONS][:] = (safe_html(x)
                                        for x in config[_KEY_OPTIONS])
        return poll
예제 #8
0
    def create(self, validated_data):
        poll_expires_at = timezone.now() + _PollLifetime.to_relativedelta(
            validated_data['lifetime'])
        poll_equal_width = validated_data['equal_width']
        poll_title = safe_html(validated_data['title'])
        poll_option_names = [
            safe_html(str(option_name))
            for option_name in validated_data['options']
        ]

        with transaction.atomic():
            poll = Poll.objects.create(title=poll_title,
                                       expires_at=poll_expires_at,
                                       equal_width=poll_equal_width)
            for i, option_name in enumerate(poll_option_names):
                PollOption.objects.create(poll=poll,
                                          position=i,
                                          name=option_name)

            return poll
예제 #9
0
파일: poll.py 프로젝트: josefran/jawanndenn
    def from_config(config):
        poll = _Poll()

        if _KEY_OPTIONS not in config \
                or _KEY_TITLE not in config:
            raise ValueError('Malformed configuration: %s' % config)

        poll.config = {
            _KEY_EQUAL_WIDTH: bool(config.get(_KEY_EQUAL_WIDTH, False)),
            _KEY_TITLE: safe_html(config[_KEY_TITLE]),
            _KEY_OPTIONS: map(safe_html, config[_KEY_OPTIONS]),
        }
        return poll
예제 #10
0
def poll_post_view(request):
    config = json.loads(request.POST.get('config', '{}'))
    poll_equal_width = bool(config.get('equal_width', False))
    poll_title = safe_html(config.get('title', ''))
    poll_option_names = map(safe_html, config.get('options', []))

    with transaction.atomic():
        if Poll.objects.count() >= settings.JAWANNDENN_MAX_POLLS:
            return HttpResponseBadRequest(
                f'Maximum number of {settings.JAWANNDENN_MAX_POLLS} polls '
                'reached, please contact the administrator.')

        poll = Poll.objects.create(title=poll_title,
                                   equal_width=poll_equal_width)
        for i, option_name in enumerate(poll_option_names):
            PollOption.objects.create(poll=poll, position=i, name=option_name)

    return redirect(poll)
예제 #11
0
def vote_post_view(request, poll_id):
    with transaction.atomic():
        poll = Poll.objects.get(slug=poll_id)

        if poll.ballots.count() >= settings.JAWANNDENN_MAX_VOTES_PER_POLL:
            return HttpResponseBadRequest(
                f'Maximum number of {settings.JAWANNDENN_MAX_VOTES_PER_POLL} '
                'votes reached for this poll'
                ', please contact the administrator.')

        voter_name = safe_html(request.POST.get('voterName'))
        votes = [
            request.POST.get(f'option{i}', 'off') == 'on'
            for i in range(poll.options.count())
        ]

        ballot = Ballot.objects.create(poll=poll, voter_name=voter_name)
        for option, vote in zip(poll.options.order_by('position'), votes):
            Vote.objects.create(ballot=ballot, option=option, yes=vote)

    return redirect(poll)
예제 #12
0
 def test_bad_nesting(self):
     self.assertEqual(
         safe_html("*__text*__"),
         "<em><strong>text<em><strong></strong></em></strong></em>",
     )
예제 #13
0
 def test_monospace(self):
     self.assertEquals(safe_html(
             '`text`'),
             '<tt>text</tt>')
예제 #14
0
 def test_monospace(self):
     self.assertEqual(safe_html("`text`"), "<tt>text</tt>")
예제 #15
0
 def test_italic(self):
     self.assertEqual(safe_html("*text*"), "<em>text</em>")
     self.assertEqual(safe_html("_text_"), "<em>text</em>")
예제 #16
0
 def test_bold(self):
     self.assertEqual(safe_html("**text**"), "<strong>text</strong>")
     self.assertEqual(safe_html("__text__"), "<strong>text</strong>")
예제 #17
0
 def test_html(self):
     self.assertEqual(safe_html("<b>&nbsp;</b>"), "&lt;b&gt;&amp;nbsp;&lt;/b&gt;")
예제 #18
0
 def test_bad_nesting(self):
     self.assertEquals(safe_html(
             '*__text*__'),
             '<em><strong>text<em><strong></strong></em></strong></em>')
예제 #19
0
 def test_vanilla(self):
     self.assertEquals(safe_html(
             'text'),
             'text')
예제 #20
0
 def test_non_string(self):
     with self.assertRaises(ValueError):
         safe_html(123)
예제 #21
0
 def test_vanilla(self):
     self.assertEqual(safe_html("text"), "text")
예제 #22
0
 def test_html(self):
     self.assertEquals(safe_html(
             '<b>&nbsp;</b>'),
             '&lt;b&gt;&amp;nbsp;&lt;/b&gt;')