コード例 #1
0
    def index(self):
        request = self.request
        user = request.user

        if user.dom.CanViewStats != const.STATS_ALL:
            self._security_failure()

        model_state = request.model_state

        extra_validators = {"ignore_key_missing": True}
        if request.pageinfo.DbArea == const.DM_CIC:
            extra_validators["PBID"] = ciocvalidators.IDValidator()

        model_state.schema = ciocvalidators.DateSearch(today=False)(
            **extra_validators)
        model_state.method = None

        stat_rows = {}
        publist = []
        months = []
        agency_list = []
        ErrMsg = None
        link_prefix = ("~/" if request.pageinfo.DbArea == const.DM_CIC else
                       "~/volunteer/")
        publication_code = None
        publication_name = None

        with request.connmgr.get_connection("admin") as conn:
            if not model_state.validate():
                ErrMsg = _("There were validation errors.")
            else:

                if request.params.get("submit"):
                    args = [request.dboptions.MemberID]
                    args_param = "?"
                    sql = "EXEC sp_%s_AutoReport_Stats_IP_Owner %s"
                    if any(
                            model_state.value(x)
                            for x in ["DateRange", "FirstDate", "LastDate"]):
                        prefix = ""
                        range = model_state.value("DateRange")
                        if range:
                            prefix = (
                                "SET NOCOUNT ON; DECLARE @FirstDate smalldatetime, @LastDate smalldatetime; SET @FirstDate = %s; SET @LastDate = %s\n"
                                % date_search_options_sql[range])
                            args_param = "?, @FirstDate, @LastDate"
                        else:
                            args_param = "?,?,?"
                            args.extend([
                                model_state.value("FirstDate"),
                                model_state.value("LastDate"),
                            ])

                        sql = prefix + "EXEC sp_%s_Stats_IP_Owner %s"

                    if request.pageinfo.DbArea == const.DM_CIC:
                        args_param += ",?"
                        args.append(model_state.value("PBID"))

                    sql = sql % (request.pageinfo.DbAreaS, args_param)
                    cursor = conn.execute(sql, args)
                    months = cursor.fetchone()

                    if request.pageinfo.DbArea == const.DM_CIC:
                        cursor.nextset()
                        publication_code = cursor.fetchone()
                        if publication_code:
                            publication_name = publication_code[1]
                            publication_code = publication_code[0]

                    cursor.nextset()

                    stat_rows = cursor.fetchall()

                    agency_list = {x.RECORD_OWNER for x in stat_rows}

                    stat_rows = {(x.RECORD_OWNER, x.TheMonth): x
                                 for x in stat_rows}

                    cursor.close()

                if request.pageinfo.DbArea == const.DM_CIC:
                    publist = conn.execute(
                        "EXEC dbo.sp_CIC_Publication_l ?, ?, NULL",
                        request.viewdata.cic.ViewType,
                        False,
                    ).fetchall()

        title = _("Unique IPs by Record Owner", request)
        return self._create_response_namespace(
            title,
            title,
            {
                "months": list(months),
                "agency_list": list(sorted(agency_list)),
                "stat_rows": stat_rows,
                "publist": publist,
                "link_prefix": link_prefix,
                "ErrMsg": ErrMsg,
                "publication_name": publication_name,
                "publication_code": publication_code,
            },
            print_table=True,
            no_index=True,
        )
コード例 #2
0
    def index(self):
        request = self.request
        user = request.user

        if user.dom.CanViewStats != const.STATS_ALL:
            self._security_failure()

        model_state = request.model_state

        extra_validators = {"ignore_key_missing": True}
        if request.pageinfo.DbArea == const.DM_CIC:
            extra_validators["PBID"] = ciocvalidators.IDValidator()

        model_state.schema = ciocvalidators.DateSearch()(**extra_validators)
        model_state.method = None

        stat_rows = []
        publist = []
        months = []
        ErrMsg = None
        link_prefix = ("~/" if request.pageinfo.DbArea == const.DM_CIC else
                       "~/volunteer/")
        publication_code = None
        publication_name = None

        with request.connmgr.get_connection("admin") as conn:
            if not model_state.validate():
                ErrMsg = _("There were validation errors.")
            else:

                if request.params.get("submit"):
                    tax_section = []
                    display_until_section = []
                    if request.pageinfo.DbArea == const.DM_CIC:
                        tax_section = [
                            StatType(_("Last Modified - Taxonomy"), True, True)
                        ]
                    else:
                        display_until_section = [
                            StatType(_("Display Until"), True, True)
                        ]

                    stat_types = ([
                        StatType(_("Date Created"), True, True),
                        StatType(_("Last Modified"), True, True),
                    ] + tax_section + [
                        StatType(_("Last Full Update"), True, True),
                        StatType(_("Deletion Date"), True, True),
                    ] + display_until_section)

                    if request.dboptions.OtherMembersActive:
                        stat_types += [
                            StatType(_("Shared With Me"), False, True),
                            StatType(_("Shared By Me"), False, False),
                        ]

                    args = [request.dboptions.MemberID]
                    args_param = "?"
                    sql = "EXEC sp_%s_AutoReport_DataMgmt %s"
                    if any(
                            model_state.value(x)
                            for x in ["DateRange", "FirstDate", "LastDate"]):
                        prefix = ""
                        range = model_state.value("DateRange")
                        if range:
                            prefix = (
                                "SET NOCOUNT ON; DECLARE @FirstDate smalldatetime, @LastDate smalldatetime; SET @FirstDate = %s; SET @LastDate = %s\n"
                                % date_search_options_sql[range])
                            args_param = "?, @FirstDate, @LastDate"
                        else:
                            args_param = "?,?,?"
                            args.extend([
                                model_state.value("FirstDate"),
                                model_state.value("LastDate"),
                            ])

                        sql = prefix + "EXEC sp_%s_Stats_DataMgmt %s"

                    if request.pageinfo.DbArea == const.DM_CIC:
                        args_param += ",?"
                        args.append(model_state.value("PBID"))

                    sql = sql % (request.pageinfo.DbAreaS, args_param)
                    cursor = conn.execute(sql, args)
                    months = cursor.fetchone()

                    if request.pageinfo.DbArea == const.DM_CIC:
                        cursor.nextset()
                        publication_code = cursor.fetchone()
                        if publication_code:
                            publication_name = publication_code[1]
                            publication_code = publication_code[0]

                    link_template = Markup(
                        '<b>%(title)s</b>: <a href="%(url)s">%(count)d</a>')
                    nolink_template = Markup("<b>%(title)s</b>: %(count)d")
                    makeLink = request.passvars.makeLink
                    results = link_prefix + "results.asp"
                    exclude = ["Ln"]
                    for st in stat_types:
                        cursor.nextset()
                        stat_months = {}
                        for k, g in groupby(cursor.fetchall(),
                                            attrgetter("TheMonth")):
                            rows = list(g)

                            if st.hasother:
                                other = Markup("<br>").join(
                                    (link_template if x[3] else nolink_template
                                     ) % {
                                         "title":
                                         x[1],
                                         "url":
                                         makeLink(results, "Shared=Y&" +
                                                  x.Criteria, exclude),
                                         "count":
                                         x[3],
                                     } for x in rows)

                                local_shared_criteria = "Shared=N&"
                                tmpl = link_template

                            else:
                                other = None
                                local_shared_criteria = ""

                            if not st.hascriteria:
                                tmpl = nolink_template

                            local = Markup("<br>").join(
                                (tmpl if x[2] else nolink_template) % {
                                    "title":
                                    x[1],
                                    "url":
                                    makeLink(
                                        results,
                                        local_shared_criteria + x.Criteria,
                                        exclude,
                                    ) if st.hascriteria else "",
                                    "count":
                                    x[2],
                                } for x in rows)

                            stat_months[k] = (local, other)

                        stat_rows.append((st, stat_months))

                    cursor.close()

                if request.pageinfo.DbArea == const.DM_CIC:
                    publist = conn.execute(
                        "EXEC dbo.sp_CIC_Publication_l ?, ?, NULL",
                        request.viewdata.cic.ViewType,
                        False,
                    ).fetchall()

        title = _("Data Management Report", request)
        return self._create_response_namespace(
            title,
            title,
            {
                "months": list(months),
                "stat_rows": stat_rows,
                "publist": publist,
                "link_prefix": link_prefix,
                "ErrMsg": ErrMsg,
                "publication_name": publication_name,
                "publication_code": publication_code,
            },
            print_table=True,
            no_index=True,
        )