Esempio n. 1
0
    def customise_project_project_resource(r, tablename):

        from s3.s3forms import S3SQLCustomForm, S3SQLInlineComponentCheckbox
        crud_form = S3SQLCustomForm(
            "organisation_id",
            "name",
            "description",
            "status_id",
            "start_date",
            "end_date",
            "calendar",
            "human_resource_id",
            S3SQLInlineComponentCheckbox(
                "sector",
                label=T("Sectors"),
                field="sector_id",
                cols=3,
            ),
            "budget",
            "currency",
            "comments",
        )
        current.s3db.configure(
            tablename,
            crud_form=crud_form,
        )
Esempio n. 2
0
def customise_project_location_resource(r, tablename):
    from s3.s3forms import S3SQLCustomForm, S3SQLInlineComponentCheckbox
    crud_form = S3SQLCustomForm(
        "project_id",
        "location_id",
        # @ToDo: Grouped Checkboxes
        S3SQLInlineComponentCheckbox(
            "activity_type",
            label=T("Activity Types"),
            field="activity_type_id",
            cols=3,
            # Filter Activity Type by Sector
            #filter = {"linktable": "project_activity_type_sector",
            #          "lkey": "activity_type_id",
            #          "rkey": "sector_id",
            #          "lookuptable": "project_project",
            #          "lookupkey": "project_id",
            #          },
        ),
        "comments",
    )

    current.s3db.configure(
        tablename,
        crud_form=crud_form,
    )
Esempio n. 3
0
    def custom_prep(r):
        # Call standard prep
        if callable(standard_prep):
            result = standard_prep(r)
        else:
            result = True

        if r.interactive or r.representation == "aadata":
            s3db = current.s3db
            list_fields = [
                "id", "name", "acronym",
                "organisation_organisation_type.organisation_type_id",
                (T("Clusters"), "sector.name"), "country", "website"
            ]

            s3db.configure("org_organisation", list_fields=list_fields)

        if r.interactive:
            from s3.s3forms import S3SQLCustomForm, S3SQLInlineComponentCheckbox
            crud_form = S3SQLCustomForm(
                "name",
                "acronym",
                S3SQLInlineLink(
                    "organisation_type",
                    field="organisation_type_id",
                    label=T("Type"),
                    multiple=False,
                    #widget = "hierarchy",
                ),
                "region_id",
                "country",
                S3SQLInlineComponentCheckbox(
                    "sector",
                    label=T("Clusters"),
                    field="sector_id",
                    cols=3,
                ),
                "phone",
                "website",
                "year",
                "logo",
                "comments",
            )
            s3db.configure("org_organisation", crud_form=crud_form)

        return result
Esempio n. 4
0
    def customise_project_project_controller(**attr):

        db = current.db
        s3db = current.s3db
        s3 = current.response.s3
        tablename = "project_project"
        # Load normal model
        table = s3db[tablename]

        # Custom Components
        s3db.add_components(
            tablename,
            project_drrpp={
                "joinby": "project_id",
                "multiple": False,
            },
            project_output="project_id",
            doc_document=(  # Files
                {
                    "name": "file",
                    "joinby": "doc_id",
                    "filterby": {
                        "url": ("", None),
                    },
                },
                # Links
                {
                    "name": "url",
                    "joinby": "doc_id",
                    "filterby": {
                        "file": ("", None),
                    },
                },
            ),
        )

        # Custom Fields
        table.name.label = T("Project Title")
        s3db.project_project.budget.label = T("Total Funding (USD)")
        location_id = s3db.project_location.location_id
        location_id.label = ""

        # Limit to just Countries
        location_id.requires = s3db.gis_country_requires
        # Use dropdown, not AC
        location_id.widget = None

        # In DRRPP this is a free field
        table = s3db.project_organisation
        table.comments.label = T("Role")
        table.comments.widget = SQLFORM.widgets.string.widget
        table.amount.label = T("Amount")
        table = s3db.doc_document
        table.file.widget = lambda field, value, download_url: \
            SQLFORM.widgets.upload.widget(field, value, download_url, _size = 15)
        table.comments.widget = SQLFORM.widgets.string.widget

        # If not logged in, contact person is required
        logged_in = current.auth.is_logged_in()
        if not logged_in:
            table = s3db.project_drrpp
            table.focal_person.required = True
            table.email.required = True
            table.email.requires = IS_EMAIL()

        # Custom dataTable
        s3["dataTable_dom"] = 'ripl<"dataTable_table"t>p'

        # Don't show export buttons for XLS/XML
        s3.formats = Storage(xls=None, xml=None)

        # Remove rheader
        attr["rheader"] = None

        # Only show 10 Project by default to improve load time
        attr["dt_lengthMenu"] = [[10, 50, -1], [10, 50, T("All")]]
        s3.dataTable_pageLength = 10

        # Custom PreP
        standard_prep = s3.prep

        def custom_prep(r):

            resource = r.resource

            # Call standard prep
            if callable(standard_prep):
                result = standard_prep(r)
                if not result:
                    return False

            # Customise list_fields
            if r.method == "review":
                list_fields = [
                    "id",
                    "created_on",
                    "modified_on",
                    "name",
                    "start_date",
                    (T("Countries"), "location.location_id"),
                    (T("Hazards"), "hazard.name"),
                    (T("Lead Organization"), "organisation_id"),
                    (T("Donors"), "donor.organisation_id"),
                ]
            elif r.representation == "xls":
                # All readable Fields should be exported
                list_fields = [
                    "id",
                    "name",
                    "code",
                    "description",
                    "status_id",
                    "start_date",
                    "end_date",
                    "drrpp.duration",
                    (T("Countries"), "location.location_id"),
                    "drrpp.L1",
                    (T("Hazards"), "hazard.name"),
                    (T("Themes"), "theme.name"),
                    "objectives",
                    "drrpp.activities",
                    "output.name",
                    "drr.hfa",
                    "drrpp.rfa",
                    "drrpp.pifacc",
                    "drrpp.jnap",
                    (T("Lead Organization"), "organisation_id"),
                    (T("Partners"), "partner.organisation_id"),
                    (T("Donors"), "donor.organisation_id"),
                    "budget",
                    "currency",
                    "drrpp.focal_person",
                    "drrpp.organisation_id",
                    "drrpp.email",
                    "url.url",
                    "drrpp.parent_project",
                    "comments",
                ]
                if logged_in:
                    list_fields.extend([
                        "created_by",
                        "created_on",
                        "modified_by",
                        "modified_on",
                    ])
            else:
                list_fields = [
                    "id",
                    "name",
                    "start_date",
                    (T("Countries"), "location.location_id"),
                    (T("Hazards"), "hazard.name"),
                    (T("Lead Organization"), "organisation_id"),
                    (T("Donors"), "donor.organisation_id"),
                ]

            resource.configure(list_fields=list_fields)

            # Customise report_options
            if r.method == "report":
                report_fields = [
                    "name",
                    (T("Countries"), "location.location_id"),
                    (T("Hazards"), "hazard.name"),
                    (T("Themes"), "theme.name"),
                    (T("HFA Priorities"), "drr.hfa"),
                    (T("RFA Priorities"), "drrpp.rfa"),
                    (T("Lead Organization"), "organisation_id"),
                    (T("Partner Organizations"), "partner.organisation_id"),
                    (T("Donors"), "donor.organisation_id"),
                ]

                # Report Settings for charts
                if "chart" in r.get_vars and r.representation != "json":
                    s3.crud_strings[tablename].title_report = T(
                        "Project Graph")
                    report_fact_default = "count(id)"
                    report_facts = [(T("Number of Projects"), "count(id)")]
                    show_table = False
                else:
                    s3.crud_strings[tablename].title_report = T(
                        "Project Matrix")
                    report_fact_default = "count(id)"
                    report_facts = [
                        (T("Number of Projects"), "count(id)"),
                        (T("Number of Countries"),
                         "count(location.location_id)"),
                        (T("Number of Hazards"), "count(hazard.id)"),
                        (T("Number of Themes"), "count(theme.id)"),
                        (T("Number of HFA Priorities"), "count(drr.hfa)"),
                        (T("Number of RFA Priorities"), "count(drrpp.rfa)"),
                        (T("Number of Lead Organizations"),
                         "count(organisation_id)"),
                        (T("Number of Partner Organizations"),
                         "count(partner.organisation_id)"),
                        (T("Number of Donors"),
                         "count(donor.organisation_id)"),
                    ]
                    show_table = True
                report_options = Storage(rows=report_fields,
                                         cols=report_fields,
                                         fact=report_facts,
                                         defaults=Storage(
                                             rows="hazard.name",
                                             cols="location.location_id",
                                             fact=report_fact_default,
                                             totals=True,
                                             table=show_table,
                                         ))
                resource.configure(report_options=report_options)
                current.deployment_settings.ui.hide_report_options = True

            if r.interactive:

                # Don't show Update/Delete button on Search table
                if r.method is None and not r.id:
                    resource.configure(editable=False, deletable=False)

                # JS to show/hide Cook Island fields
                s3.scripts.append("/%s/static/themes/DRRPP/js/drrpp.js" %
                                  current.request.application)

                if r.method == "read":
                    table_pl = s3db.project_location
                    table_l = s3db.gis_location
                    countries = [
                        row.name
                        for row in db((table_pl.project_id == r.record.id)
                                      & (table_pl.location_id == table_l.id)).
                        select(table_l.name)
                    ]
                    if not ("Cook Islands" in countries
                            and len(countries) == 1):
                        s3db.project_drrpp.L1.readable = False
                        s3db.project_drrpp.pifacc.readable = False
                        s3db.project_drrpp.jnap.readable = False

                # Filter Options
                project_hfa_opts = s3db.project_hfa_opts()
                hfa_options = dict(
                    (key, "HFA %s" % key) for key in project_hfa_opts)
                #hfa_options[None] = NONE # to search NO HFA
                project_rfa_opts = s3db.project_rfa_opts()
                rfa_options = dict(
                    (key, "RFA %s" % key) for key in project_rfa_opts)
                #rfa_options[None] = NONE # to search NO RFA
                project_pifacc_opts = s3db.project_pifacc_opts()
                pifacc_options = dict(
                    (key, "PIFACC %s" % key) for key in project_pifacc_opts)
                #pifacc_options[None] = NONE # to search NO PIFACC
                project_jnap_opts = s3db.project_jnap_opts()
                jnap_options = dict(
                    (key, "JNAP %s" % key) for key in project_jnap_opts)
                #jnap_options[None] = NONE # to search NO JNAP

                # Filter widgets
                from s3 import S3TextFilter, S3OptionsFilter, s3_get_filter_opts
                filter_widgets = [
                    S3TextFilter(["name",
                                  "code",
                                  "description",
                                  "location.location_id",
                                  "hazard.name",
                                  "theme.name",
                                  ],
                                  label = T("Search Projects"),
                                  comment = T("Search for a Project by name, code, or description."),
                                  ),
                    S3OptionsFilter("status_id",
                                    label = T("Status"),
                                    cols = 4,
                                    ),
                    S3OptionsFilter("location.location_id",
                                    label = T("Country"),
                                    cols = 3,
                                    hidden = True,
                                    ),
                    #S3OptionsFilter("drrpp.L1",
                    #                label = T("Cook Islands"),
                    #                cols = 3,
                    #                hidden = True,
                    #                ),
                    S3OptionsFilter("hazard.id",
                                    label = T("Hazard"),
                                    options = lambda: \
                                        s3_get_filter_opts("project_hazard",
                                                           translate=True),
                                    help_field = s3db.project_hazard_help_fields,
                                    cols = 4,
                                    hidden = True,
                                    ),
                    S3OptionsFilter("theme.id",
                                    label = T("Theme"),
                                    options = lambda: \
                                        s3_get_filter_opts("project_theme",
                                                           translate=True),
                                    help_field = s3db.project_theme_help_fields,
                                    cols = 4,
                                    # Don't group
                                    size = None,
                                    hidden = True,
                                    ),
                    S3OptionsFilter("drr.hfa",
                                    label = T("HFA"),
                                    options = hfa_options,
                                    help_field = project_hfa_opts,
                                    cols = 5,
                                    hidden = True,
                                    ),
                    S3OptionsFilter("drrpp.rfa",
                                    label = T("RFA"),
                                    options = rfa_options,
                                    help_field = project_rfa_opts,
                                    cols = 6,
                                    hidden = True,
                                    ),
                    S3OptionsFilter("drrpp.pifacc",
                                    label = T("PIFACC"),
                                    options = pifacc_options,
                                    help_field = project_pifacc_opts,
                                    cols = 6,
                                    hidden = True,
                                    ),
                    S3OptionsFilter("drrpp.jnap",
                                    label = T("JNAP"),
                                    options = jnap_options,
                                    help_field = project_jnap_opts,
                                    cols = 6,
                                    hidden = True,
                                    ),
                    S3OptionsFilter("organisation_id",
                                    label = T("Lead Organization"),
                                    cols = 3,
                                    hidden = True,
                                    ),
                    S3OptionsFilter("partner.organisation_id",
                                    label = T("Partners"),
                                    cols = 3,
                                    hidden = True,
                                    ),
                    S3OptionsFilter("donor.organisation_id",
                                    label = T("Donors"),
                                    cols = 3,
                                    hidden = True,
                                    )
                ]

                resource.configure(filter_widgets=filter_widgets)
            return True

        s3.prep = custom_prep

        # Custom Crud Form
        from s3.s3forms import S3SQLCustomForm, S3SQLInlineComponent, S3SQLInlineComponentCheckbox
        crud_form = S3SQLCustomForm(
            "name",
            "code",
            "description",
            "status_id",
            "start_date",
            "end_date",
            "drrpp.duration",
            S3SQLInlineComponent("location",
                                 label=T("Countries"),
                                 fields=["location_id"],
                                 orderby="location_id$name",
                                 render_list=True),
            "drrpp.L1",
            S3SQLInlineComponentCheckbox(
                "hazard",
                label=T("Hazards"),
                field="hazard_id",
                option_help="comments",
                cols=4,
            ),
            S3SQLInlineComponentCheckbox(
                "theme",
                label=T("Themes"),
                field="theme_id",
                option_help="comments",
                cols=3,
            ),
            "objectives",
            "drrpp.activities",
            # Outputs
            S3SQLInlineComponent(
                "output",
                label=T("Outputs"),
                fields=["name", "status"],
            ),
            "drr.hfa",
            "drrpp.rfa",
            "drrpp.pifacc",
            "drrpp.jnap",
            "organisation_id",
            # Partner Orgs
            S3SQLInlineComponent(
                "organisation",
                name="partner",
                label=T("Partner Organizations"),
                fields=[
                    "organisation_id",
                    "comments",  # NB This is labelled 'Role' in DRRPP
                ],
                filterby=dict(field="role", options=[2, 9]),
                default={"role": 2}),
            # Donors
            S3SQLInlineComponent("organisation",
                                 name="donor",
                                 label=T("Donor(s)"),
                                 fields=[
                                     "organisation_id",
                                     "amount",
                                     "currency",
                                 ],
                                 filterby=dict(field="role", options=[3]),
                                 default={"role": 3}),
            "budget",
            "drrpp.local_budget",
            "drrpp.local_currency",
            "drrpp.focal_person",
            "drrpp.organisation_id",
            "drrpp.email",
            # Files
            S3SQLInlineComponent("document",
                                 name="file",
                                 label=T("Files"),
                                 fields=["file", "comments"],
                                 filterby=dict(
                                     field="file",
                                     options="",
                                     invert=True,
                                 )),
            # Links
            S3SQLInlineComponent("document",
                                 name="url",
                                 label=T("Links"),
                                 fields=["url", "comments"],
                                 filterby=dict(
                                     field="url",
                                     options=None,
                                     invert=True,
                                 )),
            "drrpp.parent_project",
            "comments",
        )

        s3db.configure(
            tablename,
            crud_form=crud_form,
            subheadings={
                1: "hazard",
                2: "theme",
                3: "objectives",
                4: "drr_hfa",
                5: "drrpp_rfa",
                6: "drrpp_pifacc",
                7: "drrpp_jnap",
                8: "organisation_id",
            },
        )

        return attr
Esempio n. 5
0
 "organisation_id",
 "name",
 "code",
 "description",
 "status_id",
 "start_date",
 "end_date",
 #S3SQLInlineComponentCheckbox(
 #    "hazard",
 #    label = T("Hazards"),
 #    field = "hazard_id",
 #    cols = 4,
 #),
 S3SQLInlineComponentCheckbox(
     "sector",
     label=T("Sectors"),
     field="sector_id",
     cols=4,
 ),
 #S3SQLInlineComponent(
 #    "location",
 #    label = T("Locations"),
 #    fields = ["location_id"],
 #),
 S3SQLInlineComponentCheckbox(
     "theme",
     label=T("Themes"),
     field="theme_id",
     cols=4,
     # Filter Theme by Sector
     #            filter = {"linktable": "project_theme_sector",
     #                      "lkey": "theme_id",
Esempio n. 6
0
def customize_project_project(**attr):
    """
        Customize project_project controller
    """

    s3db = current.s3db
    tablename = "project_project"
    # Load normal model
    table = s3db[tablename]

    # @ToDo: S3SQLInlineComponent for Project orgs
    # Get IDs for PartnerNS/Partner-Donor
    # db = current.db
    # ttable = db.org_organisation_type
    # rows = db(ttable.deleted != True).select(ttable.id,
    # ttable.name,
    # )
    # rc = []
    # not_rc = []
    # nappend = not_rc.append
    # for row in rows:
    # if row.name == "Red Cross / Red Crescent":
    # rc.append(row.id)
    # elif row.name == "Supplier":
    # pass
    # else:
    # nappend(row.id)

    # Custom Fields
    # Organisation needs to be an NS (not a branch)
    f = table.organisation_id
    ns_only(
        f,
        required=True,
        branches=False,
    )
    f.label = T("Host National Society")

    # Custom Crud Form
    crud_form = S3SQLCustomForm(
        "organisation_id",
        "name",
        "code",
        "description",
        "status_id",
        "start_date",
        "end_date",
        #S3SQLInlineComponent(
        #    "location",
        #    label = T("Countries"),
        #    fields = ["location_id"],
        #),
        # Outputs
        S3SQLInlineComponent(
            "output",
            label=T("Outputs"),
            #comment = "Bob",
            fields=["name", "status"],
        ),
        S3SQLInlineComponentCheckbox(
            "hazard",
            label=T("Hazards"),
            field="hazard_id",
            cols=4,
        ),
        S3SQLInlineComponentCheckbox(
            "sector",
            label=T("Sectors"),
            field="sector_id",
            cols=4,
        ),
        S3SQLInlineComponentCheckbox(
            "theme",
            label=T("Themes"),
            field="theme_id",
            cols=4,
            # Filter Theme by Sector
            filter={
                "linktable": "project_theme_sector",
                "lkey": "theme_id",
                "rkey": "sector_id",
            },
            script='''
S3OptionsFilter({
 'triggerName':'defaultsector-sector_id',
 'targetName':'defaulttheme-theme_id',
 'targetWidget':'defaulttheme-theme_id_widget',
 'lookupResource':'theme',
 'lookupURL':S3.Ap.concat('/project/theme_sector_widget?sector_ids='),
 'getWidgetHTML':true,
 'showEmptyField':false
})'''),
        "drr.hfa",
        "objectives",
        "human_resource_id",
        # Disabled since we need organisation_id filtering to either organisation_type_id == RC or NOT
        # & also hiding Branches from RCs
        # Partner NS
        # S3SQLInlineComponent(
        # "organisation",
        # name = "partnerns",
        # label = T("Partner National Societies"),
        # fields = ["organisation_id",
        # "comments",
        # ],
        # Filter Organisation by Type
        # filter = ["organisation_id": {"filterby": "organisation_type_id",
        # "filterfor": rc,
        # }],
        # filterby = dict(field = "role",
        # options = [9])
        # ),
        # Partner Orgs
        # S3SQLInlineComponent(
        # "organisation",
        # name = "partner",
        # label = T("Partner Organizations"),
        # fields = ["organisation_id",
        # "comments",
        # ],
        # Filter Organisation by Type
        # filter = ["organisation_id": {"filterby": "organisation_type_id",
        # "filterfor": not_rc,
        # }],
        # filterby = dict(field = "role",
        # options = [2])
        # ),
        # Donors
        # S3SQLInlineComponent(
        # "organisation",
        # name = "donor",
        # label = T("Donor(s)"),
        # fields = ["organisation_id",
        # "amount",
        # "currency"],
        # Filter Organisation by Type
        # filter = ["organisation_id": {"filterby": "organisation_type_id",
        # "filterfor": not_rc,
        # }],
        # filterby = dict(field = "role",
        # options = [3])
        # ),
        #"budget",
        #"currency",
        "comments",
    )

    s3db.configure(tablename, crud_form=crud_form)

    return attr
Esempio n. 7
0
    return attr


settings.ui.customize_project_project = customize_project_project

settings.ui.crud_form_project_location = S3SQLCustomForm(
    "project_id",
    "location_id",
    # @ToDo: Grouped Checkboxes
    S3SQLInlineComponentCheckbox(
        "activity_type",
        label=T("Activity Types"),
        field="activity_type_id",
        cols=3,
        # Filter Activity Type by Sector
        filter={
            "linktable": "project_activity_type_sector",
            "lkey": "activity_type_id",
            "rkey": "sector_id",
            "lookuptable": "project_project",
            "lookupkey": "project_id",
        },
    ),
    "comments",
)

# -----------------------------------------------------------------------------
# Inventory Management
settings.inv.show_mode_of_transport = True
settings.inv.send_show_time_in = True

# -----------------------------------------------------------------------------
Esempio n. 8
0
    def custom_prep(r):
        # Call standard prep
        if callable(standard_prep):
            result = standard_prep(r)
        else:
            result = True

        if r.interactive or r.representation == "aadata":
            s3db = current.s3db
            list_fields = ["id",
                           "name",
                           "acronym",
                           "organisation_type_id",
                           (T("Clusters"), "sector.name"),
                           "country",
                           "website"
                           ]
            
            s3db.configure("org_organisation", list_fields=list_fields)
        
        if r.interactive:
            from s3.s3forms import S3SQLCustomForm, S3SQLInlineComponentCheckbox
            crud_form = S3SQLCustomForm(
                "name",
                "acronym",
                "organisation_type_id",
                "region_id",
                "country",
                S3SQLInlineComponentCheckbox(
                    "sector",
                    label = T("Clusters"),
                    field = "sector_id",
                    cols = 3,
                ),
                "phone",
                "website",
                "year",
                "logo",
                "comments",
            )
            from s3.s3filter import S3TextFilter, S3OptionsFilter, S3LocationFilter
            filter_widgets = [
                S3TextFilter(["name", "acronym"],
                             label=T("Name"),
                             _class="filter-search",
                             ),
                S3OptionsFilter("organisation_type_id",
                                label=T("Type"),
                                represent="%(name)s",
                                widget="multiselect",
                                cols=3,
                                #hidden=True,
                                ),
                S3OptionsFilter("sector_organisation.sector_id",
                                label=T("Cluster"),
                                represent="%(name)s",
                                widget="multiselect",
                                cols=3,
                                #hidden=True,
                                ),
                S3OptionsFilter("project_organisation.project_id$theme_project.theme_id",
                                label=T("Theme"),
                                represent="%(name)s",
                                widget="multiselect",
                                cols=3,
                                #hidden=True,
                                ),
                S3LocationFilter("project_organisation.project_id$location.location_id",
                                 label=T("Location"),
                                 levels=["L1", "L2"],
                                 widget="multiselect",
                                 cols=3,
                                 #hidden=True,
                                 ),
                ]
            s3db.configure("org_organisation",
                           crud_form=crud_form,
                           filter_widgets = filter_widgets,
                           )
            
        return result
Esempio n. 9
0
def customize_project_project(**attr):
    """
        Customize project_project controller
    """

    db = current.db
    s3db = current.s3db
    s3 = current.response.s3
    tablename = "project_project"
    # Load normal model
    table = s3db[tablename]

    # Custom Components
    add_component = s3db.add_component
    add_component("project_drrpp",
                  project_project=Storage(joinby="project_id", multiple=False))
    add_component("project_output", project_project="project_id")
    add_component("doc_document",
                  project_project=dict(
                      name="file",
                      joinby="doc_id",
                      filterby="url",
                      filterfor=["", None],
                  ))
    add_component("doc_document",
                  project_project=dict(
                      name="url",
                      joinby="doc_id",
                      filterby="file",
                      filterfor=["", None],
                  ))

    # Custom CRUD Strings
    crud_strings = s3.crud_strings
    crud_strings.project_project.title_search = T("Project List")

    # Custom Fields
    table.name.label = T("Project Title")
    s3db.project_project.budget.label = T("Total Funding (USD)")
    location_id = s3db.project_location.location_id
    location_id.label = ""
    # Limit to just Countries
    location_id.requires = s3db.gis_country_requires
    # Use dropdown, not AC
    location_id.widget = None
    # In DRRPP this is a free field
    table = s3db.project_organisation
    table.comments.label = T("Role")
    table.comments.widget = SQLFORM.widgets.string.widget
    table.amount.label = T("Amount")
    table = s3db.doc_document
    table.file.widget = lambda field, value, download_url: \
        SQLFORM.widgets.upload.widget(field, value, download_url, _size = 15)
    table.comments.widget = SQLFORM.widgets.string.widget

    # If not logged in, contact person is required
    logged_in = current.auth.is_logged_in()
    if not logged_in:
        table = s3db.project_drrpp
        table.focal_person.required = True
        table.email.required = True
        table.email.requires = IS_EMAIL()

    # Custom dataTable
    s3["dataTable_sDom"] = 'ripl<"dataTable_table"t>p'

    # Don't show export buttons for XLS/XML
    s3.formats = Storage(xls=None, xml=None)

    # Remove rheader
    attr["rheader"] = None

    # Only show 10 Project by default to improve load time
    attr["dt_lengthMenu"] = [[10, 50, -1], [10, 50, T("All")]]
    s3.dataTable_iDisplayLength = 10

    # Custom PreP
    standard_prep = s3.prep

    def custom_prep(r):
        # Call standard prep
        if callable(standard_prep):
            result = standard_prep(r)
            if not result:
                return False

        if r.method == "review":
            list_fields = [
                "id",
                "created_on",
                "modified_on",
                "name",
                "start_date",
                (T("Countries"), "location.location_id"),
                (T("Hazards"), "hazard.name"),
                (T("Lead Organization"), "organisation_id"),
                (T("Donors"), "donor.organisation_id"),
            ]
            s3db.configure(tablename, list_fields=list_fields)

        if r.interactive:
            # Don't show Update/Delete button on Search table
            if r.method == "search":
                s3db.configure(tablename, editable=False, deletable=False)

            # JS to show/hide Cook Island fileds
            s3.scripts.append("/%s/static/themes/DRRPP/js/drrpp.js" %
                              current.request.application)

            if r.method == "read":
                table_pl = s3db.project_location
                table_l = s3db.gis_location
                countries = [
                    row.name
                    for row in db((table_pl.project_id == r.record.id)
                                  & (table_pl.location_id == table_l.id)).
                    select(table_l.name)
                ]
                if not ("Cook Islands" in countries and len(countries) == 1):
                    s3db.project_drrpp.L1.readable = False
                    s3db.project_drrpp.pifacc.readable = False
                    s3db.project_drrpp.jnap.readable = False

        elif r.representation == "xls":
            # All readable Fields should be exported
            list_fields = [
                "id",
                "name",
                "code",
                "description",
                "status_id",
                "start_date",
                "end_date",
                "drrpp.duration",
                (T("Countries"), "location.location_id"),
                "drrpp.L1",
                (T("Hazards"), "hazard.name"),
                (T("Themes"), "theme.name"),
                "objectives",
                "drrpp.activities",
                "output.name",
                "drr.hfa",
                "drrpp.rfa",
                "drrpp.pifacc",
                "drrpp.jnap",
                (T("Lead Organization"), "organisation_id"),
                (T("Partners"), "partner.organisation_id"),
                (T("Donors"), "donor.organisation_id"),
                "budget",
                "currency",
                "drrpp.focal_person",
                "drrpp.organisation_id",
                "drrpp.email",
                "url.url",
                "drrpp.parent_project",
                "comments",
            ]
            if logged_in:
                list_fields.extend([
                    "created_by",
                    "created_on",
                    "modified_by",
                    "modified_on",
                ])
            s3db.configure(tablename, list_fields=list_fields)
        return True

    s3.prep = custom_prep

    # Custom List Fields
    list_fields = [
        "id",
        "name",
        "start_date",
        (T("Countries"), "location.location_id"),
        (T("Hazards"), "hazard.name"),
        (T("Lead Organization"), "organisation_id"),
        (T("Donors"), "donor.organisation_id"),
    ]

    # Custom Search Fields
    from s3.s3search import S3Search, S3SearchSimpleWidget, S3SearchOptionsWidget
    simple = [
        S3SearchSimpleWidget(
            name="project_search_text_simple",
            label=T("Search Projects"),
            comment=T("Search for a Project by name, code, or description."),
            field=[
                "name",
                "code",
                "description",
                "location.location_id",
                "hazard.name",
                "theme.name",
            ]),
        S3SearchOptionsWidget(
            name="project_search_status_simple",
            label=T("Status"),
            field="status_id",
            cols=4,
        ),
    ]

    project_hfa_opts = s3db.project_hfa_opts()
    hfa_options = {}
    #hfa_options = {None:NONE} To search NO HFA
    for key in project_hfa_opts.keys():
        hfa_options[key] = "HFA %s" % key

    project_rfa_opts = s3db.project_rfa_opts()
    rfa_options = {}
    #rfa_options = {None:NONE} To search NO RFA
    for key in project_rfa_opts.keys():
        rfa_options[key] = "RFA %s" % key

    project_pifacc_opts = s3db.project_pifacc_opts()
    pifacc_options = {}
    #pifacc_options = {None:NONE} To search NO pifacc
    for key in project_pifacc_opts.keys():
        pifacc_options[key] = "PIFACC %s" % key

    project_jnap_opts = s3db.project_jnap_opts()
    jnap_options = {}
    #jnap_options = {None:NONE} To search NO jnap
    for key in project_jnap_opts.keys():
        jnap_options[key] = "JNAP %s" % key

    advanced = [
        S3SearchSimpleWidget(
            name="project_search_text_advanced",
            label=T("Search Projects"),
            comment=T("Search for a Project by name, code, or description."),
            field=[
                "name",
                "code",
                "description",
                "location.location_id",
                "hazard.name",
                "theme.name",
            ]),
        S3SearchOptionsWidget(
            name="project_search_status_advanced",
            label=T("Status"),
            field="status_id",
            cols=4,
        ),
        S3SearchOptionsWidget(name="project_search_location",
                              label=T("Country"),
                              field="location.location_id",
                              cols=3),
        #S3SearchOptionsWidget(name = "project_search_L1",
        #                      label = T("Cook Islands"),
        #                      field = "drrpp.L1",
        #                      cols = 3
        #                      ),
        S3SearchOptionsWidget(name="project_search_hazard",
                              label=T("Hazard"),
                              field="hazard.id",
                              options=s3db.project_hazard_opts,
                              help_field=s3db.project_hazard_helps,
                              cols=4),
        S3SearchOptionsWidget(
            name="project_search_theme",
            label=T("Theme"),
            field="theme.id",
            options=s3db.project_theme_opts,
            help_field=s3db.project_theme_helps,
            cols=4,
            # Don't group
            size=30),
        S3SearchOptionsWidget(name="project_search_hfa",
                              label=T("HFA"),
                              field="drr.hfa",
                              options=hfa_options,
                              help_field=project_hfa_opts,
                              cols=5),
        S3SearchOptionsWidget(name="project_search_rfa",
                              label=T("RFA"),
                              field="drrpp.rfa",
                              options=rfa_options,
                              help_field=project_rfa_opts,
                              cols=6),
        S3SearchOptionsWidget(name="project_search_pifacc",
                              label=T("PIFACC"),
                              field="drrpp.pifacc",
                              options=pifacc_options,
                              help_field=project_pifacc_opts,
                              cols=6),
        S3SearchOptionsWidget(name="project_search_jnap",
                              label=T("JNAP"),
                              field="drrpp.jnap",
                              options=jnap_options,
                              help_field=project_jnap_opts,
                              cols=6),
        S3SearchOptionsWidget(name="project_search_organisation_id",
                              label=T("Lead Organisation"),
                              field="organisation_id",
                              cols=3),
        S3SearchOptionsWidget(
            name="project_search_partners",
            field="partner.organisation_id",
            label=T("Partners"),
            cols=3,
        ),
        S3SearchOptionsWidget(
            name="project_search_donors",
            field="donor.organisation_id",
            label=T("Donors"),
            cols=3,
        )
    ]
    search_method = S3Search(simple=simple, advanced=advanced)

    # Custom Report Fields
    report_fields = [
        "name",
        (T("Countries"), "location.location_id"),
        (T("Hazards"), "hazard.name"),
        (T("Themes"), "theme.name"),
        (T("HFA Priorities"), "drr.hfa"),
        (T("RFA Priorities"), "drrpp.rfa"),
        (T("Lead Organization"), "organisation_id"),
        (T("Partner Organizations"), "partner.organisation_id"),
        (T("Donors"), "donor.organisation_id"),
    ]
    # Report Settings for charts
    if "chart" in current.request.vars:
        crud_strings[tablename].title_report = T("Project Graph")
        report_fact_fields = [("project.name", "count")]
        report_fact_default = "project.name"
    else:
        crud_strings[tablename].title_report = T("Project Matrix")
        report_fact_fields = [(field, "count") for field in report_fields]
        report_fact_default = "theme.name"
    report_options = Storage(search=advanced,
                             rows=report_fields,
                             cols=report_fields,
                             fact=report_fact_fields,
                             defaults=Storage(rows="hazard.name",
                                              cols="location.location_id",
                                              fact=report_fact_default,
                                              aggregate="count",
                                              totals=True))

    # Custom Crud Form
    from s3.s3forms import S3SQLCustomForm, S3SQLInlineComponent, S3SQLInlineComponentCheckbox
    crud_form = S3SQLCustomForm(
        "name",
        "code",
        "description",
        "status_id",
        "start_date",
        "end_date",
        "drrpp.duration",
        S3SQLInlineComponent("location",
                             label=T("Countries"),
                             fields=["location_id"],
                             orderby="location_id$name",
                             render_list=True),
        "drrpp.L1",
        S3SQLInlineComponentCheckbox(
            "hazard",
            label=T("Hazards"),
            field="hazard_id",
            option_help="comments",
            cols=4,
        ),
        S3SQLInlineComponentCheckbox(
            "theme",
            label=T("Themes"),
            field="theme_id",
            option_help="comments",
            cols=3,
        ),
        "objectives",
        "drrpp.activities",
        # Outputs
        S3SQLInlineComponent(
            "output",
            label=T("Outputs"),
            fields=["name", "status"],
        ),
        "drr.hfa",
        "drrpp.rfa",
        "drrpp.pifacc",
        "drrpp.jnap",
        "organisation_id",
        # Partner Orgs
        S3SQLInlineComponent(
            "organisation",
            name="partner",
            label=T("Partner Organizations"),
            fields=[
                "organisation_id",
                "comments",  # NB This is labelled 'Role' in DRRPP
            ],
            filterby=dict(field="role", options=[2, 9]),
            default={"role": 2}),
        # Donors
        S3SQLInlineComponent("organisation",
                             name="donor",
                             label=T("Donor(s)"),
                             fields=[
                                 "organisation_id",
                                 "amount",
                                 "currency",
                             ],
                             filterby=dict(field="role", options=[3]),
                             default={"role": 3}),
        "budget",
        "drrpp.local_budget",
        "drrpp.local_currency",
        "drrpp.focal_person",
        "drrpp.organisation_id",
        "drrpp.email",
        # Files
        S3SQLInlineComponent("document",
                             name="file",
                             label=T("Files"),
                             fields=["file", "comments"],
                             filterby=dict(
                                 field="file",
                                 options="",
                                 invert=True,
                             )),
        # Links
        S3SQLInlineComponent("document",
                             name="url",
                             label=T("Links"),
                             fields=["url", "comments"],
                             filterby=dict(
                                 field="url",
                                 options=None,
                                 invert=True,
                             )),
        "drrpp.parent_project",
        "comments",
    )

    s3db.configure(
        tablename,
        crud_form=crud_form,
        list_fields=list_fields,
        report_options=report_options,
        search_method=search_method,
        subheadings={
            1: "hazard",
            2: "theme",
            3: "objectives",
            4: "drr_hfa",
            5: "drrpp_rfa",
            6: "drrpp_pifacc",
            7: "drrpp_jnap",
            8: "organisation_id",
        },
    )

    return attr
Esempio n. 10
0
def customise_project_project_resource(r, tablename):
    from s3.s3forms import S3SQLCustomForm, S3SQLInlineComponentCheckbox
    crud_form = S3SQLCustomForm(
        "organisation_id",
        "name",
        "code",
        "description",
        "status_id",
        "start_date",
        "end_date",
        #S3SQLInlineComponentCheckbox(
        #    "hazard",
        #    label = T("Hazards"),
        #    field = "hazard_id",
        #    cols = 4,
        #),
        S3SQLInlineComponentCheckbox(
            "sector",
            label=T("Sectors"),
            field="sector_id",
            cols=4,
        ),
        #S3SQLInlineComponent(
        #    "location",
        #    label = T("Locations"),
        #    fields = ["location_id"],
        #),
        S3SQLInlineComponentCheckbox(
            "theme",
            label=T("Themes"),
            field="theme_id",
            cols=4,
            # Filter Theme by Sector
            #            filter = {"linktable": "project_theme_sector",
            #                      "lkey": "theme_id",
            #                      "rkey": "sector_id",
            #                      },
            #            script = '''
            #S3OptionsFilter({
            # 'triggerName':'defaultsector-sector_id',
            # 'targetName':'defaulttheme-theme_id',
            # 'targetWidget':'defaulttheme-theme_id_widget',
            # 'lookupResource':'theme',
            # 'lookupURL':S3.Ap.concat('/project/theme_sector_widget?sector_ids='),
            # 'getWidgetHTML':true,
            # 'showEmptyField':false
            #})'''
        ),
        #"drr.hfa",
        "objectives",
        "human_resource_id",
        # Partner Orgs
        #S3SQLInlineComponent(
        #    "organisation",
        #    name = "partner",
        #    label = T("Partner Organizations"),
        #    fields = ["organisation_id",
        #              "comments",
        #              ],
        #    filterby = dict(field = "role",
        #                    options = "2"
        #                    )
        #),
        # Donors
        #S3SQLInlineComponent(
        #    "organisation",
        #    name = "donor",
        #    label = T("Donor(s)"),
        #    fields = ["organisation_id",
        #              "amount",
        #              "currency"],
        #    filterby = dict(field = "role",
        #                    options = "3"
        #                    )
        #),
        #"budget",
        #"currency",
        "comments",
    )

    current.s3db.configure(
        tablename,
        crud_form=crud_form,
    )
Esempio n. 11
0
    def custom_prep(r):
        # Call standard prep
        if callable(standard_prep):
            result = standard_prep(r)
        else:
            result = True

        if r.interactive or r.representation == "aadata":
            from s3.s3forms import S3SQLCustomForm, S3SQLInlineComponent, S3SQLInlineComponentCheckbox
            s3db = current.s3db

            table = r.table
            table.code.label = T("Project blurb (max. 100 characters)")
            table.code.max_length = 100
            table.comments.label = T("How people can help")

            script = '''$('#project_project_code').attr('maxlength','100')'''
            s3.jquery_ready.append(script)

            crud_form = S3SQLCustomForm(
                "organisation_id",
                "name",
                "code",
                "description",
                "status_id",
                "start_date",
                "end_date",
                "calendar",
                #"drr.hfa",
                #"objectives",
                "human_resource_id",
                # Activities
                S3SQLInlineComponent(
                    "location",
                    label=T("Location"),
                    fields=["location_id"],
                ),
                # Partner Orgs
                S3SQLInlineComponent(
                    "organisation",
                    name="partner",
                    label=T("Partner Organizations"),
                    fields=[
                        "organisation_id",
                        "comments",  # NB This is labelled 'Role' in DRRPP
                    ],
                    filterby=dict(field="role", options="2")),
                S3SQLInlineComponent(
                    "document",
                    name="media",
                    label=T(
                        "URLs (media, fundraising, website, social media, etc."
                    ),
                    fields=[
                        "document_id",
                        "name",
                        "url",
                        "comments",
                    ],
                    filterby=dict(field="name")),
                S3SQLInlineComponentCheckbox(
                    "activity_type",
                    label=T("Categories"),
                    field="activity_type_id",
                    cols=3,
                    # Filter Activity Type by Project
                    filter={
                        "linktable": "project_activity_type_project",
                        "lkey": "project_id",
                        "rkey": "activity_type_id",
                    },
                ),
                #"budget",
                #"currency",
                "comments",
            )

            s3db.configure("project_project", crud_form=crud_form)

        return result
Esempio n. 12
0
    def custom_prep(r):
        # Call standard prep
        if callable(standard_prep):
            result = standard_prep(r)
        else:
            result = True

        if r.interactive or r.representation.lower() == "aadata":
            list_fields = [
                "id",
                "name",
                "acronym",
                "organisation_type_id",
                (T("Services"), "service.name"),
                (T("Neighborhoods Served"), "location.name"),
            ]
            s3db.configure("org_organisation", list_fields=list_fields)

        if r.interactive:
            from s3.s3forms import S3SQLCustomForm, S3SQLInlineComponent, S3SQLInlineComponentCheckbox
            s3db.pr_address.comments.label = ""
            s3db.pr_contact.value.label = ""
            crud_form = S3SQLCustomForm(
                "name",
                "acronym",
                "organisation_type_id",
                S3SQLInlineComponentCheckbox(
                    "service",
                    label=T("Services"),
                    field="service_id",
                    cols=4,
                ),
                S3SQLInlineComponentCheckbox(
                    "group",
                    label=T("Network"),
                    field="group_id",
                    cols=3,
                ),
                S3SQLInlineComponent(
                    "address",
                    label=T("Address"),
                    multiple=False,
                    # This is just Text - put into the Comments box for now
                    # Ultimately should go into location_id$addr_street
                    fields=["comments"],
                ),
                S3SQLInlineComponentCheckbox(
                    "location",
                    label=T("Neighborhoods Served"),
                    field="location_id",
                    filterby=dict(field="level", options="L4"),
                    cols=5,
                ),
                "phone",
                S3SQLInlineComponent("contact",
                                     name="phone2",
                                     label=T("Phone2"),
                                     multiple=False,
                                     fields=["value"],
                                     filterby=dict(field="contact_method",
                                                   options="WORK_PHONE")),
                S3SQLInlineComponent("contact",
                                     name="email",
                                     label=T("Email"),
                                     multiple=False,
                                     fields=["value"],
                                     filterby=dict(field="contact_method",
                                                   options="EMAIL")),
                "website",
                S3SQLInlineComponent("contact",
                                     name="rss",
                                     label=T("RSS"),
                                     multiple=False,
                                     fields=["value"],
                                     filterby=dict(field="contact_method",
                                                   options="RSS")),
                S3SQLInlineComponent("contact",
                                     name="twitter",
                                     label=T("Twitter"),
                                     multiple=False,
                                     fields=["value"],
                                     filterby=dict(field="contact_method",
                                                   options="TWITTER")),
                "comments",
            )

            from s3.s3filter import S3LocationFilter, S3OptionsFilter, S3TextFilter
            filter_widgets = [
                S3TextFilter(
                    ["name", "acronym"],
                    label=T("Name"),
                    _class="filter-search",
                ),
                S3OptionsFilter(
                    "group_membership.group_id",
                    label=T("Network"),
                    represent="%(name)s",
                    widget="multiselect",
                    cols=3,
                    #hidden=True,
                ),
                S3LocationFilter(
                    "organisation_location.location_id",
                    label=T("Neighborhood"),
                    levels=["L3", "L4"],
                    widget="multiselect",
                    cols=3,
                    #hidden=True,
                ),
                S3OptionsFilter(
                    "service_organisation.service_id",
                    label=T("Service"),
                    represent="%(name)s",
                    widget="multiselect",
                    cols=3,
                    #hidden=True,
                ),
                S3OptionsFilter(
                    "organisation_type_id",
                    label=T("Type"),
                    represent="%(name)s",
                    widget="multiselect",
                    cols=3,
                    #hidden=True,
                ),
            ]
            from s3.s3search import S3Search, S3SearchSimpleWidget, S3SearchOptionsWidget
            search_method = S3Search(
                simple=(),
                advanced=(
                    S3SearchSimpleWidget(
                        name="org_search_text_advanced",
                        label=T("Name"),
                        comment=T(
                            "Search for an Organization by name or acronym"),
                        field=["name", "acronym"]),
                    S3SearchOptionsWidget(name="org_search_network",
                                          label=T("Network"),
                                          field="group.name",
                                          cols=2),
                    S3SearchOptionsWidget(name="org_search_location",
                                          label=T("Neighborhood"),
                                          field="location.L4",
                                          location_level="L4",
                                          cols=2),
                    S3SearchOptionsWidget(name="org_search_service",
                                          label=T("Services"),
                                          field="service.name",
                                          cols=2),
                    S3SearchOptionsWidget(name="org_search_type",
                                          label=T("Type"),
                                          field="organisation_type_id",
                                          cols=2),
                ))
            s3db.configure(
                "org_organisation",
                crud_form=crud_form,
                # @ToDo: Style & Enable
                #filter_widgets = filter_widgets,
                search_method=search_method,
            )

        return result
Esempio n. 13
0
    def custom_prep(r):
        # Call standard prep
        if callable(standard_prep):
            result = standard_prep(r)
        else:
            result = True

        if r.interactive or r.representation == "aadata":
            from s3.s3forms import S3SQLCustomForm, S3SQLInlineComponent, S3SQLInlineComponentCheckbox
            s3db = current.s3db

            table = r.table
            tablename = "project_project"
            table.code.label = T("Project blurb (max. 100 characters)")
            table.code.max_length = 100 
            table.comments.label = T("How people can help")

            script = '''$('#project_project_code').attr('maxlength','100')'''
            s3.jquery_ready.append(script)

            crud_form = S3SQLCustomForm(
                "organisation_id",
                "name",
                "code",        
                "description",
                "status_id",
                "start_date",
                "end_date",
                "calendar",
                #"drr.hfa",
                #"objectives",
                "human_resource_id",
                # Activities
                S3SQLInlineComponent(
                    "location",
                    label = T("Location"),
                    fields = ["location_id"],
                ),
                # Partner Orgs
                S3SQLInlineComponent(
                    "organisation",
                    name = "partner",
                    label = T("Partner Organizations"),
                    fields = ["organisation_id",
                              "comments", # NB This is labelled 'Role' in DRRPP
                              ],
                    filterby = dict(field = "role",
                    options = "2"
                    )
                ),
                S3SQLInlineComponent(
                    "document",
                    name = "media",
                    label = T("URLs (media, fundraising, website, social media, etc."),
                    fields = ["document_id",
                              "name",
                              "url",
                              "comments",
                              ],
                    filterby = dict(field = "name")
                ),                                                                
                S3SQLInlineComponentCheckbox(
                    "activity_type",
                    label = T("Categories"),
                    field = "activity_type_id",
                    cols = 3,
                    # Filter Activity Type by Project
                    filter = {"linktable": "project_activity_type_project",
                              "lkey": "project_id",
                              "rkey": "activity_type_id",
                              },
                ),
                #"budget",
                #"currency",
                "comments",
            )
            
            from s3.s3filter import S3TextFilter, S3OptionsFilter, S3LocationFilter, S3DateFilter
            filter_widgets = [
                S3TextFilter(["name",
                              "code",
                              "description",
                              "organisation.name",
                              "organisation.acronym",
                              ],
                             label=T("Name"),
                             _class="filter-search",
                             ),
                S3OptionsFilter("status_id",
                                label=T("Status"),
                                represent="%(name)s",
                                cols=3,
                                ),
                #S3OptionsFilter("theme_project.theme_id",
                #                label=T("Theme"),
                #                represent="%(name)s",
                #                widget="multiselect",
                #                #hidden=True,
                #                ),
                S3LocationFilter("location.location_id",
                                 label=T("Location"),
                                 levels=["L1", "L2", "L3", "L4"],
                                 widget="multiselect",
                                 #hidden=True,
                                 ),
                # @ToDo: Widget to handle Start & End in 1!
                S3DateFilter("start_date",
                             label=T("Start Date"),
                             hide_time=True,
                             #hidden=True,
                             ),
                S3DateFilter("end_date",
                             label=T("End Date"),
                             hide_time=True,
                             #hidden=True,
                             ),
                ]

            list_fields = ["id",
                           "name",
                           "code",
                           "organisation_id",
                           "start_date",
                           "end_date",
                           (T("Locations"), "location.location_id"),
                           ]

            s3db.configure(tablename,
                           crud_form = crud_form,
                           filter_widgets = filter_widgets,
                           list_fields = list_fields,
                           )

        return result