コード例 #1
0
def test_create_quote(app):
    user = factories.UserFactory()
    topic = factories.TopicFactory()

    # First try to create a quote as no non-curator user
    source, quote, arguments = factories.get_quote_form_data(
        text='Nepasiduokime paviršutiniškiems šūkiams – šiuolaikiška, modernu.'
    )
    services.create_quote(user, topic, source, quote, arguments)
    assert services.dump_topic_posts(topic) == ''
    assert services.dump_topic_posts(topic, queue=True) == '\n'.join([
        '( ) (-) Mantas Adomėnas (seimo narys)                                          kauno.diena.lt 2016-03-22    ',
        ' |      Nepasiduokime paviršutiniškiems šūkiams – šiuolaikiška, modernu.                                 (0)',
        ' |      - (y) šiuolaikiška, modernu < (counterargument)                                                     ',
    ])

    # Now create a post as a curator user
    factories.TopicCuratorFactory(user=user, topic=topic)
    source, quote, arguments = factories.get_quote_form_data(
        text='Atidaroma galimybė prekiauti balsais ir likti nebaudžiamam.')
    services.create_quote(user, topic, source, quote, arguments)
    assert services.dump_topic_posts(topic) == '\n'.join([
        '( ) (n) Mantas Adomėnas (seimo narys)                                          kauno.diena.lt 2016-03-22    ',
        ' |      Atidaroma galimybė prekiauti balsais ir likti nebaudžiamam.                                      (0)',
        ' |      - (y) šiuolaikiška, modernu < (counterargument)                                                     ',
    ])
コード例 #2
0
ファイル: views.py プロジェクト: sirex/manopozicija.lt
def quote_form(request, object_id, slug):
    topic = get_object_or_404(models.Topic, pk=object_id)
    ArgumentFormSet = formset_factory(
        forms.ArgumentForm, min_num=0, max_num=3, extra=3,
        validate_min=True, validate_max=True,
    )

    if request.method == 'POST':
        source_form = forms.SourceForm(request.POST)
        source_form.full_clean()
        source = source_form.cleaned_data
        form = forms.CombinedForms(
            source=source_form,
            quote=forms.QuoteForm(topic, source.get('actor'), source.get('source_link'), request.POST),
            arguments=ArgumentFormSet(request.POST),
        )
        if form.is_valid():
            services.create_quote(request.user, topic, **form.cleaned_data)
            return redirect(topic)
    else:
        form = forms.CombinedForms(
            source=forms.SourceForm(),
            quote=forms.QuoteForm(topic, actor=None, source_link=None),
            arguments=ArgumentFormSet(),
        )

    return render(request, 'manopozicija/quote_form.html', {
        'topic': topic,
        'source_form': form['source'],
        'quote_form': form['quote'],
        'arguments_formset': form['arguments'],
    })
コード例 #3
0
def test_create_quote(app):
    user = factories.UserFactory()
    topic = factories.TopicFactory()

    # First try to create a quote as no non-curator user
    source, quote, arguments = factories.get_quote_form_data(
        text='Nepasiduokime paviršutiniškiems šūkiams – šiuolaikiška, modernu.'
    )
    services.create_quote(user, topic, source, quote, arguments)
    assert services.dump_topic_posts(topic) == ''
    assert services.dump_topic_posts(topic, queue=True) == '\n'.join([
        '( ) (-) Mantas Adomėnas (seimo narys)                                          kauno.diena.lt 2016-03-22    ',
        ' |      Nepasiduokime paviršutiniškiems šūkiams – šiuolaikiška, modernu.                                 (0)',
        ' |      - (y) šiuolaikiška, modernu < (counterargument)                                                     ',
    ])

    # Now create a post as a curator user
    factories.TopicCuratorFactory(user=user, topic=topic)
    source, quote, arguments = factories.get_quote_form_data(
        text='Atidaroma galimybė prekiauti balsais ir likti nebaudžiamam.'
    )
    services.create_quote(user, topic, source, quote, arguments)
    assert services.dump_topic_posts(topic) == '\n'.join([
        '( ) (n) Mantas Adomėnas (seimo narys)                                          kauno.diena.lt 2016-03-22    ',
        ' |      Atidaroma galimybė prekiauti balsais ir likti nebaudžiamam.                                      (0)',
        ' |      - (y) šiuolaikiška, modernu < (counterargument)                                                     ',
    ])
コード例 #4
0
ファイル: views.py プロジェクト: mgedmin/manopozicija.lt
def quote_form(request, object_id, slug):
    topic = get_object_or_404(models.Topic, pk=object_id)
    ArgumentFormSet = formset_factory(
        forms.ArgumentForm,
        min_num=0,
        max_num=3,
        extra=3,
        validate_min=True,
        validate_max=True,
    )

    if request.method == 'POST':
        source_form = forms.SourceForm(request.POST)
        source_form.full_clean()
        source = source_form.cleaned_data
        form = forms.CombinedForms(
            source=source_form,
            quote=forms.QuoteForm(topic, source.get('actor'),
                                  source.get('source_link'), request.POST),
            arguments=ArgumentFormSet(request.POST),
        )
        if form.is_valid():
            services.create_quote(request.user, topic, **form.cleaned_data)
            return redirect(topic)
    else:
        form = forms.CombinedForms(
            source=forms.SourceForm(),
            quote=forms.QuoteForm(topic, actor=None, source_link=None),
            arguments=ArgumentFormSet(),
        )

    return render(
        request, 'manopozicija/quote_form.html', {
            'topic': topic,
            'source_form': form['source'],
            'quote_form': form['quote'],
            'arguments_formset': form['arguments'],
        })
コード例 #5
0
ファイル: factories.py プロジェクト: mgedmin/manopozicija.lt
def create_topic_quotes(topic, user, actor, title, source, date, quotes):
    result = []
    user = user or UserFactory()
    first_name, last_name = actor.split()
    actor = PersonActorFactory(first_name=first_name, last_name=last_name)
    source = {
        'actor': actor,
        'source_link': _get_source_link(source, date),
        'timestamp': datetime.datetime.strptime(date, '%Y-%m-%d'),
    }
    for upvotes, downvotes, text, arguments in quotes:
        quote = {
            'text': text,
            'reference_link': '',
        }
        quote = services.create_quote(user, topic, source, quote, _prep_quote_arguments(arguments))
        post = quote.post.first()

        position = 1 if upvotes > downvotes else -1 if upvotes < downvotes else 0
        services.update_user_position(user, post, position)

        result.append(post)

    return result
コード例 #6
0
ファイル: factories.py プロジェクト: sirex/manopozicija.lt
def create_topic_quotes(topic, user, actor, title, source, date, quotes):
    result = []
    user = user or UserFactory()
    first_name, last_name = actor.split()
    actor = PersonActorFactory(first_name=first_name, last_name=last_name)
    source = {
        'actor': actor,
        'source_link': _get_source_link(source, date),
        'timestamp': datetime.datetime.strptime(date, '%Y-%m-%d'),
    }
    for upvotes, downvotes, text, arguments in quotes:
        quote = {
            'text': text,
            'reference_link': '',
        }
        quote = services.create_quote(user, topic, source, quote, _prep_quote_arguments(arguments))
        post = quote.post.first()

        position = 1 if upvotes > downvotes else -1 if upvotes < downvotes else 0
        services.update_user_position(user, post, position)

        result.append(post)

    return result