Пример #1
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