Beispiel #1
0
 def test_linebreaks(self):
     self.assertEqual(linebreaks_filter('line 1'), '<p>line 1</p>')
     self.assertEqual(linebreaks_filter('line 1\nline 2'),
                       '<p>line 1<br />line 2</p>')
     self.assertEqual(linebreaks_filter('line 1\rline 2'),
                       '<p>line 1<br />line 2</p>')
     self.assertEqual(linebreaks_filter('line 1\r\nline 2'),
                       '<p>line 1<br />line 2</p>')
Beispiel #2
0
 def test_linebreaks(self):
     self.assertEqual(linebreaks_filter('line 1'), '<p>line 1</p>')
     self.assertEqual(linebreaks_filter('line 1\nline 2'),
                      '<p>line 1<br />line 2</p>')
     self.assertEqual(linebreaks_filter('line 1\rline 2'),
                      '<p>line 1<br />line 2</p>')
     self.assertEqual(linebreaks_filter('line 1\r\nline 2'),
                      '<p>line 1<br />line 2</p>')
Beispiel #3
0
 def html_body(self):
     """
     Returns the rendered HTML body to show to browsers.
     You could change this method to instead render using RST/Markdown,
     or make it pass through HTML directly (but marked safe).
     """
     return linebreaks_filter(self.body)
Beispiel #4
0
 def html_body(self):
     """
     Returns the rendered HTML body to show to browsers.
     You could change this method to instead render using RST/Markdown,
     or make it pass through HTML directly (but marked safe).
     """
     return linebreaks_filter(self.comment)
Beispiel #5
0
 def test_non_string_input(self):
     # Filters shouldn't break if passed non-strings
     self.assertEqual(addslashes(123), '123')
     self.assertEqual(linenumbers(123), '1. 123')
     self.assertEqual(lower(123), '123')
     self.assertEqual(make_list(123), ['1', '2', '3'])
     self.assertEqual(slugify(123), '123')
     self.assertEqual(title(123), '123')
     self.assertEqual(truncatewords(123, 2), '123')
     self.assertEqual(upper(123), '123')
     self.assertEqual(urlencode(123), '123')
     self.assertEqual(urlize(123), '123')
     self.assertEqual(urlizetrunc(123, 1), '123')
     self.assertEqual(wordcount(123), 1)
     self.assertEqual(wordwrap(123, 2), '123')
     self.assertEqual(ljust('123', 4), '123 ')
     self.assertEqual(rjust('123', 4), ' 123')
     self.assertEqual(center('123', 5), ' 123 ')
     self.assertEqual(center('123', 6), ' 123  ')
     self.assertEqual(cut(123, '2'), '13')
     self.assertEqual(escape(123), '123')
     self.assertEqual(linebreaks_filter(123), '<p>123</p>')
     self.assertEqual(linebreaksbr(123), '123')
     self.assertEqual(removetags(123, 'a'), '123')
     self.assertEqual(striptags(123), '123')
Beispiel #6
0
 def test_non_string_input(self):
     # Filters shouldn't break if passed non-strings
     self.assertEqual(addslashes(123), '123')
     self.assertEqual(linenumbers(123), '1. 123')
     self.assertEqual(lower(123), '123')
     self.assertEqual(make_list(123), ['1', '2', '3'])
     self.assertEqual(slugify(123), '123')
     self.assertEqual(title(123), '123')
     self.assertEqual(truncatewords(123, 2), '123')
     self.assertEqual(upper(123), '123')
     self.assertEqual(urlencode(123), '123')
     self.assertEqual(urlize(123), '123')
     self.assertEqual(urlizetrunc(123, 1), '123')
     self.assertEqual(wordcount(123), 1)
     self.assertEqual(wordwrap(123, 2), '123')
     self.assertEqual(ljust('123', 4), '123 ')
     self.assertEqual(rjust('123', 4), ' 123')
     self.assertEqual(center('123', 5), ' 123 ')
     self.assertEqual(center('123', 6), ' 123  ')
     self.assertEqual(cut(123, '2'), '13')
     self.assertEqual(escape(123), '123')
     self.assertEqual(linebreaks_filter(123), '<p>123</p>')
     self.assertEqual(linebreaksbr(123), '123')
     self.assertEqual(removetags(123, 'a'), '123')
     self.assertEqual(striptags(123), '123')
Beispiel #7
0
def linebreaks_safe(value, autoescape=True):
    """
    Adds linebreaks only for text that has a newline character.
    """
    if isinstance(value, string_types) and '\n' in value:
        return linebreaks_filter(value, autoescape=autoescape)

    return value
Beispiel #8
0
def linebreaks_safe(value, autoescape=True):
    """
    Adds linebreaks only for text that has a newline character.
    """
    if isinstance(value, string_types) and '\n' in value:
        return linebreaks_filter(value, autoescape=autoescape)

    return value
Beispiel #9
0
 def formated_article(self):
     if re.search(r'<.*?>.*<\/.*?>|<br>|<br/>', self.text, re.MULTILINE):
         soup = BeautifulSoup(self.text, 'html.parser')
         links = soup.find_all('a')
         for link in links:
             link['target'] = '_blank'
             link['rel'] = 'nofollow'
         return str(soup)
     return linebreaks_filter(self.text)
Beispiel #10
0
    def normalize_text(self, text):
        if self.configuration.text_format == 'MARKDOWN':
            return markdown.markdown(text)

        if re.search(r'<.*?>.*<\/.*?>|<br>|<br\/>|<br\ \/>', text,
                     re.MULTILINE):
            soup = BeautifulSoup(text, 'html.parser')
            links = soup.find_all('a')
            for link in links:
                link['target'] = '_blank'
                link['rel'] = 'nofollow'
            return str(soup)
        return linebreaks_filter(text)
Beispiel #11
0
def linebreaks_first(text):
    """
    Does the same as the standard Djanago `linebreaks` filter:

    Replace line breaks in plain text with appropriate HTML; a single
    newline becomes an HTML line break (``<br />``) and a new line
    followed by a blank line becomes a paragraph break (``</p>``).

    But also adds the CSS class 'first' to the first paragraph tag.

    Used for old Weblog post_detail templates.
    """
    text = linebreaks_filter(text)
    text = re.sub(r'^<p>', '<p class="first">', text)
    return mark_safe(text)
Beispiel #12
0
 def test_autoescape(self):
     self.assertEqual(
         linebreaks_filter("foo\n<a>bar</a>\nbuz"),
         "<p>foo<br>&lt;a&gt;bar&lt;/a&gt;<br>buz</p>",
     )
Beispiel #13
0
 def test_carriage_newline(self):
     self.assertEqual(
         linebreaks_filter("line 1\r\nline 2"), "<p>line 1<br>line 2</p>"
     )
Beispiel #14
0
    def handle(self, *args, **options):
        try:
            fake_threads_to_create = int(args[0])
        except IndexError:
            fake_threads_to_create = 5
        except ValueError:
            self.stderr.write("\nOptional argument should be integer.")
            sys.exit(1)

        forums = [f for f in Forum.objects.all_forums().filter(role='forum')]

        fake = Factory.create()

        User = get_user_model()
        total_users = User.objects.count()

        self.stdout.write('Creating fake threads...\n')

        message = '\nSuccessfully created %s fake threads'

        created_threads = 0
        start_time = time.time()
        show_progress(self, created_threads, fake_threads_to_create)
        for i in xrange(fake_threads_to_create):
            with atomic():
                datetime = timezone.now()
                forum = random.choice(forums)
                user = User.objects.order_by('?')[:1][0]

                thread_is_moderated = random.randint(0, 100) > 90
                thread_is_hidden = random.randint(0, 100) > 90
                thread_is_closed = random.randint(0, 100) > 90

                thread = Thread(
                    forum=forum,
                    started_on=datetime,
                    starter_name='-',
                    starter_slug='-',
                    last_post_on=datetime,
                    last_poster_name='-',
                    last_poster_slug='-',
                    replies=random.randint(0, 2000),
                    is_moderated=thread_is_moderated,
                    is_hidden=thread_is_hidden,
                    is_closed=thread_is_closed)
                thread.set_title(fake.sentence())
                thread.save()

                fake_message = "\n\n".join(fake.paragraphs())
                post = Post.objects.create(
                    forum=forum,
                    thread=thread,
                    poster=user,
                    poster_name=user.username,
                    poster_ip=fake.ipv4(),
                    original=fake_message,
                    parsed=linebreaks_filter(fake_message),
                    posted_on=datetime,
                    updated_on=datetime)
                update_post_checksum(post)
                post.save(update_fields=['checksum'])

                thread.set_first_post(post)
                thread.set_last_post(post)
                thread.save()

                forum.threads += 1
                forum.posts += 1
                forum.set_last_thread(thread)
                forum.save()

                user.threads += 1
                user.posts += 1
                user.save()

                created_threads += 1
                show_progress(
                    self, created_threads, fake_threads_to_create, start_time)

        pinned_threads = random.randint(0, int(created_threads * 0.025)) or 1
        self.stdout.write('\nPinning %s threads...' % pinned_threads)
        for i in xrange(0, pinned_threads):
            thread = Thread.objects.order_by('?')[:1][0]
            thread.is_pinned = True
            thread.save()

        self.stdout.write(message % created_threads)
Beispiel #15
0
 def text_body(self):
     return linebreaks_filter(self.text)
Beispiel #16
0
 def test_autoescape_off(self):
     self.assertEqual(
         linebreaks_filter('foo\n<a>bar</a>\nbuz', autoescape=False),
         '<p>foo<br><a>bar</a><br>buz</p>',
     )
Beispiel #17
0
 def test_carriage_newline(self):
     self.assertEqual(linebreaks_filter("line 1\r\nline 2"), "<p>line 1<br />line 2</p>")
Beispiel #18
0
	def parse(self, text):
		self.output = linebreaks_filter(escape(text))
Beispiel #19
0
 def test_carriage_newline(self):
     self.assertEqual(linebreaks_filter('line 1\r\nline 2'),
                      '<p>line 1<br />line 2</p>')
Beispiel #20
0
 def test_line(self):
     self.assertEqual(linebreaks_filter('line 1'), '<p>line 1</p>')
 def test_newline(self):
     self.assertEqual(linebreaks_filter('line 1\nline 2'),
                      '<p>line 1<br>line 2</p>')
 def test_newline(self):
     self.assertEqual(linebreaks_filter('line 1\nline 2'), '<p>line 1<br />line 2</p>')
Beispiel #23
0
	def parse(self, text):
		self.output = linebreaks_filter(escape(text))
Beispiel #24
0
 def test_lazy_string_input(self):
     add_header = lazy(lambda string: "Header\n\n" + string, str)
     self.assertEqual(
         linebreaks_filter(add_header("line 1\r\nline2")),
         "<p>Header</p>\n\n<p>line 1<br>line2</p>",
     )
Beispiel #25
0
 def html_body(self):
     return linebreaks_filter(self.body)
Beispiel #26
0
 def test_autoescape(self):
     self.assertEqual(
         linebreaks_filter('foo\n<a>bar</a>\nbuz'),
         '<p>foo<br />&lt;a&gt;bar&lt;/a&gt;<br />buz</p>',
     )
Beispiel #27
0
 def test_autoescape(self):
     self.assertEqual(linebreaks_filter("foo\n<a>bar</a>\nbuz"), "<p>foo<br />&lt;a&gt;bar&lt;/a&gt;<br />buz</p>")
Beispiel #28
0
 def test_autoescape_off(self):
     self.assertEqual(
         linebreaks_filter('foo\n<a>bar</a>\nbuz', autoescape=False),
         '<p>foo<br /><a>bar</a><br />buz</p>',
     )
 def supply_chains(self, obj):
     scs = obj.supply_chains.values("name").order_by("name")
     names = [x["name"] for x in scs]
     return linebreaks_filter("\n".join(names))
Beispiel #30
0
 def test_lazy_string_input(self):
     add_header = lazy(lambda string: 'Header\n\n' + string, str)
     self.assertEqual(linebreaks_filter(add_header('line 1\r\nline2')),
                      '<p>Header</p>\n\n<p>line 1<br />line2</p>')
Beispiel #31
0
 def test_lazy_string_input(self):
     add_header = lazy(lambda string: 'Header\n\n' + string, str)
     self.assertEqual(
         linebreaks_filter(add_header('line 1\r\nline2')),
         '<p>Header</p>\n\n<p>line 1<br>line2</p>'
     )
Beispiel #32
0
 def body_br(self, obj):
     return linebreaks_filter(obj.body)
Beispiel #33
0
    def handle(self, *args, **options):
        items_to_create = options['threads']

        categories = list(Category.objects.all_categories())

        fake = Factory.create()

        User = get_user_model()
        total_users = User.objects.count()

        self.stdout.write('Creating fake threads...\n')

        message = '\nSuccessfully created %s fake threads in %s'

        created_threads = 0
        start_time = time.time()
        show_progress(self, created_threads, items_to_create)

        while created_threads < items_to_create:
            with atomic():
                datetime = timezone.now()
                category = random.choice(categories)
                user = User.objects.order_by('?')[:1][0]

                thread_is_unapproved = random.randint(0, 100) > 90
                thread_is_hidden = random.randint(0, 100) > 90
                thread_is_closed = random.randint(0, 100) > 90

                thread = Thread(
                    category=category,
                    started_on=datetime,
                    starter_name='-',
                    starter_slug='-',
                    last_post_on=datetime,
                    last_poster_name='-',
                    last_poster_slug='-',
                    replies=0,
                    is_unapproved=thread_is_unapproved,
                    is_hidden=thread_is_hidden,
                    is_closed=thread_is_closed
                )
                thread.set_title(fake.sentence())
                thread.save()

                fake_message = "\n\n".join(fake.paragraphs())
                post = Post.objects.create(
                    category=category,
                    thread=thread,
                    poster=user,
                    poster_name=user.username,
                    poster_ip=fake.ipv4(),
                    original=fake_message,
                    parsed=linebreaks_filter(fake_message),
                    posted_on=datetime,
                    updated_on=datetime
                )
                update_post_checksum(post)
                post.save(update_fields=['checksum'])

                thread.set_first_post(post)
                thread.set_last_post(post)
                thread.save()

                user.threads += 1
                user.posts += 1
                user.save()

                thread_type = random.randint(0, 100)
                if thread_type > 95:
                    thread_replies = random.randint(200, 2500)
                elif thread_type > 50:
                    thread_replies = random.randint(5, 30)
                else:
                    thread_replies = random.randint(0, 10)

                for x in range(thread_replies):
                    datetime = timezone.now()
                    user = User.objects.order_by('?')[:1][0]
                    fake_message = "\n\n".join(fake.paragraphs())

                    is_unapproved = random.randint(0, 100) > 97
                    if not is_unapproved:
                        is_hidden = random.randint(0, 100) > 97
                    else:
                        is_hidden = False

                    post = Post.objects.create(
                        category=category,
                        thread=thread,
                        poster=user,
                        poster_name=user.username,
                        poster_ip=fake.ipv4(),
                        original=fake_message,
                        parsed=linebreaks_filter(fake_message),
                        is_hidden=is_hidden,
                        is_unapproved=is_unapproved,
                        posted_on=datetime,
                        updated_on=datetime
                    )
                    update_post_checksum(post)
                    post.save(update_fields=['checksum'])

                    user.posts += 1
                    user.save()

                thread.synchronize()
                thread.save()

                created_threads += 1
                show_progress(
                    self, created_threads, items_to_create, start_time)

        pinned_threads = random.randint(0, int(created_threads * 0.025)) or 1
        self.stdout.write('\nPinning %s threads...' % pinned_threads)
        for i in range(0, pinned_threads):
            thread = Thread.objects.order_by('?')[:1][0]
            if random.randint(0, 100) > 75:
                thread.weight = 2
            else:
                thread.weight = 1
            thread.save()

        for category in categories:
            category.synchronize()
            category.save()

        total_time = time.time() - start_time
        total_humanized = time.strftime('%H:%M:%S', time.gmtime(total_time))
        self.stdout.write(message % (created_threads, total_humanized))
Beispiel #34
0
 def body_br(self, obj):
     return mark_safe(linebreaks_filter(obj.body))
Beispiel #35
0
 def test_line(self):
     self.assertEqual(linebreaks_filter("line 1"), "<p>line 1</p>")
Beispiel #36
0
 def item_description(self, item):
     # This must be HTML, can't be changed to text...
     return linebreaks_filter(item.description)
Beispiel #37
0
 def test_non_string_input(self):
     self.assertEqual(linebreaks_filter(123), "<p>123</p>")
Beispiel #38
0
 def item_description(self, item):
     return linebreaks_filter(item.description)
Beispiel #39
0
 def test_autoescape_off(self):
     self.assertEqual(
         linebreaks_filter("foo\n<a>bar</a>\nbuz", autoescape=False),
         "<p>foo<br><a>bar</a><br>buz</p>",
     )
Beispiel #40
0
def send_event_promotion(event_promotion_id):
    """
    Send event promotion via BSD triggered emails

    Requires that event and event promotion are approved and list is complete.
    Otherwise do nothing.

    Parameters
    ----------
    event_promotion_id : int
        EventPromotion id

    Returns
        -------
        int
            Returns count of promotion emails sent
    """

    sent_count = 0
    """If there is no promotion mailing id, then do nothing"""
    if EVENTS_PROMOTE_MAILING_ID is None:
        return sent_count
    """If event promotion is not approved, then do nothing"""
    event_promotion = EventPromotion.objects.select_related(
        'contact_list').get(id=event_promotion_id)
    if event_promotion.status != EventPromotionStatus.approved.value[0]:
        return sent_count

    event = find_event_by_id_obfuscated(event_promotion.event_external_id)

    if event:
        """If event is not approved, then do nothing"""
        if not event.is_approved:
            event_promotion.status = EventPromotionStatus.event_not_approved.value[
                0]
            event_promotion.save()
            return sent_count
        """If event is in past, then do nothing"""
        if event.start_datetime_utc <= timezone.now():
            event_promotion.status = EventPromotionStatus.expired.value[0]
            event_promotion.save()
            return sent_count
    else:
        """If no event, do nothing"""
        return sent_count
    """If contact list is not complete, then do nothing"""
    contact_list = event_promotion.contact_list
    if contact_list.status != ContactListStatus.complete.value[0]:
        return sent_count
    """Update promotion status to in progress"""
    event_promotion.status = EventPromotionStatus.in_progress.value[0]
    event_promotion.save()
    """Send promotion email to each contact in list"""
    trigger_values = {
        'subject': event_promotion.subject,
        'email_body_html': linebreaks_filter(event_promotion.message),
        'email_body_text': event_promotion.message,
    }
    trigger_values_json = json.dumps(trigger_values)
    trigger_values_encoded = urlquote_plus(trigger_values_json)
    for contact in contact_list.contacts.all():
        send_email_result = send_triggered_email(EVENTS_PROMOTE_MAILING_ID,
                                                 contact.email_address,
                                                 trigger_values_encoded)
        """Check result status and increment on success"""
        if send_email_result is not None and (send_email_result.http_status
                                              == 202):
            sent_count += 1
    """Update status, date sent, sent count if emails were sent"""
    if sent_count > 0:
        event_promotion.status = EventPromotionStatus.sent.value[0]
        event_promotion.date_sent = timezone.now()
        event_promotion.sent_count = sent_count
        event_promotion.save()
    """Return count of sent emails"""
    return sent_count
Beispiel #41
0
    def handle(self, *args, **options):
        try:
            fake_threads_to_create = int(args[0])
        except IndexError:
            fake_threads_to_create = 5
        except ValueError:
            self.stderr.write("\nOptional argument should be integer.")
            sys.exit(1)

        forums = [f for f in Forum.objects.all_forums().filter(role='forum')]

        fake = Factory.create()

        User = get_user_model()
        total_users = User.objects.count()

        self.stdout.write('Creating fake threads...\n')

        message = '\nSuccessfully created %s fake threads'

        created_threads = 0
        start_time = time.time()
        show_progress(self, created_threads, fake_threads_to_create)
        for i in xrange(fake_threads_to_create):
            with atomic():
                datetime = timezone.now()
                forum = random.choice(forums)
                user = User.objects.order_by('?')[:1][0]

                thread_is_moderated = random.randint(0, 100) > 90
                thread_is_hidden = random.randint(0, 100) > 90
                thread_is_closed = random.randint(0, 100) > 90

                thread = Thread(forum=forum,
                                started_on=datetime,
                                starter_name='-',
                                starter_slug='-',
                                last_post_on=datetime,
                                last_poster_name='-',
                                last_poster_slug='-',
                                replies=0,
                                is_moderated=thread_is_moderated,
                                is_hidden=thread_is_hidden,
                                is_closed=thread_is_closed)
                thread.set_title(fake.sentence())
                thread.save()

                fake_message = "\n\n".join(fake.paragraphs())
                post = Post.objects.create(
                    forum=forum,
                    thread=thread,
                    poster=user,
                    poster_name=user.username,
                    poster_ip=fake.ipv4(),
                    original=fake_message,
                    parsed=linebreaks_filter(fake_message),
                    posted_on=datetime,
                    updated_on=datetime)
                update_post_checksum(post)
                post.save(update_fields=['checksum'])

                thread.set_first_post(post)
                thread.set_last_post(post)
                thread.save()

                user.threads += 1
                user.posts += 1
                user.save()

                thread_type = random.randint(0, 100)
                if thread_type > 95:
                    thread_replies = random.randint(200, 500)
                elif thread_type > 50:
                    thread_replies = random.randint(5, 30)
                else:
                    thread_replies = random.randint(0, 10)

                for x in xrange(thread_replies):
                    datetime = timezone.now()
                    user = User.objects.order_by('?')[:1][0]
                    fake_message = "\n\n".join(fake.paragraphs())

                    is_moderated = random.randint(0, 100) > 97
                    if not is_moderated:
                        is_hidden = random.randint(0, 100) > 97
                    else:
                        is_hidden = False

                    post = Post.objects.create(
                        forum=forum,
                        thread=thread,
                        poster=user,
                        poster_name=user.username,
                        poster_ip=fake.ipv4(),
                        original=fake_message,
                        parsed=linebreaks_filter(fake_message),
                        is_hidden=is_hidden,
                        is_moderated=is_moderated,
                        posted_on=datetime,
                        updated_on=datetime)
                    update_post_checksum(post)
                    post.save(update_fields=['checksum'])

                    user.posts += 1
                    user.save()

                thread.synchronize()
                thread.save()

                created_threads += 1
                show_progress(self, created_threads, fake_threads_to_create,
                              start_time)

        pinned_threads = random.randint(0, int(created_threads * 0.025)) or 1
        self.stdout.write('\nPinning %s threads...' % pinned_threads)
        for i in xrange(0, pinned_threads):
            thread = Thread.objects.order_by('?')[:1][0]
            thread.is_pinned = True
            thread.save()

        for forum in forums:
            forum.synchronize()
            forum.save()

        self.stdout.write(message % created_threads)
Beispiel #42
0
 def test_line(self):
     self.assertEqual(linebreaks_filter("line 1"), "<p>line 1</p>")
Beispiel #43
0
    def handle(self, *args, **options):
        items_to_create = options['threads']

        categories = list(Category.objects.all_categories())

        fake = Factory.create()

        User = get_user_model()
        total_users = User.objects.count()

        self.stdout.write('Creating fake threads...\n')

        message = '\nSuccessfully created %s fake threads in %s'

        created_threads = 0
        start_time = time.time()
        show_progress(self, created_threads, items_to_create)

        while created_threads < items_to_create:
            with atomic():
                datetime = timezone.now()
                category = random.choice(categories)
                user = User.objects.order_by('?')[:1][0]

                thread_is_unapproved = random.randint(0, 100) > 90
                thread_is_hidden = random.randint(0, 100) > 90
                thread_is_closed = random.randint(0, 100) > 90

                thread = Thread(
                    category=category,
                    started_on=datetime,
                    starter_name='-',
                    starter_slug='-',
                    last_post_on=datetime,
                    last_poster_name='-',
                    last_poster_slug='-',
                    replies=0,
                    is_unapproved=thread_is_unapproved,
                    is_hidden=thread_is_hidden,
                    is_closed=thread_is_closed
                )
                thread.set_title(fake.sentence())
                thread.save()

                fake_message = "\n\n".join(fake.paragraphs())
                post = Post.objects.create(
                    category=category,
                    thread=thread,
                    poster=user,
                    poster_name=user.username,
                    poster_ip=fake.ipv4(),
                    original=fake_message,
                    parsed=linebreaks_filter(fake_message),
                    posted_on=datetime,
                    updated_on=datetime
                )
                update_post_checksum(post)
                post.save(update_fields=['checksum'])

                thread.set_first_post(post)
                thread.set_last_post(post)
                thread.save()

                user.threads += 1
                user.posts += 1
                user.save()

                thread_type = random.randint(0, 100)
                if thread_type > 95:
                    thread_replies = random.randint(200, 2500)
                elif thread_type > 50:
                    thread_replies = random.randint(5, 30)
                else:
                    thread_replies = random.randint(0, 10)

                for x in range(thread_replies):
                    datetime = timezone.now()
                    user = User.objects.order_by('?')[:1][0]
                    fake_message = "\n\n".join(fake.paragraphs())

                    is_unapproved = random.randint(0, 100) > 97

                    post = Post.objects.create(
                        category=category,
                        thread=thread,
                        poster=user,
                        poster_name=user.username,
                        poster_ip=fake.ipv4(),
                        original=fake_message,
                        parsed=linebreaks_filter(fake_message),
                        is_unapproved=is_unapproved,
                        posted_on=datetime,
                        updated_on=datetime
                    )

                    if not is_unapproved:
                        is_hidden = random.randint(0, 100) > 97
                    else:
                        is_hidden = False

                    if is_hidden:
                        post.is_hidden = True

                        if random.randint(0, 100) < 80:
                            user = User.objects.order_by('?')[:1][0]
                            post.hidden_by = user
                            post.hidden_by_name = user.username
                            post.hidden_by_slug = user.username
                        else:
                            post.hidden_by_name = fake.first_name()
                            post.hidden_by_slug = post.hidden_by_name.lower()

                    update_post_checksum(post)
                    post.save()

                    user.posts += 1
                    user.save()

                thread.synchronize()
                thread.save()

                created_threads += 1
                show_progress(
                    self, created_threads, items_to_create, start_time)

        pinned_threads = random.randint(0, int(created_threads * 0.025)) or 1
        self.stdout.write('\nPinning %s threads...' % pinned_threads)
        for i in range(0, pinned_threads):
            thread = Thread.objects.order_by('?')[:1][0]
            if random.randint(0, 100) > 75:
                thread.weight = 2
            else:
                thread.weight = 1
            thread.save()

        for category in categories:
            category.synchronize()
            category.save()

        total_time = time.time() - start_time
        total_humanized = time.strftime('%H:%M:%S', time.gmtime(total_time))
        self.stdout.write(message % (created_threads, total_humanized))
Beispiel #44
0
 def test_line(self):
     self.assertEqual(linebreaks_filter('line 1'), '<p>line 1</p>')
Beispiel #45
0
 def test_autoescape_off(self):
     self.assertEqual(
         linebreaks_filter("foo\n<a>bar</a>\nbuz", autoescape=False), "<p>foo<br /><a>bar</a><br />buz</p>"
     )
Beispiel #46
0
 def test_carriage_newline(self):
     self.assertEqual(linebreaks_filter('line 1\r\nline 2'), '<p>line 1<br>line 2</p>')
Beispiel #47
0
 def html_body(self):
     return linebreaks_filter(self.body)
Beispiel #48
0
 def test_non_string_input(self):
     self.assertEqual(linebreaks_filter(123), '<p>123</p>')
Beispiel #49
0
 def test_autoescape(self):
     self.assertEqual(
         linebreaks_filter('foo\n<a>bar</a>\nbuz'),
         '<p>foo<br>&lt;a&gt;bar&lt;/a&gt;<br>buz</p>',
     )
Beispiel #50
0
def format_text(text):
    if settings.RICH_TEXT_ENABLED:
        return parse_markdown(text)
    else:
        return linebreaks_filter(text)