Beispiel #1
0
    def post_revoke(self, proj, asset_id, comment=None):
        """Revoke approval for an asset."""
        session = session_get()
        user = tmpl_context.user
        asset = asset_get(proj, asset_id)

        if asset.approved:
            asset.revoke(user)
            text = u'[%s v%03d]\n%s' % (_('revoked approval'),
                                            asset.current.ver, comment or '')
            asset.current.notes.append(Note(user, text))
            session.refresh(asset.current.annotable)

            msg = '%s %s' % (_('Revoked approval for Asset:'), asset.path)
            updates = [dict(item=asset, type='updated', topic=TOPIC_ASSETS)]
            status = 'ok'

            # log into Journal
            journal.add(user, '%s - %s' % (msg, asset))

            # notify clients
            notify.send(updates)
        else:
            msg = '%s %s' % (_('Asset is not approved:'), asset.path)
            updates = []
            status = 'error'

        return dict(msg=msg, status=status, updates=updates)
Beispiel #2
0
    def release(self, proj, asset_id):
        """Release an asset.
        
        The asset will be unblocked and available for other users to checkout.
        """
        asset = asset_get(proj, asset_id)
        user = tmpl_context.user

        if asset.checkedout:
            asset.release()

            msg = '%s %s' % (_('Released Asset:'), asset.path)
            updates = [dict(item=asset, type='updated', topic=TOPIC_ASSETS)]
            status = 'ok'

            # log into Journal
            journal.add(user, '%s - %s' % (msg, asset))

            # notify clients
            notify.send(updates)
        else:
            msg = '%s %s' % (_('Asset is not checkedout:'), asset.path)
            updates = []
            status = 'error'

        return dict(msg=msg, status=status, updates=updates)
Beispiel #3
0
    def checkout(self, proj, asset_id):
        """Checkout an asset.
        
        The asset will be blocked and only the current owner will be able to
        publish new versions until it is released.
        """
        session = session_get()
        asset = asset_get(proj, asset_id)
        user = tmpl_context.user

        if not asset.checkedout:
            asset.checkout(user)

            msg = '%s %s' % (_('Checkedout Asset:'), asset.path)
            updates = [dict(item=asset, type='updated', topic=TOPIC_ASSETS)]
            status = 'ok'

            # log into Journal
            journal.add(user, '%s - %s' % (msg, asset))

            # notify clients
            notify.send(updates)
        else:
            msg = '%s %s' % (_('Asset is already checkedout:'), asset.path)
            updates = []
            status = 'error'

        return dict(msg=msg, status=status, updates=updates)
Beispiel #4
0
    def post_delete(self, proj, asset_id):
        """Delete an asset.
        
        Only delete the asset record from the db, the asset file(s) must be
        removed manually.
        (This should help prevent awful accidents) ;)
        """
        session = session_get()
        user = tmpl_context.user
        asset = asset_get(proj, asset_id)

        session.delete(asset)

        # delete association objects or they will be orphaned
        session.flush()
        for ver in asset.versions:
            session.delete(ver.annotable)
        session.delete(asset.taggable)

        msg = '%s %s' % (_('Deleted Asset:'), asset.path)

        # log into Journal
        journal.add(user, '%s - %s' % (msg, asset))

        # notify clients
        updates = [dict(item=asset, type='deleted', topic=TOPIC_ASSETS)]
        notify.send(updates)

        return dict(msg=msg, status='ok', updates=updates)
Beispiel #5
0
 def get_one(self, proj, asset_id):
     """Return a `standalone` page with the asset history"""
     tmpl_context.t_history = t_history
     asset = asset_get(proj, asset_id)
     
     # thumb, ver, note
     history = []
     for ver in asset.versions:
         if ver.notes:
             for note in ver.notes:
                 history.append(dict(id=None, proj_id=None, thumbnail=None,
                                 ver=None, fmtver=None, header=note.header,
                                 text=note.text, lines=note.lines))
         else:
             history.append(dict(id=None, proj_id=None, thumbnail=None,
                                 ver=None, fmtver=None, header='',
                                 text='', lines=[]))
         
         history[-1]['id'] = ver.id
         history[-1]['proj_id'] = ver.asset.proj_id
         history[-1]['has_preview'] = ver.has_preview
         history[-1]['thumbnail'] = ver.thumbnail
         history[-1]['ver'] = ver.ver
         history[-1]['fmtver'] = ver.fmtver
     
     return dict(asset=asset, history=history)
Beispiel #6
0
    def get_revoke(self, proj, asset_id, **kwargs):
        """Display a REVOKE form."""
        asset = asset_get(proj, asset_id)

        f_status.custom_method = 'REVOKE'
        f_status.value = dict(proj=asset.project.id,
                              asset_id=asset.id,
                              project_name_=asset.project.name,
                              container_=asset.parent.owner.path,
                              category_id_=asset.category.id,
                              asset_name_=asset.name,
                             )
                     
        tmpl_context.form = f_status
        return dict(title='%s: %s' % (_('Revoke approval for'), asset.path))
Beispiel #7
0
    def get_sendback(self, proj, asset_id, **kwargs):
        """Display a SENDBACK form."""
        asset = asset_get(proj, asset_id)

        f_status.custom_method = 'SENDBACK'
        f_status.value = dict(proj=asset.project.id,
                              asset_id=asset.id,
                              project_name_=asset.project.name,
                              container_=asset.parent.owner.path,
                              category_id_=asset.category.id,
                              asset_name_=asset.name,
                             )

        tmpl_context.form = f_status
        return dict(title='%s: %s' % (_('Send back for revisions'), asset.path))
Beispiel #8
0
    def get_submit(self, proj, asset_id, **kwargs):
        """Display a SUBMIT form."""
        asset = asset_get(proj, asset_id)

        f_status.custom_method = 'SUBMIT'
        f_status.value = dict(proj=asset.project.id,
                              asset_id=asset.id,
                              project_name_=asset.project.name,
                              container_=asset.parent.owner.path,
                              category_id_=asset.category.id,
                              asset_name_=asset.name,
                             )

        tmpl_context.form = f_status
        return dict(title='%s: %s' % (_('Submit for approval'), asset.path))
Beispiel #9
0
def asset_set_active(func, *args, **kwargs):
    """Extract the current asset id from the args passed to the function
    and puts the corresponding asset in the template context.
    
    If the asset id is not valid raise an error."""
    if 'asset_id' in kwargs:
        asset_id = kwargs['asset_id']
    elif len(args)>2:
        asset_id = args[2]
    else:
        raise SPAMError('No asset_id defined')

    project = tmpl_context.project
    tmpl_context.asset = asset_get(project.id, asset_id)
    return func(*args, **kwargs)
Beispiel #10
0
    def get_publish(self, proj, asset_id, **kwargs):
        """Display a PUBLISH form."""
        asset = asset_get(proj, asset_id)

        f_publish.custom_method = 'PUBLISH'
        f_publish.value = dict(proj=asset.project.id,
                               asset_id=asset.id,
                               project_name_=asset.project.name,
                               container_=asset.parent.owner.path,
                               category_id_=asset.category.id,
                               asset_name_=asset.name,
                              )
        
        name, ext = os.path.splitext(asset.name)
        f_publish.child.children.uploader.ext = ext
        tmpl_context.form = f_publish
        return dict(title='%s %s' % (_('Publish a new version for Asset:'),
                                                                    asset.path))
Beispiel #11
0
    def get_delete(self, proj, asset_id, **kwargs):
        """Display a DELETE confirmation form."""
        asset = asset_get(proj, asset_id)

        f_confirm.custom_method = 'DELETE'
        f_confirm.value = dict(proj=asset.project.id,
                               project_name_=asset.project.name,
                               container_=asset.parent.owner.path,
                               category_id_=asset.category.id,
                               asset_id=asset.id,
                               asset_name_=asset.name,
                              )
                     
        warning = ('This will only delete the asset entry in the database. '
                   'The data must be deleted manually if needed.')
        tmpl_context.form = f_confirm
        return dict(title='%s %s?' % (_('Are you sure you want to delete:'),
                                                asset.path), warning=warning)
Beispiel #12
0
    def post_publish(self, proj, asset_id, uploaded, comment=None,
                                                                uploader=None):
        """Publish a new version of an asset.

        This will commit to the repo the file(s) already uploaded in a temporary
        storage area, and create a thumbnail and preview if required.
        """
        session = session_get()
        asset = asset_get(proj, asset_id)
        user = tmpl_context.user

        if not asset.checkedout or user != asset.owner:
            msg = '%s %s' % (_('Cannot publish Asset:'), asset.path)
            return dict(msg=msg, status='error', updates=[])

        if isinstance(uploaded, list):
            # the form might send empty strings, so we strip them
            uploaded = [uf for uf in uploaded if uf]
        else:
            uploaded = [uploaded]

        # check that uploaded file extension matches asset name
        name, ext = os.path.splitext(asset.name)
        for uf in uploaded:
            uf_name, uf_ext = os.path.splitext(uf)
            if not uf_ext == ext:
                msg = '%s %s' % (_('Uploaded file must be of type:'), ext)
                return dict(msg=msg, status='error', updates=[])

        # commit file to repo
        if comment is None or comment=='None':
            comment = ''
        header = u'[%s %s v%03d]' % (_('published'), asset.path,
                                                            asset.current.ver+1)
        text = comment and u'%s\n%s' % (header, comment) or header
        repo_id = repo.commit(proj, asset, uploaded, text, user.user_name)
        if not repo_id:
            msg = '%s %s' % (_('The latest version is already:'), uploaded)
            return dict(msg=msg, status='info', updates=[])

        # create a new version
        newver = AssetVersion(asset, asset.current.ver+1, user, repo_id)
        text = u'[%s v%03d]\n%s' % (_('published'), newver.ver, comment)
        newver.notes.append(Note(user, text))
        session.flush()
        session.refresh(asset)

        # create thumbnail and preview
        preview.make_thumb(asset)
        preview.make_preview(asset)

        msg = '%s %s v%03d' % (_('Published'), asset.path, newver.ver)
        updates = [dict(item=asset, type='updated', topic=TOPIC_ASSETS)]

        # log into Journal
        journal.add(user, '%s - %s' % (msg, asset))

        # notify clients
        notify.send(updates)

        return dict(msg=msg, status='ok', updates=updates)