Exemplo n.º 1
0
    def prep(r):
        if r.interactive:
            if s3.rtl:
                # Ensure that + appears at the beginning of the number
                # - using table alias to only apply to filtered component
                from s3 import s3_phone_represent, S3PhoneWidget
                f = s3db.get_aliased(s3db.pr_contact, "pr_phone_contact").value
                f.represent = s3_phone_represent
                f.widget = S3PhoneWidget()

            if r.id and r.component is None and r.method != "delete":
                # Redirect to person controller
                vars = {"membership.id": r.id}
                redirect(URL(f="person", vars=vars))

            # Assume members under 120
            s3db.pr_person.date_of_birth.widget = \
                                        S3CalendarWidget(past_months=1440)

        elif r.representation == "xls":
            # Split person_id into first/middle/last to make it match Import sheets
            list_fields = s3db.get_config("member_membership", "list_fields")
            list_fields.remove("person_id")
            list_fields = [
                "person_id$first_name",
                "person_id$middle_name",
                "person_id$last_name",
            ] + list_fields

            s3db.configure("member_membership", list_fields=list_fields)

        return True
Exemplo n.º 2
0
    def customise_org_organisation_resource(r, tablename):

        s3db = current.s3db

        # Custom Components
        s3db.add_components(
            tablename,
            org_organisation_tag=(  # On-call Duty Number
                {
                    "name": "duty",
                    "joinby": "organisation_id",
                    "filterby": {
                        "tag": "duty",
                    },
                    "multiple": False,
                }, ),
        )

        from s3 import S3SQLCustomForm, S3SQLInlineComponent, S3SQLInlineLink, \
                       IS_EMPTY_OR, IS_PHONE_NUMBER_MULTI, S3PhoneWidget, s3_phone_represent

        # Individual settings for specific tag components
        components_get = s3db.resource(tablename).components.get

        duty = components_get("duty")
        f = duty.table.value
        f.represent = s3_phone_represent,
        f.requires = IS_EMPTY_OR(IS_PHONE_NUMBER_MULTI())
        f.widget = S3PhoneWidget()

        crud_form = S3SQLCustomForm(
            "name",
            "acronym",
            S3SQLInlineLink(
                "organisation_type",
                field="organisation_type_id",
                # Default 10 options just triggers which adds unnecessary complexity to a commonly-used form & commonly an early one (create Org when registering)
                filter=False,
                label=T("Type"),
                multiple=False,
                widget="multiselect",
            ),
            "country",
            (T("Reception Phone #"), "phone"),
            S3SQLInlineComponent(
                "duty",
                label=T("On-call Duty Number"),
                fields=[("", "value")],
                multiple=False,
            ),
            "website",
            "logo",
            "comments",
        )

        s3db.configure(
            tablename,
            crud_form=crud_form,
        )
Exemplo n.º 3
0
    def prep(r):
        if r.interactive:
            if s3.rtl:
                # Ensure that + appears at the beginning of the number
                # - using table alias to only apply to filtered component
                from s3 import s3_phone_represent, S3PhoneWidget
                f = s3db.get_aliased(s3db.pr_contact, "pr_phone_contact").value
                f.represent = s3_phone_represent
                f.widget = S3PhoneWidget()

            if r.component_name == "membership":
                s3.crud_strings["member_membership"].update(
                    label_delete_button = T("Delete Membership"),
                    label_list_button = T("List Memberships")
                )

            if r.method not in ("import", "search_ac", "validate"):
                if not r.component:
                    # Assume members under 120
                    from s3 import S3CalendarWidget
                    s3db.pr_person.date_of_birth.widget = \
                                        S3CalendarWidget(past_months=1440)
                resource = r.resource
                if resource.count() == 1:
                    resource.load()
                    r.record = resource.records().first()
                    if r.record:
                        r.id = r.record.id
                if not r.record:
                    session.error = T("Record not found")
                    redirect(URL(f="membership"))
                member_id = get_vars.get("membership.id", None)
                if member_id and r.component_name == "membership":
                    r.component_id = member_id
                s3db.configure("member_membership",
                               insertable = False,
                               )
        return True