# Path: tidings/compat.py
# def iteritems(d, **kw):
# def iterkeys(d, **kw):
# 
# Path: tidings/utils.py
# def collate(*iterables, **kwargs):
#     def gather_next_value(row, index):
# def hash_to_unsigned(data):
# def emails_with_users_and_watches(
#         subject, template_path, vars, users_and_watches,
#         from_email=settings.TIDINGS_FROM_ADDRESS, **extra_kwargs):
# def import_from_setting(setting_name, fallback):


from django.conf import settings
from django.contrib.auth.models import AnonymousUser
from django.contrib.contenttypes.fields import (GenericForeignKey,
                                                GenericRelation)
from django.contrib.contenttypes.models import ContentType
from django.contrib.sites.models import Site
from django.db import models, connections, router
from .compat import next, text_type
from .utils import import_from_setting, reverse



ModelBase = import_from_setting('TIDINGS_MODEL_BASE', models.Model)


def multi_raw(query, params, models, model_to_fields):
    """Scoop multiple model instances out of the DB at once, given a query that
    returns all fields of each.

    Return an iterable of sequences of model instances parallel to the
    ``models`` sequence of classes. For example::

        [(<User such-and-such>, <Watch such-and-such>), ...]

    """
    cursor = connections[router.db_for_read(models[0])].cursor()
    cursor.execute(query, params)
    rows = cursor.fetchall()

    for row in rows:
        row_iter = iter(row)

# Path: tidings/compat.py
# def iteritems(d, **kw):
# def iterkeys(d, **kw):
# 
# Path: tidings/utils.py
# def collate(*iterables, **kwargs):
#     def gather_next_value(row, index):
# def hash_to_unsigned(data):
# def emails_with_users_and_watches(
#         subject, template_path, vars, users_and_watches,
#         from_email=settings.TIDINGS_FROM_ADDRESS, **extra_kwargs):
# def import_from_setting(setting_name, fallback):


# Path: tidings/models.py
from django.conf import settings
from django.contrib.auth.models import AnonymousUser
from django.contrib.contenttypes.fields import (GenericForeignKey,
                                                GenericRelation)
from django.contrib.contenttypes.models import ContentType
from django.contrib.sites.models import Site
from django.db import models, connections, router
from .compat import next, text_type
from .utils import import_from_setting, reverse




ModelBase = import_from_setting('TIDINGS_MODEL_BASE', models.Model)


def multi_raw(query, params, models, model_to_fields):
    """Scoop multiple model instances out of the DB at once, given a query that
    returns all fields of each.

    Return an iterable of sequences of model instances parallel to the
    ``models`` sequence of classes. For example::

        [(<User such-and-such>, <Watch such-and-such>), ...]

    """
    cursor = connections[router.db_for_read(models[0])].cursor()
    cursor.execute(query, params)
    rows = cursor.fetchall()

    for row in rows:
        row_iter = iter(row)

        yield [model_class(**dict((a, next(row_iter))