How to use the spam.model.User 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 / project / main.py View on Github external
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)
github lento / spam / spam / websetup / bootstrap.py View on Github external
def bootstrap(command, conf, vars):
    """Commands for the first-time setup of SPAM database data."""

    session = model.session_get()
    # auth
    from sqlalchemy.exc import IntegrityError
    try:
        admin = model.User(u'admin', display_name=u'SPAM Administrator')
        admin.password = u'none'

        session.add(admin)

        administrators = model.Group(u'administrators',
                                            display_name=u'SPAM Administrators')

        administrators.users.append(admin)

        session.add(administrators)
        
        session.flush()
        transaction.commit()
    except IntegrityError:
        log.info('Warning, there was a problem adding your auth data, it may '
                                                    'have already been added:')
github lento / spam / spam / controllers / user / tabs.py View on Github external
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)
github lento / spam / spam / controllers / user / main.py View on Github external
def post(self, user_name, display_name, password):
        """Create a new user"""
        session = session_get()
        user = tmpl_context.user

        # add user to shared db
        newuser = User(user_name, display_name=display_name)
        newuser.password = password
        session.add(newuser)
        session.flush()

        msg = '%s %s' % (_('Created User:'), newuser.id)

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

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

        return dict(msg=msg, status='ok', updates=updates)
github lento / spam / spam / lib / notifications.py View on Github external
'projects_archived')
TOPIC_SCENES = config.get('topic_scenes', 'scenes')
TOPIC_SHOTS = config.get('topic_shots', 'shots')
TOPIC_ASSETS = config.get('topic_assets', 'assets')
TOPIC_LIBGROUPS = config.get('topic_libgroups', 'libgroups')
TOPIC_PROJECT_STRUCTURE = config.get('topic_project_structure',
    'projects_structure')
TOPIC_PROJECT_ADMINS = config.get('topic_project_admins', 'project_admins')
TOPIC_PROJECT_SUPERVISORS = config.get('topic_project_supervisors',
    'project_supervisors')
TOPIC_PROJECT_ARTISTS = config.get('topic_project_artists', 'project_artists')
TOPIC_JOURNAL = config.get('topic_journal', 'journal')
TOPIC_NOTES = config.get('topic_notes', 'notes')
TOPIC_TAGS = config.get('topic_tags', 'tags')

TOPICS = {User: TOPIC_USERS,
          Category: TOPIC_CATEGORIES,
          Project: TOPIC_PROJECTS_ACTIVE,
          Scene: TOPIC_SCENES,
          Shot: TOPIC_SHOTS,
          Asset: TOPIC_ASSETS,
          Libgroup: TOPIC_LIBGROUPS,
          Journal: TOPIC_JOURNAL,
          Note: TOPIC_NOTES,
          Tag: TOPIC_TAGS,
         }


class DummyClient(object):
    def send(self, *args, **kw):
        pass
github lento / spam / spam / config / app_cfg.py View on Github external
#base_config.renderers.append('chameleon_genshi')

#Configure the base SQLALchemy Setup
base_config.use_sqlalchemy = True
base_config.model = spam.model
base_config.DBSession = spam.model.DBSession


# YOU MUST CHANGE THIS VALUE IN PRODUCTION TO SECURE YOUR APP
base_config.sa_auth.cookie_secret = "ChangeME"

# Configure the authentication backend
base_config.auth_backend = 'sqlalchemy'
base_config.sa_auth.dbsession = model.DBSession
# what is the class you want to use to search for users in the database
base_config.sa_auth.user_class = model.User
# what is the class you want to use to search for groups in the database
base_config.sa_auth.group_class = model.Group
# what is the class you want to use to search for permissions in the database
base_config.sa_auth.permission_class = model.Permission


# override this if you would like to provide a different who plugin for
# managing login and logout of your application
base_config.sa_auth.form_plugin = None

# You may optionally define a page where you want users to be redirected to
# on login:
base_config.sa_auth.post_login_url = '/post_login'

# You may optionally define a page where you want users to be redirected to
# on logout:
github lento / spam / spam / controllers / user / main.py View on Github external
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))
github lento / spam / spam / model / helpers.py View on Github external
def user_get(user_id):
    """Return a user."""
    query = session_get().query(User)
    try:
        return query.filter_by(user_id=user_id.decode('utf-8')).one()
    except NoResultFound:
        try:
            domain = config.auth_domain.decode('utf-8')
            user_id = '%s-%s' % (domain, user_id)
            return query.filter_by(user_id=user_id).one()
        except NoResultFound:
            raise SPAMDBNotFound('User "%s" could not be found.' % user_id)
        except MultipleResultsFound:
            raise SPAMDBError('Error when searching user "%s".' % user_id)
    except MultipleResultsFound:
        raise SPAMDBError('Error when searching user "%s".' % user_id)