예제 #1
0
def create_request(agency_name):
    """
    returns unsaved!
    """

    language, ntn, govt = get_defaults()
    govt = get_or_create_us_govt(agency_name, 'city')
    agency, created = Agency.objects.get_or_create(name=agency_name,
                                                   government=govt)
    contact = Contact.objects.get_or_create(first_name='FOIA Officer',
                                            last_name=agency_name)
    # if a query returns, get contact out of response tuple
    if type(contact) == tuple:
        contact = contact[0]
    agency.save()

    request = Request.objects.create(author_id=me.id,
                                     government_id=govt.id,
                                     agency_id=agency.id,
                                     text=req.text,
                                     free_edit_body=req.free_edit_body,
                                     title=req.title)

    contact.agency_related_contacts.add(agency)
    request.contacts.add(contact)

    return request
예제 #2
0
def create_mdrange_contacts():
    language, ntn, govt = get_defaults()
    govt = get_or_create_us_govt('California', 'state')
    agency, created = Agency.objects.get_or_create(name="California Department of Public Health", government=govt)
    contact, created = Contact.objects.get_or_create(first_name='default', middle_name='', last_name='contact')
    contact.save()
    contact.add_email('*****@*****.**')
    agency.contacts.add(contact)
    contact, created = Contact.objects.get_or_create(first_name='Ken', middle_name='', last_name='August')
    contact.save()
    contact.add_email('*****@*****.**')
    agency.contacts.add(contact)
예제 #3
0
def update_california_contacts(local=True):
    wb = xlrd.open_workbook(filename=os.path.join(settings.SITE_ROOT, 'apps/contacts/data/ca-state-contacts.xlsx'))
    sheet_names = [u'FOIA Contacts',]
    language, ntn, govt = get_defaults()
    govt = get_or_create_us_govt('California', 'state')

    for sn in sheet_names:
        sh = wb.sheet_by_name(sn)
        num_rows = sh.nrows - 1
        row = 0#header
        while row < num_rows:
            row += 1
            create_ca_contact(sh, row, govt)
예제 #4
0
def new_request(agency_name,req_id=1):
    from apps.government.utils import get_defaults, get_or_create_us_govt
    req = Request.objects.get(id=req_id)    
    me = User.objects.get(username='******')
    govt = get_or_create_us_govt(agency_name,'city')
    agency, created = Agency.objects.get_or_create(name=agency_name,government=govt)
    contact, created = Contact.objects.get_or_create(first_name='FOIA Officer', last_name=agency_name)
    request = Request.objects.create(
                            author_id= me.id, 
                            government_id = govt.id, 
                            agency_id = agency.id, 
                            text = req.text, 
                            free_edit_body = req.free_edit_body, 
                            title = req.title
              )   
    contact.agency_related_contacts.add(agency)
    request.contacts.add(contact)
    request.save()
예제 #5
0
def create_msmith_contacts():
    language, ntn, govt = get_defaults()
    govt = get_or_create_us_govt('The City and County of San Francisco', 'city')
    agency, created = Agency.objects.get_or_create(name="Mayor's Office on Economic and Work Development", government=govt)
    contact, created = Contact.objects.get_or_create(first_name='Myisha', middle_name='', last_name='Hervey')
    contact.save()
    contact.add_email('*****@*****.**')
    contact.add_phone('415.554.6969')
    agency.contacts.add(contact)

    agency, created = Agency.objects.get_or_create(name="Office of Community Investment and Infrastructure", government=govt)
    contact, created = Contact.objects.get_or_create(first_name='Natasha', middle_name='', last_name='Jones')
    contact.save()
    contact.add_email('*****@*****.**')
    contact.add_phone('415.749.2458')
    contact.add_phone('fax:415.749.2525')
    agency.contacts.add(contact)

    agency, created = Agency.objects.get_or_create(name="CEQA and Central Records Public Records Requests", government=govt)
    contact, created = Contact.objects.get_or_create(first_name='Stanley', middle_name='', last_name='Muraoka')
    contact.save()
    contact.add_email('*****@*****.**')
    contact.add_phone('415-749-2577')
    agency.contacts.add(contact)

    agency, created = Agency.objects.get_or_create(name="CEQA and Central Records Public Records Requests", government=govt)
    contact, created = Contact.objects.get_or_create(first_name='Stanley', middle_name='', last_name='Muraoka')
    contact.save()
    contact.add_email('*****@*****.**')
    contact.add_phone('415-749-2577')
    agency.contacts.add(contact)

    agency, created = Agency.objects.get_or_create(name="Mayor's Sunshine/FOIA Office", government=govt)
    contact, created = Contact.objects.get_or_create(first_name='NA', middle_name='', last_name='NA')
    contact.save()
    contact.add_email('*****@*****.**')
    agency.contacts.add(contact)
예제 #6
0
    def handle(self, *args, **options):
        letter_responses = {}
        if len(args) < 1:
            print "Please provide ID of Google Spreadsheet"
            return -1
        idd = args[0]
        resp = requests.get("https://docs.google.com/spreadsheets/d/%s/pub?output=csv" % idd)
        reader = list(csv.reader(resp.content.split('\n'), delimiter=','))
        header = reader[0]
        for row in reader[1:-1]:
            #get user, contact and agency
            user = User.objects.get(username=row[header.index('username')])
            user_profile = UserProfile.objects.get(user=user)
            govt = get_or_create_us_govt(row[header.index("state")], 'state')
            agency, acreated = Agency.objects.get_or_create(name=row[header.index("agency")], government=govt)
            contact, ccreated = agency.contacts.get_or_create(
                first_name=row[header.index("contact.first.name")], 
                middle_name=row[header.index("contact.middle.name")], 
                last_name=row[header.index("contact.last.name")])
            if row[header.index("contact.email")] != "":
                contact.add_email(row[header.index("contact.email")])
            if row[header.index("contact.phone")] != "":
                contact.add_phone(row[header.index("contact.phone")])

            #set up group and tags
            group, created = Group.objects.get_or_create(name=row[header.index("group")])
            assign_perm(UserProfile.get_permission_name('edit'), user, group)
            assign_perm(UserProfile.get_permission_name('view'), user, group)
            user.groups.add(group)
            user_profile.tags.add(row[header.index("tag")])

            #assemble law text
            law_texts = []
            for l in govt.statutes.all():
                law_texts.append('%s' % (l.short_title,))
            law_text = ' and '.join(law_texts)

            #get the letter template
            letter_url = row[header.index("letter.url")]
            letter_template = ''
            if letter_url in letter_responses.keys():
                letter_template = letter_responses[letter_url]
            else:
                letter_resp = requests.get(letter_url)
                letter_template = letter_resp.content
                letter_responses[letter_url] = letter_template

            #render the template
            context = Context({ 
                'contact': contact, 
                'user_profile': user_profile,
                'user': user,
                'law_text': law_text
            })
            template = Template(letter_template)
            letter = template.render(context)

            #create the request
            fields_to_use = {
                'author': user,
                'title': row[header.index("request.title")],
                'free_edit_body': letter,
                'private': True if row[header.index("request.private")] == "TRUE" else False,
                'text': letter#silly distinction leftover from old days but fill it in
            }
            #delete all requests that look like the one i'm about to make so we don't have duplicates floating around
            Request.objects.filter(author=user, title=row[header.index("request.title")]).delete()
            #create the request
            therequest = Request(**fields_to_use)
            therequest.date_added = datetime.now()
            therequest.save()
            therequest.contacts = [contact]
            therequest.government = govt
            therequest.agency = agency
            therequest.tags.add(row[header.index("tag")])
            therequest.save()
            #assing permissions to the request
            assign_perm(Request.get_permission_name('view'), group, therequest)
            assign_perm(Request.get_permission_name('edit'), group, therequest)

            if row[header.index("request.send")] == "TRUE":
                therequest.send()
                print "SENT request %s" % row[header.index("request.title")]
            else:
                print "STAGED request %s" % row[header.index("request.title")]
예제 #7
0
# IPython log file

import csv
from apps.government.utils import get_defaults, get_or_create_us_govt
from apps.agency.models import Agency
from apps.contacts.models import Contact
from apps.contacts.models import EmailAddress
from apps.users.models import User
from apps.requests.models import Request
from django.conf import settings
me = User.objects.get(username='******')
language, ntn, govt = get_defaults()
govt = get_or_create_us_govt('All Elementary/High School Employees', 'city')
agency, created = Agency.objects.get_or_create(
    name='All Elementary/High School Employees', government=govt)
contact, created = Contact.objects.get_or_create(first_name='FOIA',
                                                 middle_name='',
                                                 last_name='Officer')
contact.add_email('NA')
agency.contacts.add(contact)
agency.creator_id = me.id
contact.save()
agency.save()

req = Request.objects.get(id=1)
request = Request.objects.create(author_id=me.id,
                                 government_id=govt.id,
                                 agency_id=agency.id,
                                 text=req.text,
                                 free_edit_body=req.free_edit_body,
                                 title=req.title)
예제 #8
0
    def handle(self, *args, **options):


        users = [
            User.objects.get(username='******'),
            #User.objects.get(username='******'),
            #User.objects.get(username='******'),
            #User.objects.get(username='******')
        ]
        up = UserProfile.objects.get(user=users[0])
        up.tags.add(ncaa_tag_name)
        up.tags.add(coach_tag_name)
        for user in users:
            assign_perm(UserProfile.get_permission_name('edit'), user, ncaa_group)
            assign_perm(UserProfile.get_permission_name('view'), user, ncaa_group)
            assign_perm(UserProfile.get_permission_name('edit'), user, coach_group)
            assign_perm(UserProfile.get_permission_name('view'), user, coach_group)

        #Request.objects.all().delete()
        ncaa_text_to_use = """
        Pursuant to the %s, I am requesting the following documents:<br/><br/>\
        The equity/revenue-and-expenses report completed by the athletic department for the \
        National Collegiate Athletic Association for the 2014 fiscal year. This report is a \
        multi-page document that had to be submitted to the NCAA by Jan. 15, 2015. \
        It contains 38 revenue and expense categories, followed by specific breakdowns of \
        each of those categories, by sport and gender. I am requesting the full report, \
        including the detail tables and the Statement of Revenues and Expenses that appear at the end of the report. <br/><br/>\
        PLEASE NOTE: The NCAA report is different than the equity report that is sent to the\
        U.S. Department of Education for Title IX compliance. <br/><br/>\
        %s
        """

        coach_text_to_use = """
        Pursuant to %s, I am requesting the following documents:<br/><br/>\
        The current contracts for %s. If a contract is under negotiation, \
        please forward the current contract but let me know that a new contract may be forthcoming. \
        If there is no contact for one or both, please forward the letter(s) of intent or other \
        document(s) outlining each employee's conditions of employment \
        -- including bonus structure -- and/or a current statement of salary. <br/><br/>\
        %s
        """

        fname = settings.SITE_ROOT + "/apps/requests/data/NCAA-pio.csv"
        #with codecs.open(fname, 'w', encoding="utf-8") as f:
        #    resp = requests.get("https://docs.google.com/spreadsheets/d/1kccaiCCYIHOTEvpUWQiKs51v6K2TNRX7-NN6l1WtzyM/pub?output=csv")
        #    f.write(resp.text)

        reader = list(UnicodeReader(open(fname, 'rb')))
        #create contacts
        header = reader[0]
        for idx, row in enumerate(reader[1:]):
            user = users[0]
            up = UserProfile.objects.get(user=user)

            state = row[header.index('STATE')]
            agency_name = row[header.index("UNIVERSITY")]
            pio = row[header.index("PIO OFFICER")]
            email = row[header.index("PIO Email")]
            phone = row[header.index("PIO Phone")]

            sid_pio = row[header.index("SID ")]
            sid_email = row[header.index("SID Email")]
            sid_phone = row[header.index("SID Phone")]

            is_power = (row[header.index("Power Conference")] == 'TRUE')
            is_private = (row[header.index("Is Private")] == 'TRUE')

            if not is_private and state != '' and email != 'N/A' and pio != 'N/A' and agency_name != '':
                govt = get_or_create_us_govt(state, 'state')
                fname = pio.split(" ")[0]
                lname = pio.split(" ")[-1]
                middle = ''
                #alter table `contacts_contact` convert to character set utf8 collate utf8_general_ci;
                #alter table `agency_agency` convert to character set utf8 collate utf8_general_ci;
                #alter table `requests_request` convert to character set utf8 collate utf8_general_ci;
                try:
                    agency, acreated = Agency.objects.get_or_create(name=agency_name, government=govt)
                except Exception as e:
                    print e
                    print "If more than one agency was returned, pick one!"
                    import pdb;pdb.set_trace() 
                try:
                    contact, ccreated = agency.contacts.get_or_create(first_name=fname, middle_name=middle, last_name=lname)
                except Exception as e:
                    print e
                    print "If more than one contact was returned, pick one!"
                    import pdb;pdb.set_trace()

                sid_contact = None

                if phone != 'N/A':
                    contact.add_phone(phone)
                contact.add_email(email)

                #agency.contacts.add(contact)

                if sid_pio != 'N/A' and sid_email != 'N/A':
                    fname = sid_pio.split(" ")[0]
                    lname = sid_pio.split(" ")[-1]
                    sid_contact, ccreated = Contact.objects.get_or_create(first_name=fname, middle_name='', last_name=lname)
                    sid_contact.add_title("SID")
                    sid_contact.add_email(sid_email)
                    if sid_phone != 'N/A':
                        sid_contact.add_phone(sid_phone)
                    agency.contacts.add(sid_contact)

                contacts = [contact]
                if sid_contact is not None:
                    contacts = [contact, sid_contact]

                agency.save()

                #logger.info('agency %s %s contact %s %s %s %s' % (agency_name, acreated, fname, middle, lname, ccreated))

                law_texts = []
                for l in govt.statutes.all():
                    law_texts.append('%s' % (l.short_title,))

                misc_graf = """
                    Please advise me in advance of the estimated charges associated with fulfilling \
                    this request.</br></br>In the interest of expediency, and to minimize the research\
                    and/or duplication burden on your staff, please send records electronically if possible.\
                    If this is not possible, please notify me by phone at %s before sending to the address listed below.
                """ % (up.phone)
                misc_graf += '<br/></br>Sincerly,<br/><br/>%s<br/>%s<br/>%s<br/>%s' % (user.first_name + ' ' + user.last_name, up.mailing_address, up.mailing_city + ', ' + up.mailing_state + ' ' + up.mailing_zip, up.phone)

                if not is_power:
                    fields_to_use = {
                        'author': user,
                        'title': 'NCAA Report - %s' % agency_name,
                        'free_edit_body': ncaa_text_to_use % (' and '.join(law_texts), misc_graf),
                        'private': True,
                        'text': ncaa_text_to_use
                    }
                    therequest = Request(**fields_to_use)
                    therequest.date_added = datetime.now()
                    therequest.save()
                    therequest.contacts = contacts
                    therequest.government = govt
                    therequest.agency = agency
                    therequest.tags.add(ncaa_tag_name)
                    therequest.save()

                    assign_perm(Request.get_permission_name('view'), ncaa_group, therequest)
                    #assign_perm(Request.get_permission_name('edit'), thegroup, therequest)

                coaches = [
                    'Football Coach',
                    'Offensive Coord.',
                    'Defensive Coord.',
                    "Men's BB Coach",
                    "Women's BB Coach"
                ]

                coaches_str = []
                for coach in coaches:
                    val = row[header.index(coach)].strip()
                    if val != 'N/A' and val != '':
                        coaches_str.append("%s (%s)" % (val, coach))
                        print val

                fields_to_use = {
                    'author': user,
                    'title': 'Coach Contracts - %s' % agency_name,
                    'free_edit_body': coach_text_to_use % (' and '.join(law_texts), ', '.join(coaches_str), misc_graf),
                    'private': True,
                    'text': coach_text_to_use
                }
                therequest = Request(**fields_to_use)
                therequest.date_added = datetime.now()
                therequest.save()
                therequest.contacts = contacts
                therequest.government = govt
                therequest.agency = agency
                therequest.tags.add(coach_tag_name)
                therequest.save()

                assign_perm(Request.get_permission_name('view'), coach_group, therequest)
예제 #9
0
    print orow

# sender
me = User.objects.filter(username=sender_username)[0]

for icontact in icontacts:
    # don't spam ... need to map this to current request in future cases (tags?)
    if list(EmailAddress.objects.filter(
            content=icontact['email'])) and not test:
        # print 'contact exists:', icontact['email']
        pass  #continue

    try:
        language, ntn, govt = get_defaults()
        govt = get_or_create_us_govt(
            icontact['government'],
            'city')  # TODO fix dumb hardcoded gov type using string inferences
        agency, created = Agency.objects.get_or_create(
            name=icontact['government'], government=govt)
        # TODO: NEED TO USE EMAIL FOR GET OR CREATE
        contact, created = Contact.objects.get_or_create(
            first_name=icontact['first_name'],
            middle_name='',
            last_name=icontact['last_name'])
        contact.add_email(icontact['email'])
        agency.contacts.add(contact)
        agency.creator_id = me.id
        contact.save()
        agency.save()

        # create request for each contact
예제 #10
0
    def handle(self, *args, **options):

        users = [
            User.objects.get(username='******'),
            #User.objects.get(username='******'),
            #User.objects.get(username='******'),
            #User.objects.get(username='******')
        ]
        up = UserProfile.objects.get(user=users[0])
        up.tags.add(ncaa_tag_name)
        up.tags.add(coach_tag_name)
        for user in users:
            assign_perm(UserProfile.get_permission_name('edit'), user,
                        ncaa_group)
            assign_perm(UserProfile.get_permission_name('view'), user,
                        ncaa_group)
            assign_perm(UserProfile.get_permission_name('edit'), user,
                        coach_group)
            assign_perm(UserProfile.get_permission_name('view'), user,
                        coach_group)

        #Request.objects.all().delete()
        ncaa_text_to_use = """
        Pursuant to the %s, I am requesting the following documents:<br/><br/>\
        The equity/revenue-and-expenses report completed by the athletic department for the \
        National Collegiate Athletic Association for the 2014 fiscal year. This report is a \
        multi-page document that had to be submitted to the NCAA by Jan. 15, 2015. \
        It contains 38 revenue and expense categories, followed by specific breakdowns of \
        each of those categories, by sport and gender. I am requesting the full report, \
        including the detail tables and the Statement of Revenues and Expenses that appear at the end of the report. <br/><br/>\
        PLEASE NOTE: The NCAA report is different than the equity report that is sent to the\
        U.S. Department of Education for Title IX compliance. <br/><br/>\
        %s
        """

        coach_text_to_use = """
        Pursuant to %s, I am requesting the following documents:<br/><br/>\
        The current contracts for %s. If a contract is under negotiation, \
        please forward the current contract but let me know that a new contract may be forthcoming. \
        If there is no contact for one or both, please forward the letter(s) of intent or other \
        document(s) outlining each employee's conditions of employment \
        -- including bonus structure -- and/or a current statement of salary. <br/><br/>\
        %s
        """

        fname = settings.SITE_ROOT + "/apps/requests/data/NCAA-pio.csv"
        #with codecs.open(fname, 'w', encoding="utf-8") as f:
        #    resp = requests.get("https://docs.google.com/spreadsheets/d/1kccaiCCYIHOTEvpUWQiKs51v6K2TNRX7-NN6l1WtzyM/pub?output=csv")
        #    f.write(resp.text)

        reader = list(UnicodeReader(open(fname, 'rb')))
        #create contacts
        header = reader[0]
        for idx, row in enumerate(reader[1:]):
            user = users[0]
            up = UserProfile.objects.get(user=user)

            state = row[header.index('STATE')]
            agency_name = row[header.index("UNIVERSITY")]
            pio = row[header.index("PIO OFFICER")]
            email = row[header.index("PIO Email")]
            phone = row[header.index("PIO Phone")]

            sid_pio = row[header.index("SID ")]
            sid_email = row[header.index("SID Email")]
            sid_phone = row[header.index("SID Phone")]

            is_power = (row[header.index("Power Conference")] == 'TRUE')
            is_private = (row[header.index("Is Private")] == 'TRUE')

            if not is_private and state != '' and email != 'N/A' and pio != 'N/A' and agency_name != '':
                govt = get_or_create_us_govt(state, 'state')
                fname = pio.split(" ")[0]
                lname = pio.split(" ")[-1]
                middle = ''
                #alter table `contacts_contact` convert to character set utf8 collate utf8_general_ci;
                #alter table `agency_agency` convert to character set utf8 collate utf8_general_ci;
                #alter table `requests_request` convert to character set utf8 collate utf8_general_ci;
                try:
                    agency, acreated = Agency.objects.get_or_create(
                        name=agency_name, government=govt)
                except Exception as e:
                    print e
                    print "If more than one agency was returned, pick one!"
                    import pdb
                    pdb.set_trace()
                try:
                    contact, ccreated = agency.contacts.get_or_create(
                        first_name=fname, middle_name=middle, last_name=lname)
                except Exception as e:
                    print e
                    print "If more than one contact was returned, pick one!"
                    import pdb
                    pdb.set_trace()

                sid_contact = None

                if phone != 'N/A':
                    contact.add_phone(phone)
                contact.add_email(email)

                #agency.contacts.add(contact)

                if sid_pio != 'N/A' and sid_email != 'N/A':
                    fname = sid_pio.split(" ")[0]
                    lname = sid_pio.split(" ")[-1]
                    sid_contact, ccreated = Contact.objects.get_or_create(
                        first_name=fname, middle_name='', last_name=lname)
                    sid_contact.add_title("SID")
                    sid_contact.add_email(sid_email)
                    if sid_phone != 'N/A':
                        sid_contact.add_phone(sid_phone)
                    agency.contacts.add(sid_contact)

                contacts = [contact]
                if sid_contact is not None:
                    contacts = [contact, sid_contact]

                agency.save()

                #logger.info('agency %s %s contact %s %s %s %s' % (agency_name, acreated, fname, middle, lname, ccreated))

                law_texts = []
                for l in govt.statutes.all():
                    law_texts.append('%s' % (l.short_title, ))

                misc_graf = """
                    Please advise me in advance of the estimated charges associated with fulfilling \
                    this request.</br></br>In the interest of expediency, and to minimize the research\
                    and/or duplication burden on your staff, please send records electronically if possible.\
                    If this is not possible, please notify me by phone at %s before sending to the address listed below.
                """ % (up.phone)
                misc_graf += '<br/></br>Sincerly,<br/><br/>%s<br/>%s<br/>%s<br/>%s' % (
                    user.first_name + ' ' + user.last_name, up.mailing_address,
                    up.mailing_city + ', ' + up.mailing_state + ' ' +
                    up.mailing_zip, up.phone)

                if not is_power:
                    fields_to_use = {
                        'author':
                        user,
                        'title':
                        'NCAA Report - %s' % agency_name,
                        'free_edit_body':
                        ncaa_text_to_use %
                        (' and '.join(law_texts), misc_graf),
                        'private':
                        True,
                        'text':
                        ncaa_text_to_use
                    }
                    therequest = Request(**fields_to_use)
                    therequest.date_added = datetime.now()
                    therequest.save()
                    therequest.contacts = contacts
                    therequest.government = govt
                    therequest.agency = agency
                    therequest.tags.add(ncaa_tag_name)
                    therequest.save()

                    assign_perm(Request.get_permission_name('view'),
                                ncaa_group, therequest)
                    #assign_perm(Request.get_permission_name('edit'), thegroup, therequest)

                coaches = [
                    'Football Coach', 'Offensive Coord.', 'Defensive Coord.',
                    "Men's BB Coach", "Women's BB Coach"
                ]

                coaches_str = []
                for coach in coaches:
                    val = row[header.index(coach)].strip()
                    if val != 'N/A' and val != '':
                        coaches_str.append("%s (%s)" % (val, coach))
                        print val

                fields_to_use = {
                    'author':
                    user,
                    'title':
                    'Coach Contracts - %s' % agency_name,
                    'free_edit_body':
                    coach_text_to_use % (' and '.join(law_texts),
                                         ', '.join(coaches_str), misc_graf),
                    'private':
                    True,
                    'text':
                    coach_text_to_use
                }
                therequest = Request(**fields_to_use)
                therequest.date_added = datetime.now()
                therequest.save()
                therequest.contacts = contacts
                therequest.government = govt
                therequest.agency = agency
                therequest.tags.add(coach_tag_name)
                therequest.save()

                assign_perm(Request.get_permission_name('view'), coach_group,
                            therequest)
예제 #11
0
    def handle(self, *args, **options):
        letter_responses = {}
        if len(args) < 1:
            print "Please provide ID of Google Spreadsheet"
            return -1
        idd = args[0]
        resp = requests.get(
            "https://docs.google.com/spreadsheets/d/%s/pub?output=csv" % idd)
        reader = list(csv.reader(resp.content.split('\n'), delimiter=','))
        header = reader[0]
        for row in reader[1:-1]:
            #get user, contact and agency
            user = User.objects.get(username=row[header.index('username')])
            user_profile = UserProfile.objects.get(user=user)
            govt = get_or_create_us_govt(row[header.index("state")], 'state')
            agency, acreated = Agency.objects.get_or_create(
                name=row[header.index("agency")], government=govt)
            contact, ccreated = agency.contacts.get_or_create(
                first_name=row[header.index("contact.first.name")],
                middle_name=row[header.index("contact.middle.name")],
                last_name=row[header.index("contact.last.name")])
            if row[header.index("contact.email")] != "":
                contact.add_email(row[header.index("contact.email")])
            if row[header.index("contact.phone")] != "":
                contact.add_phone(row[header.index("contact.phone")])

            #set up group and tags
            group, created = Group.objects.get_or_create(
                name=row[header.index("group")])
            assign_perm(UserProfile.get_permission_name('edit'), user, group)
            assign_perm(UserProfile.get_permission_name('view'), user, group)
            user.groups.add(group)
            user_profile.tags.add(row[header.index("tag")])

            #assemble law text
            law_texts = []
            for l in govt.statutes.all():
                law_texts.append('%s' % (l.short_title, ))
            law_text = ' and '.join(law_texts)

            #get the letter template
            letter_url = row[header.index("letter.url")]
            letter_template = ''
            if letter_url in letter_responses.keys():
                letter_template = letter_responses[letter_url]
            else:
                letter_resp = requests.get(letter_url)
                letter_template = letter_resp.content
                letter_responses[letter_url] = letter_template

            #render the template
            context = Context({
                'contact': contact,
                'user_profile': user_profile,
                'user': user,
                'law_text': law_text
            })
            template = Template(letter_template)
            letter = template.render(context)

            #create the request
            fields_to_use = {
                'author':
                user,
                'title':
                row[header.index("request.title")],
                'free_edit_body':
                letter,
                'private':
                True
                if row[header.index("request.private")] == "TRUE" else False,
                'text':
                letter  #silly distinction leftover from old days but fill it in
            }
            #delete all requests that look like the one i'm about to make so we don't have duplicates floating around
            Request.objects.filter(
                author=user,
                title=row[header.index("request.title")]).delete()
            #create the request
            therequest = Request(**fields_to_use)
            therequest.date_added = datetime.now()
            therequest.save()
            therequest.contacts = [contact]
            therequest.government = govt
            therequest.agency = agency
            therequest.tags.add(row[header.index("tag")])
            therequest.save()
            #assing permissions to the request
            assign_perm(Request.get_permission_name('view'), group, therequest)
            assign_perm(Request.get_permission_name('edit'), group, therequest)

            if row[header.index("request.send")] == "TRUE":
                therequest.send()
                print "SENT request %s" % row[header.index("request.title")]
            else:
                print "STAGED request %s" % row[header.index("request.title")]