# 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

    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.')

        if not from_assoc and not to_assoc:
            to_assoc = UserToGroup(group=Group(project=project),
                                   project=project, user=to_user)
            Session.add(to_assoc)
            from_count = 1
        elif not to_assoc:
            from_assoc, to_assoc = to_assoc, from_assoc
            from_user, to_user = to_user, from_user
            from_count = 1
        elif not from_assoc:
            from_count = 1
        elif to_assoc.user_count > from_assoc.user_count:
            from_assoc, to_assoc = to_assoc, from_assoc
            from_user, to_user = to_user, from_user
            from_count = from_assoc.user_count
        else:
            from_count = from_assoc.user_count

        if not bypass_limit and \
                project.group_max < to_assoc.user_count + from_count:

# 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


    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.')

        if not from_assoc and not to_assoc:
            to_assoc = UserToGroup(group=Group(project=project),
                                   project=project, user=to_user)
            Session.add(to_assoc)
            from_count = 1
        elif not to_assoc:
            from_assoc, to_assoc = to_assoc, from_assoc
            from_user, to_user = to_user, from_user
            from_count = 1
        elif not from_assoc:
            from_count = 1
        elif to_assoc.user_count > from_assoc.user_count:
            from_assoc, to_assoc = to_assoc, from_assoc
            from_user, to_user = to_user, from_user
            from_count = from_assoc.user_count
        else:
            from_count = from_assoc.user_count

        if not bypass_limit and \
                project.group_max < to_assoc.user_count + from_count:

            raise GroupWithException('There are too many users to join that '