# mailer/queries.py

from django.contrib.auth.models import User, Group
from django.conf import settings

#from models import Message, MessageLog

"""
These are the queries that define who gets emailed what.
"""

# This is to prevent someone from trying to call an inappropiate query
# It makes the person writing the python query code the only one responcible.
# Someone who is just creating Message definition records will not be able
# to call a function that is not listed.
__all__ = ['users', 'groups']
def get_queries():
    return __all__

def test1(queryParams):
    return     [ {'email':'Carl Test <carl@personnelware.com>'}, ]

def test2(queryParams):
    # http://xkcd.com/325/
    return [{'email':'Sheila m. <shekay@pobox.com>', 'adj': 'wonderful', 'name':'Sheila', 'product':'office chair', 'x':20 },
        {'email':'Carl Test <carl>', 'adj': 'carp', 'name':'Carl', 'product':'bob cat', 'x':2000 },
        ]

def test3(queryParams):
    # grab 4 people from the user table.
    users = User.objects.filter(id__in=[1,2,26,27]).values()
    return users

def test4(queryParams):
    return     [ {'email':queryParams['bsd']['test_to']}, ]

def users(queryParams):
    u=queryParams['bsd']['users']
    return [x.__dict__ for x in u]
    # return User.objects.filter(id__in=[x.id for x in u]).values() # works, but extra trip through the ORM.
    # return [x.values() for x in u] # 'User' object has no attribute 'values'
    # return [dict(x) for x in u] # 'User' object is not iterable

# eof: queries.py
