Example #1
0
File: main.py Project: MrPetru/spam
    def post_delete(self, proj):
        """Delete a project.

        Only delete the project record from the common db, the project
        repository must be removed manually.
        (This should help prevent awful accidents) ;)
        """
        session = session_get()
        user = tmpl_context.user
        project = tmpl_context.project

        if project.scenes or project.libgroups:
            return dict(
                msg="%s %s" % (_("Cannot delete project because it contains scenes or " "libgroups:"), project.id),
                status="error",
                updates=[],
            )

        session.delete(project)

        msg = "%s %s" % (_("Deleted project:"), proj)

        # log into Journal
        journal.add(user, "%s %s" % (msg, project))

        # notify clients
        updates = [dict(item=project, type="deleted", topic=TOPIC_PROJECTS_ACTIVE)]
        notify.send(updates)

        return dict(msg=msg, status="ok", updates=updates)
Example #2
0
File: main.py Project: MrPetru/spam
    def put(self, proj, project_name=None, description=None):
        """Edit a project"""
        project = tmpl_context.project
        old = project.__dict__.copy()
        session = session_get()
        user = tmpl_context.user

        modified = False
        if project_name is not None and not project.name == project_name:
            project.name = project_name
            modified = True

        if description is not None and not project.description == description:
            project.description = description
            modified = True

        if modified:
            new = project.__dict__.copy()

            # invalidate cache
            project.touch()

            msg = "%s %s" % (_("Updated project:"), proj)

            # log into Journal
            journal.add(user, u"%s - %s" % (msg, diff_dicts(old, new)))

            # notify clients
            updates = [dict(item=project, type="updated", topic=TOPIC_PROJECTS_ACTIVE)]
            notify.send(updates)

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

        return dict(msg="%s %s" % (_("Project is unchanged:"), proj), status="info", updates=[])
Example #3
0
File: main.py Project: MrPetru/spam
    def post_activate(self, proj):
        """Activate a project"""
        query = query_projects_archived().filter_by(id=proj.decode("utf-8"))
        project = query.one()
        session = session_get()
        user = tmpl_context.user

        project.archived = False

        # invalidate cache
        project.touch()

        msg = "%s %s" % (_("Activated project:"), proj)

        # log into Journal
        journal.add(user, "%s %s" % (msg, project))

        # notify clients
        updates = [
            dict(item=project, type="added", topic=TOPIC_PROJECTS_ACTIVE),
            dict(item=project, type="deleted", topic=TOPIC_PROJECTS_ARCHIVED),
        ]
        notify.send(updates)

        return dict(msg=msg, status="ok", updates=updates)
Example #4
0
File: main.py Project: MrPetru/spam
    def post(self, proj, project_name=None, description=None):
        """Create a new project"""
        session = session_get()
        user = tmpl_context.user

        # add project to db
        project = Project(proj, name=project_name, description=description)
        session.add(project)

        # create directories and init hg repo
        repo.project_create_dirs(project.id)
        repo.repo_init(project.id)

        # grant project rights to user "admin"
        admin = session.query(User).filter_by(user_name=u"admin").one()
        project.admins.append(admin)

        msg = "%s %s" % (_("Created project:"), project.id)

        # log into Journal
        journal.add(user, "%s %s" % (msg, project))

        # notify clients
        updates = [dict(item=project, type="added", topic=TOPIC_PROJECTS_ACTIVE)]
        notify.send(updates)

        return dict(msg=msg, status="ok", updates=updates)
Example #5
0
File: main.py Project: MrPetru/spam
    def remove_admin(self, proj, user_id):
        """Remove an administrator from a project"""
        session = session_get()
        user = tmpl_context.user
        project = tmpl_context.project
        remuser = user_get(user_id)
        updates = []
        
        if remuser in project.admins:
            project.admins.remove(remuser)
            
            # prepare updates to notify clients
            updates.append(dict(item=remuser, type='deleted',
                        topic=TOPIC_PROJECT_ADMINS, filter=project.id))

            # log into Journal
            msg = '%s %s %s' % (remuser.user_id,
                                _('revoked as administrator for:'),
                                project.id)
            journal.add(user, msg)
            notify.send(updates)

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

        return dict(msg='%s %s %s' % (
                remuser.user_id, _('is not an administrator for:'), project.id),
                status='error', updates=[])
Example #6
0
File: main.py Project: MrPetru/spam
    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)
Example #7
0
File: main.py Project: MrPetru/spam
    def remove_artist(self, proj, category_id, user_id):
        """Remove an artist from a category"""
        session = session_get()
        user = tmpl_context.user
        project = project_get(proj)
        category = category_get(category_id)
        remuser = user_get(user_id)
        updates = []

        if remuser in project.artists[category]:
            query = session.query(Artist).filter_by(proj_id=project.id)
            query = query.filter_by(category_id=category.id)
            query = query.filter_by(user_id=remuser.user_id)
            artist = query.one()
            session.delete(artist)

            # prepare updates to notify clients
            updates.append(dict(item=remuser, type='deleted',
                        topic=TOPIC_PROJECT_ARTISTS,
                        filter='%s-%s' % (project.id, category.id)))

            # log into Journal
            msg = '%s %s %s/%s' % (remuser.user_id,
                                   _('revoked as artist from:'),
                                   project.id, category.id)
            journal.add(user, msg)
            notify.send(updates)

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

        return dict(msg='%s %s %s' % (
                remuser.user_id, _('is not an artist for:'), project.id),
                status='error', updates=[])
Example #8
0
    def put(self, category_id, ordering=None, naming_convention=None):
        """Edit a category"""
        session = session_get()
        user = tmpl_context.user
        category = category_get(category_id)
        old = category.__dict__.copy()

        modified = False
        if ordering is not None and not ordering == category.ordering:
            category.ordering = ordering
            modified = True

        if (naming_convention is not None and
                        not naming_convention == category.naming_convention):
            category.naming_convention = naming_convention
            modified = True

        if modified:
            new = category.__dict__.copy()

            msg = '%s %s' % (_('Updated category:'), category_id)

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

            # notify clients
            updates = [
                dict(item=category, type='updated', topic=TOPIC_CATEGORIES)
                ]
            notify.send(updates)

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

        return dict(msg='%s %s' % (_('Category is unchanged:'), category_id),
                                                    status='info', updates=[])
Example #9
0
File: main.py Project: MrPetru/spam
    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)
Example #10
0
File: main.py Project: MrPetru/spam
    def post(self, proj, container_type, container_id, category_id, name,
                                                                comment=None):
        """Create a new asset"""
        session = session_get()
        project = tmpl_context.project
        user = tmpl_context.user
        container = container_get(project.id, container_type, container_id)
        category = category_get(category_id)

        # add asset to db
        asset = Asset(container, category, name, user)
        session.add(asset)
        session.flush()
        text = '[%s v000]\n%s' % (_('created'), comment or '')
        asset.current.notes.append(Note(user, text))

        msg = '%s %s' % (_('Created Asset:'), asset.name)

        # log into Journal
        new = asset.__dict__.copy()
        new.pop('_sa_instance_state', None)
        journal.add(user, '%s - %s' % (msg, asset))

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

        return dict(msg=msg, status='ok', updates=updates)
Example #11
0
File: main.py Project: MrPetru/spam
    def put(self, proj, sc, description=None):
        """Edit a scene"""
        session = session_get()
        user = tmpl_context.user
        scene = scene_get(proj, sc)
        old = scene.__dict__.copy()

        modified = False
        if description is not None and not scene.description == description:
            scene.description = description
            modified = True
        
        if modified:
            new = scene.__dict__.copy()

            msg = '%s %s' % (_('Updated scene:'), scene.path)

            # log into Journal
            journal.add(user, '%s - %s' % (msg, diff_dicts(old, new)))
            
            # notify clients
            updates = [dict(item=scene, type='updated', topic=TOPIC_SCENES)]
            notify.send(updates)
            return dict(msg=msg, status='ok', updates=updates)
        return dict(msg='%s %s' % (_('Scene is unchanged:'), scene.path),
                                                    status='info', updates=[])
Example #12
0
File: main.py Project: MrPetru/spam
    def post(self, proj, parent_id, name, description=None):
        """Create a new libgroup"""
        session = session_get()
        project = tmpl_context.project
        user = tmpl_context.user
        parent = parent_id and libgroup_get(proj, parent_id) or None
        
        # add libgroup to db
        libgroup = Libgroup(project.id, name, parent, description)
        session.add(libgroup)
        session.flush()
        
        # create directories
        repo.libgroup_create_dirs(project.id, libgroup)
        
        # invalidate project cache
        project.touch()

        msg = '%s %s' % (_('Created libgroup:'), libgroup.path)

        # log into Journal
        journal.add(user, '%s - %s' % (msg, libgroup))
        
        # notify clients
        updates = [
            dict(item=libgroup, type='added', topic=TOPIC_LIBGROUPS),
            dict(item=project, type='updated', topic=TOPIC_PROJECT_STRUCTURE),
            ]
        notify.send(updates)

        return dict(msg=msg, status='ok', updates=updates)
Example #13
0
 def index(self):
     """Return a `full` page with a paginated table of journal entries."""
     tmpl_context.t_journal = t_journal
     query = session_get().query(Journal)
     journal = query.order_by(desc('created'))
     return dict(page='user/journal', sidebar=('admin', 'journal'),
                                                             journal=journal)
Example #14
0
File: main.py Project: MrPetru/spam
    def post(self, proj, sc, description=None):
        """Create a new scene"""
        session = session_get()
        user = tmpl_context.user
        project = tmpl_context.project
        
        # add scene to db
        scene = Scene(project.id, sc, description)
        session.add(scene)
        session.flush()
        
        # create directories
        repo.scene_create_dirs(project.id, scene)
        
        # invalidate project cache
        project.touch()

        msg = '%s %s' % (_('Created scene:'), scene.path)

        # log into Journal
        journal.add(user, '%s - %s' % (msg, scene))
        
        # notify clients
        updates = [
            dict(item=scene, type='added', topic=TOPIC_SCENES),
            dict(item=project, type='updated', topic=TOPIC_PROJECT_STRUCTURE),
            ]
        notify.send(updates)
        return dict(msg=msg, status='ok', updates=updates)
Example #15
0
File: main.py Project: MrPetru/spam
    def put(self, user_id, display_name=None):
        """Edit a user"""
        session = session_get()
        user = tmpl_context.user
        edituser = user_get(user_id)
        old = edituser.__dict__.copy()
        
        modified = False
        if display_name and not edituser.display_name == display_name:
            edituser.display_name = display_name
            modified = True
        
        if modified:
            new = edituser.__dict__.copy()

            msg = '%s %s' % (_('Updated user:'******'%s - %s' % (msg, diff_dicts(old, new)))

            # notify clients
            updates = [
                dict(item=edituser, type='updated', topic=TOPIC_USERS)
                ]
            notify.send(updates)

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

        return dict(msg='%s %s' % (_('User is unchanged:'), edituser.user_id),
                                                    status='info', updates=[])
Example #16
0
File: main.py Project: MrPetru/spam
    def post(self, proj, sc, sh, description=None, action=None, frames=None,
                                            handle_in=None, handle_out=None):
        """Create a new shot"""
        project = tmpl_context.project
        session = session_get()
        user = tmpl_context.user
        scene = scene_get(proj, sc)
        
        # add shot to db
        shot = Shot(scene, sh, description=description, action=action,
                    frames=frames, handle_in=handle_in, handle_out=handle_out)
        session.add(shot)
        session.flush()
        
        # create directories
        repo.shot_create_dirs(scene.project.id, shot)
        
        # invalidate project cache
        project.touch()

        msg = '%s %s' % (_('Created shot:'), shot.path)

        # log into Journal
        journal.add(user, '%s - %s' % (msg, shot))
        
        # notify clients
        updates = [
            dict(item=shot, type='added', topic=TOPIC_SHOTS),
            dict(item=project, type='updated', topic=TOPIC_PROJECT_STRUCTURE),
            ]
        notify.send(updates)

        return dict(msg=msg, status='ok', updates=updates)
Example #17
0
File: main.py Project: MrPetru/spam
    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)
Example #18
0
File: main.py Project: MrPetru/spam
    def post_add_to_group(self, group_id, userids):
        """Add users to a group"""
        session = session_get()
        user = tmpl_context.user
        group = group_get(group_id)
        added = []
        updates = []
        
        for uid in userids:
            adduser = user_get(uid)
            if adduser not in group.users:
                group.users.append(adduser)
                added.append(adduser.user_id)
                
                # prepare updates to notify clients
                updates.append(dict(item=adduser, type='added',
                            topic=TOPIC_GROUPS, filter=group.group_name))
        
        added = ', '.join(added)

        if added:
            # log into Journal
            msg = '%s %s %s' % (added,
                                n_('added to group:',
                                   'added to group:', len(added)),
                                group.group_id)
            journal.add(user, msg)
            notify.send(updates)

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

        return dict(msg='%s %s' % (_('Selected users are already in group:'),
                                    group.group_id), status='info', updates=[])
Example #19
0
File: main.py Project: MrPetru/spam
    def post_add_admins(self, proj, userids):
        """Add administrators to a project"""
        session = session_get()
        user = tmpl_context.user
        project = tmpl_context.project
        added = []
        updates = []

        for uid in userids:
            adduser = user_get(uid)
            if adduser not in project.admins:
                project.admins.append(adduser)
                added.append(adduser.user_id)
                
                # prepare updates to notify clients
                updates.append(dict(item=adduser, type='added',
                            topic=TOPIC_PROJECT_ADMINS, filter=project.id))
            
        added = ', '.join(added)
        
        if added:
            # log into Journal
            msg = '%s %s %s' % (added,
                                n_('set as administrator for:',
                                   'set as administrators for:', len(added)),
                                project.id)
            journal.add(user, msg)
            notify.send(updates)

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

        return dict(msg='%s %s' % (
            _('Selected users are already administrators for:'), project.id),
            status='info', updates=[])
Example #20
0
File: main.py Project: MrPetru/spam
    def remove_supervisor(self, proj, category_id, user_id):
        """Remove a supervisor from a category"""
        session = session_get()
        user = tmpl_context.user
        project = tmpl_context.project
        category = category_get(category_id)
        remuser = user_get(user_id)
        updates = []

        if remuser in project.supervisors[category]:
            query = session.query(Supervisor).filter_by(proj_id=project.id)
            query = query.filter_by(category_id=category.id)
            query = query.filter_by(user_id=remuser.user_id)
            sup = query.one()
            session.delete(sup)

            # prepare updates to notify clients
            updates.append(dict(item=remuser, type='deleted',
                        topic=TOPIC_PROJECT_SUPERVISORS,
                        filter='%s-%s' % (project.id, category.id)))

            # log into Journal
            msg = '%s %s %s/%s' % (remuser.user_id,
                                   _('revoked as supervisor from:'),
                                   project.id, category.id)
            journal.add(user, msg)
            notify.send(updates)

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

        return dict(msg='%s %s %s' % (
                remuser.user_id, _('is not a supervisor for:'), project.id),
                status='error', updates=[])
Example #21
0
File: main.py Project: MrPetru/spam
    def remove_from_group(self, user_id, group_id):
        """Remove a user from a group"""
        session = session_get()
        user = tmpl_context.user
        remuser = user_get(user_id)
        group = group_get(group_id)
        updates = []
        
        if remuser in group.users:
            group.users.remove(remuser)
            
            # prepare updates to notify clients
            updates.append(dict(item=remuser, type='deleted',
                        topic=TOPIC_GROUPS, filter=group.group_name))

            # log into Journal
            msg = '%s %s %s' % (remuser.user_id,
                                _('removed from group'),
                                group.group_id)
            journal.add(user, msg)
            notify.send(updates)

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

        return dict(msg='%s %s %s' % (remuser.user_id, _('is not in group:'),
                                    group.group_id), status='error', updates=[])
Example #22
0
File: main.py Project: MrPetru/spam
    def put(self, proj, libgroup_id, description=None):
        """Edit a libgroup"""
        session = session_get()
        user = tmpl_context.user
        libgroup = libgroup_get(proj, libgroup_id)
        old = libgroup.__dict__.copy()

        modified = False
        if description is not None and not libgroup.description == description:
            libgroup.description = description
            modified = True
        
        if modified:
            new = libgroup.__dict__.copy()

            msg = '%s %s' % (_('Updated libgroup:'), libgroup.path)

            # log into Journal
            journal.add(user, '%s - %s' % (msg, diff_dicts(old, new)))
            
            # notify clients
            updates = [
                dict(item=libgroup, type='updated', topic=TOPIC_LIBGROUPS),
                ]
            notify.send(updates)

            return dict(msg=msg, status='ok', updates=updates)
        return dict(msg='%s %s' % (_('Libgroup is unchanged:'), libgroup.path),
                                                    status='info', updates=[])
Example #23
0
File: tabs.py Project: MrPetru/spam
 def groups(self):
     """Handle the 'groups' tab.
     
     This tab allows to add users to the `SPAM administrators` group.
     """
     tmpl_context.t_group_users = t_group_users
     groups = session_get().query(Group)
     return dict(groups=groups)
Example #24
0
    def get_all(self):
        """Return a `full` page with a list of all categories and a button to
        add new categories."""
        query = session_get().query(Category)
        categories = query.order_by('ordering', 'id')

        t_categories.value = categories.all()
        tmpl_context.t_categories = t_categories
        return dict(page='admin/categories', sidebar=('admin', 'categories'))
Example #25
0
File: main.py Project: MrPetru/spam
 def get_add_admins(self, proj, **kwargs):
     """Display a ADD users form."""
     project = tmpl_context.project
     users = session_get().query(User)
     choices = [(u.user_id, '%-16s (%s)' % (u.user_id, u.display_name))
                                                             for u in users]
     f_add_admins.value = dict(proj=project.id)
     f_add_admins.child.children.userids.options = choices
     tmpl_context.form = f_add_admins
     return dict(title='%s %s' % (_('Add administrators for:'), project.id))
Example #26
0
File: tabs.py Project: MrPetru/spam
 def users(self):
     """Handle the 'users' tab.
     
     This tab allows to add, remove and edit SPAM users. Users added here
     can then be assigned to a project as artists or supervisors in the
     project's ``users`` tab: :meth:`spam.controllers.project.tabs.users`.
     """
     tmpl_context.t_users = t_users
     users = session_get().query(User)
     return dict(users=users)
Example #27
0
File: main.py Project: MrPetru/spam
 def get_add_to_group(self, group_id, **kwargs):
     """Display a ADD users form."""
     group = group_get(group_id)
     users = session_get().query(User)
     choices = [(u.user_id, '%-16s (%s)' % (u.user_id, u.display_name))
                                                             for u in users]
     f_add_to_group.child.children.userids.options = choices
     f_add_to_group.value = dict(group_id=group.group_id)
     tmpl_context.form = f_add_to_group
     return dict(title='%s %s' % (_('Add users to group:'), group.group_id))
Example #28
0
File: note.py Project: MrPetru/spam
 def new(self, proj, annotable_id, **kwargs):
     """Display a NEW form."""
     project = tmpl_context.project
     session = session_get()
     annotable = annotable_get(annotable_id)
     
     f_new.value = dict(proj=project.id, annotable_id=annotable.id)
     tmpl_context.form = f_new
     return dict(title='%s %s' % (_('Add a note to:'),
                                                 annotable.annotated.path))
Example #29
0
File: tabs.py Project: MrPetru/spam
 def users(self):
     """Handle the 'users' tab.
     
     This tab allows to assign users to a category as artists or supervisors,
     and to define project administrators.
     """
     session = session_get()
     project = tmpl_context.project
     tmpl_context.t_project_admins = t_project_admins
     tmpl_context.t_project_supervisors = t_project_supervisors
     tmpl_context.t_project_artists = t_project_artists
     categories = session_get().query(Category)
     supervisors = {}
     for cat in categories:
         supervisors[cat.id] = project.supervisors[cat]
     artists = {}
     for cat in categories:
         artists[cat.id] = project.artists[cat]
     
     return dict(categories=categories, supervisors=supervisors,
                                                             artists=artists)
Example #30
0
File: main.py Project: MrPetru/spam
 def get_add_artists(self, proj, category_id, **kwargs):
     """Display a ADD artists form."""
     project = tmpl_context.project
     category = category_get(category_id)
     users = session_get().query(User)
     choices = [(u.user_id, '%-16s (%s)' % (u.user_id, u.display_name))
                                                             for u in users]
     f_add_to_category.custom_method = 'ADD_ARTISTS'
     f_add_to_category.value = dict(proj=project.id,
                                    category_id=category.id)
     f_add_to_category.child.children.userids.options = choices
     tmpl_context.form = f_add_to_category
     return dict(title='%s %s/%s' % (_('Add artists for:'), project.id,
                                                             category.id))