示例#1
0
文件: work.py 项目: nck0405/MyOwn
    def prep(r):
        # @todo: for assigments, filter person_id to persons not
        #        currently assigned to this job

        # @todo: for assigments, set default to current user if
        #        not assigned to this job yet

        if r.method == "datalist":
            # Filter to open jobs by default
            from s3 import s3_set_default_filter
            s3_set_default_filter("~.status", "OPEN",
                                  tablename = "work_job",
                                  )
            if r.representation == "html":
                # Set default formstyle for side filter form
                # (=labels above fields)
                filter_formstyle = settings.get_ui_formstyle()
                s3db.configure("work_job",
                               filter_formstyle = filter_formstyle,
                               )

        if not r.component:
            r.resource.configure(create_next = r.url(method=""),
                                 update_next = r.url(method=""),
                                 )
        return True
示例#2
0
    def customise_event_event_controller(**attr):

        # Default Filter: Only open Events
        from s3 import s3_set_default_filter

        s3_set_default_filter("~.closed", False, tablename="event_event")

        return attr
示例#3
0
    def customise_doc_sitrep_controller(**attr):

        # Default Filter: Only open Events
        etable = current.s3db.event_event
        query = (etable.closed == False) & (etable.deleted == False)
        open = current.db(query).select(etable.id, etable.name)
        len_open = len(open)
        if len_open:
            if len_open == 1:
                current.session.s3.event = open.first().id
            else:
                current.session.s3.event = None
            open = {row.id: row.name for row in open}

            from s3 import s3_set_default_filter

            s3_set_default_filter("event_sitrep.event_id", open, tablename="doc_sitrep")

        return attr
示例#4
0
    def customise_project_project_controller(**attr):

        # Default Filter: Only open Projects
        # @ToDo: Fix (not activating for some reason)
        stable = current.s3db.project_status
        active = current.db(stable.name.belongs("Active", "Proposed")).select(stable.id, stable.name)
        active = {row.id: row.name for row in active}

        from s3 import s3_set_default_filter

        s3_set_default_filter("~.status_id", active, tablename="project_project")

        has_role = current.auth.s3_has_role
        ERT_LEADER = has_role("ERT_LEADER") and not has_role("ADMIN")

        s3 = current.response.s3
        standard_postp = s3.postp

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

            if ERT_LEADER:
                # Don't open Projects: Open Activities
                from gluon import URL
                from s3 import s3_str

                s3.actions = [dict(label=s3_str(T("Open")), _class="action-btn", url=URL(args=["[id]", "activity"]))]

            return output

        s3.postp = custom_postp

        if ERT_LEADER:
            # Simplified RHeader for Operational Requirements
            attr["rheader"] = lambda r: project_rheader(r, ert=True)
        else:
            # Tweaked RHeader
            attr["rheader"] = lambda r: project_rheader(r, ert=False)

        return attr
示例#5
0
文件: work.py 项目: AyudaEcuador/eden
    def prep(r):

        if r.method == "datalist":
            # Filter to open jobs by default
            from s3 import s3_set_default_filter
            s3_set_default_filter("~.status", "OPEN",
                                  tablename = "work_job",
                                  )
            if r.representation == "html":
                # Set default formstyle for side filter form
                # (=labels above fields)
                filter_formstyle = settings.get_ui_formstyle()
                s3db.configure("work_job",
                               filter_formstyle = filter_formstyle,
                               )

        if not r.component:
            # Return to list after create/update
            r.resource.configure(create_next = r.url(method=""),
                                 update_next = r.url(method=""),
                                 )

        elif r.component_name == "assignment":
            ctable = r.component.table
            field = ctable.person_id

            # Set default to current user if not assigned yet
            logged_in_person = auth.s3_logged_in_person()
            if logged_in_person:
                query = (ctable.job_id == r.id) & \
                        (ctable.person_id == logged_in_person) & \
                        (ctable.deleted != True)
                existing = db(query).select(ctable.id, limitby=(0, 1)).first()
                if not existing:
                    field.default = logged_in_person
                else:
                    field.default = None

        return True