예제 #1
0
def create_verdict():

    check_has_role(current_user, 'EDITOR')

    verdict = Verdict()
    verdict.modify(request.json)
    verdict.user = current_user
    ApiHandler.save(verdict)
    return jsonify(as_dict(verdict, includes=VERDICT_INCLUDES)), 201
def create_verdict():

    check_has_role(current_user, 'editor')

    verdict = Verdict()
    verdict.populate_from_dict(request.json)
    verdict.user = current_user
    ApiHandler.save(verdict)
    return jsonify(as_dict(verdict, includes=VERDICT_INCLUDES)), 201
def create_verdicts():
    logger.info('create_verdicts')

    verdicts_by_name = {}
    articles = Article.query.all()
    user = User.query.filter_by(
        email="*****@*****.**").one()

    article = Article.query.filter_by(
        url=
        "https://www.breitbart.com/big-government/2017/03/20/delingpole-great-barrier-reef-still-not-dying-whatever-washington-post-says"
    ).one()
    evaluation_value = -2
    evaluation = Evaluation.query.filter_by(type="article",
                                            value=evaluation_value).one()
    verdicts_by_name[article.id] = Verdict(
        article=article,
        comment=
        '{"blocks":[{"key":"2l86g","text":"C\'est abusé, voici mon verdict lol","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}}],"entityMap":{}}',
        evaluation=evaluation,
        rating=evaluation_value,
        user=user)

    ApiHandler.save(*verdicts_by_name.values())

    logger.info('created {} verdicts'.format(len(verdicts_by_name)))

    return verdicts_by_name
예제 #4
0
def verdict_from_row(row, unused_index=None):
    science_feedback_editor_ids = row.get('Review editor(s)')
    if not science_feedback_editor_ids:
        return None
    editor = User.query.filter_by(scienceFeedbackIdentifier=science_feedback_editor_ids[0]).first()
    if not editor:
        return None

    claim = Claim.query.filter_by(scienceFeedbackIdentifier=row['Items reviewed'][0]).first()
    if not claim:
        return None

    medium = Medium.query.filter_by(url='/'.join(row['Review url'].split('/')[0:3])).first()
    published_date = strptime(row['Date of publication'], '%Y-%m-%d')
    post_type = row['Post type'].lower()

    verdict_dict = {
        '__SEARCH_BY__': 'scienceFeedbackIdentifier',
        'claim': claim,
        'editor': editor,
        'medium': medium,
        'scienceFeedbackIdentifier': row['airtableId'],
        'scienceFeedbackUrl': row['Review url'],
        'scienceFeedbackPublishedDate': published_date,
        'title': row['Review headline'],
        'type': PostType._value2member_map_[post_type]
    }

    return Verdict.create_or_modify(verdict_dict)
예제 #5
0
def create_verdicts():
    logger.info('create_verdicts')

    verdicts = []
    user = User.query.filter_by(email='{}test.editor0@{}.{}'.format(
        COMMAND_NAME, APP_NAME, TLD)).one()

    content = Content.query.filter_by(
        url=
        'https://www.breitbart.com/big-government/2017/03/20/delingpole-great-barrier-reef-still-not-dying-whatever-washington-post-says'
    ).one()
    verdicts.append(
        Verdict(
            comment=
            '{"blocks":[{"key":"2l86g","text":"C\'est abusé, voici mon verdict lol","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}}],"entityMap":{}}',
            content=content,
            editor=user))

    ApiHandler.save(*verdicts)

    logger.info('created {} verdicts'.format(len(verdicts)))
def content_verdicts_from_scrap(verdicts_max=3):
    feedbacks = scrap_feedbacks(feedbacks_max=verdicts_max)
    verdicts = []
    for feedback in feedbacks:
        verdict = Verdict.create_or_modify(feedback)
        content = content_from_url(feedback['article']['url'])
        for reviewer in verdict['reviewer']:
            reviewer = reviewer_from_url(reviewer['url'])
            user = User.create_or_modify({
                '__SEARCH_BY__': ['firstName', 'lastName'],
                **reviewer
            })
            role = Role.create_or_modify({
                '__SEARCH_BY__': ['type', 'userId'],
                'type': 'reviewer',
                'userId': humanize(user.id)
            })
            user.roles = user.roles + [role]
            review = Review.create_or_modify({
                '__SEARCH_BY__': ['contentId', 'userId'],
                'contentId':
                humanize(content.id),
                'userId':
                humanize(user.id),
                **reviewer['review']
            })
            user.reviews = user.reviews + [review]
            verdict_user = VerdictUser.create_or_modify({
                '__SEARCH_BY__': ['verdictId', 'userId'],
                'verdictId':
                humanize(verdict.id),
                'userId':
                humanize(user.id)
            })
            verdict.verdictUsers = verdict.verdictUsers + [verdict_user]
    return verdicts