Ejemplo n.º 1
0
def suggestions(request):
    """Show a list of all accepted suggestions and their status."""
    if request.method == 'POST':
        form = SuggestionForm(request.POST)
        if form.is_valid():
            obj = form.save()
            mark_if_spam(obj)
            messages.add_message(request, messages.INFO,
                                 'Suggestion submitted.')
            return redirect('suggestions-list')
    else:
        form = SuggestionForm()

    open_objs = Suggestion.objects.filter(
        state__in=Suggestion.OPEN_STATES,
        is_reviewed=True)
    resolved_objs = Suggestion.objects.filter(
        state__in=Suggestion.RESOLVED_STATES,
        is_reviewed=True)

    ret = render(
        request, 'suggestions/suggestions_list.html',
        {'form': form,
         'open_suggestions': open_objs,
         'resolved_suggestions': resolved_objs})
    return ret
Ejemplo n.º 2
0
def suggestions(request):
    """Show a list of all accepted suggestions and their status."""
    if request.method == 'POST':
        form = SuggestionForm(request.POST)
        if form.is_valid():
            obj = form.save()
            mark_if_spam(obj)
            messages.add_message(request, messages.INFO,
                                 'Suggestion submitted.')
            return redirect('suggestions-list')
    else:
        form = SuggestionForm()

    open_objs = Suggestion.objects.filter(
        state__in=Suggestion.OPEN_STATES,
        is_reviewed=True).order_by('-submitted')
    resolved_objs = Suggestion.objects.filter(
        state__in=Suggestion.RESOLVED_STATES,
        is_reviewed=True).order_by('-resolved')

    ret = render(
        request, 'suggestions/suggestions_list.html',
        {'form': form,
         'open_suggestions': open_objs,
         'resolved_suggestions': resolved_objs})
    return ret
Ejemplo n.º 3
0
    def test_mark_if_spam_with_words(self):
        # handle name
        s = factories.SuggestionFactory(name='1 foo 2', comment='1 bar 2')
        utils.mark_if_spam(s)

        assert s.state == Suggestion.STATE_SPAM

        # handle comment
        s = factories.SuggestionFactory(name='1 bar 2', comment='1 foo 2')
        utils.mark_if_spam(s)

        assert s.state == Suggestion.STATE_SPAM

        # not case-sensitive
        s = factories.SuggestionFactory(name='1 FOO 2', comment='1 FOO 2')
        utils.mark_if_spam(s)

        assert s.state == Suggestion.STATE_SPAM

        # don't flag superstrings
        s = factories.SuggestionFactory(name='1 food 2', comment='1 food 2')
        utils.mark_if_spam(s)

        assert s.state == Suggestion.STATE_NEW
Ejemplo n.º 4
0
    def test_mark_if_spam_with_words(self):
        # handle name
        s = suggestion(name='1 foo 2', comment='1 bar 2', save=True)
        utils.mark_if_spam(s)

        eq_(s.state, Suggestion.STATE_SPAM)

        # handle comment
        s = suggestion(name='1 bar 2', comment='1 foo 2', save=True)
        utils.mark_if_spam(s)

        eq_(s.state, Suggestion.STATE_SPAM)

        # not case-sensitive
        s = suggestion(name='1 FOO 2', comment='1 FOO 2', save=True)
        utils.mark_if_spam(s)

        eq_(s.state, Suggestion.STATE_SPAM)

        # don't flag superstrings
        s = suggestion(name='1 food 2', comment='1 food 2', save=True)
        utils.mark_if_spam(s)

        eq_(s.state, Suggestion.STATE_NEW)
Ejemplo n.º 5
0
    def test_mark_if_spam_no_spam_words(self):
        s = factories.SuggestionFactory(name='foo', comment='foo')
        utils.mark_if_spam(s)

        assert s.state == Suggestion.STATE_NEW
Ejemplo n.º 6
0
    def test_mark_if_spam_no_spam_words(self):
        s = suggestion(name='foo', comment='foo', save=True)
        utils.mark_if_spam(s)

        eq_(s.state, Suggestion.STATE_NEW)