Esempio n. 1
0
def customize_hrm_credential(**attr):
    """
        Customize hrm_credential controller
    """

    # Currently just used by RDRT
    table = current.s3db.hrm_credential
    field = table.job_title_id
    field.comment = None
    field.label = T("Sector")
    from s3.s3validators import IS_ONE_OF
    field.requires = IS_ONE_OF(
        current.db,
        "hrm_job_title.id",
        field.represent,
        filterby="type",
        filter_opts=(4, ),
    )
    table.organisation_id.readable = table.organisation_id.writable = False
    table.performance_rating.readable = table.performance_rating.writable = False
    table.start_date.readable = table.start_date.writable = False
    table.end_date.readable = table.end_date.writable = False

    return attr
Esempio n. 2
0
def ns_only(f, required=True, branches=True, updateable=True):
    """
        Function to configure an organisation_id field to be restricted to just NS/Branch
    """

    # Label
    if branches:
        f.label = T("National Society / Branch")
    else:
        f.label = T("National Society")
    # Requires
    db = current.db
    ttable = db.org_organisation_type
    type_id = db(ttable.name == "Red Cross / Red Crescent").select(
        ttable.id, limitby=(0, 1)).first().id
    if branches:
        not_filterby = None
        not_filter_opts = []
    else:
        btable = db.org_organisation_branch
        rows = db(btable.deleted != True).select(btable.branch_id)
        branches = [row.branch_id for row in rows]
        not_filterby = "id"
        not_filter_opts = branches

    from s3.s3validators import IS_ONE_OF
    requires = IS_ONE_OF(db,
                         "org_organisation.id",
                         current.s3db.org_OrganisationRepresent(),
                         filterby="organisation_type_id",
                         filter_opts=[type_id],
                         not_filterby=not_filterby,
                         not_filter_opts=not_filter_opts,
                         updateable=updateable,
                         orderby="org_organisation.name",
                         sort=True)
    if not required:
        requires = IS_EMPTY_OR(requires)
    f.requires = requires
    # Dropdown not Autocomplete
    f.widget = None
    # Comment
    s3_has_role = current.auth.s3_has_role
    if s3_has_role("ADMIN") or \
       s3_has_role("ORG_ADMIN"):
        # Need to do import after setting Theme
        from s3layouts import S3AddResourceLink
        from s3.s3navigation import S3ScriptItem
        add_link = S3AddResourceLink(
            c="org",
            f="organisation",
            vars={
                "organisation.organisation_type_id$name":
                "Red Cross / Red Crescent"
            },
            label=T("Add National Society"),
            title=T("National Society"),
        )
        comment = f.comment
        if not comment or isinstance(comment, S3AddResourceLink):
            f.comment = add_link
        elif isinstance(comment[1], S3ScriptItem):
            # Don't overwrite scripts
            f.comment[0] = add_link
        else:
            f.comment = add_link
    else:
        # Not allowed to add NS/Branch
        f.comment = ""
Esempio n. 3
0
def customize_pr_person(**attr):
    """
        Customize pr_person controller
    """

    s3db = current.s3db
    request = current.request
    s3 = current.response.s3

    tablename = "pr_person"
    table = s3db.pr_person

    # CRUD Strings
    ADD_CONTACT = T("Add New Contact")
    s3.crud_strings[tablename] = Storage(
        title_create=T("Add Contact"),
        title_display=T("Contact Details"),
        title_list=T("Contact Directory"),
        title_update=T("Edit Contact Details"),
        title_search=T("Search Contacts"),
        subtitle_create=ADD_CONTACT,
        label_list_button=T("List Contacts"),
        label_create_button=ADD_CONTACT,
        label_delete_button=T("Delete Contact"),
        msg_record_created=T("Contact added"),
        msg_record_modified=T("Contact details updated"),
        msg_record_deleted=T("Contact deleted"),
        msg_list_empty=T("No Contacts currently registered"))

    # Custom PreP
    standard_prep = s3.prep

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

        if r.method == "validate":
            # Can't validate image without the file
            image_field = s3db.pr_image.image
            image_field.requires = None

    MOBILE = settings.get_ui_label_mobile_phone()
    EMAIL = T("Email")

    htable = s3db.hrm_human_resource
    htable.organisation_id.widget = None
    site_field = htable.site_id
    represent = S3Represent(lookup="org_site")
    site_field.label = T("Office")
    site_field.represent = represent
    site_field.requires = IS_ONE_OF(current.db,
                                    "org_site.site_id",
                                    represent,
                                    orderby="org_site.name")

    from s3layouts import S3AddResourceLink
    site_field.comment = S3AddResourceLink(
        c="org",
        f="office",
        vars={"child": "site_id"},
        label=T("Add New Office"),
        title=T("Office"),
        tooltip=
        T("If you don't see the Office in the list, you can add a new one by clicking link 'Add New Office'."
          ))

    # Best to have no labels when only 1 field in the row
    s3db.pr_contact.value.label = ""
    image_field = s3db.pr_image.image
    image_field.label = ""
    # ImageCrop widget doesn't currently work within an Inline Form
    from gluon.validators import IS_IMAGE
    image_field.requires = IS_IMAGE()
    image_field.widget = None

    hr_fields = [
        "organisation_id",
        "job_title_id",
        "site_id",
    ]

    # Context from a Profile page?"
    organisation_id = request.get_vars.get("(organisation)", None)
    if organisation_id:
        field = s3db.hrm_human_resource.organisation_id
        field.default = organisation_id
        field.readable = field.writable = False
        hr_fields.remove("organisation_id")

    s3_sql_custom_fields = [
        "first_name",
        #"middle_name",
        "last_name",
        S3SQLInlineComponent(
            "human_resource",
            name="human_resource",
            label="",
            multiple=False,
            fields=hr_fields,
        ),
        S3SQLInlineComponent("image",
                             name="image",
                             label=T("Photo"),
                             multiple=False,
                             fields=["image"],
                             filterby=dict(field="profile", options=[True])),
    ]

    list_fields = [
        "human_resource.organisation_id",
        "first_name",
        #"middle_name",
        "last_name",
        (T("Job Title"), "human_resource.job_title_id"),
        (T("Office"), "human_resource.site_id"),
    ]

    # Don't include Email/Phone for unauthenticated users
    if current.auth.is_logged_in():
        list_fields += [
            (MOBILE, "phone.value"),
            (EMAIL, "email.value"),
        ]
        s3_sql_custom_fields.insert(
            3,
            S3SQLInlineComponent("contact",
                                 name="phone",
                                 label=MOBILE,
                                 multiple=False,
                                 fields=["value"],
                                 filterby=dict(field="contact_method",
                                               options="SMS")),
        )
        s3_sql_custom_fields.insert(
            3,
            S3SQLInlineComponent("contact",
                                 name="email",
                                 label=EMAIL,
                                 multiple=False,
                                 fields=["value"],
                                 filterby=dict(field="contact_method",
                                               options="EMAIL")),
        )

    crud_form = S3SQLCustomForm(*s3_sql_custom_fields)

    filter_widgets = [
        S3TextFilter(
            [
                "pe_label",
                "first_name",
                "middle_name",
                "last_name",
                "local_name",
                "identity.value",
                "human_resource.organisation_id",
                "human_resource.job_title_id",
                "human_resource.site_id",
            ],
            label=T("Search"),
        ),
        S3OptionsFilter(
            "human_resource.organisation_id",
            # Doesn't support translation
            #represent="%(name)s",
            widget="multiselect",
        ),
        S3OptionsFilter(
            "human_resource.job_title_id",
            # Doesn't support translation
            #represent="%(name)s",
            widget="multiselect",
        ),
        S3OptionsFilter(
            "human_resource.site_id",
            # Doesn't support translation
            #represent="%(name)s",
            widget="multiselect",
        ),
    ]

    # Return to List view after create/update/delete (unless done via Modal)
    #url_next = URL(c="pr", f="person", )

    # Report options
    report_fields = [
        "organisation_id",
    ]

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

    s3db.configure(
        tablename,
        #create_next = url_next,
        #delete_next = url_next,
        #update_next = url_next,
        crud_form=crud_form,
        filter_widgets=filter_widgets,
        list_fields=list_fields,
        report_options=report_options,
        # Don't include a Create form in 'More' popups
        #listadd = False if r.method=="datalist" else True,
        #list_layout = render_contacts,
    )

    # Custom postp
    standard_postp = s3.postp

    def custom_postp(r, output):
        # Call standard postp
        if callable(standard_postp):
            output = standard_postp(r, output)

        if r.interactive and isinstance(output, dict):
            output["rheader"] = ""
            actions = [
                dict(label=str(T("Open")),
                     _class="action-btn",
                     url=URL(c="pr", f="person", args=["[id]", "read"]))
            ]
            s3.actions = actions
            if "form" in output:
                output["form"].add_class("pr_person")
            elif "item" in output and hasattr(output["item"], "add_class"):
                output["item"].add_class("pr_person")

        return output

    s3.postp = custom_postp

    # Remove rheader
    attr["rheader"] = None

    return attr
Esempio n. 4
0
    def custom_prep(r):
        # Call standard prep
        if callable(standard_prep):
            result = standard_prep(r)
        else:
            result = True

        if r.component_name == "appraisal":
            atable = r.component.table
            # Organisation needs to be an NS
            ns_only(
                atable.organisation_id,
                required=True,
                branches=False,
            )
            field = atable.supervisor_id
            field.readable = field.writable = False
            field = atable.job_title_id
            field.comment = None
            field.label = T("Sector")
            from s3.s3validators import IS_ONE_OF
            field.requires = IS_ONE_OF(
                db,
                "hrm_job_title.id",
                field.represent,
                filterby="type",
                filter_opts=(4, ),
            )

        if vnrc:
            if r.component_name == "address":
                settings.gis.building_name = False
                settings.gis.latlon_selector = False
                settings.gis.map_selector = False
                settings.gis.postcode_selector = False

            elif r.component_name == "identity":
                table = s3db.pr_identity
                table.description.readable = False
                table.description.writable = False
                pr_id_type_opts = {
                    1: T("Passport"),
                    2: T("National ID Card"),
                }
                from gluon.validators import IS_IN_SET
                table.type.requires = IS_IN_SET(pr_id_type_opts, zero=None)

            elif r.method == "cv" or r.component_name == "experience":
                table = s3db.hrm_experience
                # Use simple free-text variants
                table.organisation.readable = True
                table.organisation.writable = True
                table.job_title.readable = True
                table.job_title.writable = True
                table.comments.label = T("Main Duties")
                crud_form = S3SQLCustomForm(
                    "organisation",
                    "job_title",
                    "comments",
                    "start_date",
                    "end_date",
                )
                s3db.configure(
                    "hrm_experience",
                    crud_form=crud_form,
                    list_fields=[
                        "id",
                        "organisation",
                        "job_title",
                        "comments",
                        "start_date",
                        "end_date",
                    ],
                )

        return result
Esempio n. 5
0
def customize_deploy_mission(**attr):
    """
        Customize deploy_mission controller
    """

    db = current.db
    s3db = current.s3db
    s3 = current.response.s3
    MEMBER = T("Member")
    from gluon.html import DIV
    hr_comment =  \
        DIV(_class="tooltip",
            _title="%s|%s" % (MEMBER,
                              T("Enter some characters to bring up "
                                "a list of possible matches")))

    table = s3db.deploy_mission
    table.code.label = T("Operation Code")
    table.event_type_id.label = T("Disaster Type")
    table.organisation_id.readable = table.organisation_id.writable = False

    # Restrict Location to just Countries
    from s3.s3fields import S3Represent
    from s3.s3widgets import S3SelectChosenWidget
    field = table.location_id
    field.label = current.messages.COUNTRY
    field.requires = s3db.gis_country_requires
    field.widget = S3SelectChosenWidget()
    field.represent = S3Represent(lookup="gis_location", translate=True)

    rtable = s3db.deploy_response
    rtable.human_resource_id.label = MEMBER
    rtable.human_resource_id.comment = hr_comment

    from s3.s3validators import IS_ONE_OF
    atable = s3db.deploy_assignment
    atable.human_resource_id.label = MEMBER
    atable.human_resource_id.comment = hr_comment
    field = atable.job_title_id
    field.comment = None
    field.label = T("Sector")
    field.requires = IS_ONE_OF(
        db,
        "hrm_job_title.id",
        field.represent,
        filterby="type",
        filter_opts=(4, ),
    )

    # CRUD Strings
    s3.crud_strings["deploy_assignment"] = Storage(
        title_create=T("New Deployment"),
        title_display=T("Deployment Details"),
        title_list=T("Deployments"),
        title_update=T("Edit Deployment Details"),
        title_search=T("Search Deployments"),
        title_upload=T("Import Deployments"),
        subtitle_create=T("Add New Deployment"),
        label_list_button=T("List Deployments"),
        label_create_button=T("Add Deployment"),
        label_delete_button=T("Delete Deployment"),
        msg_record_created=T("Deployment added"),
        msg_record_modified=T("Deployment Details updated"),
        msg_record_deleted=T("Deployment deleted"),
        msg_list_empty=T("No Deployments currently registered"))

    # Custom prep
    standard_prep = s3.prep

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

        if not r.component and r.method == "create":
            # Org is always IFRC
            otable = s3db.org_organisation
            query = (
                otable.name ==
                "International Federation of Red Cross and Red Crescent Societies"
            )
            organisation = db(query).select(
                otable.id,
                limitby=(0, 1),
            ).first()
            if organisation:
                r.table.organisation_id.default = organisation.id

        return result

    s3.prep = custom_prep

    return attr