Example #1
0
def customize_org_office(**attr):
    """
        Customize org_office controller
    """

    s3 = current.response.s3
    s3db = current.s3db
    table = s3db.org_office

    location_id_field = table.location_id
    location_id_field.requires = IS_LOCATION_SELECTOR2(levels=levels)
    location_id_field.widget = S3LocationSelectorWidget2(levels=levels,
                                                         show_address=True,
                                                         show_map=True)
    # Don't add new Locations here
    location_id_field.comment = None

    list_fields = [
        "name",
        "organisation_id",
        "location_id",
        "phone1",
        "comments",
    ]

    crud_form = S3SQLCustomForm(*list_fields)

    # Report options
    report_fields = [
        "organisation_id",
    ]

    report_options = Storage(
        rows=report_fields,
        cols=report_fields,
        fact=["count(id)"],
        defaults=Storage(
            rows="organisation_id",
            cols="",
            fact="count(id)",
            totals=True,
            chart="barchart:rows",
            #table = "collapse",
        ))

    s3db.configure(
        "org_office",
        crud_form=crud_form,
        list_fields=list_fields,
        report_options=report_options,
    )

    # Remove rheader
    attr["rheader"] = None
    return attr
Example #2
0
def customize_project_project(**attr):
    """
        Customize project_project controller
    """

    s3 = current.response.s3
    s3db = current.s3db
    table = s3db.project_project

    # Custom Form
    location_id_field = s3db.project_location.location_id
    location_id_field.requires = IS_LOCATION_SELECTOR2(levels=levels)
    location_id_field.widget = S3LocationSelectorWidget2(levels=levels,
                                                         show_address=True,
                                                         show_map=True)
    # Don't add new Locations here
    location_id_field.comment = None

    table.name.label = T("Description")
    table.comments.label = T("Details")
    #s3db.project_project_organisation.organisation_id.label = ""
    #s3db.project_project_project_type.project_type_id.label = ""
    crud_form = S3SQLCustomForm(
        "status_id",
        "name",
        "description",
        #"location.location_id",
        "organisation_id",
        S3SQLInlineComponent(
            "location",
            label=T("Location"),
            fields=["location_id"],
            orderby="location_id$name",
            #multiple = False,
        ),
        "start_date",
        "end_date",
    )

    filter_widgets = [
        S3TextFilter(
            [
                "name",
            ],
            label=T("Description"),
            _class="filter-search",
        ),
        S3LocationFilter(
            "location_id",
            widget="multiselect",
            levels=levels,
        ),
        S3OptionsFilter(
            "status_id",
            label=T("Status"),
            # Doesn't support translation
            #represent="%(name)s",
            # @ToDo: Introspect cols
            cols=3,
            #widget="multiselect",
        ),
        S3OptionsFilter(
            "project_project_type.project_type_id",
            # Doesn't support translation
            #represent="%(name)s",
            widget="multiselect",
        ),
        S3OptionsFilter(
            "project_organisation.organisation_id",
            # Doesn't support translation
            #represent="%(name)s",
            widget="multiselect",
        ),
        S3OptionsFilter(
            "project_organisation.organisation_id$organisation_type_id",
            # Doesn't support translation
            #represent="%(name)s",
            widget="multiselect",
        ),
    ]

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

    # Remove rheader
    attr["rheader"] = None
    return attr
Example #3
0
def customize_project_activity(**attr):
    """
        Customize project_activity controller
    """

    s3 = current.response.s3
    s3db = current.s3db
    table = s3db.project_activity

    #Use activities as projects (Temporary - location widget broken inline
    s3.crud_strings["project_activity"] = s3.crud_strings["project_project"]

    # Custom PreP
    standard_prep = s3.prep

    def custom_prep(r):
        if r.method in ["create", "update"]:
            # hide inline labels
            s3db.project_activity_organisation.organisation_id.label = ""
            s3db.project_activity_activity_type.activity_type_id.label = ""
        return True

    s3.prep = custom_prep

    list_fields = [
        "id",
        "status_id",
        "name",
        "location_id",
        "activity_organisation.organisation_id",
        "date",
        "end_date",
    ]

    # Custom Form
    table.location_id.requires = IS_LOCATION_SELECTOR2(levels=levels)
    table.location_id.widget = S3LocationSelectorWidget2(levels=levels,
                                                         show_address=True,
                                                         show_map=True)
    # Don't add new Locations here
    table.location_id.comment = None

    table.name.label = T("Name")
    table.comments.label = T("Description")

    crud_form = S3SQLCustomForm(
        "status_id",
        "name",
        "comments",
        "location_id",
        S3SQLInlineComponent(
            "activity_organisation",
            label=T("Organization"),
            fields=["organisation_id"],
            multiple=False,
        ),
        #S3SQLInlineComponent("activity_activity_type",
        #                     label = T("Activity Type"),
        #                     fields = ["activity_type_id"],
        #                     multiple = False,
        #                     ),
        "date",
        "end_date",
    )

    filter_widgets = [
        S3TextFilter(
            [
                "name",
            ],
            label=T("Description"),
            _class="filter-search",
        ),
        S3LocationFilter(
            "location_id",
            widget="multiselect",
            levels=levels,
        ),
        S3OptionsFilter(
            "status_id",
            label=T("Status"),
            # Doesn't support translation
            #represent="%(name)s",
            # @ToDo: Introspect cols
            cols=3,
            #widget="multiselect",
        ),
        #S3OptionsFilter("activity_activity_type.activity_type_id",
        # Doesn't support translation
        #represent="%(name)s",
        #                widget="multiselect",
        #                ),
        S3OptionsFilter(
            "activity_organisation.organisation_id",
            # Doesn't support translation
            #represent="%(name)s",
            widget="multiselect",
        ),
        S3OptionsFilter(
            "activity_organisation.organisation_id$organisation_type_id",
            # Doesn't support translation
            #represent="%(name)s",
            widget="multiselect",
        ),
    ]

    # Report options
    report_fields = [
        "activity_organisation.organisation_id",
        "status_id",
    ]

    report_options = Storage(
        rows=report_fields,
        cols=report_fields,
        fact=["count(id)"],
        defaults=Storage(
            rows="activity_organisation.organisation_id",
            cols="status_id",
            fact="count(id)",
            totals=True,
            chart="barchart:rows",
            #table = "collapse",
        ))

    s3db.configure(
        "project_activity",
        list_fields=list_fields,
        crud_form=crud_form,
        filter_widgets=filter_widgets,
        report_options=report_options,
    )

    # Remove rheader
    attr["rheader"] = None
    return attr
Example #4
0
def customize_cms_post(**attr):
    """
        Customize cms_post controller
    """

    s3 = current.response.s3
    s3db = current.s3db
    table = s3db.cms_post

    s3.dl_pagelength = 12
    s3.dl_rowsize = 2
    # CRUD Form

    table.location_id.requires = IS_LOCATION_SELECTOR2(levels=levels)
    table.location_id.widget = S3LocationSelectorWidget2(levels=levels,
                                                         show_address=True,
                                                         show_map=True)
    # Don't add new Locations here
    table.location_id.comment = None

    table.series_id.readable = table.series_id.writable = True
    table.series_id.label = T("Type")

    table.body.label = T("Description")
    table.body.widget = None
    s3db.event_event_post.event_id.label = ""
    s3db.doc_document.file.label = ""
    crud_form = S3SQLCustomForm(
        "date",
        "series_id",
        "body",
        "location_id",
        S3SQLInlineComponent(
            "event_post",
            #label = T("Disaster(s)"),
            label=T("Disaster"),
            multiple=False,
            fields=["event_id"],
            orderby="event_id$name",
        ),
        S3SQLInlineComponent(
            "document",
            name="file",
            label=T("Files"),
            fields=[
                "file",
                #"comments",
            ],
        ),
    )

    # Return to List view after create/update/delete
    # We now do all this in Popups
    #url_next = URL(c="default", f="index", args="newsfeed")

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

    # Remove rheader
    attr["rheader"] = None
    return attr
Example #5
0
    def custom_prep(r):
        # Call standard prep
        if callable(standard_prep):
            result = standard_prep(r)
            if not result:
                return False

        if r.interactive or r.representation == "aadata":
            s3db.org_customize_org_resource_fields(r.method)

            # Configure fields
            #table.site_id.readable = table.site_id.readable = False
            location_field = table.location_id
            #location_field.label = T("District")

            from s3.s3filter import S3TextFilter, S3OptionsFilter
            filter_widgets = [
                S3TextFilter([
                    "organisation_id$name",
                    "location_id",
                    "parameter_id$name",
                    "comments",
                ],
                             label=T("Search")),
                S3OptionsFilter(
                    "parameter_id",
                    label=T("Type"),
                    widget="multiselect",
                ),
            ]

            s3db.configure("org_resource", filter_widgets=filter_widgets)

            # Filter from a Profile page?
            # If so, then default the fields we know
            get_vars = current.request.get_vars
            location_id = get_vars.get("~.(location)", None)
            organisation_id = get_vars.get("~.(organisation)", None)
            if organisation_id:
                org_field = table.organisation_id
                org_field.default = organisation_id
                org_field.readable = org_field.writable = False
            if location_id:
                location_field.default = location_id
                # We still want to be able to specify a precise location
                #location_field.readable = location_field.writable = False
            location_field.requires = IS_LOCATION_SELECTOR2(levels=levels)
            location_field.widget = S3LocationSelectorWidget2(
                levels=levels, show_address=True, show_map=True)

            # Don't add new Locations here
            location_field.comment = None

            # Return to Sumamry view after create/update/delete (unless done via Modal)
            url_next = URL(c="org", f="resource", args="summary")

            s3db.configure(
                "org_resource",
                create_next=url_next,
                delete_next=url_next,
                update_next=url_next,
                # Don't include a Create form in 'More' popups
                listadd=False if r.method == "datalist" else True,
            )

            # This is awful in Popups & inconsistent in dataTable view (People/Documents don't have this & it breaks the styling of the main Save button)
            #s3.cancel = URL(c="org", f="resource")

        return True
Example #6
0
def customise_event_event_resource(r, tablename):
    """
        Customise event_event resource
        - List Fields
        - CRUD Strings
        - Form
        - Filter
        - Report 
        Runs after controller customisation
        But runs before prep
    """

    from s3.s3forms import S3SQLCustomForm, S3SQLInlineComponent
    from s3.s3validators import IS_LOCATION_SELECTOR2
    from s3.s3widgets import S3LocationSelectorWidget2

    db = current.db
    s3db = current.s3db
    table = r.table
    table.name.label = T("Disaster Number")

    location_field = s3db.event_event_location.location_id
    location_field.requires = IS_LOCATION_SELECTOR2(levels=gis_levels)
    location_field.widget = S3LocationSelectorWidget2(levels=gis_levels)

    impact_fields = OrderedDict(
        killed="Killed",
        total_affected="Total Affected",
        est_damage="Estimated Damage (US$ Million)",
    )

    ptable = s3db.stats_impact_type
    rows = db(ptable.name.belongs(impact_fields.values())).select(
        ptable.id,
        ptable.name,
    )
    parameters = rows.as_dict(key="name")

    impact_components = []
    impact_crud_form_fields = []
    impact_list_fields = []
    impact_report_fields = []
    for tag, label in impact_fields.items():
        parameter = parameters[label]["id"]
        impact_components.append({
            "name": tag,
            "link": "event_event_impact",
            "joinby": "event_id",
            "key": "impact_id",
            "filterby": "parameter_id",
            "filterfor": (parameter, ),
        })
        label = T(label)
        impact_crud_form_fields.append(
            S3SQLInlineComponent(tag,
                                 label=label,
                                 link=False,
                                 multiple=False,
                                 fields=[("", "value")],
                                 filterby=dict(field="parameter_id",
                                               options=parameter)))
        impact_list_fields.append((label, "%s.value" % tag))
        impact_report_fields.append(
            (T("Total %(param)s") % dict(param=label), "sum(%s.value)" % tag))

    s3db.add_components(
        "event_event",
        stats_impact=impact_components,
    )

    crud_form = S3SQLCustomForm(
        "name",
        "event_type_id",
        "start_date",
        "end_date",
        # @ToDo: Inline location_id field
        #S3SQLInlineComponent("event_location",
        #                     label = T("Location"),
        #                     multiple = False,
        #                     fields = [("", "location_id")],
        #                     ),
        "comments",
        *impact_crud_form_fields)

    list_fields = [
        "name",
        "event_type_id",
    ]
    lappend = list_fields.append

    for level in gis_levels:
        location_level = "event_location.location_id$%s" % level
        lappend(location_level)

    list_fields.extend((
        "start_date",
        "end_date",
    ))
    list_fields.extend(impact_list_fields)

    report_facts = [(T("Number of Disasters"), "count(id)")]
    report_facts.extend(impact_report_fields)

    report_options = s3db.get_config("event_event", "report_options")
    report_options.fact = report_facts

    s3db.configure(
        "event_event",
        crud_form=crud_form,
        list_fields=list_fields,
    )

    if r.interactive:
        # Labels
        table.comments.label = T("Description")

        s3.crud_strings["event_event"] = Storage(
            label_create=T("Record Disaster"),
            title_display=T("Disaster Details"),
            title_list=T("Disasters"),
            title_update=T("Edit Disaster"),
            label_list_button=T("List Disasters"),
            label_delete_button=T("Delete Disaster"),
            msg_record_created=T("Disaster added"),
            msg_record_modified=T("Disaster updated"),
            msg_record_deleted=T("Disaster deleted"),
            msg_list_empty=T("No Disasters currently registered"))
Example #7
0
def customise_org_facility_resource(r, tablename):
    """
        Customise event_event resource
        - List Fields
        - Form
        - Filter
        - Report 
        Runs after controller customisation
        But runs before prep
    """

    s3db = current.s3db

    from s3.s3validators import IS_LOCATION_SELECTOR2
    from s3.s3widgets import S3LocationSelectorWidget2
    levels = ("L0", "L1", "L2")
    loc_field = r.table.location_id
    loc_field.requires = IS_LOCATION_SELECTOR2(levels=levels)
    loc_field.widget = S3LocationSelectorWidget2(levels=levels,
                                                 show_address = True)

    list_fields = ["name",
                   (T("Type"),"facility_type.name"),
                   #"organisation_id",
                   "location_id",
                   "contact",
                   "phone1",
                   "email",
                   "comments",
                   ]

    from s3.s3filter import S3OptionsFilter, S3TextFilter
    filter_widgets = [S3TextFilter(["name",
                                    "site_facility_type.facility_type_id",
                                    #"organisation_id",
                                    "location_id",
                                    "contact",
                                    "phone1",
                                    "email",
                                    "comments"
                                    ],
                                    label = T("Search"),
                                   ),
                      S3OptionsFilter("site_facility_type.facility_type_id",
                                        header = True,
                                        label = T("Type of Place"),
                                        ),
                      #S3OptionsFilter("organisation_id",
                      #                header = True,
                      #                represent = "%(name)s",
                      #                ),
                      ]

    report_fields = [#"name",
                     "site_facility_type.facility_type_id",
                     "site_org_group.group_id",
                     "location_id$L3",
                     "organisation_id",
                     ]

    report_options = Storage(
        rows = report_fields,
        cols = [],
        fact = [(T("Number of Facilities"), "count(name)")],
        defaults = Storage(rows = "site_facility_type.facility_type_id",
                           #cols = "site_org_group.group_id",
                           fact = "count(name)",
                           totals = True,
                           chart = "barchart:rows",
                           table = "collapse",
                           )
        )

    from s3.s3forms import S3SQLCustomForm, S3SQLInlineComponentMultiSelectWidget
    # Custom Crud Form
    crud_form = S3SQLCustomForm("name",
                                S3SQLInlineComponentMultiSelectWidget(
                                    "facility_type",
                                    #label = T("Type of Place"),
                                    field = "facility_type_id",
                                ),
                                #"organisation_id",
                                "location_id",
                                "contact",
                                "phone1",
                                "email",
                                "comments",
                                )

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