예제 #1
0
파일: requests.py 프로젝트: sahana/eden
def recv_filter_widgets():
    """
        Filter widgets for incoming shipments

        @returns: list of filter widgets
    """

    T = current.T

    from s3 import S3DateFilter, \
                   S3OptionsFilter, \
                   S3TextFilter, \
                   s3_get_filter_opts
    from s3db.inv import SHIP_STATUS_CANCEL, \
                         SHIP_STATUS_RETURNING, \
                         inv_shipment_status_labels

    recv_status_opts = OrderedDict(
        sorted(
            inv_shipment_status_labels().items(),
            key=lambda i: i[0],
        ))
    # We don't currently use these statuses
    del recv_status_opts[SHIP_STATUS_CANCEL]
    del recv_status_opts[SHIP_STATUS_RETURNING]

    filter_widgets = [
        S3TextFilter(
            [
                "req_ref",
                #"send_ref",
            ],
            label=T("Search"),
        ),
        S3OptionsFilter(
            "status",
            cols=3,
            options=recv_status_opts,
            sort=False,
        ),
        S3DateFilter(
            "date",
            hidden=True,
        ),
        S3OptionsFilter(
            "track_item.item_id",
            hidden=True,
            options=lambda: s3_get_filter_opts("supply_item"),
        ),
    ]

    return filter_widgets
예제 #2
0
    def customise_hrm_human_resource_resource(r, tablename):

        s3db = current.s3db

        if r.interactive:
            # Custom CRUD form
            from s3 import S3SQLCustomForm
            crud_form = S3SQLCustomForm(
                "organisation_id",
                "person_id",
                "job_title_id",
                "department_id",
            )

            # Custom filter widgets
            from s3 import S3TextFilter, S3OptionsFilter, s3_get_filter_opts
            filter_widgets = [
                S3TextFilter(
                    [
                        "person_id$first_name",
                        "person_id$middle_name",
                        "person_id$last_name",
                        "person_id$email.value",
                    ],
                    label=T("Search"),
                    comment=T("You can search by name or email address."),
                ),
                S3OptionsFilter(
                    "organisation_id",
                    filter=True,
                    header="",
                ),
                S3OptionsFilter(
                    "job_title_id",
                    options=s3_get_filter_opts("hrm_job_title"),
                    hidden=True,
                ),
            ]

            s3db.configure(
                "hrm_human_resource",
                crud_form=crud_form,
                filter_widgets=filter_widgets,
            )

        # Configure table
        s3db.configure(
            "hrm_human_resource",
            list_fields=human_resource_list_fields,
        )
예제 #3
0
파일: config.py 프로젝트: redhumus/eden
    def customise_hrm_human_resource_resource(r, tablename):

        s3db = current.s3db

        if r.interactive:
            # Custom CRUD form
            from s3 import S3SQLCustomForm
            crud_form = S3SQLCustomForm("organisation_id",
                                        "person_id",
                                        "job_title_id",
                                        "department_id",
                                        )

            # Custom filter widgets
            from s3 import S3TextFilter, S3OptionsFilter, s3_get_filter_opts
            filter_widgets = [
                S3TextFilter(["person_id$first_name",
                              "person_id$middle_name",
                              "person_id$last_name",
                              "person_id$email.value",
                              ],
                              label = T("Search"),
                              comment = T("You can search by name or email address."),
                             ),
                S3OptionsFilter("organisation_id",
                                filter = True,
                                header = "",
                                ),
                S3OptionsFilter("job_title_id",
                                options = s3_get_filter_opts("hrm_job_title"),
                                hidden = True,
                                ),
                ]

            s3db.configure("hrm_human_resource",
                           crud_form = crud_form,
                           filter_widgets = filter_widgets,
                           )

        # Configure table
        s3db.configure("hrm_human_resource",
                       list_fields = human_resource_list_fields,
                       )
예제 #4
0
    def prep(r):

        # Filter to persons who have a case registered
        resource = r.resource
        resource.add_filter(FS("dvr_case.id") != None)

        get_vars = r.get_vars
        mine = True if get_vars.get("mine") == "1" else False

        beneficiary = settings.get_dvr_label(
        )  # If we add more options in future then == "Beneficiary"
        if beneficiary:
            CASES = T("Beneficiaries")
            CURRENT = T("Current Beneficiaries")
            CLOSED = T("Former Beneficiaries")
        else:
            if mine:
                CASES = T("My Cases")
                CURRENT = T("My Current Cases")
            else:
                CASES = T("Cases")
                CURRENT = T("Current Cases")
            CLOSED = T("Closed Cases")

        # Filters to split case list
        if not r.record:

            # Filter to active/archived cases
            archived = get_vars.get("archived")
            if archived == "1":
                archived = True
                CASES = T("Archived Cases")
                query = FS("dvr_case.archived") == True
            else:
                archived = False
                query = (FS("dvr_case.archived") == False) | \
                        (FS("dvr_case.archived") == None)

            # Filter for cases assigned to the logged-in user
            if mine:
                human_resource_id = auth.s3_logged_in_human_resource()
                if human_resource_id:
                    query &= (
                        FS("dvr_case.human_resource_id") == human_resource_id)
                else:
                    query &= (FS("dvr_case.human_resource_id").belongs(set()))

            # Filter to open/closed cases
            # (also filtering status filter opts)
            closed = get_vars.get("closed")
            get_status_opts = s3db.dvr_case_status_filter_opts
            if closed == "1":
                CASES = CLOSED
                query &= FS("dvr_case.status_id$is_closed") == True
                status_opts = lambda: get_status_opts(closed=True)
            elif closed == "0":
                CASES = CURRENT
                query &= (FS("dvr_case.status_id$is_closed") == False) | \
                         (FS("dvr_case.status_id$is_closed") == None)
                status_opts = lambda: get_status_opts(closed=False)
            else:
                status_opts = get_status_opts

            resource.add_filter(query)
        else:
            archived = False
            status_opts = s3db.dvr_case_status_filter_opts

            # Set default for dvr_case_effort.person_id and hide it
            etable = s3db.dvr_case_effort
            field = etable.person_id
            field.default = r.record.id
            field.readable = field.writable = False

            # Set default for dvr_case_effort.human_resource_id
            field = etable.human_resource_id
            field.default = auth.s3_logged_in_human_resource()

        # Should not be able to delete records in this view
        resource.configure(deletable=False)

        if r.component and r.id:
            ctable = r.component.table
            if "case_id" in ctable.fields and \
               str(ctable.case_id.type)[:18] == "reference dvr_case":

                # Find the Case ID
                dvr_case = s3db.dvr_case
                query = (dvr_case.person_id == r.id) & \
                        (dvr_case.deleted != True)
                cases = db(query).select(dvr_case.id, limitby=(0, 2))

                case_id = ctable.case_id
                if cases:
                    # Set default
                    case_id.default = cases.first().id
                if len(cases) == 1:
                    # Only one case => hide case selector
                    case_id.readable = case_id.writable = False
                else:
                    # Configure case selector
                    case_id.requires = IS_ONE_OF(
                        db(query),
                        "dvr_case.id",
                        case_id.represent,
                    )

        if r.interactive:

            # Adapt CRUD strings to context
            if beneficiary:
                s3.crud_strings["pr_person"] = Storage(
                    label_create=T("Create Beneficiary"),
                    title_display=T("Beneficiary Details"),
                    title_list=CASES,
                    title_update=T("Edit Beneficiary Details"),
                    label_list_button=T("List Beneficiaries"),
                    label_delete_button=T("Delete Beneficiary"),
                    msg_record_created=T("Beneficiary added"),
                    msg_record_modified=T("Beneficiary details updated"),
                    msg_record_deleted=T("Beneficiary deleted"),
                    msg_list_empty=T("No Beneficiaries currently registered"))
            else:
                s3.crud_strings["pr_person"] = Storage(
                    label_create=T("Create Case"),
                    title_display=T("Case Details"),
                    title_list=CASES,
                    title_update=T("Edit Case Details"),
                    label_list_button=T("List Cases"),
                    label_delete_button=T("Delete Case"),
                    msg_record_created=T("Case added"),
                    msg_record_modified=T("Case details updated"),
                    msg_record_deleted=T("Case deleted"),
                    msg_list_empty=T("No Cases currently registered"))

            if not r.component:

                from s3 import S3SQLCustomForm, \
                               S3SQLInlineComponent, \
                               S3TextFilter, \
                               S3OptionsFilter, \
                               s3_get_filter_opts

                # Expose the "archived"-flag? (update forms only)
                if r.record and r.method != "read":
                    ctable = s3db.dvr_case
                    field = ctable.archived
                    field.readable = field.writable = True

                # Module-specific CRUD form
                # NB: this assumes single case per person, must use
                #     case perspective (dvr/case) for multiple cases
                #     per person!
                crud_form = S3SQLCustomForm(
                    "dvr_case.reference",
                    "dvr_case.organisation_id",
                    "dvr_case.date",
                    "dvr_case.status_id",
                    "first_name",
                    "middle_name",
                    "last_name",
                    "date_of_birth",
                    "gender",
                    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",
                    S3SQLInlineComponent(
                        "address",
                        label=T("Current Address"),
                        fields=[
                            ("", "location_id"),
                        ],
                        filterby={
                            "field": "type",
                            "options": "1",
                        },
                        link=False,
                        multiple=False,
                    ),
                    "dvr_case.comments",
                    "dvr_case.archived",
                )

                # Module-specific filter widgets
                filter_widgets = [
                    S3TextFilter(
                        [
                            "pe_label",
                            "first_name",
                            "middle_name",
                            "last_name",
                            #"email.value",
                            #"phone.value",
                            "dvr_case.reference",
                        ],
                        label=T("Search"),
                        comment=T("You can search by name, ID or case number"),
                    ),
                    S3OptionsFilter(
                        "dvr_case.status_id",
                        cols=3,
                        default=default_status,
                        #label = T("Case Status"),
                        options=status_opts,
                        sort=False,
                    ),
                    S3OptionsFilter("person_details.nationality", ),
                ]

                # Add filter for case flags
                if settings.get_dvr_case_flags():
                    filter_widgets.append(
                        S3OptionsFilter(
                            "case_flag_case.flag_id",
                            label=T("Flags"),
                            options=s3_get_filter_opts(
                                "dvr_case_flag",
                                translate=True,
                            ),
                            cols=3,
                            hidden=True,
                        ))

                # Add filter for transferability if relevant for deployment
                if settings.get_dvr_manage_transferability():
                    filter_widgets.append(
                        S3OptionsFilter(
                            "dvr_case.transferable",
                            options={
                                True: T("Yes"),
                                False: T("No"),
                            },
                            cols=2,
                            hidden=True,
                        ))

                resource.configure(
                    crud_form=crud_form,
                    filter_widgets=filter_widgets,
                )

            elif r.component.tablename == "dvr_case_activity":

                # Set default statuses for components
                if settings.get_dvr_case_activity_use_status():
                    s3db.dvr_case_activity_default_status()

                if settings.get_dvr_manage_response_actions():
                    s3db.dvr_response_default_status()

            elif r.component_name == "allowance" and \
                 r.method in (None, "update"):

                records = r.component.select(["status"], as_rows=True)
                if len(records) == 1:
                    record = records[0]
                    table = r.component.table
                    readonly = []
                    if record.status == 2:
                        # Can't change payment details if already paid
                        readonly = [
                            "person_id",
                            "entitlement_period",
                            "date",
                            "paid_on",
                            "amount",
                            "currency",
                        ]
                    for fn in readonly:
                        if fn in table.fields:
                            field = table[fn]
                            field.writable = False
                            field.comment = None

            elif r.component_name == "evaluation":

                from s3 import S3SQLInlineComponent

                crud_fields = [  #"person_id",
                    #"case_id",
                    #"date",
                ]
                cappend = crud_fields.append

                table = s3db.dvr_evaluation_question
                rows = db(table.deleted != True).select(
                    table.id,
                    table.section,
                    #table.header,
                    table.number,
                    table.name,
                    orderby=table.number,
                )

                #subheadings = {}

                section = None
                for row in rows:
                    name = "number%s" % row.number
                    if row.section != section:
                        label = section = row.section
                        #subheadings[T(section)] = "sub_%sdata" % name
                    else:
                        label = ""
                    cappend(
                        S3SQLInlineComponent(
                            "data",
                            name=name,
                            label=label,
                            fields=(
                                ("", "question_id"),
                                ("", "answer"),
                            ),
                            filterby=dict(field="question_id", options=row.id),
                            multiple=False,
                        ), )

                cappend("comments")
                crud_form = s3base.S3SQLCustomForm(*crud_fields)

                s3db.configure(
                    "dvr_evaluation",
                    crud_form=crud_form,
                    #subheadings = subheadings,
                )

        # Module-specific list fields (must be outside of r.interactive)
        list_fields = [
            "dvr_case.reference",
            "first_name",
            "middle_name",
            "last_name",
            "date_of_birth",
            "gender",
            "dvr_case.date",
            "dvr_case.status_id",
        ]
        resource.configure(list_fields=list_fields, )

        return True
예제 #5
0
파일: config.py 프로젝트: redhumus/eden
    def customise_org_organisation_resource(r, tablename):

        s3db = current.s3db

        # Use comments field for org description
        table = s3db.org_organisation
        field = table.comments
        from gluon import DIV
        field.comment = DIV(_class="tooltip",
                            _title="%s|%s" % (T("About"),
                                              T("Describe the organisation, e.g. mission, history and other relevant details")))

        if not current.auth.is_logged_in():
            field = table.logo
            field.readable = field.writable = False
            # User can create records since we need this during registration,
            # but we don't want to let the user do this from the list view
            s3db.configure("org_organisation",
                           listadd = False,
                           )

        # Custom filters to match the information provided
        from s3 import S3LocationFilter, \
                       S3OptionsFilter, \
                       S3TextFilter, \
                       s3_get_filter_opts

        filter_widgets = [
            S3TextFilter(["name",
                          "acronym",
                          #"website",
                          #"comments",
                          ],
                         label = T("Search"),
                         comment = T("Search by organization name or acronym. You can use * as wildcard."),
                         ),
            S3OptionsFilter("organisation_organisation_type.organisation_type_id",
                            label = T("Type"),
                            ),
            S3OptionsFilter("service_location.service_location_service.service_id",
                            options = s3_get_filter_opts("org_service",
                                                         translate = True,
                                                         ),
                            ),
            S3OptionsFilter("sector_organisation.sector_id",
                            options = s3_get_filter_opts("org_sector",
                                                         translate = True,
                                                         ),
                            hidden = True,
                            ),
            ]

        # CRUD Form
        from s3 import S3SQLCustomForm, \
                       S3SQLInlineComponent, \
                       S3SQLInlineLink, \
                       S3SQLVerticalSubFormLayout
        multitype = settings.get_org_organisation_types_multiple()
        crud_form = S3SQLCustomForm("name",
                                    "acronym",
                                    S3SQLInlineLink(
                                            "organisation_type",
                                            field = "organisation_type_id",
                                            filter = False,
                                            label = T("Type"),
                                            multiple = multitype,
                                            ),
                                    "country",
                                    S3SQLInlineLink("sector",
                                            cols = 3,
                                            label = T("Sectors"),
                                            field = "sector_id",
                                            #required = True,
                                            ),
                                    (T("About"), "comments"),
                                    "website",
                                    S3SQLInlineComponent(
                                            "contact",
                                            name = "email",
                                            label = T("Email"),
                                            #multiple = False,
                                            fields = [("", "value"),
                                                      ],
                                            filterby = [{"field": "contact_method",
                                                         "options": "EMAIL",
                                                         },
                                                        ],
                                            ),
                                    S3SQLInlineComponent(
                                            "facility",
                                            label = T("Main Office"),
                                            fields = ["name",
                                                      "phone1",
                                                      "phone2",
                                                      #"email",
                                                      "location_id",
                                                      ],
                                            layout = S3SQLVerticalSubFormLayout,
                                            filterby = {"field": "main_facility",
                                                        "options": True,
                                                        },
                                            multiple = False,
                                            ),
                                    S3SQLInlineComponent(
                                        "document",
                                        fields = [(T("Title"), "name"),
                                                  "file",
                                                  ],
                                        filterby = {"field": "file",
                                                    "options": "",
                                                    "invert": True,
                                                    },
                                        label = T("Files"),
                                        name = "file",
                                        ),
                                    S3SQLInlineComponent(
                                        "document",
                                        fields = [(T("Title"), "name"),
                                                  "url",
                                                  ],
                                        filterby = {"field": "url",
                                                    "options": None,
                                                    "invert": True,
                                                    },
                                        label = T("Links"),
                                        name = "url",
                                        ),
                                    )

        s3db.configure("org_organisation",
                       filter_widgets = filter_widgets,
                       crud_form = crud_form,
                       )
예제 #6
0
파일: dvr.py 프로젝트: nursix/eden
    def prep(r):

        # Filter to persons who have a case registered
        resource = r.resource
        resource.add_filter(FS("dvr_case.id") != None)

        get_vars = r.get_vars
        mine = True if get_vars.get("mine") == "1" else False

        beneficiary = settings.get_dvr_label() # If we add more options in future then == "Beneficiary"
        if beneficiary:
            CASES = T("Beneficiaries")
            CURRENT = T("Current Beneficiaries")
            CLOSED = T("Former Beneficiaries")
        else:
            if mine:
                CASES = T("My Cases")
                CURRENT = T("My Current Cases")
            else:
                CASES = T("Cases")
                CURRENT = T("Current Cases")
            CLOSED = T("Closed Cases")

        # Filters to split case list
        if not r.record:

            # Filter to active/archived cases
            archived = get_vars.get("archived")
            if archived == "1":
                archived = True
                CASES = T("Archived Cases")
                query = FS("dvr_case.archived") == True
            else:
                archived = False
                query = (FS("dvr_case.archived") == False) | \
                        (FS("dvr_case.archived") == None)

            # Filter for cases assigned to the logged-in user
            if mine:
                human_resource_id = auth.s3_logged_in_human_resource()
                if human_resource_id:
                    query &= (FS("dvr_case.human_resource_id") == human_resource_id)
                else:
                    query &= (FS("dvr_case.human_resource_id").belongs(set()))

            # Filter to open/closed cases
            # (also filtering status filter opts)
            closed = get_vars.get("closed")
            get_status_opts = s3db.dvr_case_status_filter_opts
            if closed == "1":
                CASES = CLOSED
                query &= FS("dvr_case.status_id$is_closed") == True
                status_opts = lambda: get_status_opts(closed=True)
            elif closed == "0":
                CASES = CURRENT
                query &= (FS("dvr_case.status_id$is_closed") == False) | \
                         (FS("dvr_case.status_id$is_closed") == None)
                status_opts = lambda: get_status_opts(closed=False)
            else:
                status_opts = get_status_opts

            resource.add_filter(query)
        else:
            archived = False
            status_opts = s3db.dvr_case_status_filter_opts

            # Set default for dvr_case_effort.person_id and hide it
            etable = s3db.dvr_case_effort
            field = etable.person_id
            field.default = r.record.id
            field.readable = field.writable = False

            # Set default for dvr_case_effort.human_resource_id
            field = etable.human_resource_id
            field.default = auth.s3_logged_in_human_resource()

        # Should not be able to delete records in this view
        resource.configure(deletable = False)

        if r.component and r.id:
            ctable = r.component.table
            if "case_id" in ctable.fields and \
               str(ctable.case_id.type)[:18] == "reference dvr_case":

                # Find the Case ID
                dvr_case = s3db.dvr_case
                query = (dvr_case.person_id == r.id) & \
                        (dvr_case.deleted != True)
                cases = db(query).select(dvr_case.id, limitby=(0, 2))

                case_id = ctable.case_id
                if cases:
                    # Set default
                    case_id.default = cases.first().id
                if len(cases) == 1:
                    # Only one case => hide case selector
                    case_id.readable = case_id.writable = False
                else:
                    # Configure case selector
                    case_id.requires = IS_ONE_OF(db(query), "dvr_case.id",
                                                 case_id.represent,
                                                 )

        if r.interactive:

            # Adapt CRUD strings to context
            if beneficiary:
                s3.crud_strings["pr_person"] = Storage(
                    label_create = T("Create Beneficiary"),
                    title_display = T("Beneficiary Details"),
                    title_list = CASES,
                    title_update = T("Edit Beneficiary Details"),
                    label_list_button = T("List Beneficiaries"),
                    label_delete_button = T("Delete Beneficiary"),
                    msg_record_created = T("Beneficiary added"),
                    msg_record_modified = T("Beneficiary details updated"),
                    msg_record_deleted = T("Beneficiary deleted"),
                    msg_list_empty = T("No Beneficiaries currently registered")
                    )
            else:
                s3.crud_strings["pr_person"] = Storage(
                    label_create = T("Create Case"),
                    title_display = T("Case Details"),
                    title_list = CASES,
                    title_update = T("Edit Case Details"),
                    label_list_button = T("List Cases"),
                    label_delete_button = T("Delete Case"),
                    msg_record_created = T("Case added"),
                    msg_record_modified = T("Case details updated"),
                    msg_record_deleted = T("Case deleted"),
                    msg_list_empty = T("No Cases currently registered")
                    )

            component = r.component
            if not component:

                from s3 import S3SQLCustomForm, \
                               S3SQLInlineComponent, \
                               S3TextFilter, \
                               S3OptionsFilter, \
                               s3_get_filter_opts

                # Expose the "archived"-flag? (update forms only)
                if r.record and r.method != "read":
                    ctable = s3db.dvr_case
                    field = ctable.archived
                    field.readable = field.writable = True

                # Module-specific CRUD form
                # NB: this assumes single case per person, must use
                #     case perspective (dvr/case) for multiple cases
                #     per person!
                crud_form = S3SQLCustomForm(
                                #"dvr_case.reference",
                                "dvr_case.organisation_id",
                                "dvr_case.date",
                                "dvr_case.status_id",
                                #"pe_label",
                                "first_name",
                                "middle_name",
                                "last_name",
                                "date_of_birth",
                                "gender",
                                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",
                                S3SQLInlineComponent(
                                        "address",
                                        label = T("Current Address"),
                                        fields = [("", "location_id")],
                                        filterby = {"field": "type",
                                                    "options": "1",
                                                    },
                                        link = False,
                                        multiple = False,
                                        ),
                                "dvr_case.comments",
                                "dvr_case.archived",
                                )

                # Module-specific filter widgets
                filter_widgets = [
                    S3TextFilter(["pe_label",
                                  "first_name",
                                  "middle_name",
                                  "last_name",
                                  #"email.value",
                                  #"phone.value",
                                  #"dvr_case.reference",
                                  ],
                                  label = T("Search"),
                                  comment = T("You can search by name, ID or case number"),
                                  ),
                    S3OptionsFilter("dvr_case.status_id",
                                    cols = 3,
                                    default = default_status,
                                    #label = T("Case Status"),
                                    options = status_opts,
                                    sort = False,
                                    ),
                    S3OptionsFilter("person_details.nationality",
                                    ),
                    ]

                # Add filter for case flags
                if settings.get_dvr_case_flags():
                    filter_widgets.append(
                        S3OptionsFilter("case_flag_case.flag_id",
                                        label = T("Flags"),
                                        options = s3_get_filter_opts("dvr_case_flag",
                                                                     translate = True,
                                                                     ),
                                        cols = 3,
                                        hidden = True,
                                        ))

                # Add filter for transferability if relevant for deployment
                if settings.get_dvr_manage_transferability():
                    filter_widgets.append(
                        S3OptionsFilter("dvr_case.transferable",
                                        options = {True: T("Yes"),
                                                   False: T("No"),
                                                   },
                                        cols = 2,
                                        hidden = True,
                                        ))

                resource.configure(crud_form = crud_form,
                                   filter_widgets = filter_widgets,
                                   )

            elif component.tablename == "dvr_case_activity":

                # Set default statuses for components
                if settings.get_dvr_case_activity_use_status():
                    s3db.dvr_case_activity_default_status()

                if settings.get_dvr_manage_response_actions():
                    s3db.dvr_response_default_status()

            elif component.tablename == "dvr_response_action":

                if settings.get_dvr_manage_response_actions():
                    s3db.dvr_response_default_status()

            elif r.component_name == "allowance" and \
                 r.method in (None, "update"):

                records = component.select(["status"], as_rows=True)
                if len(records) == 1:
                    record = records[0]
                    table = component.table
                    readonly = []
                    if record.status == 2:
                        # Can't change payment details if already paid
                        readonly = ["person_id",
                                    "entitlement_period",
                                    "date",
                                    "paid_on",
                                    "amount",
                                    "currency",
                                    ]
                    for fn in readonly:
                        if fn in table.fields:
                            field = table[fn]
                            field.writable = False
                            field.comment = None

            elif r.component_name == "evaluation":

                from s3 import S3SQLInlineComponent

                crud_fields = [#"person_id",
                               #"case_id",
                               #"date",
                               ]
                cappend = crud_fields.append

                table = s3db.dvr_evaluation_question
                rows = db(table.deleted != True).select(table.id,
                                                        table.section,
                                                        #table.header,
                                                        table.number,
                                                        table.name,
                                                        orderby = table.number,
                                                        )

                #subheadings = {}

                section = None
                for row in rows:
                    name = "number%s" % row.number
                    if row.section != section:
                        label = section = row.section
                        #subheadings["sub_%sdata" % name] = T(section)
                    else:
                        label = ""
                    cappend(S3SQLInlineComponent("data",
                                                 name = name,
                                                 label = label,
                                                 fields = (("", "question_id"),
                                                           ("", "answer"),
                                                           ),
                                                 filterby = dict(field = "question_id",
                                                                 options = row.id
                                                                 ),
                                                 multiple = False,
                                                 ),
                            )

                cappend("comments")
                crud_form = s3base.S3SQLCustomForm(*crud_fields)

                s3db.configure("dvr_evaluation",
                               crud_form = crud_form,
                               #subheadings = subheadings,
                               )

        # Module-specific list fields (must be outside of r.interactive)
        list_fields = [#"dvr_case.reference",
                       #"pe_label",
                       "first_name",
                       "middle_name",
                       "last_name",
                       "date_of_birth",
                       "gender",
                       "dvr_case.date",
                       "dvr_case.status_id",
                       ]
        resource.configure(list_fields = list_fields,
                           )

        return True
예제 #7
0
파일: requests.py 프로젝트: sahana/eden
def req_filter_widgets():
    """
        Filter widgets for requests

        @returns: list of filter widgets
    """

    T = current.T

    from s3 import S3DateFilter, \
                   S3LocationFilter, \
                   S3OptionsFilter, \
                   S3TextFilter, \
                   s3_get_filter_opts

    from s3db.req import req_status_opts

    req_status_opts = OrderedDict(
        sorted(
            req_status_opts().items(),
            key=lambda i: i[0],
        ))

    filter_widgets = [
        S3TextFilter(
            ["req_ref"],
            label=T("Order No."),
        ),
        S3DateFilter("date"),
        S3OptionsFilter(
            "transit_status",
            cols=3,
            options=req_status_opts,
            sort=False,
        ),
        S3OptionsFilter(
            "fulfil_status",
            cols=3,
            hidden=True,
            options=req_status_opts,
            sort=False,
        ),
        S3OptionsFilter(
            "req_item.item_id",
            hidden=True,
            options=lambda: s3_get_filter_opts("supply_item"),
        ),
    ]

    if current.auth.s3_has_role("SUPPLY_COORDINATOR"):

        coordinator_filters = [
            S3LocationFilter(
                "site_id$location_id",
                levels=["L3", "L4"],
            ),
            S3TextFilter(
                "site_id$location_id$addr_postcode",
                label=T("Postcode"),
            ),
            S3OptionsFilter("site_id", hidden=True),
            S3OptionsFilter(
                "site_id$organisation_id$delivery.value",
                label=T("Delivery##supplying"),
                options=delivery_tag_opts(),
            ),
        ]
        filter_widgets[2:2] = coordinator_filters

    return filter_widgets
예제 #8
0
    def customise_org_organisation_resource(r, tablename):

        s3db = current.s3db

        # Use comments field for org description
        table = s3db.org_organisation
        field = table.comments
        from gluon import DIV
        field.comment = DIV(
            _class="tooltip",
            _title="%s|%s" %
            (T("About"),
             T("Describe the organisation, e.g. mission, history and other relevant details"
               )))

        if not current.auth.is_logged_in():
            field = table.logo
            field.readable = field.writable = False
            # User can create records since we need this during registration,
            # but we don't want to let the user do this from the list view
            s3db.configure(
                "org_organisation",
                listadd=False,
            )

        # Custom filters to match the information provided
        from s3 import S3LocationFilter, \
                       S3OptionsFilter, \
                       S3TextFilter, \
                       s3_get_filter_opts

        filter_widgets = [
            S3TextFilter(
                [
                    "name",
                    "acronym",
                    #"website",
                    #"comments",
                ],
                label=T("Search"),
                comment=
                T("Search by organization name or acronym. You can use * as wildcard."
                  ),
            ),
            S3OptionsFilter(
                "organisation_organisation_type.organisation_type_id",
                label=T("Type"),
            ),
            S3OptionsFilter(
                "service_location.service_location_service.service_id",
                options=s3_get_filter_opts(
                    "org_service",
                    translate=True,
                ),
            ),
            S3OptionsFilter(
                "sector_organisation.sector_id",
                options=s3_get_filter_opts(
                    "org_sector",
                    translate=True,
                ),
                hidden=True,
            ),
        ]

        # CRUD Form
        from s3 import S3SQLCustomForm, \
                       S3SQLInlineComponent, \
                       S3SQLInlineLink, \
                       S3SQLVerticalSubFormLayout
        multitype = settings.get_org_organisation_types_multiple()
        crud_form = S3SQLCustomForm(
            "name",
            "acronym",
            S3SQLInlineLink(
                "organisation_type",
                field="organisation_type_id",
                filter=False,
                label=T("Type"),
                multiple=multitype,
            ),
            "country",
            S3SQLInlineLink(
                "sector",
                cols=3,
                label=T("Sectors"),
                field="sector_id",
                #required = True,
            ),
            (T("About"), "comments"),
            "website",
            S3SQLInlineComponent(
                "contact",
                name="email",
                label=T("Email"),
                #multiple = False,
                fields=[
                    ("", "value"),
                ],
                filterby=[
                    {
                        "field": "contact_method",
                        "options": "EMAIL",
                    },
                ],
            ),
            S3SQLInlineComponent(
                "facility",
                label=T("Main Office"),
                fields=[
                    "name",
                    "phone1",
                    "phone2",
                    #"email",
                    "location_id",
                ],
                layout=S3SQLVerticalSubFormLayout,
                filterby={
                    "field": "main_facility",
                    "options": True,
                },
                multiple=False,
            ),
            S3SQLInlineComponent(
                "document",
                fields=[
                    (T("Title"), "name"),
                    "file",
                ],
                filterby={
                    "field": "file",
                    "options": "",
                    "invert": True,
                },
                label=T("Files"),
                name="file",
            ),
            S3SQLInlineComponent(
                "document",
                fields=[
                    (T("Title"), "name"),
                    "url",
                ],
                filterby={
                    "field": "url",
                    "options": None,
                    "invert": True,
                },
                label=T("Links"),
                name="url",
            ),
        )

        s3db.configure(
            "org_organisation",
            filter_widgets=filter_widgets,
            crud_form=crud_form,
        )
예제 #9
0
파일: config.py 프로젝트: nck0405/MyOwn
        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",
                                )

                    # 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
예제 #10
0
파일: config.py 프로젝트: BIGGANI/eden-1
        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
예제 #11
0
    def prep(r):

        # Filter to persons who have a case registered
        resource = r.resource
        resource.add_filter(FS("dvr_case.id") != None)

        CASES = T("Cases")

        # Filters to split case list
        if not r.record:
            get_vars = r.get_vars

            # Filter to active/archived cases
            archived = get_vars.get("archived")
            if archived == "1":
                archived = True
                CASES = T("Archived Cases")
                query = FS("dvr_case.archived") == True
            else:
                archived = False
                query = (FS("dvr_case.archived") == False) | \
                        (FS("dvr_case.archived") == None)

            # Filter to open/closed cases
            # (also filtering status filter opts)
            closed = get_vars.get("closed")
            get_status_opts = s3db.dvr_case_status_filter_opts
            if closed == "1":
                CASES = T("Closed Cases")
                query &= FS("dvr_case.status_id$is_closed") == True
                status_opts = lambda: get_status_opts(closed=True)
            elif closed == "0":
                CASES = T("Current Cases")
                query &= (FS("dvr_case.status_id$is_closed") == False) | \
                         (FS("dvr_case.status_id$is_closed") == None)
                status_opts = lambda: get_status_opts(closed=False)
            else:
                status_opts = get_status_opts

            resource.add_filter(query)
        else:
            archived = False
            status_opts = s3db.dvr_case_status_filter_opts

        # Should not be able to delete records in this view
        resource.configure(deletable = False)

        if r.component and r.id:
            ctable = r.component.table
            if "case_id" in ctable.fields and \
               str(ctable.case_id.type)[:18] == "reference dvr_case":

                # Find the Case ID
                dvr_case = s3db.dvr_case
                query = (dvr_case.person_id == r.id) & \
                        (dvr_case.deleted != True)
                cases = db(query).select(dvr_case.id, limitby=(0, 2))

                case_id = ctable.case_id
                if cases:
                    # Set default
                    case_id.default = cases.first().id
                if len(cases) == 1:
                    # Only one case => hide case selector
                    case_id.readable = case_id.writable = False
                else:
                    # Configure case selector
                    case_id.requires = IS_ONE_OF(db(query), "dvr_case.id",
                                                 case_id.represent,
                                                 )

        if r.interactive:

            # Adapt CRUD strings to context

            s3.crud_strings["pr_person"] = Storage(
                label_create = T("Create Case"),
                title_display = T("Case Details"),
                title_list = CASES,
                title_update = T("Edit Case Details"),
                label_list_button = T("List Cases"),
                label_delete_button = T("Delete Case"),
                msg_record_created = T("Case added"),
                msg_record_modified = T("Case details updated"),
                msg_record_deleted = T("Case deleted"),
                msg_list_empty = T("No Cases currently registered")
                )

            if not r.component:

                # Expose the "archived"-flag? (update forms only)
                if r.record and r.method != "read":
                    ctable = s3db.dvr_case
                    field = ctable.archived
                    field.readable = field.writable = True

                # Module-specific CRUD form
                # NB: this assumes single case per person, must use
                #     case perspective (dvr/case) for multiple cases
                #     per person!
                from s3 import S3SQLCustomForm, S3SQLInlineComponent
                crud_form = S3SQLCustomForm(
                                "dvr_case.reference",
                                "dvr_case.organisation_id",
                                "dvr_case.date",
                                "dvr_case.status_id",
                                "first_name",
                                "middle_name",
                                "last_name",
                                "date_of_birth",
                                "gender",
                                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",
                                S3SQLInlineComponent(
                                        "address",
                                        label = T("Current Address"),
                                        fields = [("", "location_id"),
                                                  ],
                                        filterby = {"field": "type",
                                                    "options": "1",
                                                    },
                                        link = False,
                                        multiple = False,
                                        ),
                                "dvr_case.comments",
                                "dvr_case.archived",
                                )

                # Module-specific filter widgets
                from s3 import s3_get_filter_opts, S3TextFilter, S3OptionsFilter
                filter_widgets = [
                    S3TextFilter(["pe_label",
                                  "first_name",
                                  "middle_name",
                                  "last_name",
                                  #"email.value",
                                  #"phone.value",
                                  "dvr_case.reference",
                                  ],
                                  label = T("Search"),
                                  comment = T("You can search by name, ID or case number"),
                                  ),
                    S3OptionsFilter("dvr_case.status_id",
                                    cols = 3,
                                    default = default_status,
                                    #label = T("Case Status"),
                                    options = status_opts,
                                    sort = False,
                                    ),
                    S3OptionsFilter("person_details.nationality",
                                    ),
                    S3OptionsFilter("case_flag_case.flag_id",
                                    label = T("Flags"),
                                    options = s3_get_filter_opts("dvr_case_flag",
                                                                 translate = True,
                                                                 ),
                                    cols = 3,
                                    hidden = True,
                                    ),
                    ]

                # Add filter for transferability if relevant for deployment
                if settings.get_dvr_manage_transferability():
                    filter_widgets.append(
                        S3OptionsFilter("dvr_case.transferable",
                                        options = {True: T("Yes"),
                                                   False: T("No"),
                                                   },
                                        cols = 2,
                                        hidden = True,
                                        )
                        )

                resource.configure(crud_form = crud_form,
                                   filter_widgets = filter_widgets,
                                   )

        # Module-specific list fields (must be outside of r.interactive)
        list_fields = ["dvr_case.reference",
                       "first_name",
                       "middle_name",
                       "last_name",
                       "date_of_birth",
                       "gender",
                       "dvr_case.date",
                       "dvr_case.status_id",
                       ]
        resource.configure(list_fields = list_fields,
                           )

        return True
예제 #12
0
파일: config.py 프로젝트: flavour/aidiq
        def custom_prep(r):

            resource = r.resource

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

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

            resource.configure(list_fields = list_fields)

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

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

            if r.interactive:

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

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

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

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

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

                resource.configure(filter_widgets=filter_widgets)
            return True
예제 #13
0
파일: dvr.py 프로젝트: nck0405/MyOwn
    def prep(r):

        # Filter to persons who have a case registered
        resource = r.resource
        resource.add_filter(FS("dvr_case.id") != None)

        if r.component and r.id:
            ctable = r.component.table
            if "case_id" in ctable.fields and \
               str(ctable.case_id.type)[:18] == "reference dvr_case":

                # Find the Case ID
                dvr_case = s3db.dvr_case
                query = (dvr_case.person_id == r.id) & \
                        (dvr_case.deleted != True)
                cases = db(query).select(dvr_case.id, limitby=(0, 2))

                case_id = ctable.case_id
                if cases:
                    # Set default
                    case_id.default = cases.first().id
                if len(cases) == 1:
                    # Only one case => hide case selector
                    case_id.readable = case_id.writable = False
                else:
                    # Configure case selector
                    case_id.requires = IS_ONE_OF(db(query), "dvr_case.id",
                                                 case_id.represent,
                                                 )

        if r.interactive:

            # Adapt CRUD strings to context
            s3.crud_strings["pr_person"] = Storage(
                label_create = T("Create Case"),
                title_display = T("Case Details"),
                title_list = T("Cases"),
                title_update = T("Edit Case Details"),
                label_list_button = T("List Cases"),
                label_delete_button = T("Delete Case"),
                msg_record_created = T("Case added"),
                msg_record_modified = T("Case details updated"),
                msg_record_deleted = T("Case deleted"),
                msg_list_empty = T("No Cases currently registered")
                )

            if not r.component:
                # Module-specific CRUD form
                # NB: this assumes single case per person, must use
                #     case perspective (dvr/case) for multiple cases
                #     per person!
                from s3 import S3SQLCustomForm, S3SQLInlineComponent
                crud_form = S3SQLCustomForm(
                                "dvr_case.reference",
                                "dvr_case.organisation_id",
                                "dvr_case.date",
                                "dvr_case.status_id",
                                "first_name",
                                "middle_name",
                                "last_name",
                                "date_of_birth",
                                "gender",
                                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",
                                S3SQLInlineComponent(
                                        "address",
                                        label = T("Current Address"),
                                        fields = [("", "location_id"),
                                                  ],
                                        filterby = {"field": "type",
                                                    "options": "1",
                                                    },
                                        link = False,
                                        multiple = False,
                                        ),
                                "dvr_case.comments",
                                )

                # Module-specific filter widgets
                from s3 import s3_get_filter_opts, S3TextFilter, S3OptionsFilter
                filter_widgets = [
                    S3TextFilter(["pe_label",
                                  "first_name",
                                  "middle_name",
                                  "last_name",
                                  #"email.value",
                                  #"phone.value",
                                  "dvr_case.reference",
                                  ],
                                  label = T("Search"),
                                  comment = T("You can search by name, ID or case number"),
                                  ),
                    S3OptionsFilter("dvr_case.status_id",
                                    cols = 3,
                                    default = default_status,
                                    #label = T("Case Status"),
                                    options = s3db.dvr_case_status_filter_opts,
                                    sort = False,
                                    ),
                    S3OptionsFilter("person_details.nationality",
                                    ),
                    S3OptionsFilter("case_flag_case.flag_id",
                                    label = T("Flags"),
                                    options = s3_get_filter_opts("dvr_case_flag",
                                                                 translate = True,
                                                                 ),
                                    cols = 3,
                                    hidden = True,
                                    ),
                    ]

                resource.configure(crud_form = crud_form,
                                   filter_widgets = filter_widgets,
                                   )

        # Module-specific list fields (must be outside of r.interactive)
        list_fields = ["dvr_case.reference",
                       "first_name",
                       "middle_name",
                       "last_name",
                       "date_of_birth",
                       "gender",
                       "dvr_case.date",
                       "dvr_case.status_id",
                       ]
        resource.configure(list_fields = list_fields,
                           )

        return True
예제 #14
0
파일: br.py 프로젝트: rashedomar/eden
    def prep(r):

        resource = r.resource
        table = resource.table

        labels = s3db.br_terminology()
        human_resource_id = auth.s3_logged_in_human_resource()

        # Filter for valid+open cases
        query = (FS("person_id$case.id") != None) & \
                (FS("person_id$case.invalid") == False) & \
                (FS("person_id$case.status_id$is_closed") == False)

        resource.add_filter(query)

        if not r.record:

            # Enable bigtable features for better performance
            settings.base.bigtable = True

            get_vars = r.get_vars
            crud_strings = response.s3.crud_strings["br_case_activity"]

            # Filter for "my activities"
            mine = get_vars.get("mine")
            if mine == "1":
                mine = True
                if human_resource_id:
                    query = FS("human_resource_id") == human_resource_id
                else:
                    query = FS("human_resource_id").belongs(set())
                resource.add_filter(query)
                crud_strings.title_list = T("My Activities")
            else:
                mine = False

            # Adapt list title when filtering for priority 0 (Emergency)
            if get_vars.get("~.priority") == "0":
                crud_strings.title_list = T("Emergencies")

            case_activity_status = settings.get_br_case_activity_status()
            case_activity_need = settings.get_br_case_activity_need()

            # Default status
            if case_activity_status:
                s3db.br_case_activity_default_status()

            # Filter widgets
            from s3 import S3DateFilter, \
                           S3OptionsFilter, \
                           S3TextFilter, \
                           s3_get_filter_opts

            text_filter_fields = [
                "person_id$pe_label",
                "person_id$first_name",
                "person_id$middle_name",
                "person_id$last_name",
            ]
            if settings.get_br_case_activity_subject():
                text_filter_fields.append("subject")
            if settings.get_br_case_activity_need_details():
                text_filter_fields.append("need_details")

            filter_widgets = [
                S3TextFilter(
                    text_filter_fields,
                    label=T("Search"),
                ),
            ]

            multiple_orgs = s3db.br_case_read_orgs()[0]
            if multiple_orgs:
                filter_widgets.append(
                    S3OptionsFilter("person_id$case.organisation_id"))

            if case_activity_status:
                stable = s3db.br_case_activity_status
                query = (stable.deleted == False)
                rows = db(query).select(
                    stable.id,
                    stable.name,
                    stable.is_closed,
                    cache=s3db.cache,
                    orderby=stable.workflow_position,
                )
                status_filter_options = OrderedDict(
                    (row.id, T(row.name)) for row in rows)
                status_filter_defaults = [
                    row.id for row in rows if not row.is_closed
                ]
                filter_widgets.append(
                    S3OptionsFilter(
                        "status_id",
                        options=status_filter_options,
                        default=status_filter_defaults,
                        cols=3,
                        hidden=True,
                        sort=False,
                    ))

            if not mine and settings.get_br_case_activity_manager():
                filter_widgets.append(
                    S3OptionsFilter(
                        "human_resource_id",
                        hidden=True,
                    ))

            filter_widgets.extend([
                S3DateFilter(
                    "date",
                    hidden=True,
                ),
                S3OptionsFilter(
                    "person_id$person_details.nationality",
                    label=T("Client Nationality"),
                    hidden=True,
                ),
            ])

            if case_activity_need:
                org_specific_needs = settings.get_br_needs_org_specific()
                filter_widgets.append(S3OptionsFilter("need_id",
                                                      hidden = True,
                                                      header = True,
                                                      options = lambda: \
                                                                s3_get_filter_opts(
                                                                  "br_need",
                                                                  org_filter = org_specific_needs,
                                                                  translate = True,
                                                                  ),
                                                      ))

            resource.configure(filter_widgets=filter_widgets)

            # Report options
            if r.method == "report":
                facts = (
                    (T("Number of Activities"), "count(id)"),
                    (labels.NUMBER_OF_CASES, "count(person_id)"),
                )
                axes = [
                    "person_id$case.organisation_id",
                    "person_id$gender",
                    "person_id$person_details.nationality",
                    "person_id$person_details.marital_status",
                    "priority",
                ]
                default_rows = "person_id$case.organisation_id"
                default_cols = "person_id$person_details.nationality"

                if settings.get_br_manage_assistance() and \
                   settings.get_br_assistance_themes():
                    axes.insert(1, "assistance_measure_theme.theme_id")
                if case_activity_need:
                    axes.insert(1, "need_id")
                    default_cols = "need_id"
                if case_activity_status:
                    axes.insert(4, "status_id")

                report_options = {
                    "rows": axes,
                    "cols": axes,
                    "fact": facts,
                    "defaults": {
                        "rows": default_rows,
                        "cols": default_cols,
                        "fact": "count(id)",
                        "totals": True,
                    },
                }
                resource.configure(report_options=report_options)

        # Set default for human_resource_ids
        if human_resource_id:
            table.human_resource_id.default = human_resource_id

            utable = s3db.br_case_activity_update
            utable.human_resource_id.default = human_resource_id

        # Represent person_id as link to case file
        field = table.person_id
        field.label = labels.CASE
        field.represent = s3db.pr_PersonRepresent(show_link=True)

        # Add case data to list fields
        list_fields = resource.get_config("list_fields")
        list_fields[1:1] = [
            (T("ID"), "person_id$pe_label"),
            "person_id",
        ]

        # Create/delete must happen on case file tab, not here
        resource.configure(
            insertable=False,
            deletable=False,
        )

        return True
예제 #15
0
파일: requests.py 프로젝트: sahana/eden
def send_filter_widgets():
    """
        Filter widgets for outgoing shipments

        @returns: list of filter widgets
    """

    T = current.T

    from s3 import S3DateFilter, \
                   S3LocationFilter, \
                   S3OptionsFilter, \
                   S3TextFilter, \
                   s3_get_filter_opts
    from s3db.inv import SHIP_STATUS_CANCEL, \
                         SHIP_STATUS_RETURNING, \
                         inv_shipment_status_labels

    send_status_opts = OrderedDict(inv_shipment_status_labels())

    # We don't currently use these statuses
    del send_status_opts[SHIP_STATUS_CANCEL]
    del send_status_opts[SHIP_STATUS_RETURNING]

    filter_widgets = [
        S3TextFilter(
            [
                "req_ref",
                #"send_ref",
            ],
            label=T("Search"),
        ),
        S3DateFilter("date"),
        S3OptionsFilter(
            "status",
            cols=3,
            options=send_status_opts,
            sort=False,
        ),
        S3OptionsFilter(
            "track_item.item_id",
            hidden=True,
            options=lambda: s3_get_filter_opts("supply_item"),
        ),
    ]

    if current.auth.s3_has_role("SUPPLY_COORDINATOR"):

        coordinator_filters = [
            S3OptionsFilter(
                "to_site_id$organisation_id$delivery.value",
                label=T("Delivery##supplying"),
                options=delivery_tag_opts(),
            ),
            S3OptionsFilter(
                "site_id",
                label=T("Distribution Center"),
            ),
            S3OptionsFilter(
                "to_site_id",
                hidden=True,
            ),
            S3LocationFilter("to_site_id$location_id",
                             levels=["L3", "L4"],
                             hidden=True),
            S3TextFilter("to_site_id$location_id$addr_postcode",
                         label=T("Postcode"),
                         hidden=True),
        ]
        filter_widgets[3:3] = coordinator_filters

    return filter_widgets
예제 #16
0
        def custom_prep(r):

            resource = r.resource

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

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

            resource.configure(list_fields=list_fields)

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

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

            if r.interactive:

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

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

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

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

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

                resource.configure(filter_widgets=filter_widgets)
            return True
예제 #17
0
파일: br.py 프로젝트: nursix/eden
    def prep(r):

        resource = r.resource
        table = resource.table

        labels = s3db.br_terminology()
        human_resource_id = auth.s3_logged_in_human_resource()

        # Filter for valid+open cases
        query = (FS("person_id$case.id") != None) & \
                (FS("person_id$case.invalid") == False) & \
                (FS("person_id$case.status_id$is_closed") == False)

        resource.add_filter(query)

        if not r.record:

            # Enable bigtable features for better performance
            settings.base.bigtable = True

            get_vars = r.get_vars
            crud_strings = response.s3.crud_strings["br_case_activity"]

            # Filter for "my activities"
            mine = get_vars.get("mine")
            if mine == "1":
                mine = True
                if human_resource_id:
                    query = FS("human_resource_id") == human_resource_id
                else:
                    query = FS("human_resource_id").belongs(set())
                resource.add_filter(query)
                crud_strings.title_list = T("My Activities")
            else:
                mine = False

            # Adapt list title when filtering for priority 0 (Emergency)
            if get_vars.get("~.priority") == "0":
                crud_strings.title_list = T("Emergencies")

            case_activity_status = settings.get_br_case_activity_status()
            case_activity_need = settings.get_br_case_activity_need()

            # Default status
            if case_activity_status:
                s3db.br_case_activity_default_status()

            # Filter widgets
            from s3 import S3DateFilter, \
                           S3OptionsFilter, \
                           S3TextFilter, \
                           s3_get_filter_opts

            text_filter_fields = ["person_id$pe_label",
                                  "person_id$first_name",
                                  "person_id$middle_name",
                                  "person_id$last_name",
                                  ]
            if settings.get_br_case_activity_subject():
                text_filter_fields.append("subject")
            if settings.get_br_case_activity_need_details():
                text_filter_fields.append("need_details")

            filter_widgets = [S3TextFilter(text_filter_fields,
                                           label = T("Search"),
                                           ),
                             ]

            multiple_orgs = s3db.br_case_read_orgs()[0]
            if multiple_orgs:
                filter_widgets.append(S3OptionsFilter("person_id$case.organisation_id"))

            if case_activity_status:
                stable = s3db.br_case_activity_status
                query = (stable.deleted == False)
                rows = db(query).select(stable.id,
                                        stable.name,
                                        stable.is_closed,
                                        cache = s3db.cache,
                                        orderby = stable.workflow_position,
                                        )
                status_filter_options = OrderedDict((row.id, T(row.name)) for row in rows)
                status_filter_defaults = [row.id for row in rows if not row.is_closed]
                filter_widgets.append(S3OptionsFilter("status_id",
                                                      options = status_filter_options,
                                                      default = status_filter_defaults,
                                                      cols = 3,
                                                      hidden = True,
                                                      sort = False,
                                                      ))

            if not mine and settings.get_br_case_activity_manager():
                filter_widgets.append(S3OptionsFilter("human_resource_id",
                                                      hidden = True,
                                                      ))

            filter_widgets.extend([S3DateFilter("date",
                                                hidden = True,
                                                ),
                                   S3OptionsFilter("person_id$person_details.nationality",
                                                   label = T("Client Nationality"),
                                                   hidden = True,
                                                   ),
                                   ])

            if case_activity_need:
                org_specific_needs = settings.get_br_needs_org_specific()
                filter_widgets.append(S3OptionsFilter("need_id",
                                                      hidden = True,
                                                      header = True,
                                                      options = lambda: \
                                                                s3_get_filter_opts(
                                                                  "br_need",
                                                                  org_filter = org_specific_needs,
                                                                  translate = True,
                                                                  ),
                                                      ))

            resource.configure(filter_widgets=filter_widgets)

            # Report options
            if r.method == "report":
                facts = ((T("Number of Activities"), "count(id)"),
                         (labels.NUMBER_OF_CASES, "count(person_id)"),
                         )
                axes = ["person_id$case.organisation_id",
                        "person_id$gender",
                        "person_id$person_details.nationality",
                        "person_id$person_details.marital_status",
                        "priority",
                        ]
                default_rows = "person_id$case.organisation_id"
                default_cols = "person_id$person_details.nationality"

                if settings.get_br_manage_assistance() and \
                   settings.get_br_assistance_themes():
                    axes.insert(1, "assistance_measure_theme.theme_id")
                if case_activity_need:
                    axes.insert(1, "need_id")
                    default_cols = "need_id"
                if case_activity_status:
                    axes.insert(4, "status_id")

                report_options = {
                    "rows": axes,
                    "cols": axes,
                    "fact": facts,
                    "defaults": {"rows": default_rows,
                                 "cols": default_cols,
                                 "fact": "count(id)",
                                 "totals": True,
                                 },
                    }
                resource.configure(report_options=report_options)

        # Set default for human_resource_ids
        if human_resource_id:
            table.human_resource_id.default = human_resource_id

            utable = s3db.br_case_activity_update
            utable.human_resource_id.default = human_resource_id

        # Represent person_id as link to case file
        field = table.person_id
        field.label = labels.CASE
        field.represent = s3db.pr_PersonRepresent(show_link=True)

        # Add case data to list fields
        list_fields = resource.get_config("list_fields")
        list_fields[1:1] = [(T("ID"), "person_id$pe_label"),
                            "person_id",
                            ]

        # Create/delete must happen on case file tab, not here
        resource.configure(insertable = False,
                           deletable = False,
                           )

        return True