Beispiel #1
0
    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)
Beispiel #2
0
    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=[])
Beispiel #3
0
    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=[])
Beispiel #4
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=[])
Beispiel #5
0
 def edit(self, category_id, **kwargs):
     """Display a EDIT form."""
     category = category_get(category_id)
     f_edit.value = dict(category_id=category.id,
                         id_=category.id,
                         ordering=category.ordering,
                         naming_convention=category.naming_convention)
     tmpl_context.form = f_edit
     return dict(title='%s %s' % (_('Edit category:'), category.id))
Beispiel #6
0
 def get_delete(self, category_id, **kwargs):
     """Display a DELETE confirmation form."""
     category = category_get(category_id)
     f_confirm.custom_method = 'DELETE'
     f_confirm.value = dict(category_id=category.id,
                            id_=category.id,
                            ordering_=str(category.ordering),
                            naming_convention_=category.naming_convention)
     warning = ('This will delete the category entry in the database. '
                'All the assets in this category will be orphaned.')
     tmpl_context.form = f_confirm
     return dict(title='%s %s?' % (_('Are you sure you want to delete:'),
                                             category.id), warning=warning)
Beispiel #7
0
 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))
Beispiel #8
0
    def post_delete(self, category_id):
        """Delete a category.

        Only delete the category record from the common db, all the assets
        in this category will be orphaned, and must be removed manually.
        """
        session = session_get()
        user = tmpl_context.user
        category = category_get(category_id)
        session.delete(category)

        msg = '%s %s' % (_('Deleted category:'), category.id)

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

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

        return dict(msg=msg, status='ok', updates=updates)
Beispiel #9
0
    def post_add_artists(self, proj, category_id, userids):
        """Add artists to a category"""
        session = session_get()
        user = tmpl_context.user
        project = tmpl_context.project
        category = category_get(category_id)
        added = []
        updates = []

        users = [user_get(uid) for uid in userids]
        artists = [Artist(project.id, category, adduser) for adduser in users if
                                    adduser not in project.artists[category]]
        for artist in artists:
            added.append(artist.user.user_id)

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

        added = ', '.join(added)

        if added:
            # log into Journal
            msg = '%s %s %s/%s' % (added,
                                   n_('set as artist for:',
                                      'set as artists for:', len(added)),
                                   project.id, category.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 artists for:'), project.id),
                status='info', updates=[])
Beispiel #10
0
 def get_one(self, name):
     """This method is currently unused, but is needed for the 
     RESTController to work."""
     category = category_get(name)
     return dict(category=category)