示例#1
0
 def on_create(self):
     """Application-internal creation logic i.e. logic NOT subject to config.
     """
     # requires self db id to have been updated
     from bungeni.core.workflows import utils
     utils.assign_ownership(self)
     utils.unset_group_local_role(self)
示例#2
0
def spawn_doc(source_doc, target_chamber_type, target_type_key, target_state_id):
    """Utility to help create parametrized "transfer to chamber" actions.
    Returns the newly spawned doc.
    
    Notes:
    
    - sub-docs "signatories", "attachments", "events" are not carried over to 
        the new doc
    
    - the "owner" of the new doc is the original owner i.e. the member of the 
        originating chamber (but this could be changed on the spawned document?)
    
    - if an explicit version prior to spawning is desired, include the "version"
        action in the actions of the workflow destination state.
    
    """
    from bungeni.core.workflow.interfaces import IStateController
    from bungeni.core.workflows.utils import assign_ownership
    from bungeni.utils import naming
    from bungeni.capi import capi
    
    source_doc = removeSecurityProxy(source_doc)
    session = Session()
    session.merge(source_doc)
    
    # !+GENERALIZE_GROUP
    # !+get the singleton "active" chamber of target_group_conceptual_name
    # get the singleton "active" chamber of target_chamber_type
    target_chamber = session.query(domain.Chamber
        ).filter(sa.and_(
                #!+domain.Chamber.conceptual_name == target_group_conceptual_name, 
                domain.Chamber.sub_type == target_chamber_type, 
                domain.Chamber.status == "active")).one()
    
    # get target domain model type, source/target descriptors
    source_ti = capi.get_type_info(source_doc.__class__)
    target_ti = capi.get_type_info(target_type_key)
    
    # create target instance
    target_doc = target_ti.domain_model()
    session.add(target_doc)
    
    # set new "key" values
    target_doc.chamber = target_chamber #!+GENERALIZE_GROUP
    target_doc.group = target_chamber
    target_doc.owner_id = source_doc.owner.user_id # !+PrincipalRoleMap
    target_doc.head = source_doc
    
    # carry-over other values
    for attr_name in [
            #files -> not carried over !+ parametrize as optional?
            #signatories -> not carried over
            #events -> not carried over
            
            #"doc_id", -> auto
            #"chamber_id", -> target_chamber.group_id
            #"owner_id",
            #"type", -> auto, from target_type
            "doc_type",
            "doc_procedure",
            #"type_number", -> a progressive number by type?
            #"registry_number", -> a reference to this resource !+ when do we set it here?
            # "uri", -> ?
            "acronym",
            "title",
            "sub_title",
            "description",
            "summary",
            "language",
            "body",
            #"status", -> auto
            #"status_date", -> auto
            #"group_id", -> target_chamber.group_id
            "subject",
            "doc_date",
            "coverage",
            "doc_urgency",
            "geolocation",
            #"head_id", -> here, this is the "origin" document 
            #"timestamp", -> auto
            
            "source_title",
            "source_creator",
            "source_subject",
            "source_description",
            "source_publisher",
            "source_publisher_address",
            "source_contributors",
            "source_date",
            "source_type",
            "source_format",
            "source_doc_source",
            "source_language",
            "source_relation",
            "source_coverage",
            "source_rights",
        ]:
        source_value = getattr(source_doc, attr_name)
        if source_value is not None:
            setattr(target_doc, attr_name, source_value)
    
    # transfer any extended properties
    for (xp_name, xp_type) in target_ti.domain_model.extended_properties:
        if has_attr(source_doc, xp_name):
            source_value = getattr(source_doc, xp_name)
            if source_value is not None:
                setattr(target_doc, xp_name, source_value)
    
    # status (needs values to be updated first), also does a db flush()
    IStateController(target_doc).set_status(target_state_id)
    
    # !+PrincipalRoleMap
    assign_ownership(target_doc)
    
    log.info("Spawned new document [%s] : (%r, %r, %r) -- from: %s", 
        #!+target_doc, target_group_conceptual_name, target_type_key, target_state_id, source_doc)
        target_doc, target_chamber_type, target_type_key, target_state_id, source_doc)
    return target_doc
示例#3
0
 def on_create(self):
     from bungeni.core.workflows import utils
     utils.assign_ownership(self)
示例#4
0
def spawn_doc(source_doc, target_chamber_type, target_type_key,
              target_state_id):
    """Utility to help create parametrized "transfer to chamber" actions.
    Returns the newly spawned doc.
    
    Notes:
    
    - sub-docs "signatories", "attachments", "events" are not carried over to 
        the new doc
    
    - the "owner" of the new doc is the original owner i.e. the member of the 
        originating chamber (but this could be changed on the spawned document?)
    
    - if an explicit version prior to spawning is desired, include the "version"
        action in the actions of the workflow destination state.
    
    """
    from bungeni.core.workflow.interfaces import IStateController
    from bungeni.core.workflows.utils import assign_ownership
    from bungeni.utils import naming
    from bungeni.capi import capi

    source_doc = removeSecurityProxy(source_doc)
    session = Session()
    session.merge(source_doc)

    # !+GENERALIZE_GROUP
    # !+get the singleton "active" chamber of target_group_conceptual_name
    # get the singleton "active" chamber of target_chamber_type
    target_chamber = session.query(domain.Chamber).filter(
        sa.and_(
            #!+domain.Chamber.conceptual_name == target_group_conceptual_name,
            domain.Chamber.sub_type == target_chamber_type,
            domain.Chamber.status == "active")).one()

    # get target domain model type, source/target descriptors
    source_ti = capi.get_type_info(source_doc.__class__)
    target_ti = capi.get_type_info(target_type_key)

    # create target instance
    target_doc = target_ti.domain_model()
    session.add(target_doc)

    # set new "key" values
    target_doc.chamber = target_chamber  #!+GENERALIZE_GROUP
    target_doc.group = target_chamber
    target_doc.owner_id = source_doc.owner.user_id  # !+PrincipalRoleMap
    target_doc.head = source_doc

    # carry-over other values
    for attr_name in [
            #files -> not carried over !+ parametrize as optional?
            #signatories -> not carried over
            #events -> not carried over

            #"doc_id", -> auto
            #"chamber_id", -> target_chamber.group_id
            #"owner_id",
            #"type", -> auto, from target_type
            "doc_type",
            "doc_procedure",
            #"type_number", -> a progressive number by type?
            #"registry_number", -> a reference to this resource !+ when do we set it here?
            # "uri", -> ?
            "acronym",
            "title",
            "sub_title",
            "description",
            "summary",
            "language",
            "body",
            #"status", -> auto
            #"status_date", -> auto
            #"group_id", -> target_chamber.group_id
            "subject",
            "doc_date",
            "coverage",
            "doc_urgency",
            "geolocation",
            #"head_id", -> here, this is the "origin" document
            #"timestamp", -> auto
            "source_title",
            "source_creator",
            "source_subject",
            "source_description",
            "source_publisher",
            "source_publisher_address",
            "source_contributors",
            "source_date",
            "source_type",
            "source_format",
            "source_doc_source",
            "source_language",
            "source_relation",
            "source_coverage",
            "source_rights",
    ]:
        source_value = getattr(source_doc, attr_name)
        if source_value is not None:
            setattr(target_doc, attr_name, source_value)

    # transfer any extended properties
    for (xp_name, xp_type) in target_ti.domain_model.extended_properties:
        if has_attr(source_doc, xp_name):
            source_value = getattr(source_doc, xp_name)
            if source_value is not None:
                setattr(target_doc, xp_name, source_value)

    # status (needs values to be updated first), also does a db flush()
    IStateController(target_doc).set_status(target_state_id)

    # !+PrincipalRoleMap
    assign_ownership(target_doc)

    log.info(
        "Spawned new document [%s] : (%r, %r, %r) -- from: %s",
        #!+target_doc, target_group_conceptual_name, target_type_key, target_state_id, source_doc)
        target_doc,
        target_chamber_type,
        target_type_key,
        target_state_id,
        source_doc)
    return target_doc