# Path: signup/db.py
# class UserSignup(models.Model):
# 
# Path: signup/emails.py
# def send_welcome_emails(emails):
# 
# Path: mailgun/api.py
# def call_mailgun(method, api_sub_url, data, params=None):
# def send_email(to_email, from_email, subject, text_body, html_body=None, tags=None, campaign_id=None):
# def send_mass_email(to_emails, from_email, subject, text_body, html_body=None, tags=None, campaign_id=None, recipient_variables=None):
# def create_campaign(campaign_id, campaign_name):
# def create_list(address, name=None, description=None, access_level=None):
# def update_list(address, name=None, description=None, access_level=None):
# def add_list_member(list_address, member_address):
# def remove_list_member(list_address, member_address):
# def get_list(list_address):
# def get_list_members(list_address):
# def get_unsubscribes(address):
# def delete_all_unsubscribes(address):
# def get_list_stats(list_address):
# def get_logs(limit=100, skip=0):
# def fetch_all_logs():
# def get_events(limit, **kwargs):
# def get_all_events(**kwargs):
# def get_campaign_events(campaign_id, event, recipient=None, limit=None, page=None, count=None):
# def _get_campaign_action(campaign_id, action, group_by, limit=None, page=None, count=None):
# def get_campaign_opens(campaign_id, group_by, limit=None, page=None, count=None):
# def get_campaign_clicks(campaign_id, group_by, limit=None, page=None, count=None):
# 
# Path: sequence/models.py
# def sequence_list_name( sequence_number ):
# def sequence_campaign( sequence_number ):
# def sequence2dict( sequence_db ):
# def create_sequence( start_date, signup_close_date ):
# def get_all_sequences( ):
# def get_current_sequence( ):
# def get_current_sequence_number( ):


import random
import string
import json
from datetime import datetime
from signup import db
from signup import emails
from mailgun import api as mailgun_api
from sequence import models as sequence_model
    }
    return signup


def get_signup( email, sequence ):
    if not db.UserSignup.objects.filter(email__iexact=email, sequence=sequence, date_deleted__isnull=True).exists():
        raise Exception(u'Signup for {0} not found'.format(email))

    signup_db = db.UserSignup.objects.get(email__iexact=email, sequence=sequence, date_deleted__isnull=True)
    
    return _signup2json(signup_db)


def get_all_user_signups( email ):
    signups = db.UserSignup.objects.filter(email__iexact=email, date_deleted__isnull=True)
    return [ _signup2json(su) for su in signups ]


def get_signup_by_invite_code( invite_code ):
    user_set = db.UserSignup.objects.filter(
        invite_code=invite_code,
        date_deleted__isnull=True
    )
    if not user_set.exists():
        raise Exception()

    return _signup2json(user_set[0])


def get_signups( sequence ):

# Path: signup/db.py
# class UserSignup(models.Model):
# 
# Path: signup/emails.py
# def send_welcome_emails(emails):
# 
# Path: mailgun/api.py
# def call_mailgun(method, api_sub_url, data, params=None):
# def send_email(to_email, from_email, subject, text_body, html_body=None, tags=None, campaign_id=None):
# def send_mass_email(to_emails, from_email, subject, text_body, html_body=None, tags=None, campaign_id=None, recipient_variables=None):
# def create_campaign(campaign_id, campaign_name):
# def create_list(address, name=None, description=None, access_level=None):
# def update_list(address, name=None, description=None, access_level=None):
# def add_list_member(list_address, member_address):
# def remove_list_member(list_address, member_address):
# def get_list(list_address):
# def get_list_members(list_address):
# def get_unsubscribes(address):
# def delete_all_unsubscribes(address):
# def get_list_stats(list_address):
# def get_logs(limit=100, skip=0):
# def fetch_all_logs():
# def get_events(limit, **kwargs):
# def get_all_events(**kwargs):
# def get_campaign_events(campaign_id, event, recipient=None, limit=None, page=None, count=None):
# def _get_campaign_action(campaign_id, action, group_by, limit=None, page=None, count=None):
# def get_campaign_opens(campaign_id, group_by, limit=None, page=None, count=None):
# def get_campaign_clicks(campaign_id, group_by, limit=None, page=None, count=None):
# 
# Path: sequence/models.py
# def sequence_list_name( sequence_number ):
# def sequence_campaign( sequence_number ):
# def sequence2dict( sequence_db ):
# def create_sequence( start_date, signup_close_date ):
# def get_all_sequences( ):
# def get_current_sequence( ):
# def get_current_sequence_number( ):


# Path: signup/models.py
import random
import string
import json
from datetime import datetime
from signup import db
from signup import emails
from mailgun import api as mailgun_api
from sequence import models as sequence_model

    }
    return signup


def get_signup( email, sequence ):
    if not db.UserSignup.objects.filter(email__iexact=email, sequence=sequence, date_deleted__isnull=True).exists():
        raise Exception(u'Signup for {0} not found'.format(email))

    signup_db = db.UserSignup.objects.get(email__iexact=email, sequence=sequence, date_deleted__isnull=True)
    
    return _signup2json(signup_db)


def get_all_user_signups( email ):
    signups = db.UserSignup.objects.filter(email__iexact=email, date_deleted__isnull=True)
    return [ _signup2json(su) for su in signups ]


def get_signup_by_invite_code( invite_code ):
    user_set = db.UserSignup.objects.filter(
        invite_code=invite_code,
        date_deleted__isnull=True
    )
    if not user_set.exists():
        raise Exception()

    return _signup2json(user_set[0])


def get_signups( sequence ):

    signups = db.UserSignup.objects.filter(date_deleted__isnull=True)