Esempio n. 1
0
def version_up_asset(request, asset_id=0, asset_pointer=""):
    '''
    Since version handling is done via django we can pass to and
    update the proper controllers.

    NOTE: This will eventually be completely django handled once
    the nPath app is more built-in.

    @params
    $asset_id : (int) : ID of the asset we're version-ing off of in our
    database.

    $asset_pointer : (str) : Pointer to the asset we'll be creating.

    $return : (bool) : If the version up was successful. 
    '''
    _u = utils.get_username(request)
    current_asset = nAsset.objects.get(id=asset_id)
    vc = current_asset.version_controller

    new_asset = nAsset.objects.create(asset_pointer=asset_pointer,
                                      version=(vc.highest_version + 1),
                                      version_controller=vc,
                                      author=_u)

    vc.versionUp()
    vc.save()

    return True
Esempio n. 2
0
def create_asset(request, asset_pointer={}, asset_type="", version=0,
                 asset_name="", hub_name="", project_name=""):  
    """
    Create an nAsset. This takes quite a few params but needs to be potent and
    well connected. This has to point quite a few directions without being dependent
    on too much.

    @params
    $asset_pointer : (dict) : The path and other params to organize our path with.

    $asset_type : (str) : What kind of asset is this?

    $version : (int) : The version of the asset we're going to add

    $asset_name : (str) : Name to be tied to the asset for Version Group control

    $hub_name : (str) : The name associated with this

    $return : (dict) : New asset in dict form.
    """
    if request:
        _u = utils.get_username(request)
    else:
        _u = "aimee"
    _a_type = nAssetType.objects.get(name=asset_type)

    ## Pathing break down to give us any other information we'll
    ## need. This gives us fine tuned control as long as the path
    ## minimums are kept in the setup.
    _path_data = extract_basic(asset_pointer['path'])
    if not _path_data:
        e = "The path: %s isn't compatible with Nocits."%asset_pointer
        e += "(There must be an extension)"
        raise TypeError(e)
    # path_setup = nPath.objects.get(extension=_path_data['ext'], asset_type=asset_type)
    hub = nProjectHub.objects.get(name=hub_name, project__name=project_name)

    ## Getting the version controller requires knowing the project name
    version_control, created = nVersionController.objects.get_or_create(hub_pointer=hub,
                                                                       group_name=asset_name,
                                                                       asset_type=_a_type)

    if version_control.highest_version < version:
        version_control.highest_version = version
        version_control.save() # To keep our new data

    asset = nAsset.objects.create(asset_pointer=asset_pointer,
                                  version=version,
                                  version_controller=version_control,
                                  author=_u)

    return nAsset.make_dicts(nAsset.objects.filter(id=asset.id))[0]