コード例 #1
0
ファイル: config.py プロジェクト: Timileyin5/eden
    def customise_event_asset_resource(r, tablename):

        table = current.s3db.event_asset
        table.item_id.label = T("Item Type")
        table.asset_id.label = T("Specific Item")
        # DateTime
        from gluon import IS_EMPTY_OR
        from s3 import IS_UTC_DATETIME, S3CalendarWidget, S3DateTime
        for f in (table.start_date, table.end_date):
            f.requires = IS_EMPTY_OR(IS_UTC_DATETIME())
            f.represent = lambda dt: S3DateTime.datetime_represent(dt,
                                                                   utc=True)
            f.widget = S3CalendarWidget(timepicker=True)

        current.response.s3.crud_strings[tablename] = Storage(
            label_create=T("Add Equipment"),
            title_display=T("Equipment Details"),
            title_list=T("Equipment"),
            title_update=T("Edit Equipment"),
            label_list_button=T("List Equipment"),
            label_delete_button=T("Remove Equipment from this incident"),
            msg_record_created=T("Equipment added"),
            msg_record_modified=T("Equipment updated"),
            msg_record_deleted=T("Equipment removed"),
            msg_list_empty=T(
                "No Equipment currently registered for this incident"))
コード例 #2
0
ファイル: config.py プロジェクト: Timileyin5/eden
    def customise_event_human_resource_resource(r, tablename):

        s3db = current.s3db
        table = s3db.event_human_resource
        # DateTime
        from gluon import IS_EMPTY_OR
        from s3 import IS_UTC_DATETIME, S3CalendarWidget, S3DateTime
        for f in (table.start_date, table.end_date):
            f.requires = IS_EMPTY_OR(IS_UTC_DATETIME())
            f.represent = lambda dt: S3DateTime.datetime_represent(dt,
                                                                   utc=True)
            f.widget = S3CalendarWidget(timepicker=True)

        current.response.s3.crud_strings[tablename] = Storage(
            label_create=T("Add Person"),
            title_display=T("Person Details"),
            title_list=T("Personnel"),
            title_update=T("Edit Person"),
            label_list_button=T("List Personnel"),
            label_delete_button=T("Remove Person from this incident"),
            msg_record_created=T("Person added"),
            msg_record_modified=T("Person updated"),
            msg_record_deleted=T("Person removed"),
            msg_list_empty=T(
                "No Persons currently registered for this incident"))

        s3db.configure(
            tablename,
            # Deliberately over-rides
            create_onaccept=event_human_resource_onaccept,
            update_onaccept=lambda form: event_human_resource_onaccept(
                form, create=False),
        )
コード例 #3
0
ファイル: member.py プロジェクト: sahana/eden
    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
            from s3 import S3CalendarWidget
            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
コード例 #4
0
ファイル: hrm.py プロジェクト: sahana/eden
 def prep(r):
     if r.interactive and r.method != "import":
         if r.component:
             if r.component_name == "physical_description":
                 # Hide all but those details that we want
                 # Lock all the fields
                 table = r.component.table
                 for field in table.fields:
                     table[field].writable = table[field].readable = False
                 # Now enable those that we want
                 table.ethnicity.writable = table.ethnicity.readable = True
                 table.blood_type.writable = table.blood_type.readable = True
                 table.medical_conditions.writable = table.medical_conditions.readable = True
                 table.other_details.writable = table.other_details.readable = True
         else:
             table = r.table
             table.pe_label.readable = table.pe_label.writable = False
             table.missing.readable = table.missing.writable = False
             table.age_group.readable = table.age_group.writable = False
             # Assume volunteers only between 12-81
             from s3 import S3CalendarWidget
             table.date_of_birth.widget = S3CalendarWidget(
                 past_months=972,
                 future_months=-144,
             )
             return True
     else:
         # Disable non-interactive & import
         return False
コード例 #5
0
ファイル: member.py プロジェクト: sahana/eden
    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
コード例 #6
0
ファイル: hrm.py プロジェクト: sahana/eden
    def prep(r):

        table = r.table
        tablename = r.tablename
        get_vars = r.get_vars

        # Use CRUD strings for staff
        crud_strings = s3.crud_strings
        crud_strings[tablename] = crud_strings["hrm_staff"]

        resource = r.resource
        if "expiring" in get_vars:
            # Filter for staff with contracts expiring in the next 4 weeks
            query = FS("end_date") < \
                        (request.utcnow + datetime.timedelta(weeks=4))
            resource.add_filter(query)
            # Adapt CRUD strings
            crud_strings[tablename].title_list = \
                T("Staff with Contracts Expiring in the next Month")
            # Reconfigure
            resource.configure(  # Sort by Expiry
                sortby=table.end_date,
                # Remove the Add button
                insertable=False)
            # Adapt list_fields
            list_fields = [
                (T("Contract End Date"), "end_date"),
                "person_id",
                "job_title_id",
                "organisation_id",
                "site_id",
                #"site_contact",
            ]
            if settings.get_hrm_staff_departments():
                list_fields.insert(4, "department_id")
            resource.configure(list_fields=list_fields)
        elif r.representation == "xls":
            s3db.hrm_xls_list_fields(r, vol=False)
        else:
            # Adapt list_fields
            list_fields = [
                "person_id",
                "job_title_id",
                "organisation_id",
                "site_id",
                #"site_contact",
                (T("Email"), "email.value"),
                (settings.get_ui_label_mobile_phone(), "phone.value"),
            ]
            if settings.get_hrm_staff_departments():
                list_fields.insert(3, "department_id")
            if settings.get_hrm_use_trainings():
                list_fields.append("person_id$training.course_id")
            if settings.get_hrm_use_certificates():
                list_fields.append("person_id$certification.certificate_id")
            list_fields.append((T("Contract End Date"), "end_date"))
            list_fields.append("status")
            resource.configure(list_fields=list_fields)

        if r.interactive:
            if r.id:
                if r.method not in ("profile", "delete"):
                    # Redirect to person controller
                    url_vars = {"human_resource.id": r.id, "group": "staff"}
                    if r.method is not None:
                        args = [r.method]
                    else:
                        args = []
                    if r.representation == "iframe":
                        url_vars["format"] = "iframe"
                    redirect(URL(
                        f="person",
                        args=args,
                        vars=url_vars,
                    ))
            else:
                if r.method == "import":
                    # Redirect to person controller
                    redirect(
                        URL(
                            f="person",
                            args="import",
                            vars={"group": "staff"},
                        ))
                elif not r.component and r.method != "delete":
                    # Configure site_id
                    field = table.site_id
                    site_id = get_vars.get("site_id", None)
                    if site_id:
                        field.default = site_id
                        field.writable = False
                    field.comment = DIV(
                        DIV(
                            _class="tooltip",
                            _title="%s|%s" % (
                                settings.get_org_site_label(),
                                T("The facility where this position is based."
                                  ),
                                #messages.AUTOCOMPLETE_HELP,
                            )))
                    #field.comment = S3PopupLink(c="org", f="facility",
                    #                            vars = dict(child="site_id",
                    #                                        parent="req"),
                    #                            title=T("Add New Site"),
                    #                            )

                    # Hide status field
                    table.status.writable = table.status.readable = False

                    # Assume staff only between 16-81
                    from s3 import S3CalendarWidget
                    s3db.pr_person.date_of_birth.widget = \
                        S3CalendarWidget(past_months = 972,
                                         future_months = -192,
                                         )

        return True
コード例 #7
0
ファイル: event.py プロジェクト: sahana/eden
    def prep(r):
        if r.interactive or r.representation == "aadata":
            if r.component:
                if r.component.alias == "assign":
                    if not r.method:
                        r.method = "assign"
                    if r.method == "assign":
                        r.custom_action = s3db.hrm_AssignMethod(component = "assign")

                cname = r.component_name
                if cname == "config":
                    s3db.configure("gis_config",
                                   deletable = False,
                                   )
                    s3.crud.submit_button = T("Update")

                elif cname == "sitrep":
                    stable = s3db.event_sitrep
                    stable.location_id.default = r.record.location_id
                    stable.event_id.readable = stable.event_id.writable = False
                    list_fields = s3db.get_config("event_sitrep", "list_fields")
                    try:
                        list_fields.remove("event_id")
                    except ValueError:
                        # Already removed
                        pass
                    # @ToDo: PDF export of Single SitReps
                    # - UI Button
                    # - Custom layout
                    # Remove PDF export of List of SitReps
                    # - currently crashing when there is significant richtext content & an unlikely usecase
                    export_formats = settings.ui.export_formats
                    if not export_formats:
                        export_formats = settings.get_ui_export_formats()
                    if "pdf" in export_formats:
                        export_formats = list(export_formats)
                        export_formats.remove("pdf")
                        settings.ui.export_formats = export_formats

                elif cname in ("asset", "human_resource", "event_organisation", "organisation", "site"):
                    atable = s3db.table("budget_allocation")
                    if atable:
                        atable.budget_entity_id.default = r.record.budget_entity_id

                    #s3.crud.submit_button = T("Assign")
                    #s3.crud.submit_button = T("Add")
                    s3.crud_labels["DELETE"] = T("Remove")

                    if cname == "asset":
                        # Filter Assets by Item Type
                        s3.scripts.append("/%s/static/scripts/S3/s3.event_asset.js" % r.application)
                        # Modify Popup URL
                        s3db.event_asset.asset_id.comment.vars = {"prefix": "event",
                                                                  "parent": "asset",
                                                                  }

                    # Default Event in the link to that of the Incident
                    if cname == "event_organisation":
                        ltable = s3db.table(cname)
                    else:
                        ltable = s3db.table("event_%s" % cname)
                    if ltable:
                        f = ltable.event_id
                        f.default = r.record.event_id
                        f.readable = f.writable = False

                elif cname == "incident_asset":
                    atable = s3db.table("budget_allocation")
                    if atable:
                        atable.budget_entity_id.default = r.record.budget_entity_id

                    #s3.crud.submit_button = T("Assign")
                    #s3.crud.submit_button = T("Add")
                    s3.crud_labels["DELETE"] = T("Remove")

                    # Default Event in the link to that of the Incident
                    ltable = s3db.table("event_asset")
                    f = ltable.event_id
                    f.default = r.record.event_id
                    f.readable = f.writable = False
                    # DateTime
                    from s3 import IS_UTC_DATETIME, S3DateTime, S3CalendarWidget
                    datetime_represent = S3DateTime.datetime_represent
                    for f in (ltable.start_date, ltable.end_date):
                        f.requires = IS_EMPTY_OR(IS_UTC_DATETIME())
                        f.represent = lambda dt: datetime_represent(dt, utc=True)
                        f.widget = S3CalendarWidget(timepicker = True)

            elif r.method not in ("read", "update"):
                # Create or ListCreate
                table = r.table
                table.closed.writable = table.closed.readable = False
                table.end_date.writable = table.end_date.readable = False

            elif r.method == "update":
                # Can't change details after event activation
                table = r.table
                table.exercise.writable = False
                table.exercise.comment = None
                table.date.writable = False

        return True