def mission():
    """ RESTful CRUD Controller """

    def prep(r):
        # Configure created_on field in deploy_mission
        #created_on = r.table.created_on
        #created_on.readable = True
        #created_on.label = T("Date Created")
        #created_on.represent = lambda d: \
        #                       s3base.S3DateTime.date_represent(d, utc=True)
        if r.id:
            # Mission-specific workflows return to the profile page
            tablename = r.tablename if not r.component else r.component.tablename
            next_url = r.url(component="", method="profile", vars={})
            if r.component_name == "alert":
                alert_create_script()
                if settings.get_deploy_manual_recipients():
                    create_next = URL(f="alert", args=["[id]", "select"])
                else:
                    create_next = next_url
                s3db.configure(tablename,
                               create_next = create_next,
                               delete_next = next_url,
                               update_next = next_url,
                               )
            else:
                s3db.configure(tablename,
                               create_next = next_url,
                               delete_next = next_url,
                               update_next = next_url,
                               )
            s3.cancel = next_url
            if r.component_name == "assignment":
                member_id = r.get_vars.get("member_id", None)
                if member_id and str(member_id).isdigit():
                    # Deploy-this-member action
                    htable = s3db.hrm_human_resource
                    query = (htable.id == member_id) & \
                            (htable.deleted != True)
                    row = db(query).select(htable.id, limitby=(0, 1)).first()
                    if row:
                        field = s3db.deploy_assignment.human_resource_id
                        field.default = row.id
                        field.writable = False
                        field.comment = None
                elif r.method == "create":
                    atable = s3db.deploy_assignment
                    atable.end_date.writable = atable.end_date.readable = False
            if not r.component and r.method == "profile":
                represent = lambda d: \
                            s3base.S3DateTime.datetime_represent(d, utc=True)
                s3db.deploy_alert.modified_on.represent = represent
                s3db.deploy_response.created_on.represent = represent
                s3base.s3_trunk8(lines=1)
        else:
            # All other workflows return to the summary page
            s3.cancel = r.url(method="summary", component=None, id=0)
            if not r.component:
                status = r.get_vars.get("~.status__belongs")
                if status == "2":
                    s3.crud_strings[r.tablename]["title_list"] = T("Active Missions")
                elif status == "1":
                    s3.crud_strings[r.tablename]["title_list"] = T("Closed Missions")

        return True
    s3.prep = prep

    def postp(r, output):
        if not r.component:
            # Override mission open actions to go to the profile page
            s3_action_buttons(r,
                              deletable=True,
                              editable=True,
                              read_url=r.url(method="profile", id="[id]"),
                              update_url=r.url(method="profile", id="[id]"),
                              delete_url=r.url(method="delete", id="[id]"),
                              )
            # Override the missions list-button go to the summary page
            if isinstance(output, dict) and "buttons" in output:
                # Override standard "List" button
                buttons = output["buttons"]
                if "list_btn" in buttons and "summary_btn" in buttons:
                    buttons["list_btn"] = buttons["summary_btn"]

        elif "subtitle" in output and "rheader" in output:
            # In component CRUD views, have a subtitle after the rheader
            output["rheader"] = TAG[""](output["rheader"],
                                        H3(output["subtitle"]))

        return output
    s3.postp = postp

    return s3_rest_controller(# Remove the title if we have a component
                              # (rheader includes the title)
                              notitle = lambda r: {"title": ""} \
                                               if r.component else None,
                              rheader = s3db.deploy_rheader,
                              )

# -----------------------------------------------------------------------------
dataset/ETHPy150Open sahana/eden/controllers/deploy.py/mission/original