import settings


def _group_by_domain(domain, **kwargs):
    from corehq.apps.groups.models import Group
    return list(Group.view(
        'groups/by_domain',
        key=domain,
        **kwargs
    ))


def group_by_domain(domain, include_docs=True):
    return _group_by_domain(
        domain,
        include_docs=include_docs,
    )


def stale_group_by_domain(domain, include_docs=True):
    return _group_by_domain(
        domain,
        include_docs=include_docs,
        stale=settings.COUCH_STALE_QUERY,
    )


def _group_by_name(domain, name, **kwargs):
    from corehq.apps.groups.models import Group
    return list(Group.view(
        'groups/by_name',
        key=[domain, name],
        **kwargs
    ))


def group_by_name(domain, name, include_docs=True):
    return _group_by_name(
        domain,
        name,
        include_docs=include_docs,
    )


def stale_group_by_name(domain, name, include_docs=True):
    return _group_by_name(
        domain,
        name,
        include_docs=include_docs,
        stale=settings.COUCH_STALE_QUERY,
    )


def refresh_group_views():
    from corehq.apps.groups.models import Group
    Group.view(
        'groups/by_domain',
        include_docs=False,
        limit=1,
    ).fetch()
    Group.view(
        'groups/by_name',
        include_docs=False,
        limit=1,
    ).fetch()

@@ -1,12 +1,29 @@
+from django.conf 
 import setti

use django.conf