Esempio n. 1
0
def customize_project_project(**attr):
    s3db = current.s3db
    s3 = current.response.s3

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

    location_id = s3db.project_location.location_id
    # Limit to just Countries
    location_id.requires = s3db.gis_location_id
    # Use dropdown, not AC
    #location_id.widget = s3.s3widgets.S3LocationAutocompleteWidget()

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

    from s3 import s3forms

    crud_form = s3forms.S3SQLCustomForm(
        "organisation_id",
        "name",
        "code",        
        "description",
        "status_id",
        "start_date",
        "end_date",
        "calendar",
        #"drr.hfa",
        #"objectives",
        "human_resource_id",
        # Activities
       s3forms.S3SQLInlineComponent(
            "location",
            label = T("Location"),
            fields = ["location_id"],
        ),
        # Partner Orgs
        s3forms.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"
         )
        ),
        s3forms.S3SQLInlineComponent(
         "document",
         name = "media",
         label = T("URLs (media, fundraising, website, social media, etc."),
         fields = ["document_id",
         "name",
         "url",
         "comments",
         ],
         filterby = dict(field = "name")
        ),                                                                
        s3forms.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(tablename, crud_form = crud_form)
    
    return attr
Esempio n. 2
0
def customize_project_project(**attr):
    """
        Customize project_project controller
    """

    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")

    # 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

    # 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

    # 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.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)

        elif r.representation == "xls":
            # All readable Fields should be exported
            list_fields = [
                "id",
                "name",
                "code",
                "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",
            ]
            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
    S3SearchSimpleWidget = s3search.S3SearchSimpleWidget
    S3SearchOptionsWidget = s3search.S3SearchOptionsWidget
    status_search_widget = S3SearchOptionsWidget(
        name="project_search_status",
        label=T("Status"),
        field="status_id",
        cols=4,
    )
    simple = [
        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",
            ]),
        status_search_widget,
    ]

    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 = [
        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.S3Search(simple=simple,
                                      advanced=simple + advanced)

    # Custom Report Fields
    report_fields = [
        (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.id", "count")]
        report_fact_default = "project.id"
    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=[status_search_widget] + 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
    crud_form = s3forms.S3SQLCustomForm(
        "name",
        "code",
        "status_id",
        "start_date",
        "end_date",
        "drrpp.duration",
        s3forms.S3SQLInlineComponent("location",
                                     label=T("Countries"),
                                     fields=["location_id"],
                                     orderby="location_id$name",
                                     render_list=True),
        "drrpp.L1",
        s3forms.S3SQLInlineComponentCheckbox(
            "hazard",
            label=T("Hazards"),
            field="hazard_id",
            option_help="comments",
            cols=4,
        ),
        s3forms.S3SQLInlineComponentCheckbox(
            "theme",
            label=T("Themes"),
            field="theme_id",
            option_help="comments",
            cols=3,
        ),
        "objectives",
        "drrpp.activities",
        # Outputs
        s3forms.S3SQLInlineComponent(
            "output",
            label=T("Outputs"),
            #comment = "Bob",
            fields=["name", "status"],
        ),
        "drr.hfa",
        "drrpp.rfa",
        "drrpp.pifacc",
        "drrpp.jnap",
        "organisation_id",
        # Partner Orgs
        s3forms.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")),
        # Donors
        s3forms.S3SQLInlineComponent(
            "organisation",
            name="donor",
            label=T("Donor(s)"),
            fields=["organisation_id", "amount", "currency"],
            filterby=dict(field="role", options="3")),
        "budget",
        "drrpp.local_budget",
        "drrpp.local_currency",
        "drrpp.focal_person",
        "drrpp.organisation_id",
        "drrpp.email",
        # Files
        s3forms.S3SQLInlineComponent("document",
                                     name="file",
                                     label=T("Files"),
                                     fields=["file", "comments"],
                                     filterby=dict(
                                         field="file",
                                         options="",
                                         invert=True,
                                     )),
        # Links
        s3forms.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. 3
0
settings.ui.formstyle_row = formstyle_row
settings.ui.formstyle = formstyle_row

from s3 import s3forms
settings.ui.crud_form_project_project = s3forms.S3SQLCustomForm(
    "organisation_id",
    "name",
    "description",
    "status_id",
    "start_date",
    "end_date",
    "calendar",
    "human_resource_id",
    s3forms.S3SQLInlineComponentCheckbox(
        "sector",
        label=T("Sectors"),
        field="sector_id",
        cols=4,
    ),
    "budget",
    "currency",
    "comments",
)

# Comment/uncomment modules here to disable/enable them
settings.modules = OrderedDict([
    # Core modules which shouldn't be disabled
    (
        "default",
        Storage(
            name_nice=T("Home"),
            restricted=False,  # Use ACLs to control access to this module
Esempio n. 4
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 = s3forms.S3SQLCustomForm(
        "organisation_id",
        "name",
        "code",
        "description",
        "status_id",
        "start_date",
        "end_date",
        #s3forms.S3SQLInlineComponent(
        #    "location",
        #    label = T("Countries"),
        #    fields = ["location_id"],
        #),
        # Outputs
        s3forms.S3SQLInlineComponent(
            "output",
            label = T("Outputs"),
            #comment = "Bob",
            fields = ["name", "status"],
        ),
        s3forms.S3SQLInlineComponentCheckbox(
            "hazard",
            label = T("Hazards"),
            field = "hazard_id",
            cols = 4,
        ),
        s3forms.S3SQLInlineComponentCheckbox(
            "sector",
            label = T("Sectors"),
            field = "sector_id",
            cols = 4,
        ),
        s3forms.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 organsiation_type_id == RC or NOT
        # & also hiding Branches from RCs
        # Partner NS
        # s3forms.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
        # s3forms.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
        # s3forms.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. 5
0
    return attr

settings.ui.customize_project_project = customize_project_project

settings.ui.crud_form_project_location = s3forms.S3SQLCustomForm(
        "project_id",
        "location_id",
        # @ToDo: Grouped Checkboxes
        s3forms.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. 6
0
        "organisation_id",
        "name",
        "code",
        "description",
        "status_id",
        "start_date",
        "end_date",
        #s3forms.S3SQLInlineComponentCheckbox(
        #    "hazard",
        #    label = T("Hazards"),
        #    field = "hazard_id",
        #    cols = 4,
        #),
        s3forms.S3SQLInlineComponentCheckbox(
            "sector",
            label = T("Sectors"),
            field = "sector_id",
            cols = 4,
        ),
        #s3forms.S3SQLInlineComponent(
        #    "location",
        #    label = T("Locations"),
        #    fields = ["location_id"],
        #),
        s3forms.S3SQLInlineComponentCheckbox(
            "theme",
            label = T("Themes"),
            field = "theme_id",
            cols = 4,
            # Filter Theme by Sector
#            filter = {"linktable": "project_theme_sector",
#                      "lkey": "theme_id",
Esempio n. 7
0
def customize_project_project(**attr):
    """
        Customize project_project controller
    """

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

    # 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 = s3forms.S3SQLCustomForm(
        "organisation_id",
        "name",
        #"code",
        "description",
        "status_id",
        "start_date",
        "end_date",
        #s3forms.S3SQLInlineComponent(
        #    "location",
        #    label = T("Countries"),
        #    fields = ["location_id"],
        #),
        s3forms.S3SQLInlineComponentCheckbox(
            "hazard",
            label = T("Hazards"),
            field = "hazard_id",
            cols = 4,
        ),
        s3forms.S3SQLInlineComponentCheckbox(
            "sector",
            label = T("Sectors"),
            field = "sector_id",
            cols = 4,
        ),
        s3forms.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
        #s3forms.S3SQLInlineComponent(
        #    "organisation",
        #    name = "partner",
        #    label = T("Partner Organizations"),
        #    fields = ["organisation_id",
        #              "comments",
        #              ],
        #    filterby = dict(field = "role",
        #                    options = "2"
        #                    )
        #),
        # Donors
        #s3forms.S3SQLInlineComponent(
        #    "organisation",
        #    name = "donor",
        #    label = T("Donor(s)"),
        #    fields = ["organisation_id",
        #              "amount",
        #              "currency"],
        #    filterby = dict(field = "role",
        #                    options = "3"
        #                    )
        #),
        #"budget",
        #"currency",
        "comments",
    )

    s3db.configure(tablename,
                   crud_form = crud_form)

    return attr