# Path: raggregate/queries/users.py
# def get_user_by_id(id):
# def get_user_by_name(name):
# def get_user_by_email(email):
# def get_user_by_token(token):
# def is_user_allowed_admin_action(user_id, target_id, request = None, target_class = 'user_post',):
# def get_followed_users(id):
# def get_user_votes(user_id, vote_type, submission_id=None):
# def create_temp_user(initial_pw = None):
# def fuzzify_date(d):
# def create_user(**kwargs):
# def login_user(request, u, password, bypass_password = False):
# def add_user_picture(orig_filename, new_prefix, up_dir, image_file):
# def send_email_to_user(request, to_email, title, body):
# def send_lost_password_verify_email(request, user):
# def generate_new_password(request, user):
# 
# Path: raggregate/queries/submission.py
# def get_story_list(page_num = 1, per_page = 30, sort = 'new', request = None, self_only = False, section = None):
# def get_story_by_id(id):
# def get_story_by_url_oldest(url):
# def update_story_vote_tally(story_id):
# def get_endpoints_from_page_num(page_num, per_page):
# def get_comments(id, organize_parentage = False, page_num = 1, per_page = 30, sort = 'new', target = 'story', target_id = None):
# def _build_comment_trees(all_comments, allowed_roots):
# def count_comment_children(comment_id):
# def get_comment_parent_story(id):
# def get_comment_by_id(id):
# def get_recent_comments(num):
# def get_story_id_from_slug(slug):
# 
# Path: raggregate/models/sublist.py
# class Sublist(Base):
#     __tablename__ = 'sublists'
#     id = Column(GUID, primary_key=True)
#     title = Column(UnicodeText)
#     description = Column(UnicodeText)
#     visibility = Column(UnicodeText)
#     added_by = Column(GUID, ForeignKey('users.id'))
#     added_on = Column(DateTime)
# 
#     def __init__(self, title = None, description = None, visibility = None,
#                  added_by = None, added_on = None):
#         self.title = title
#         self.description = description
#         self.visibility = visibility
#         self.added_by = added_by
#         self.added_on = added_on
# 
# Path: raggregate/models/sublist_member.py
# class SublistMember(Base):
#     __tablename__ = 'sublists_members'
#     id = Column(GUID, primary_key=True)
#     sublist_id = Column(GUID, ForeignKey('sublists.id'))
#     member_id = Column(GUID, ForeignKey('submissions.id'))
#     added_by = Column(GUID, ForeignKey('users.id'))
#     added_on = Column(DateTime)
# 
#     def __init__(self, sublist_id = None, member_id = None, added_by = None,
#                   added_on = None):
#         self.sublist_id = sublist_id
#         self.member_id = member_id
#         self.added_by = added_by
#         self.added_on = added_on


import sqlalchemy
import sqlahelper
from raggregate.queries import users
from raggregate.queries import submission as submission_queries
from raggregate.models.sublist import Sublist
from raggregate.models.sublist_member import SublistMember

dbsession = sqlahelper.get_session()

def get_sublists():
    return dbsession.query(Sublist).all()

def get_sublist_by_title(title):
    return dbsession.query(Sublist).filter(Sublist.title == title).all()

def get_sublist_members(sublist_id):
    members = dbsession.query(SublistMember).filter(SublistMember.sublist_id == sublist_id).all()
    member_list = []
    for m in members:

# Path: raggregate/queries/users.py
# def get_user_by_id(id):
# def get_user_by_name(name):
# def get_user_by_email(email):
# def get_user_by_token(token):
# def is_user_allowed_admin_action(user_id, target_id, request = None, target_class = 'user_post',):
# def get_followed_users(id):
# def get_user_votes(user_id, vote_type, submission_id=None):
# def create_temp_user(initial_pw = None):
# def fuzzify_date(d):
# def create_user(**kwargs):
# def login_user(request, u, password, bypass_password = False):
# def add_user_picture(orig_filename, new_prefix, up_dir, image_file):
# def send_email_to_user(request, to_email, title, body):
# def send_lost_password_verify_email(request, user):
# def generate_new_password(request, user):
# 
# Path: raggregate/queries/submission.py
# def get_story_list(page_num = 1, per_page = 30, sort = 'new', request = None, self_only = False, section = None):
# def get_story_by_id(id):
# def get_story_by_url_oldest(url):
# def update_story_vote_tally(story_id):
# def get_endpoints_from_page_num(page_num, per_page):
# def get_comments(id, organize_parentage = False, page_num = 1, per_page = 30, sort = 'new', target = 'story', target_id = None):
# def _build_comment_trees(all_comments, allowed_roots):
# def count_comment_children(comment_id):
# def get_comment_parent_story(id):
# def get_comment_by_id(id):
# def get_recent_comments(num):
# def get_story_id_from_slug(slug):
# 
# Path: raggregate/models/sublist.py
# class Sublist(Base):
#     __tablename__ = 'sublists'
#     id = Column(GUID, primary_key=True)
#     title = Column(UnicodeText)
#     description = Column(UnicodeText)
#     visibility = Column(UnicodeText)
#     added_by = Column(GUID, ForeignKey('users.id'))
#     added_on = Column(DateTime)
# 
#     def __init__(self, title = None, description = None, visibility = None,
#                  added_by = None, added_on = None):
#         self.title = title
#         self.description = description
#         self.visibility = visibility
#         self.added_by = added_by
#         self.added_on = added_on
# 
# Path: raggregate/models/sublist_member.py
# class SublistMember(Base):
#     __tablename__ = 'sublists_members'
#     id = Column(GUID, primary_key=True)
#     sublist_id = Column(GUID, ForeignKey('sublists.id'))
#     member_id = Column(GUID, ForeignKey('submissions.id'))
#     added_by = Column(GUID, ForeignKey('users.id'))
#     added_on = Column(DateTime)
# 
#     def __init__(self, sublist_id = None, member_id = None, added_by = None,
#                   added_on = None):
#         self.sublist_id = sublist_id
#         self.member_id = member_id
#         self.added_by = added_by
#         self.added_on = added_on


# Path: raggregate/queries/sublist.py
import sqlalchemy
import sqlahelper
from raggregate.queries import users
from raggregate.queries import submission as submission_queries
from raggregate.models.sublist import Sublist
from raggregate.models.sublist_member import SublistMember


dbsession = sqlahelper.get_session()

def get_sublists():
    return dbsession.query(Sublist).all()

def get_sublist_by_title(title):
    return dbsession.query(Sublist).filter(Sublist.title == title).all()

def get_sublist_members(sublist_id):
    members = dbsession.query(SublistMember).filter(SublistMember.sublist_id == sublist_id).all()
    member_list = []
    for m in members:

        member_list.append(submission_queries.get_story_by_id(m.member_id))