# Path: submit/exceptions.py
# class GroupWithException(SubmitException):
# 
#     """Indicates there are too many users to join a group."""
# 
# Path: submit/helpers.py
# def alphanum_key(string):
#     """Return a comparable tuple with extracted number segments.
# 
#     Adapted from: http://stackoverflow.com/a/2669120/176978
# 
#     """
#     convert = lambda text: int(text) if text.isdigit() else text
#     return [convert(segment) for segment in re.split('([0-9]+)', string)]


import errno
import json
import os
import re
import sys
import transaction
import uuid
    import builtins
        import pprint
from datetime import datetime, timedelta
from hashlib import sha1
from pyramid_addons.helpers import UTC
from sqla_mixins import BasicBase, UserMixin
from sqlalchemy import (Binary, Boolean, Column, DateTime, Enum, ForeignKey,
                        Integer, PickleType, String, Table, Unicode,
                        UnicodeText, and_, func)
from sqlalchemy.exc import IntegrityError, OperationalError
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import backref, relationship, scoped_session, sessionmaker
from sqlalchemy.schema import UniqueConstraint
from zope.sqlalchemy import ZopeTransactionExtension
from .exceptions import GroupWithException
from .helpers import alphanum_key
        from alembic.config import Config
        from alembic import command
        return '{0} <{1}>{2}'.format(self.name, self.username, admin_str)

    def can_join_group(self, project):
        """Return whether or not user can join a group on `project`."""
        if project.class_.is_locked or project.group_max < 2:
            return False
        u2g = self.fetch_group_assoc(project)
        if u2g:
            return len(list(u2g.group.users)) < project.group_max
        return True

    def can_view(self, user):
        """Return whether or not `user` can view information about the user."""
        return user.is_admin or self == user \
            or set(self.classes).intersection(user.admin_for)

    def classes_can_admin(self):
        """Return all the classes (sorted) that this user can admin."""
        if self.is_admin:
            return sorted(Session.query(Class).all())
        else:
            return sorted(self.admin_for)

    def group_with(self, to_user, project, bypass_limit=False):
        """Join the users in a group."""
        from_user = self
        from_assoc = from_user.fetch_group_assoc(project)
        to_assoc = to_user.fetch_group_assoc(project)

        if from_user == to_user or from_assoc == to_assoc and from_assoc:

# Path: submit/exceptions.py
# class GroupWithException(SubmitException):
# 
#     """Indicates there are too many users to join a group."""
# 
# Path: submit/helpers.py
# def alphanum_key(string):
#     """Return a comparable tuple with extracted number segments.
# 
#     Adapted from: http://stackoverflow.com/a/2669120/176978
# 
#     """
#     convert = lambda text: int(text) if text.isdigit() else text
#     return [convert(segment) for segment in re.split('([0-9]+)', string)]


# Path: submit/models.py
import errno
import json
import os
import re
import sys
import transaction
import uuid
    import builtins
        import pprint
from datetime import datetime, timedelta
from hashlib import sha1
from pyramid_addons.helpers import UTC
from sqla_mixins import BasicBase, UserMixin
from sqlalchemy import (Binary, Boolean, Column, DateTime, Enum, ForeignKey,
                        Integer, PickleType, String, Table, Unicode,
                        UnicodeText, and_, func)
from sqlalchemy.exc import IntegrityError, OperationalError
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import backref, relationship, scoped_session, sessionmaker
from sqlalchemy.schema import UniqueConstraint
from zope.sqlalchemy import ZopeTransactionExtension
from .exceptions import GroupWithException
from .helpers import alphanum_key
        from alembic.config import Config
        from alembic import command

        return '{0} <{1}>{2}'.format(self.name, self.username, admin_str)

    def can_join_group(self, project):
        """Return whether or not user can join a group on `project`."""
        if project.class_.is_locked or project.group_max < 2:
            return False
        u2g = self.fetch_group_assoc(project)
        if u2g:
            return len(list(u2g.group.users)) < project.group_max
        return True

    def can_view(self, user):
        """Return whether or not `user` can view information about the user."""
        return user.is_admin or self == user \
            or set(self.classes).intersection(user.admin_for)

    def classes_can_admin(self):
        """Return all the classes (sorted) that this user can admin."""
        if self.is_admin:
            return sorted(Session.query(Class).all())
        else:
            return sorted(self.admin_for)

    def group_with(self, to_user, project, bypass_limit=False):
        """Join the users in a group."""
        from_user = self
        from_assoc = from_user.fetch_group_assoc(project)
        to_assoc = to_user.fetch_group_assoc(project)

        if from_user == to_user or from_assoc == to_assoc and from_assoc:

            raise GroupWithException('You are already part of that group.')