Example #1
0
def checklist():
    s1 = Section('First section', 'A', [Line('A.1', 'A1sum', 'First A line'),
                                        Line('A.2', 'A2sum', 'Second A line')])
    s2 = Section('Second section', 'B', [Line('B.1', 'B1sum', 'First B line'),
                                         Line('B.2', 'B2sum', 'Second B line')])
    cl = Checklist('My Checklist', [s1, s2])
    return cl
Example #2
0
def make_table_of_links():
    """
    Generates table where lefthand column contains checklist items (from checklist.yml) and righthand column contains
    hyperlinks to examples where things have gone wrong (from examples.yml). Table appears in docs/docs/examples.md.
    """
    root = Path(__file__).absolute().parents[1] / "deon" / "assets"

    cl = Checklist.read(root / "checklist.yml")

    with open(root / "examples_of_ethical_issues.yml", "r") as f:
        refs = yaml.load(f, Loader=yaml.SafeLoader)

    refs_dict = dict()
    for r in refs:
        refs_dict[r["line_id"]] = r["links"]

    template = """<center>Checklist Question</center> | <center>Examples of Ethical Issues</center>
--- | ---
{lines}
"""
    line_template = "**{line_id} {line_summary}**: {line} | {row_text}"
    section_title_template = " | <center>**{section_title}**</center>"
    line_delimiter = "\n"

    formatted_rows = []
    for s in cl.sections:
        # section title row
        row = section_title_template.format(section_title=s.title)
        formatted_rows.append(row)

        for line in s.lines:
            # create bulleted list of links for each checklist item in that section
            bulleted_list = []
            for link in refs_dict[line.line_id]:
                text = link["text"]
                url = link["url"]
                bullet_hyperlink = f"<li>[{text}]({url})</li>"
                bulleted_list.append(bullet_hyperlink)
            formatted_bullets = "".join(bulleted_list)

            row = line_template.format(
                line_id=line.line_id,
                line_summary=line.line_summary,
                line=line.line,
                row_text=f"<ul>{formatted_bullets}</ul>",
            )
            formatted_rows.append(row)

    # bring all the rows together
    all_rows = line_delimiter.join(formatted_rows)
    return template.format(lines=all_rows)
Example #3
0
def create_context():
    cl = Checklist.read(
        Path(__file__).absolute().parents[1] / 'deon' / 'assets' /
        'checklist.yml')
    checklist_template = Markdown(cl)
    rendered_checklist = checklist_template.render()

    runner = CliRunner()
    result = runner.invoke(deon_command, ['--help'])

    table = make_table_of_links()

    return {
        'default_checklist': rendered_checklist,
        'cli_options': result.output,
        'supported_formats': EXTENSIONS,
        'links_table': table,
    }
Example #4
0
def create_context():
    cl = Checklist.read(
        Path(__file__).absolute().parents[1] / "deon" / "assets" /
        "checklist.yml")
    checklist_template = Markdown(cl)
    rendered_checklist = checklist_template.render()

    runner = CliRunner()
    result = runner.invoke(deon_command, ["--help"])

    table = make_table_of_links()

    return {
        "default_checklist": rendered_checklist,
        "cli_options": result.output,
        "supported_formats": EXTENSIONS,
        "links_table": table,
    }
Example #5
0
def test_checklist():
    checklist_path = Path(
        __file__).parents[1] / 'deon' / 'assets' / 'checklist.yml'
    c = Checklist.read(checklist_path)

    with open(checklist_path, "r") as f:
        raw_parsed = yaml.load(f, Loader=yaml.SafeLoader)

    assert c.title == raw_parsed['title']

    assert [s.title
            for s in c.sections][2] == raw_parsed['sections'][2]['title']
    assert [s.section_id
            for s in c.sections][2] == raw_parsed['sections'][2]['section_id']

    assert c.sections[1].lines[1].line == raw_parsed['sections'][1]['lines'][
        1]['line']
    assert c.sections[1].lines[1].line_id == raw_parsed['sections'][1][
        'lines'][1]['line_id']
Example #6
0
def test_checklist():
    checklist_path = Path(
        __file__).parents[1] / "deon" / "assets" / "checklist.yml"
    c = Checklist.read(checklist_path)

    with open(checklist_path, "r") as f:
        raw_parsed = yaml.load(f, Loader=yaml.SafeLoader)

    assert c.title == raw_parsed["title"]

    assert [s.title
            for s in c.sections][2] == raw_parsed["sections"][2]["title"]
    assert [s.section_id
            for s in c.sections][2] == raw_parsed["sections"][2]["section_id"]

    assert c.sections[1].lines[1].line == raw_parsed["sections"][1]["lines"][
        1]["line"]
    assert c.sections[1].lines[1].line_id == raw_parsed["sections"][1][
        "lines"][1]["line_id"]
Example #7
0
def checklist():
    s1 = Section(
        "First section",
        "A",
        [
            Line("A.1", "A1sum", "First A line"),
            Line("A.2", "A2sum", "Second A line")
        ],
    )
    s2 = Section(
        "Second section",
        "B",
        [
            Line("B.1", "B1sum", "First B line"),
            Line("B.2", "B2sum", "Second B line")
        ],
    )
    cl = Checklist("My Checklist", [s1, s2])
    return cl