Ejemplo n.º 1
0
def build_report_object(report_form, media_entry=None, comment=None):
    """
    This function is used to convert a form object (from a User filing a
        report) into a Report.

    :param report_form          A MediaReportForm or a CommentReportForm object
                                  with valid information from a POST request.
    :param media_entry          A MediaEntry object. The MediaEntry being repo-
                                  -rted by a Report.
    :param comment              A Comment object. The Comment being
                                  reported by a Report.

    :returns                A Report object if a valid MediaReportForm is
                              passed as kwarg media_entry. This Report has
                              not been saved.
    :returns                None if the form_dict is invalid.
    """
    report_object = Report()
    if report_form.validate() and comment is not None:
        report_object.obj = comment.comment()
        report_object.reported_user_id = TextComment.query.get(
            comment.id).get_actor.id
    elif report_form.validate() and media_entry is not None:
        report_object.obj = media_entry
        report_object.reported_user_id = MediaEntry.query.get(
            media_entry.id).get_actor.id
    else:
        return None

    report_object.report_content = report_form.report_reason.data
    report_object.reporter_id = report_form.reporter_id.data
    return report_object
Ejemplo n.º 2
0
def build_report_object(report_form, media_entry=None, comment=None):
    """
    This function is used to convert a form object (from a User filing a
        report) into a Report.

    :param report_form          A MediaReportForm or a CommentReportForm object
                                  with valid information from a POST request.
    :param media_entry          A MediaEntry object. The MediaEntry being repo-
                                  -rted by a Report.
    :param comment              A Comment object. The Comment being
                                  reported by a Report.

    :returns                A Report object if a valid MediaReportForm is
                              passed as kwarg media_entry. This Report has
                              not been saved.
    :returns                None if the form_dict is invalid.
    """
    report_object = Report()
    if report_form.validate() and comment is not None:
        report_object.obj = comment.comment()
        report_object.reported_user_id = TextComment.query.get(
            comment.id).get_actor.id
    elif report_form.validate() and media_entry is not None:
        report_object.obj = media_entry
        report_object.reported_user_id = MediaEntry.query.get(
            media_entry.id).get_actor.id
    else:
        return None

    report_object.report_content = report_form.report_reason.data
    report_object.reporter_id = report_form.reporter_id.data
    return report_object
Ejemplo n.º 3
0
def fixture_add_comment_report(comment=None,
                               reported_user=None,
                               reporter=None,
                               created=None,
                               report_content=None):
    if comment is None:
        comment = fixture_add_comment()

    if reported_user is None:
        reported_user = fixture_add_user()

    if reporter is None:
        reporter = fixture_add_user()

    if created is None:
        created = datetime.now()

    if report_content is None:
        report_content = \
            'Auto-generated test report'

    comment_report = Report()
    comment_report.obj = comment
    comment_report.reported_user = reported_user
    comment_report.reporter = reporter
    comment_report.created = created
    comment_report.report_content = report_content
    comment_report.obj = comment
    comment_report.save()

    Session.expunge(comment_report)

    return comment_report
Ejemplo n.º 4
0
def fixture_add_comment_report(comment=None, reported_user=None,
        reporter=None, created=None, report_content=None):
    if comment is None:
        comment = fixture_add_comment()

    if reported_user is None:
        reported_user = fixture_add_user()

    if reporter is None:
        reporter = fixture_add_user()

    if created is None:
        created=datetime.now()

    if report_content is None:
        report_content = \
            'Auto-generated test report'

    comment_report = Report()
    comment_report.obj = comment
    comment_report.reported_user = reported_user
    comment_report.reporter = reporter
    comment_report.created = created
    comment_report.report_content = report_content
    comment_report.obj = comment
    comment_report.save()

    Session.expunge(comment_report)

    return comment_report