How to use the spam.model.category_get function in spam

To help you get started, we’ve selected a few spam examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lento / spam / spam / controllers / category.py View on Github external
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))
github lento / spam / spam / controllers / asset / main.py View on Github external
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))
        
        # log into Journal
        new = asset.__dict__.copy()
        new.pop('_sa_instance_state', None)
        journal.add(user, 'created %s' % asset)

        # send a stomp message to notify clients
        notify.send(asset, update_type='added')
        return dict(msg='created asset "%s"' % asset.name, result='success',
github lento / spam / spam / controllers / user / main.py View on Github external
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))
github lento / spam / spam / controllers / category.py View on Github external
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)
github lento / spam / spam / controllers / category.py View on Github external
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)
github lento / spam / spam / controllers / category.py View on Github external
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)
github lento / spam / spam / controllers / user / main.py View on Github external
def post_add_supervisors(self, proj, category_id, userids):
        """Add supervisors 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]
        supervisors = [Supervisor(project.id, category, adduser) for adduser in
                        users if adduser not in project.supervisors[category]]
        for supervisor in supervisors:
            added.append(supervisor.user.user_id)

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

        added = ', '.join(added)
github lento / spam / spam / controllers / user / main.py View on Github external
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
github lento / spam / spam / controllers / user / main.py View on Github external
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
github lento / spam / spam / controllers / user / main.py View on Github external
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)