How to use the spam.model.session_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 / libgroup / main.py View on Github external
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)
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)))
github lento / spam / spam / controllers / project / main.py View on Github external
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),
github lento / spam / spam / controllers / note.py View on Github external
def pin(self, proj, note_id):
        """Pin a note."""
        session = session_get()
        note = note_get(note_id)
        ob = note.annotated

        if note.sticky:
            msg = '%s %s' % (_('Note is already pinned:'), note.id)
            return dict(msg=msg, status='info', updates=[])

        note.sticky = True
        session.refresh(ob.annotable)

        msg = '%s %s' % (_('Pinned note:'), note.id)

        updates = [
            dict(item=note, topic=TOPIC_NOTES, filter=ob.annotable.id),
            dict(item=ob, topic=TOPICS[ob.__class__]),
            ]
github lento / spam / spam / controllers / scene / main.py View on Github external
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)))
github lento / spam / spam / controllers / user / main.py View on Github external
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)
github lento / spam / spam / lib / journaling.py View on Github external
def add(self, user, text):
        entry = Journal(user, text)
        session_get().add(entry)
        notify.send(entry, update_type='added')
github lento / spam / spam / controllers / user / main.py View on Github external
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)
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()