Beispiel #1
0
    def customise_event_incident_resource(r, tablename):

        from s3 import S3LocationSelector

        s3db = current.s3db

        table = s3db.event_incident
        f = table.severity
        f.readable = f.writable = True
        f = table.level
        f.readable = f.writable = True
        table.location_id.widget = S3LocationSelector(
            polygons=True,
            show_address=True,
        )
        f = table.organisation_id
        f.readable = f.writable = True
        f.label = T("Lead Response Organization")
        if r.method == "plan":
            table.action_plan.label = T("Event Action Plan")
        else:
            f = table.action_plan
            f.readable = f.writable = False

        if r.interactive:
            s3db.add_custom_callback(
                tablename,
                "create_onaccept",
                event_incident_create_onaccept,
            )
Beispiel #2
0
    def customise_event_event_resource(r, tablename):

        from gluon import IS_EMPTY_OR, IS_INT_IN_RANGE
        from s3 import S3LocationSelector, S3SQLCustomForm, S3SQLInlineComponent
        s3db = current.s3db
        s3db.event_event_location.location_id.widget = \
                                    S3LocationSelector(levels=("L1", "L2"))
        # Cat 1: Extra-ordinary
        # Cat 2: Large
        # Cat 3: Medium
        # Cat 4: Small
        s3db.event_event_tag.value.requires = IS_EMPTY_OR(IS_INT_IN_RANGE(
            1, 5))
        crud_form = S3SQLCustomForm(
            "name",
            "event_type_id",
            "start_date",
            S3SQLInlineComponent(
                "tag",
                fields=[
                    ("", "value"),
                ],
                filterby={
                    "field": "tag",
                    "options": "category",
                },
                label=T("Category"),
                multiple=False,
            ),
            "closed",
            "comments",
        )

        list_fields = [
            "name",
            "event_type_id",
            "start_date",
            (T("Category"), "tag.value"),
            "closed",
            "comments",
        ]

        # If we have default ones defined then need to add them in a cascade:
        #onaccept = s3db.get_config("event_event", "onaccept")
        #ondelete = s3db.get_config("event_event", "ondelete")
        onaccept = lambda form: response_locations()
        update_onaccept = s3db.get_config("event_event", "update_onaccept")
        update_onaccept = [update_onaccept, onaccept]

        s3db.configure(
            "event_event",
            crud_form=crud_form,
            list_fields=list_fields,
            onaccept=onaccept,
            ondelete=onaccept,
            update_onaccept=update_onaccept,
        )
Beispiel #3
0
    def customise_org_organisation_location_resource(r, tablename):

        table = current.s3db.org_organisation_location

        # Use location selector for "Areas served"
        from s3 import S3LocationSelector
        field = table.location_id
        field.widget = S3LocationSelector(
            levels=["L1", "L2", "L3", "L4"],
            show_postcode=False,
            show_map=False,
        )
Beispiel #4
0
    def customise_project_location_resource(r, tablename):

        s3db = current.s3db

        table = s3db.project_location

        # Allow editing of names
        field = table.name
        field.readable = field.writable = True

        # Hide percentage field (not needed)
        field = table.percentage
        field.readable = field.writable = False

        # Use location selector
        from s3 import S3LocationSelector
        field = table.location_id
        field.widget = S3LocationSelector(show_address=True)

        # List fields
        list_fields = [
            "project_id",
            "name",
            "location_id",
            "location_id$addr_street",
            "activity_type_location.activity_type_id",
        ]

        # CRUD Form
        from s3 import S3SQLCustomForm
        crud_form = S3SQLCustomForm(
            "project_id",
            "name",
            "location_id",
            S3SQLInlineLink(
                "activity_type",
                field="activity_type_id",
                multiple=True,
            ),
            "comments",
        )

        # Reconfigure resource
        s3db.configure(
            "project_location",
            crud_form=crud_form,
            list_fields=list_fields,
            create_next=None,
            onaccept=None,
        )
Beispiel #5
0
    def customise_dc_collection_resource(r, tablename):

        # @ToDo: Filters inc 'Assigned to me'

        db = current.db
        s3db = current.s3db
        table = s3db.dc_collection

        # Always at L4
        from s3 import S3LocationSelector
        table.location_id.widget = S3LocationSelector(levels=("L1", "L2", "L3",
                                                              "L4"))

        # Always SC
        otable = s3db.org_organisation
        org = db(otable.name == SAVE).select(otable.id,
                                             cache=s3db.cache,
                                             limitby=(0, 1)).first()
        try:
            SCI = org.id
        except:
            current.log.error("Cannot find org %s - prepop not done?" % SAVE)
        else:
            f = table.organisation_id
            f.default = SCI
            f.readable = f.writable = False

        has_role = current.auth.s3_has_role
        if has_role("ERT_LEADER") or has_role("HUM_MANAGER"):
            # Default to the Rapid Assessment Form
            ttable = s3db.dc_template
            RAPID = db(ttable.name == "Rapid Assessment").select(
                ttable.id, cache=s3db.cache, limitby=(0, 1)).first()
            try:
                table.template_id.default = RAPID.id
            except:
                # Prepop not done
                current.log.warning(
                    "Cannot default Targets to Rapid Assessment form")
Beispiel #6
0
    def customise_dc_target_resource(r, tablename):

        s3db = current.s3db
        table = s3db.dc_target

        # Always at L3
        from s3 import S3LocationSelector
        table.location_id.widget = S3LocationSelector(levels=("L1", "L2",
                                                              "L3"))

        has_role = current.auth.s3_has_role
        if has_role("ERT_LEADER") or has_role("HUM_MANAGER"):
            # Default to the Rapid Assessment Form
            s3db = current.s3db
            ttable = s3db.dc_template
            RAPID = current.db(ttable.name == "Rapid Assessment").select(
                ttable.id, cache=s3db.cache, limitby=(0, 1)).first()
            try:
                table.template_id.default = RAPID.id
            except:
                # Prepop not done
                current.log.warning(
                    "Cannot default Targets to Rapid Assessment form")
Beispiel #7
0
    def customise_project_location_resource(r, tablename):

        s3db = current.s3db
        table = s3db.project_location

        # Hide name in create-form
        field = table.name
        if r.tablename == tablename and not r.id or \
           r.component.tablename == tablename and not r.component_id:
            field.readable = False

        # Hide budget percentage
        field = table.percentage
        field.readable = field.writable = False

        # Use location selector
        field = table.location_id
        from s3 import S3LocationSelector
        field.widget = S3LocationSelector(
            show_address=False,
            show_postcode=False,
            show_map=False,
        )

        # Custom list fields
        list_fields = [
            "project_id",
            "location_id",
            "comments",
        ]

        s3db.configure(
            "project_location",
            # Don't redirect to beneficiaries after create:
            create_next=None,
            list_fields=list_fields,
        )
Beispiel #8
0
    def customise_project_project_resource(r, tablename):

        from s3 import S3LocationSelector, S3Represent, S3TextFilter, S3OptionsFilter, S3LocationFilter

        s3db = current.s3db
        table = s3db.project_project

        table.code.label = "SOF"

        s3db.project_location.location_id.widget = S3LocationSelector(
            levels=("L1", "L2", "L3"),
            show_map=False,
        )

        # Always SC
        otable = s3db.org_organisation
        org = current.db(otable.name == SAVE).select(otable.id,
                                                     cache=s3db.cache,
                                                     limitby=(0, 1)).first()
        try:
            SCI = org.id
        except:
            current.log.error("Cannot find org %s - prepop not done?" % SAVE)
        else:
            f = table.organisation_id
            f.default = SCI

        org_represent = s3db.org_OrganisationRepresent(acronym=False,
                                                       show_link=True)
        s3db.project_organisation.organisation_id.represent = org_represent
        try:
            s3db.project_donor_organisation.organisation_id.represent = org_represent
        except:
            # Table not present on Activities tab
            pass

        from s3 import S3SQLCustomForm, S3SQLInlineComponent, S3SQLInlineLink

        # @ToDo: Inherit Locations from Disaster?

        crud_form = S3SQLCustomForm(
            S3SQLInlineLink(
                "programme",
                label=T("Program"),
                field="programme_id",
                multiple=False,
            ),
            "name",
            "code",
            "status_id",
            "start_date",
            "end_date",
            "budget",
            "currency",
            S3SQLInlineComponent(
                "location",
                label=T("Locations"),
                fields=["location_id"],
            ),
            S3SQLInlineComponent(
                "organisation",
                name="donor",
                label=T("Donor(s)"),
                fields=["organisation_id"],
            ),
            # @ToDo: Set Metadata on File: Org, Location, Disaster, Date
            S3SQLInlineComponent(
                "document",
                name="concept_note",
                label=T("Concept Note"),
                fields=["file"],
                multiple=False,
            ),
            # @ToDo: Be able to retrieve the correct document
            #S3SQLInlineComponent("document",
            #                     name = "log_frame",
            #                     label = T("Log Frame"),
            #                     fields = ["file"],
            #                     multiple = False,
            #                     ),
            "comments",
        )

        filter_widgets = [
            S3TextFilter(
                [
                    "name",
                    "code",
                    #"description",
                ],
                label=T("Search"),
                comment=T("Search for a Project by name or code"),
            ),
            S3OptionsFilter(
                "status_id",
                label=T("Status"),
                cols=3,
            ),
            S3OptionsFilter(
                "donor.organisation_id",
                label=T("Donor"),
                hidden=True,
            ),
            S3LocationFilter(
                "location.location_id",
                levels=("L1", "L2", "L3"),
                hidden=True,
            ),
            S3OptionsFilter(
                "programme_project.programme_id",
                label=T("Program"),
                hidden=True,
            ),
            #S3OptionsFilter("sector_project.sector_id",
            #                label = T("Sector"),
            #                location_filter = True,
            #                none = True,
            #                hidden = True,
            #                ),
        ]

        list_fields = [
            "status_id",
            "code",
            "name",
            (T("Donors"), "donor.organisation_id"),
            (T("Locations"), "location.location_id"),
            "start_date",
            "end_date",
            "budget",
            "currency",
            (T("Program"), "programme.name"),
        ]

        s3db.configure(
            "project_project",
            crud_form=crud_form,
            filter_widgets=filter_widgets,
            list_fields=list_fields,
        )
Beispiel #9
0
    def customise_doc_image_resource(r, tablename):

        from s3 import S3LocationSelector, S3SQLCustomForm  #, S3SQLInlineComponent

        s3db = current.s3db
        table = s3db.doc_image
        table.location_id.widget = S3LocationSelector()  # No Street Address

        s3db.add_components(
            "doc_image",
            event_event="doc_id",
        )

        crud_form = S3SQLCustomForm(
            "file",
            "name",
            "url",
            "date",
            # @ToDo: Have this as an event_id dropdown...defaulting to currently-open Event
            #S3SQLInlineComponent("event"),
            "organisation_id",
            "location_id",
            "comments",
        )

        # Custom filters
        from s3 import S3DateFilter, \
                       S3LocationFilter, \
                       S3OptionsFilter, \
                       S3TextFilter

        filter_widgets = [
            S3TextFilter(
                [
                    "name",
                    "comments",
                ],
                label=T("Search"),
                comment=
                T("Search by disaster name or comments. You can use * as wildcard."
                  ),
            ),
            S3OptionsFilter(
                "event.name",
                label=T("Disaster"),
            ),
            S3LocationFilter("location_id"),
            S3OptionsFilter("organisation_id"),
            S3DateFilter("date"),
        ]

        list_fields = [
            "location_id$L1",
            "location_id$L2",
            "location_id$L3",
            "location_id$L4",
        ]
        if r.controller != "event":
            list_fields.append((T("Disaster"), "event.name"))
        list_fields += [
            "organisation_id",
            "date",
            "name",
        ]

        s3db.configure(
            "doc_image",
            crud_form=crud_form,
            filter_widgets=filter_widgets,
            list_fields=list_fields,
        )
Beispiel #10
0
        def custom_prep(r):

            # Call standard prep
            if callable(standard_prep):
                result = standard_prep(r)
            else:
                result = True

            controller = r.controller

            archived = r.get_vars.get("archived")
            if archived in ("1", "true", "yes"):
                crud_strings = s3.crud_strings["pr_person"]
                crud_strings["title_list"] = T("Invalid Cases")

            if controller == "dvr" and not r.component:

                table = r.table
                ctable = s3db.dvr_case

                from s3 import IS_ONE_OF, S3HierarchyWidget, S3Represent
                from gluon import DIV, IS_EMPTY_OR

                # Expose project_id
                field = ctable.project_id
                field.readable = field.writable = True
                represent = S3Represent(
                    lookup="project_project",
                    fields=["code"],
                )
                field.represent = represent
                field.requires = IS_EMPTY_OR(
                    IS_ONE_OF(
                        current.db,
                        "project_project.id",
                        represent,
                    ))
                field.comment = None
                field.label = T("Project Code")

                # Hierarchical Organisation Selector
                field = ctable.organisation_id
                represent = s3db.org_OrganisationRepresent(parent=False)
                field.widget = S3HierarchyWidget(
                    lookup="org_organisation",
                    represent=represent,
                    multiple=False,
                    leafonly=False,
                )
                field.comment = DIV(
                    _class="tooltip",
                    _title="%s|%s" % (
                        T("Organisation"),
                        T("The organisation/branch this case is assigned to"),
                    ),
                )
                user = current.auth.user
                if user:
                    field.default = user.organisation_id

                # Individual staff assignment
                field = ctable.human_resource_id
                field.label = T("Person Responsible")
                field.readable = field.writable = True
                field.widget = None
                field.comment = None

                # Filter staff by organisation
                script = '''$.filterOptionsS3({
 'trigger':'sub_dvr_case_organisation_id',
 'target':'sub_dvr_case_human_resource_id',
 'lookupPrefix':'hrm',
 'lookupResource':'human_resource',
 'lookupKey':'organisation_id',
 'fncRepresent': function(record){return record.person_id},
 'optional': true
})'''
                s3.jquery_ready.append(script)

                # Visibility and tooltip for consent flag
                field = ctable.disclosure_consent
                field.readable = field.writable = True
                field.comment = DIV(
                    _class="tooltip",
                    _title="%s|%s" % (
                        T("Consenting to Data Disclosure"),
                        T("Is the client consenting to disclosure of their data towards partner organisations and authorities?"
                          ),
                    ),
                )

                # Custom label for registered-flag
                dtable = s3db.dvr_case_details
                field = dtable.registered
                field.default = False
                field.label = T("Registered with Turkish Authorities")
                field.comment = DIV(
                    _class="tooltip",
                    _title="%s|%s" % (
                        T("Registered with Turkish Authorities"),
                        T("Is the client officially registered with AFAD/DGMM?"
                          ),
                    ),
                )

                resource = r.resource
                if r.interactive:

                    from s3 import S3DateFilter, \
                                   S3LocationSelector, \
                                   S3SQLCustomForm, \
                                   S3SQLInlineComponent, \
                                   S3TextFilter

                    # Custom CRUD form
                    crud_form = S3SQLCustomForm(
                        (T("Case Status"), "dvr_case.status_id"),
                        "dvr_case.date",
                        "dvr_case.organisation_id",
                        "dvr_case.human_resource_id",
                        "dvr_case.project_id",
                        "first_name",
                        #"middle_name",
                        "last_name",
                        "person_details.nationality",
                        "date_of_birth",
                        "gender",
                        "person_details.marital_status",
                        "case_details.registered",
                        (T("Individual ID Number"), "pe_label"),
                        S3SQLInlineComponent(
                            "family_id",
                            fields=[
                                ("", "value"),
                            ],
                            filterby={
                                "field": "tag",
                                "options": "FAMILY_ID",
                            },
                            label=T("Family ID Number"),
                            multiple=False,
                            name="family_id",
                        ),
                        S3SQLInlineComponent(
                            "address",
                            label=T("Current Address"),
                            fields=[
                                ("", "location_id"),
                            ],
                            filterby={
                                "field": "type",
                                "options": "1",
                            },
                            link=False,
                            multiple=False,
                        ),
                        S3SQLInlineComponent(
                            "contact",
                            fields=[
                                ("", "value"),
                            ],
                            filterby={
                                "field": "contact_method",
                                "options": "SMS",
                            },
                            label=T("Mobile Phone"),
                            multiple=False,
                            name="phone",
                        ),
                        "dvr_case.disclosure_consent",
                        "dvr_case.comments",
                        (T("Invalid Record"), "dvr_case.archived"),
                    )

                    resource.configure(crud_form=crud_form, )
                    # Hide Postcode in addresses (not used)
                    atable = s3db.pr_address
                    location_id = atable.location_id
                    location_id.widget = S3LocationSelector(
                        show_address=True,
                        show_postcode=False,
                    )

                    # Extend text filter with Family ID and case comments
                    filter_widgets = resource.get_config("filter_widgets")
                    extend_text_filter = True
                    for fw in filter_widgets:
                        if fw.field == "dvr_case.status_id":
                            if fw.field == "dvr_case.status_id" and "closed" in r.get_vars:
                                fw.opts.default = None
                                fw.opts.hidden = True
                        if extend_text_filter and isinstance(fw, S3TextFilter):
                            fw.field.extend((
                                "family_id.value",
                                "dvr_case.comments",
                            ))
                            fw.opts.comment = T(
                                "You can search by name, ID, family ID and comments"
                            )
                            extend_text_filter = False

                    # Add filter for date of birth
                    dob_filter = S3DateFilter(
                        "date_of_birth",
                        hidden=True,
                    )
                    filter_widgets.append(dob_filter)

                    # Add filter for registration date
                    reg_filter = S3DateFilter(
                        "dvr_case.date",
                        hidden=True,
                    )
                    filter_widgets.append(reg_filter)

                    # Inject script to toggle Head of Household form fields
                    #path = "/%s/static/themes/STL/js/dvr.js" % current.request.application
                    #if path not in s3.scripts:
                    #    s3.scripts.append(path)

                # Custom list fields (must be outside of r.interactive)
                list_fields = [
                    (T("ID"), "pe_label"),
                    (T("Family ID"), "family_id.value"),
                    "first_name",
                    #"middle_name",
                    "last_name",
                    "date_of_birth",
                    "gender",
                    "person_details.nationality",
                    "dvr_case.date",
                    "dvr_case.status_id",
                ]
                resource.configure(list_fields=list_fields, )

            elif controller == "hrm":

                if not r.component:

                    table = s3db.pr_person_details
                    field = table.marital_status
                    field.readable = field.writable = False
                    field = table.religion
                    field.readable = field.writable = False

                elif r.method == "record" or \
                     r.component_name == "human_resource":

                    table = s3db.hrm_human_resource
                    field = table.site_id
                    field.readable = field.writable = False

            return result
Beispiel #11
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 import S3SQLCustomForm, S3SQLInlineComponent, IS_LOCATION, S3LocationSelector

        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()
        location_field.widget = S3LocationSelector(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)

        s3db.add_components(
            "gis_location",
            gis_location_tag={
                "name": "pcode",
                "joinby": "location_id",
                "filterby": "tag",
                "filterfor": ("PCode", ),
            },
        )
        lappend(("PCode", "event_location.location_id$pcode.value"))

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

            current.response.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"))
Beispiel #12
0
    def customise_pr_person_resource(r, tablename):

        s3db = current.s3db

        list_fields = [
            "first_name",
            "middle_name",
            "last_name",
            (T("National ID"), "national_id.value"),
            "gender",
            "date_of_birth",
            "person_details.marital_status",
            (T("Telephone"), "phone.value"),
            (T("Address"), "address.location_id$addr_street"),
            # @ToDo: Residence Area...which is Lx
        ]
        if current.auth.s3_has_role("INFORMAL_SETTLEMENT"):
            list_fields.insert(
                7, (T("Household Relation"), "group_membership.role_id"))

        from s3 import S3LocationSelector, S3SQLCustomForm, S3SQLInlineComponent

        s3db.pr_address.location_id.widget = S3LocationSelector(
            show_address=True,
            #show_postcode = False,
            show_map=False,
        )

        crud_form = S3SQLCustomForm(
            "first_name",
            "middle_name",
            "last_name",
            S3SQLInlineComponent(
                "identity",
                label=T("National ID"),
                fields=[("", "value")],
                filterby=dict(
                    field="type",
                    options=2,
                ),
                multiple=False,
            ),
            "gender",
            "date_of_birth",
            "person_details.marital_status",
            S3SQLInlineComponent(
                "contact",
                label=T("Telephone"),
                fields=[("", "value")],
                filterby=dict(
                    field="contact_method",
                    options="SMS",
                ),
                multiple=False,
            ),
            S3SQLInlineComponent(
                "address",
                label=T("Address"),
                fields=[("", "location_id")],
                multiple=False,
            ),
            "comments",
        )

        s3db.configure(
            "pr_person",
            crud_form=crud_form,
            list_fields=list_fields,
        )
Beispiel #13
0
    def customise_event_event_resource(r, tablename):

        from s3 import S3LocationSelector
        current.s3db.event_event_location.location_id.widget = \
                                    S3LocationSelector(levels=("L1", "L2"))
Beispiel #14
0
        def custom_prep(r):

            # Call standard prep
            if callable(standard_prep):
                result = standard_prep(r)
            else:
                result = True

            if r.controller == "dvr" and not r.component:

                ctable = s3db.dvr_case

                # Mandatory Fields
                from s3 import IS_NOT_EMPTY
                from gluon import IS_EMPTY_OR

                # Require a case number
                ctable.reference.requires = IS_NOT_EMPTY()

                # Require organisation, site and status
                for fn in (
                        "organisation_id",
                        "site_id",
                        "status_id",
                ):
                    field = ctable[fn]
                    requires = field.requires
                    if isinstance(requires, IS_EMPTY_OR):
                        field.requires = requires.other

                root_org = current.auth.root_org()

                if root_org:
                    # Set default for organisation_id and hide the field
                    field = ctable.organisation_id
                    field.default = root_org
                    field.readable = field.writable = False

                    # Hide organisation_id in list_fields, too
                    list_fields = r.resource.get_config("list_fields")
                    if "dvr_case.organisation_id" in list_fields:
                        list_fields.remove("dvr_case.organisation_id")

                    # Limit sites to root_org
                    field = ctable.site_id
                    requires = field.requires
                    if requires:
                        if isinstance(requires, IS_EMPTY_OR):
                            requires = requires.other
                        if hasattr(requires, "dbset"):
                            stable = s3db.org_site
                            query = (stable.organisation_id == root_org)
                            requires.dbset = current.db(query)

                resource = r.resource
                if r.interactive:

                    # Custom CRUD form
                    from s3 import S3SQLCustomForm, S3SQLInlineComponent
                    crud_form = S3SQLCustomForm(
                        "dvr_case.reference",
                        "dvr_case.date",
                        "dvr_case.organisation_id",
                        "dvr_case.site_id",
                        "dvr_case.priority",
                        "dvr_case.case_type_id",
                        "dvr_case.beneficiary",
                        "dvr_case.status_id",
                        "first_name",
                        "middle_name",
                        "last_name",
                        "date_of_birth",
                        "gender",
                        "person_details.marital_status",
                        S3SQLInlineComponent(
                            "contact",
                            fields=[
                                ("", "value"),
                            ],
                            filterby={
                                "field": "contact_method",
                                "options": "EMAIL",
                            },
                            label=T("Email"),
                            multiple=False,
                            name="email",
                        ),
                        S3SQLInlineComponent(
                            "contact",
                            fields=[
                                ("", "value"),
                            ],
                            filterby={
                                "field": "contact_method",
                                "options": "SMS",
                            },
                            label=T("Mobile Phone"),
                            multiple=False,
                            name="phone",
                        ),
                        "person_details.nationality",
                        "person_details.literacy",
                        S3SQLInlineComponent(
                            "case_language",
                            fields=[
                                "language",
                                "quality",
                                "comments",
                            ],
                            label=T("Language / Communication Mode"),
                        ),
                        S3SQLInlineComponent(
                            "contact_emergency",
                            fields=[
                                "name",
                                "relationship",
                                "phone",
                            ],
                            label=T("Emergency Contact"),
                            multiple=False,
                        ),
                        S3SQLInlineComponent(
                            "identity",
                            fields=[
                                "type",
                                "description",
                                "value",
                            ],
                        ),
                        S3SQLInlineComponent(
                            "address",
                            label=T("Current Address"),
                            fields=[
                                ("", "location_id"),
                            ],
                            filterby={
                                "field": "type",
                                "options": "1",
                            },
                            link=False,
                            multiple=False,
                        ),
                        "dvr_case.head_of_household",
                        "dvr_case.hoh_name",
                        "dvr_case.hoh_gender",
                        "dvr_case.hoh_relationship",
                        "dvr_case.comments",
                        "dvr_case.archived",
                    )

                    # Extend filter widgets
                    filter_widgets = resource.get_config("filter_widgets")
                    if filter_widgets is not None:
                        from s3 import s3_get_filter_opts, S3OptionsFilter
                        filter_widgets.extend([
                            S3OptionsFilter(
                                "dvr_case.case_type_id",
                                options=lambda: s3_get_filter_opts(
                                    "dvr_case_type"),
                            ),
                            S3OptionsFilter(
                                "dvr_case_activity.need_id",
                                options=lambda: s3_get_filter_opts("dvr_need"),
                                hidden=True,
                            ),
                        ])

                    resource.configure(
                        crud_form=crud_form,
                        filter_widgets=filter_widgets,
                    )
                    # Hide Postcode in addresses (not used)
                    atable = s3db.pr_address
                    from s3 import S3LocationSelector
                    location_id = atable.location_id
                    location_id.widget = S3LocationSelector(
                        show_address=True,
                        show_postcode=False,
                    )

                    # Inject filter script for sites (filter by selected org)
                    if not root_org:
                        script = '''$.filterOptionsS3({
'trigger':'sub_dvr_case_organisation_id',
'target':'sub_dvr_case_site_id',
'lookupResource':'site',
'lookupPrefix':'org',
'lookupField':'site_id',
'lookupKey':'organisation_id'
})'''
                        s3.jquery_ready.append(script)

                    # Expose additional case fields:
                    fields = ("beneficiary", "head_of_household", "hoh_name",
                              "hoh_gender", "hoh_relationship")
                    for fname in fields:
                        field = ctable[fname]
                        field.readable = field.writable = True

                    # Inject script to toggle Head of Household form fields
                    path = "/%s/static/themes/STL/js/dvr.js" % current.request.application
                    if path not in s3.scripts:
                        s3.scripts.append(path)

                # Custom list fields (must be outside of r.interactive)
                list_fields = [
                    "dvr_case.reference",
                    "dvr_case.case_type_id",
                    "dvr_case.priority",
                    "first_name",
                    "middle_name",
                    "last_name",
                    "date_of_birth",
                    "gender",
                    #"dvr_case.organisation_id",
                    "dvr_case.date",
                    "dvr_case.status_id",
                ]
                resource.configure(list_fields=list_fields,
                                   #orderby = "dvr_case.priority desc",
                                   )
            return result
    def formfields():
        """
            Generate the form fields for the registration form

            @returns: a tuple (formfields, required_fields, subheadings)
                      - formfields = list of form fields
                      - required_fields = list of field names of required fields
                      - subheadings = list of tuples (position, heading) to
                                      insert into the form
        """

        T = current.T
        request = current.request

        db = current.db
        s3db = current.s3db

        auth = current.auth
        auth_settings = auth.settings
        auth_messages = auth.messages

        utable = auth_settings.table_user
        passfield = auth_settings.password_field

        occupation_type_represent = S3Represent(
            lookup="pr_occupation_type",
            multiple=True,
        )

        # Instantiate Consent Tracker
        consent = s3db.auth_Consent(processing_types=["SHARE"])

        # Last name is required
        utable.last_name.requires = IS_NOT_EMPTY(
            error_message=T("input required"))

        ltable = s3db.gis_location

        # Form fields
        formfields = [utable.first_name,
                      utable.last_name,
                      s3_date("date_of_birth",
                              label = T("Date of Birth"),
                              future = -156,
                              empty = False,
                              ),
                      # --------------------------------------------
                      utable.email,
                      utable[passfield],

                      # Password Verification Field
                      Field("password_two", "password",
                            label = auth_messages.verify_password,
                            requires = IS_EXPR("value==%s" % \
                                               repr(request.vars.get(passfield)),
                                               error_message = auth_messages.mismatched_password,
                                               ),
                            comment = DIV(_class = "tooltip",
                                          _title = "%s|%s" % (auth_messages.verify_password,
                                                              T("Enter the same password again"),
                                                              ),
                                          ),
                            ),
                      # --------------------------------------------
                      Field("home_phone",
                            label = T("Phone"),
                            requires = IS_EMPTY_OR(IS_PHONE_NUMBER_MULTI()),
                            ),
                      Field("mobile_phone",
                            label = T("Mobile Phone"),
                            requires = IS_EMPTY_OR(IS_PHONE_NUMBER_SINGLE()),
                            ),
                      #Field("office_phone",
                      #      label = T("Office Phone"),
                      #      requires = IS_EMPTY_OR(IS_PHONE_NUMBER_MULTI()),
                      #      ),
                      # --------------------------------------------
                      s3db.gis_location_id("location_id",
                                           widget = S3LocationSelector(
                                                       show_address = False,
                                                       show_postcode = False,
                                                       show_map = False,
                                                       ),
                                           ),
                      Field("addr_street",
                            label = ltable.addr_street.label,
                            ),
                      Field("addr_postcode",
                            label = ltable.addr_postcode.label,
                            requires = IS_NOT_EMPTY(),
                            ),

                      # --------------------------------------------
                      Field("occupation_type_ids",
                            "list:reference pr_occupation_type",
                            label = T("Occupation Type"),
                            requires = IS_EMPTY_OR(IS_ONE_OF(db,
                                          "pr_occupation_type.id",
                                          occupation_type_represent,
                                          multiple=True,
                                          )),
                            represent = occupation_type_represent,
                            widget = S3MultiSelectWidget(),
                            comment = DIV(_class = "tooltip",
                                          _title = "%s|%s" % (T("Occupation Type"),
                                                              T("Select all that apply"),
                                                              ),
                                          ),
                            ),
                      Field("occupation",
                            label = T("Occupation / Speciality"),
                            comment = DIV(_class = "tooltip",
                                          _title = "%s|%s" % (T("Occupation / Speciality"),
                                                              T("Specify your exact job designation"),
                                                              ),
                                          ),
                            ),

                      # --------------------------------------------
                      s3_date("start_date",
                              label = T("Available from"),
                              default = "now",
                              past = 0,
                              set_min = "#auth_user_start_date",
                              ),
                      s3_date("end_date",
                              label = T("Available until"),
                              past = 0,
                              set_max = "#auth_user_start_date",
                              ),
                      Field("hours_per_week", "integer",
                            label = T("Hours per Week"),
                            requires = IS_EMPTY_OR(IS_INT_IN_RANGE(1, 60)),
                            comment = DIV(_class = "tooltip",
                                          _title = "%s|%s" % (T("Hours per Week"),
                                                              T("Specify the maximum number of weekly hours"),
                                                              ),
                                          ),
                            ),
                      Field("schedule", "text",
                            label = T("Availability Schedule"),
                            widget = s3_comments_widget,
                            comment = DIV(_class = "tooltip",
                                          _title = "%s|%s" % (T("Availability Schedule"),
                                                              T("Specify days/hours like: Monday 10-12; Tuesday 10-12 and 14-19; Friday 13-15"),
                                                              ),
                                          ),
                            ),
                      s3db.hrm_multi_skill_id(
                            label = T("Skills / Resources"),
                            widget = S3GroupedOptionsWidget(cols = 1,
                                                            size = None,
                                                            help_field = "comments",
                                                            ),
                            ),

                      # --------------------------------------------
                      Field("comments", "text",
                            label = T("Comments"),
                            widget = s3_comments_widget,
                            ),

                      # --------------------------------------------
                      Field("consent",
                           label = T("Consent"),
                           widget = consent.widget,
                           ),
                      ]

        # Required fields
        required_fields = [
            "first_name",
            "last_name",
        ]

        # Subheadings
        subheadings = (
            (3, T("User Account")),
            (6, T("Contact Information")),
            (8, T("Address")),
            (11, T("Occupation")),
            (13, T("Availability and Resources")),
            (18, T("Comments")),
            (19, T("Privacy")),
        )

        return formfields, required_fields, subheadings
Beispiel #16
0
def customise_pr_person_resource(r, tablename):

    T = current.T
    s3db = current.s3db
    table = r.resource.table

    # Disallow "unknown" gender and defaults to "male"
    evr_gender_opts = dict(
        (k, v) for k, v in s3db.pr_gender_opts.items() if k in (2, 3))
    gender = table.gender
    gender.requires = IS_IN_SET(evr_gender_opts, zero=None)
    gender.default = 3

    if r.controller == "evr":
        # Hide evacuees emergency contacts
        current.deployment_settings.pr.show_emergency_contacts = False

        # Last name and date of birth mandatory in EVR module
        table.last_name.requires = IS_NOT_EMPTY(
            error_message=T("Please enter a last name"))

        dob_requires = s3_date("dob", future=0, past=1320,
                               empty=False).requires
        dob_requires.error_message = T("Please enter a date of birth")
        table.date_of_birth.requires = dob_requires

        # Enable Location_id
        from gluon import DIV
        from s3 import S3LocationSelector
        location_id = table.location_id
        location_id.readable = location_id.writable = True
        location_id.label = T("Place of Birth")
        levels = (
            "L1",
            "L2",
            "L3",
        )
        location_id.widget = S3LocationSelector(
            levels=levels,
            lines=True,
        )
        location_id.represent = s3db.gis_LocationRepresent(sep=" | ")
        # Enable place of birth
        place_of_birth = s3db.pr_person_details.place_of_birth
        place_of_birth.label = "Specify a Different Place of Birth"
        place_of_birth.comment = DIV(
            _class="tooltip",
            _title="%s|%s" %
            (T("Different Place of Birth"),
             T("Specify a different place of birth (foreign country, village, hamlet)"
               )))
        place_of_birth.readable = place_of_birth.writable = True

        # Disable religion selection
        s3db.pr_person_details.religion.readable = False
        s3db.pr_person_details.religion.writable = False

    # Disable unneeded physical details
    pdtable = s3db.pr_physical_description
    hide_fields = [
        "race", "complexion", "height", "weight", "hair_length", "hair_style",
        "hair_baldness", "hair_comment", "facial_hair_type",
        "facial_hair_length", "facial_hair_color", "facial_hair_comment",
        "body_hair", "skin_marks", "medical_conditions"
    ]
    for fname in hide_fields:
        field = pdtable[fname]
        field.readable = field.writable = False

    # This set is suitable for Italy
    ethnicity_opts = (
        "Italian",
        "Chinese",
        "Albanese",
        "Philippine",
        "Pakistani",
        "English",
        "African",
        "Other",
        "Unknown",
    )
    ethnicity_opts = dict((v, T(v)) for v in ethnicity_opts)

    ethnicity = pdtable.ethnicity
    ethnicity.requires = IS_EMPTY_OR(IS_IN_SET(ethnicity_opts, sort=True))
    ethnicity.represent = S3Represent(options=ethnicity_opts, translate=True)
Beispiel #17
0
    def customise_org_organisation_resource(r, tablename):

        from gluon.html import DIV, INPUT
        from s3 import s3_comments_widget, \
                       S3LocationSelector, \
                       S3MultiSelectWidget, \
                       S3SQLCustomForm, \
                       S3SQLInlineComponent, \
                       S3SQLVerticalSubFormLayout

        s3db = current.s3db

        # Filtered component to access phone number and email
        s3db.add_components(
            tablename,
            org_facility={
                "name": "main_facility",
                "joinby": "organisation_id",
                "filterby": {
                    "main_facility": True,
                },
            },
        )

        s3db.org_organisation_location.location_id.widget = S3LocationSelector(
            levels=("L2", "L3"),
            show_map=False,
            labels=False,
        )

        crud_fields = [
            "name",
            "acronym",
            S3SQLInlineLink(
                "organisation_type",
                field="organisation_type_id",
                label=T("Type"),
                multiple=False,
            ),
            S3SQLInlineLink(
                "service",
                label=T("Services"),
                field="service_id",
            ),
            S3SQLInlineComponent(
                "facility",
                label=T("Main Facility"),
                fields=[
                    "name",
                    "phone1",
                    "phone2",
                    "email",
                    "location_id",
                ],
                layout=S3SQLVerticalSubFormLayout,
                filterby={
                    "field": "main_facility",
                    "options": True,
                },
                multiple=False,
            ),
            "website",
            S3SQLInlineComponent(
                "contact",
                name="twitter",
                label=T("Twitter"),
                multiple=False,
                fields=[("", "value")],
                filterby=dict(
                    field="contact_method",
                    options="TWITTER",
                ),
            ),
            S3SQLInlineComponent(
                "contact",
                name="facebook",
                label=T("Facebook"),
                multiple=False,
                fields=[("", "value")],
                filterby=dict(
                    field="contact_method",
                    options="FACEBOOK",
                ),
            ),
            "comments",
        ]

        crud_form = S3SQLCustomForm(*crud_fields)

        from s3 import S3LocationFilter, S3OptionsFilter, S3TextFilter  #, S3HierarchyFilter
        filter_widgets = [
            S3TextFilter(
                ["name", "acronym"],
                label=T("Search"),
                comment=
                T("Search by organization name or acronym. You can use * as wildcard."
                  ),
                _class="filter-search",
            ),
            S3LocationFilter(
                "org_facility.location_id",
                label=T("Location"),
                #hidden = True,
            ),
            S3OptionsFilter(
                "organisation_organisation_type.organisation_type_id",
                label=T("Type"),
                #hidden = True,
            ),
            S3OptionsFilter("service_organisation.service_id",
                            #hidden = True,
                            ),
        ]

        list_fields = [
            "name",
            (T("Type"), "organisation_organisation_type.organisation_type_id"),
            (T("Services"), "service.name"),
            (T("Adresse"), "main_facility.location_id"),
            (T("Phone #"), "main_facility.phone1"),
            (T("Email"), "main_facility.email"),
            (T("Facebook"), "facebook.value"),
            "website",
            (T("Last Updated"), "modified_on"),
        ]

        s3db.configure(
            tablename,
            crud_form=crud_form,
            filter_widgets=filter_widgets,
            list_fields=list_fields,
        )
Beispiel #18
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 import IS_LOCATION, S3LocationSelector
        levels = ("L0", "L1", "L2")
        loc_field = r.table.location_id
        loc_field.requires = IS_LOCATION()
        loc_field.widget = S3LocationSelector(
            levels=levels,
            show_address=True,
        )

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

        from s3 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",
            ))

        # Custom Crud Form
        from s3 import S3SQLCustomForm, S3SQLInlineComponentMultiSelectWidget
        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,
        )
Beispiel #19
0
    def customise_org_facility_resource(r, tablename):

        from s3 import S3SQLCustomForm, S3SQLInlineLink, \
                       S3LocationSelector, S3LocationFilter, S3TextFilter

        s3db = current.s3db

        s3db.org_facility.location_id.widget = S3LocationSelector(
            levels=("L1", "L2", "L3", "L4"),
            required_levels=("L1", "L2", "L3"),
            show_address=True,
            show_postcode=True,
            show_map=True,
        )

        # Geocoder
        current.response.s3.scripts.append(
            "/%s/static/themes/RLP/js/geocoderPlugin.js" % r.application)

        text_fields = [
            "name",
            #"code",
            "comments",
            "organisation_id$name",
            "organisation_id$acronym",
            "location_id$L1",
            "location_id$L2",
            "location_id$L3",
            "location_id$L4",
        ]

        filter_widgets = [
            S3TextFilter(
                text_fields,
                label=T("Search"),
                #_class = "filter-search",
            ),
            S3LocationFilter(
                "location_id",
                #label = T("Location"),
                levels=("L1", "L2", "L3", "L4"),
            ),
        ]

        crud_fields = [
            "name",
            S3SQLInlineLink(
                "facility_type",
                label=T("Facility Type"),
                field="facility_type_id",
                widget="groupedopts",
                cols=3,
            ),
            "organisation_id",
            "location_id",
            (T("Telephone"), "phone1"),
            (T("Opening Hours"), "opening_times"),
            "obsolete",
            "comments",
        ]

        list_fields = [
            "name",
            #"site_facility_type.facility_type_id",
            "location_id$L1",
            "location_id$L2",
            "location_id$L3",
            "location_id$L4",
            "location_id$addr_street",
            "location_id$addr_postcode",
            (T("Telephone"), "phone1"),
            (T("Opening Hours"), "opening_times"),
            "organisation_id",
            #"obsolete",
            #"comments",
        ]

        s3db.configure(
            tablename,
            crud_form=S3SQLCustomForm(*crud_fields),
            filter_widgets=filter_widgets,
            list_fields=list_fields,
        )