@@ -0,0 +1,2266 @@
+import argparse%0Aimport csv%0A%0Aimport ekklesia_portal.helper.markdown as md%0Afrom eliot import log_call, start_task, Message, write_traceback%0Aimport sqlalchemy.orm%0A%0A%0A@log_call%0Adef load_ballots(log_level=%22INFO%22):%0A    department = session.query(Department).filter_by(name=args.department).one()%0A%0A    maybe_voting_phase = %5Bv for v in department.voting_phases if v.name == args.voting_phase%5D%0A%0A    if not maybe_voting_phase:%0A        raise ValueError(f%22Voting phase %7Bargs.voting_phase%7D not found!%22)%0A%0A    voting_phase = maybe_voting_phase%5B0%5D%0A%0A    ballots = voting_phase.ballots%0A    return ballots%0A%0A%0A@log_call%0Adef convert_ballots_to_proposition_rows(ballots, log_level=%22INFO%22):%0A    proposition_rows = %5B%5D%0A%0A    for ballot in ballots:%0A        for proposition in ballot.propositions:%0A            proposition_rows.append(%5Bproposition.id, %22%22, proposition.title, md.convert(proposition.content),%0A                                     md.convert(proposition.motivation), %22%22, %22%22, %22%22, %22ekklesia-portal%22%5D)%0A%0A    return proposition_rows%0A%0A%0A@log_call%0Adef write_csv_file(filepath, proposition_rows, log_level=%22INFO%22):%0A    with open(filepath, 'w') as csvfile:%0A        fieldnames = %5B'Identifier', 'Submitters', 'Title', 'Text', 'Reason', 'Category', 'Tags', 'Motion block', 'Origin'%5D%0A%0A        writer = csv.writer(csvfile)%0A        # maybe convert to dictwriter for better logging view%0A%0A        writer.writerow(fieldnames)%0A        writer.writerows(proposition_rows)%0A%0A%0Aparser = argparse.ArgumentParser(%22Ekklesia Portal export_proposition_csv.py%22)%0Aparser.add_argument(%22-c%22, %22--config-file%22, help=f%22path to config file in YAML / JSON format%22)%0Aparser.add_argument(%22-d%22, %22--department%22, help=f%22Choose the department to export from.%22)%0Aparser.add_argument(%22-v%22, %22--voting-phase%22, help=f%22Choose the voting phase to export from.%22)%0Aparser.add_argument(%22-o%22, %22--out%22, help=f%22Choose output file.%22)%0A%0Aif __name__ == %22__main__%22:%0A    args = parser.parse_args()%0A%0A    from ekklesia_portal.app import make_wsgi_app%0A%0A    app = make_wsgi_app(args.config_file)%0A%0A    from ekklesia_portal.database.datamodel import Department%0A    from ekklesia_portal.database import Session%0A%0A    session = Session()%0A%0A    sqlalchemy.orm.configure_mappers()%0A%0A    write_csv_file(args.out, convert_ballots_to_proposition_rows(load_ballots()))%0A

add proposition csv export script #3