def main_page():
    global_statistic = dict.fromkeys(db.prs)
    for pr in global_statistic.keys()[:]:
        types = dict.fromkeys(["total", "critical", "unresolved"])
        types["total"] = len(launchpad.get_bugs(
            project_name=pr, statuses=launchpad.BUG_STATUSES["All"]))
        types["critical"] = len(launchpad.get_bugs(
            project_name=pr,
            statuses=launchpad.BUG_STATUSES["NotDone"],
            importance=["Critical"]))
        types["unresolved"] = len(launchpad.get_bugs(
            project_name=pr,
            statuses=launchpad.BUG_STATUSES["NotDone"]))
        global_statistic['{0}'.format(pr)] = types

    return flask.render_template("main.html",
                                 key_milestone=key_milestone,
                                 statistic=global_statistic,
                                 prs=list(db.prs),
                                 update_time=launchpad.get_update_time())
def main_page():
    global_statistic = dict.fromkeys(db.prs)
    for pr in global_statistic.keys()[:]:
        types = dict.fromkeys(["total", "critical", "unresolved"])
        types["total"] = len(
            launchpad.get_bugs(project_name=pr,
                               statuses=launchpad.BUG_STATUSES["All"]))
        types["critical"] = len(
            launchpad.get_bugs(project_name=pr,
                               statuses=launchpad.BUG_STATUSES["NotDone"],
                               importance=["Critical"]))
        types["unresolved"] = len(
            launchpad.get_bugs(project_name=pr,
                               statuses=launchpad.BUG_STATUSES["NotDone"]))
        global_statistic['{0}'.format(pr)] = types

    return flask.render_template("main.html",
                                 key_milestone=key_milestone,
                                 statistic=global_statistic,
                                 prs=list(db.prs),
                                 update_time=launchpad.get_update_time())
def bug_list_for_sbpr(project_name, bug_type, milestone_name, sbpr):
    subprojects = [sbpr]

    if sbpr == 'all':
        subprojects = list(db.subprs)

    milestones = db.bugs.milestones.find_one()["Milestone"]

    bug_importance = []
    bug_statuses = ""
    bugs_type_to_print = ""

    if bug_type == "done":
        bugs_type_to_print = "Closed"
        bug_statuses = "Closed"

    if bug_type == "total":
        bugs_type_to_print = "Total"
        bug_statuses = "All"

    if bug_type == "high":
        bugs_type_to_print = "High and Critical"
        bug_statuses = "NotDone"
        bug_importance = ["High", "Critical"]

    if bug_type == "incomplete":
        bugs_type_to_print = "Incomplete"
        bug_statuses = "Incomplete"

    bugs = list(
        set(
            launchpad.get_bugs(project_name=project_name,
                               statuses=launchpad.BUG_STATUSES[bug_statuses],
                               milestone_name=milestone_name,
                               tags=subprojects,
                               importance=bug_importance)))

    return flask.render_template("bug_table_sbpr.html",
                                 project=project_name,
                                 prs=list(db.prs),
                                 bugs=bugs,
                                 sbpr=sbpr,
                                 key_milestone=key_milestone,
                                 milestone_name=milestone_name,
                                 milestones=milestones,
                                 update_time=launchpad.get_update_time(),
                                 bugs_type_to_print=bugs_type_to_print)
def bug_list_for_sbpr(project_name, bug_type, milestone_name, sbpr):
    subprojects = [sbpr]

    if sbpr == 'all':
        subprojects = list(db.subprs)

    milestones = db.bugs.milestones.find_one()["Milestone"]

    bug_importance = []
    bug_statuses = ""
    bugs_type_to_print = ""

    if bug_type == "done":
        bugs_type_to_print = "Closed"
        bug_statuses = "Closed"

    if bug_type == "total":
        bugs_type_to_print = "Total"
        bug_statuses = "All"

    if bug_type == "high":
        bugs_type_to_print = "High and Critical"
        bug_statuses = "NotDone"
        bug_importance = ["High", "Critical"]

    if bug_type == "incomplete":
        bugs_type_to_print = "Incomplete"
        bug_statuses = "Incomplete"

    bugs = list(set(launchpad.get_bugs(project_name=project_name,
                                       statuses=launchpad.
                                       BUG_STATUSES[bug_statuses],
                                       milestone_name=milestone_name,
                                       tags=subprojects,
                                       importance=bug_importance)))

    return flask.render_template("bug_table_sbpr.html",
                                 project=project_name,
                                 prs=list(db.prs),
                                 bugs=bugs,
                                 sbpr=sbpr,
                                 key_milestone=key_milestone,
                                 milestone_name=milestone_name,
                                 milestones=milestones,
                                 update_time=launchpad.get_update_time(),
                                 bugs_type_to_print=bugs_type_to_print)
def bug_list(project_name, bug_type, milestone_name):
    project = launchpad.get_project(project_name)
    tags = None

    if 'tags' in flask.request.args:
        tags = flask.request.args['tags'].split(',')
    if bug_type == "New":
        milestone_name = None

    bugs = launchpad.get_bugs(project_name=project_name,
                              statuses=launchpad.BUG_STATUSES[bug_type],
                              milestone_name=milestone_name,
                              tags=tags)

    return flask.render_template("bug_list.html",
                                 project=project,
                                 bugs=bugs,
                                 bug_type=bug_type,
                                 milestone_name=milestone_name,
                                 selected_bug_table=True,
                                 prs=list(db.prs),
                                 key_milestone=key_milestone,
                                 update_time=launchpad.get_update_time())
def bug_list(project_name, bug_type, milestone_name):
    project = launchpad.get_project(project_name)
    tags = None

    if 'tags' in flask.request.args:
        tags = flask.request.args['tags'].split(',')
    if bug_type == "New":
        milestone_name = None

    bugs = launchpad.get_bugs(
        project_name=project_name,
        statuses=launchpad.BUG_STATUSES[bug_type],
        milestone_name=milestone_name, tags=tags)

    return flask.render_template("bug_list.html",
                                 project=project,
                                 bugs=bugs,
                                 bug_type=bug_type,
                                 milestone_name=milestone_name,
                                 selected_bug_table=True,
                                 prs=list(db.prs),
                                 key_milestone=key_milestone,
                                 update_time=launchpad.get_update_time())
def fuel_plus_mos_overview(milestone_name):
    milestones = db.bugs.milestones.find_one()["Milestone"]

    subprojects = list(db.subprs)
    page_statistic = dict.fromkeys(subprojects)

    for sbpr in subprojects:
        page_statistic["{0}".format(sbpr)] = dict.fromkeys(["fuel", "mos"])
        for pr in ("fuel", "mos"):
            page_statistic["{0}".format(sbpr)]["{0}".format(pr)] = \
                dict.fromkeys(["done", "total", "high"])

            page_statistic["{0}".format(sbpr)]["{0}".format(pr)]["done"] = \
                len(launchpad.get_bugs(
                    project_name=pr,
                    statuses=launchpad.BUG_STATUSES["Closed"],
                    milestone_name=milestone_name,
                    tags=[sbpr]))

            page_statistic["{0}".format(sbpr)]["{0}".format(pr)]["total"] = \
                len(launchpad.get_bugs(
                    project_name=pr,
                    statuses=launchpad.BUG_STATUSES["All"],
                    milestone_name=milestone_name,
                    tags=[sbpr]))

            page_statistic["{0}".format(sbpr)]["{0}".format(pr)]["high"] = \
                len(launchpad.get_bugs(
                    project_name=pr,
                    statuses=launchpad.BUG_STATUSES["NotDone"],
                    milestone_name=milestone_name,
                    tags=[sbpr],
                    importance=["High", "Critical"]))

    fuel_plus_mos = dict.fromkeys(subprojects)
    for subpr in subprojects:
        fuel_plus_mos["{0}".format(subpr)] = dict.fromkeys(
            ["done", "total", "high"])
    for subpr in subprojects:
        tag = ["{0}".format(subpr)]
        summary = launchpad.bugs_ids(tag, milestone_name)
        fuel_plus_mos["{0}".format(subpr)]["done"] = summary["done"]
        fuel_plus_mos["{0}".format(subpr)]["total"] = summary["total"]
        fuel_plus_mos["{0}".format(subpr)]["high"] = summary["high"]

    summary_statistic = dict.fromkeys("summary")
    summary_statistic["summary"] = dict.fromkeys(["tags", "others"])
    for criterion in ["tags", "others"]:
        summary_statistic["summary"][criterion] = dict.fromkeys(
            ["fuel", "mos", "fuel_mos"])

    for criterion in ["tags", "others"]:

        if criterion == "others":
            condition = True
        else:
            condition = False

        for pr in ("fuel", "mos"):
            summary_statistic["summary"][criterion]["{0}".format(pr)] = \
                dict.fromkeys(["done", "total", "high"])

            summary_statistic[
                "summary"][criterion]["{0}".format(pr)]["done"] = \
                len(launchpad.get_bugs(
                    project_name=pr,
                    statuses=launchpad.BUG_STATUSES["Closed"],
                    milestone_name=milestone_name,
                    tags=subprojects,
                    condition=condition))

            summary_statistic[
                "summary"][criterion]["{0}".format(pr)]["total"] = \
                len(launchpad.get_bugs(
                    project_name=pr,
                    statuses=launchpad.BUG_STATUSES["All"],
                    milestone_name=milestone_name,
                    tags=subprojects,
                    condition=condition))

            summary_statistic[
                "summary"][criterion]["{0}".format(pr)]["high"] = \
                len(launchpad.get_bugs(
                    project_name=pr,
                    statuses=launchpad.BUG_STATUSES["NotDone"],
                    milestone_name=milestone_name,
                    tags=subprojects,
                    importance=["High", "Critical"],
                    condition=condition))

    for criterion in ["tags", "others"]:
        summary_statistic["summary"][criterion]["fuel_mos"] = \
            dict.fromkeys(["done", "total", "high"])
        for state in ["done", "total", "high"]:
            summary_statistic["summary"][criterion]["fuel_mos"]["{0}".format(
                state)] = 0

    for state in ["done", "total", "high"]:
        for subpr in subprojects:
            summary_statistic[
                "summary"]["tags"]["fuel_mos"]["{0}".format(state)] +=\
                fuel_plus_mos["{0}".format(subpr)]["{0}".format(state)]

        summary_statistic[
            "summary"]["others"]["fuel_mos"]["{0}".format(state)] = \
            summary_statistic[
                "summary"]["others"]["fuel"]["{0}".format(state)] + \
            summary_statistic["summary"]["others"]["mos"]["{0}".format(state)]

    incomplete = dict.fromkeys("fuel", "mos")
    for pr in ("fuel", "mos"):
        incomplete['{0}'.format(pr)] = \
            len(launchpad.get_bugs(
                project_name=pr,
                statuses=["Incomplete"],
                milestone_name=milestone_name,
                tags=subprojects))

    return flask.render_template(
        "project_fuelmos.html",
        milestones=milestones,
        key_milestone=key_milestone,
        current_milestone=milestone_name,
        prs=list(db.prs),
        subprs=list(db.subprs),
        fuel_milestone_id=data["fuel"][milestone_name],
        mos_milestone_id=data["mos"][milestone_name],
        page_statistic=page_statistic,
        summary_statistic=summary_statistic,
        fuel_plus_mos=fuel_plus_mos,
        all_tags="+".join(db.subprs),
        incomplete=incomplete,
        update_time=launchpad.get_update_time())
def fuel_plus_mos_overview(milestone_name):
    milestones = db.bugs.milestones.find_one()["Milestone"]

    subprojects = list(db.subprs)
    page_statistic = dict.fromkeys(subprojects)

    for sbpr in subprojects:
        page_statistic["{0}".format(sbpr)] = dict.fromkeys(["fuel", "mos"])
        for pr in ("fuel", "mos"):
            page_statistic["{0}".format(sbpr)]["{0}".format(pr)] = \
                dict.fromkeys(["done", "total", "high"])

            page_statistic["{0}".format(sbpr)]["{0}".format(pr)]["done"] = \
                len(launchpad.get_bugs(
                    project_name=pr,
                    statuses=launchpad.BUG_STATUSES["Closed"],
                    milestone_name=milestone_name,
                    tags=[sbpr]))

            page_statistic["{0}".format(sbpr)]["{0}".format(pr)]["total"] = \
                len(launchpad.get_bugs(
                    project_name=pr,
                    statuses=launchpad.BUG_STATUSES["All"],
                    milestone_name=milestone_name,
                    tags=[sbpr]))

            page_statistic["{0}".format(sbpr)]["{0}".format(pr)]["high"] = \
                len(launchpad.get_bugs(
                    project_name=pr,
                    statuses=launchpad.BUG_STATUSES["NotDone"],
                    milestone_name=milestone_name,
                    tags=[sbpr],
                    importance=["High", "Critical"]))

    fuel_plus_mos = dict.fromkeys(subprojects)
    for subpr in subprojects:
        fuel_plus_mos["{0}".format(subpr)] = dict.fromkeys(["done",
                                                            "total",
                                                            "high"])
    for subpr in subprojects:
        tag = ["{0}".format(subpr)]
        summary = launchpad.bugs_ids(tag, milestone_name)
        fuel_plus_mos["{0}".format(subpr)]["done"] = summary["done"]
        fuel_plus_mos["{0}".format(subpr)]["total"] = summary["total"]
        fuel_plus_mos["{0}".format(subpr)]["high"] = summary["high"]

    summary_statistic = dict.fromkeys("summary")
    summary_statistic["summary"] = dict.fromkeys(["tags", "others"])
    for criterion in ["tags", "others"]:
        summary_statistic["summary"][criterion] = dict.fromkeys(
            ["fuel", "mos", "fuel_mos"])

    for criterion in ["tags", "others"]:

        if criterion == "others":
            condition = True
        else:
            condition = False

        for pr in ("fuel", "mos"):
            summary_statistic["summary"][criterion]["{0}".format(pr)] = \
                dict.fromkeys(["done", "total", "high"])

            summary_statistic[
                "summary"][criterion]["{0}".format(pr)]["done"] = \
                len(launchpad.get_bugs(
                    project_name=pr,
                    statuses=launchpad.BUG_STATUSES["Closed"],
                    milestone_name=milestone_name,
                    tags=subprojects,
                    condition=condition))

            summary_statistic[
                "summary"][criterion]["{0}".format(pr)]["total"] = \
                len(launchpad.get_bugs(
                    project_name=pr,
                    statuses=launchpad.BUG_STATUSES["All"],
                    milestone_name=milestone_name,
                    tags=subprojects,
                    condition=condition))

            summary_statistic[
                "summary"][criterion]["{0}".format(pr)]["high"] = \
                len(launchpad.get_bugs(
                    project_name=pr,
                    statuses=launchpad.BUG_STATUSES["NotDone"],
                    milestone_name=milestone_name,
                    tags=subprojects,
                    importance=["High", "Critical"],
                    condition=condition))

    for criterion in ["tags", "others"]:
        summary_statistic["summary"][criterion]["fuel_mos"] = \
            dict.fromkeys(["done", "total", "high"])
        for state in ["done", "total", "high"]:
            summary_statistic[
                "summary"][criterion]["fuel_mos"]["{0}".format(state)] = 0

    for state in ["done", "total", "high"]:
        for subpr in subprojects:
            summary_statistic[
                "summary"]["tags"]["fuel_mos"]["{0}".format(state)] +=\
                fuel_plus_mos["{0}".format(subpr)]["{0}".format(state)]

        summary_statistic[
            "summary"]["others"]["fuel_mos"]["{0}".format(state)] = \
            summary_statistic[
                "summary"]["others"]["fuel"]["{0}".format(state)] + \
            summary_statistic["summary"]["others"]["mos"]["{0}".format(state)]

    incomplete = dict.fromkeys("fuel", "mos")
    for pr in ("fuel", "mos"):
        incomplete['{0}'.format(pr)] = \
            len(launchpad.get_bugs(
                project_name=pr,
                statuses=["Incomplete"],
                milestone_name=milestone_name,
                tags=subprojects))

    return flask.render_template("project_fuelmos.html",
                                 milestones=milestones,
                                 key_milestone=key_milestone,
                                 current_milestone=milestone_name,
                                 prs=list(db.prs),
                                 subprs=list(db.subprs),
                                 fuel_milestone_id=data["fuel"][
                                     milestone_name],
                                 mos_milestone_id=data["mos"][milestone_name],
                                 page_statistic=page_statistic,
                                 summary_statistic=summary_statistic,
                                 fuel_plus_mos=fuel_plus_mos,
                                 all_tags="+".join(db.subprs),
                                 incomplete=incomplete,
                                 update_time=launchpad.get_update_time())