# Path: emailcongress/models.py
# class EmailCongressManager(models.Manager):
# class TokenManager(EmailCongressManager):
# class EmailCongressModel(models.Model):
#     class Meta:
# class Token(EmailCongressModel):
#     class Meta:
# class HasTokenMixin(object):
# class Legislator(EmailCongressModel):
# class User(EmailCongressModel, HasTokenMixin):
# class UserMessageInfo(EmailCongressModel):
# class Message(EmailCongressModel, HasTokenMixin):
# class MessageLegislator(EmailCongressModel):
#     def get_or_instantiate(self, **kwargs):
#     def select_related(self, *fields):
#     def serialize(self, to_format):
#     def __str__(self):
#     def user(self):
#     def save(self, *args, **kwargs):
#     def reset(self, key=None):
#     def link(self):
#     def uid_creator(cls):
#     def convert_token(cls, key):
#     def delete_content_object(sender, instance, **kwargs):
#     def verification_link(self):
#     def token_key(self):
#     def create_token_trigger(sender, instance, created, *args, **kwargs):
#     def delete_related_token(sender, instance, **kwargs):
#     def __str__(self):
#     def full_title(self):
#     def full_name(self):
#     def title_and_last_name(self):
#     def title_and_full_name(self):
#     def full_title_and_full_name(self):
#     def image_url(self, size='small'):
#     def create_email_address(self):
#     def humanized_district(state, district):
#     def humanized_constituency(self):
#     def humanized_state(state):
#     def get_district_geojson_url(state, district):
#     def doctor_email(email):
#     def find_by_email(recip_email):
#     def get_leg_buckets_from_emails(permitted_legs, emails):
#     def members_for_state_and_district(state, district, contactable=True):
#     def __str__(self):
#     def default_info(self):
#     def members_of_congress(self):
#     def email(self):
#     def address_change_link(self):
#     def messages(self, **filters):
#     def last_message(self):
#     def new_address_change_link(self):
#     def get_rate_limit_status(self, force_allow=False):
#     def delete_django_user(sender, instance, **kwargs):
#     def get_or_create_user_from_email(email):
#     def __str__(self):
#     def members_of_congress(self):
#     def humanized_district(self):
#     def humanized_district_no_state(self):
#     def humanized_state(self):
#     def confirm_accept_tos(self):
#     def mailing_address(self):
#     def must_update_address_info(self):
#     def complete_information(self):
#     def geolocate_address(self, force=False, save=False):
#     def determine_district(self, force=False, save=False):
#     def zip4_lookup(self, force=False):
#     def get_district_geojson_url(self):
#     def clone_instance_for_address_update(self):
#     def __str__(self):
#     def to_legislators(self):
#     def has_legislators(self):
#     def legislators(self):
#     def get_legislators(self, as_dict=False):
#     def generate_message_legislators(self, legislators):
#     def set_legislators(self, legislators):
#     def add_legislators(self, legislators):
#     def is_free_to_send(self):
#     def update_status(self):
#     def free_status(self):
#     def block_status(self):
#     def get_send_status(self):
#     def queue_to_send(self, moc=None):
#     def send(self, fresh=False):
#     def map_to_contact_congress_fields(self):
#     def __str__(self):
#     def is_sent(self):
#     def send(self):
#     def map_to_contact_congress(self, campaign_tag=False):
#     FIPS_CODES = {
#         "AK": "02", "AL": "01", "AR": "05", "AS": "60", "AZ": "04", "CA": "06", "CO": "08", "CT": "09", "DC": "11",
#         "DE": "10", "FL": "12", "GA": "13", "GU": "66", "HI": "15", "IA": "19", "ID": "16", "IL": "17", "IN": "18",
#         "KS": "20", "KY": "21", "LA": "22", "MA": "25", "MD": "24", "ME": "23", "MI": "26", "MN": "27", "MO": "29",
#         "MS": "28", "MT": "30", "NC": "37", "ND": "38", "NE": "31", "NH": "33", "NJ": "34", "NM": "35", "NV": "32",
#         "NY": "36", "OH": "39", "OK": "40", "OR": "41", "PA": "42", "PR": "72", "RI": "44", "SC": "45", "SD": "46",
#         "TN": "47", "TX": "48", "UT": "49", "VA": "51", "VI": "78", "VT": "50", "WA": "53", "WI": "55", "WV": "54",
#         "WY": "56"
#     }
#     CONGRESS_API_COLUMNS = ['bioguide_id', 'chamber', 'state', 'district', 'title',
#                             'first_name', 'last_name', 'contact_form']
#     PREFIX_CHOICES = (
#         ('Mr.', 'Mr.'),
#         ('Mrs.', 'Mrs.'),
#         ('Ms.', "Ms.")
#     )


import os
import json
import traceback
from datetime import datetime
from django.utils import timezone
from django.core.management.base import BaseCommand, CommandError
from django.conf import settings
from django.contrib.contenttypes.models import ContentType
from django.db.models import signals
from emailcongress import models




class Command(BaseCommand):

    def add_arguments(self, parser):
        parser.add_argument('datafile', type=str)

    def handle(self, **options):
        try:
            user_dict = {}
            umi_dict = {}
            msg_dict = {}
            msgleg_dict = {}
            data = json.load(open(os.path.join(settings.BASE_DIR, options.get('datafile')), 'r'))

            # we don't want to create tokens automatically on save because we're adding them at end

# Path: emailcongress/models.py
# class EmailCongressManager(models.Manager):
# class TokenManager(EmailCongressManager):
# class EmailCongressModel(models.Model):
#     class Meta:
# class Token(EmailCongressModel):
#     class Meta:
# class HasTokenMixin(object):
# class Legislator(EmailCongressModel):
# class User(EmailCongressModel, HasTokenMixin):
# class UserMessageInfo(EmailCongressModel):
# class Message(EmailCongressModel, HasTokenMixin):
# class MessageLegislator(EmailCongressModel):
#     def get_or_instantiate(self, **kwargs):
#     def select_related(self, *fields):
#     def serialize(self, to_format):
#     def __str__(self):
#     def user(self):
#     def save(self, *args, **kwargs):
#     def reset(self, key=None):
#     def link(self):
#     def uid_creator(cls):
#     def convert_token(cls, key):
#     def delete_content_object(sender, instance, **kwargs):
#     def verification_link(self):
#     def token_key(self):
#     def create_token_trigger(sender, instance, created, *args, **kwargs):
#     def delete_related_token(sender, instance, **kwargs):
#     def __str__(self):
#     def full_title(self):
#     def full_name(self):
#     def title_and_last_name(self):
#     def title_and_full_name(self):
#     def full_title_and_full_name(self):
#     def image_url(self, size='small'):
#     def create_email_address(self):
#     def humanized_district(state, district):
#     def humanized_constituency(self):
#     def humanized_state(state):
#     def get_district_geojson_url(state, district):
#     def doctor_email(email):
#     def find_by_email(recip_email):
#     def get_leg_buckets_from_emails(permitted_legs, emails):
#     def members_for_state_and_district(state, district, contactable=True):
#     def __str__(self):
#     def default_info(self):
#     def members_of_congress(self):
#     def email(self):
#     def address_change_link(self):
#     def messages(self, **filters):
#     def last_message(self):
#     def new_address_change_link(self):
#     def get_rate_limit_status(self, force_allow=False):
#     def delete_django_user(sender, instance, **kwargs):
#     def get_or_create_user_from_email(email):
#     def __str__(self):
#     def members_of_congress(self):
#     def humanized_district(self):
#     def humanized_district_no_state(self):
#     def humanized_state(self):
#     def confirm_accept_tos(self):
#     def mailing_address(self):
#     def must_update_address_info(self):
#     def complete_information(self):
#     def geolocate_address(self, force=False, save=False):
#     def determine_district(self, force=False, save=False):
#     def zip4_lookup(self, force=False):
#     def get_district_geojson_url(self):
#     def clone_instance_for_address_update(self):
#     def __str__(self):
#     def to_legislators(self):
#     def has_legislators(self):
#     def legislators(self):
#     def get_legislators(self, as_dict=False):
#     def generate_message_legislators(self, legislators):
#     def set_legislators(self, legislators):
#     def add_legislators(self, legislators):
#     def is_free_to_send(self):
#     def update_status(self):
#     def free_status(self):
#     def block_status(self):
#     def get_send_status(self):
#     def queue_to_send(self, moc=None):
#     def send(self, fresh=False):
#     def map_to_contact_congress_fields(self):
#     def __str__(self):
#     def is_sent(self):
#     def send(self):
#     def map_to_contact_congress(self, campaign_tag=False):
#     FIPS_CODES = {
#         "AK": "02", "AL": "01", "AR": "05", "AS": "60", "AZ": "04", "CA": "06", "CO": "08", "CT": "09", "DC": "11",
#         "DE": "10", "FL": "12", "GA": "13", "GU": "66", "HI": "15", "IA": "19", "ID": "16", "IL": "17", "IN": "18",
#         "KS": "20", "KY": "21", "LA": "22", "MA": "25", "MD": "24", "ME": "23", "MI": "26", "MN": "27", "MO": "29",
#         "MS": "28", "MT": "30", "NC": "37", "ND": "38", "NE": "31", "NH": "33", "NJ": "34", "NM": "35", "NV": "32",
#         "NY": "36", "OH": "39", "OK": "40", "OR": "41", "PA": "42", "PR": "72", "RI": "44", "SC": "45", "SD": "46",
#         "TN": "47", "TX": "48", "UT": "49", "VA": "51", "VI": "78", "VT": "50", "WA": "53", "WI": "55", "WV": "54",
#         "WY": "56"
#     }
#     CONGRESS_API_COLUMNS = ['bioguide_id', 'chamber', 'state', 'district', 'title',
#                             'first_name', 'last_name', 'contact_form']
#     PREFIX_CHOICES = (
#         ('Mr.', 'Mr.'),
#         ('Mrs.', 'Mrs.'),
#         ('Ms.', "Ms.")
#     )


# Path: emailcongress/management/commands/load_phantom_mask_data.py
import os
import json
import traceback
from datetime import datetime
from django.utils import timezone
from django.core.management.base import BaseCommand, CommandError
from django.conf import settings
from django.contrib.contenttypes.models import ContentType
from django.db.models import signals
from emailcongress import models





class Command(BaseCommand):

    def add_arguments(self, parser):
        parser.add_argument('datafile', type=str)

    def handle(self, **options):
        try:
            user_dict = {}
            umi_dict = {}
            msg_dict = {}
            msgleg_dict = {}
            data = json.load(open(os.path.join(settings.BASE_DIR, options.get('datafile')), 'r'))

            # we don't want to create tokens automatically on save because we're adding them at end

            signals.post_save.disconnect(models.User.create_token_trigger, sender=models.User)