# Path: cfda/models.py
# class Program(models.Model):
# 
#     def __unicode__(self):
#         return "%s %s" % (self.program_number, self.program_title)
# 
#     program_number = models.CharField("Program number", max_length=7)
#     program_title = models.CharField("Program title", max_length=255)
#     federal_agency = models.TextField("Federal agency", blank=True, default="")
#     agency = models.ForeignKey('Agency', blank=True, null=True)
#     authorization = models.TextField("Authorization",blank=True,default="")
#     objectives = models.TextField("Objectives",blank=True,default="")
#     types_of_assistance = models.ManyToManyField(AssistanceType)
#     uses_and_use_restrictions = models.TextField("Uses and use restrictions",blank=True,default="")
#     applicant_eligibility = models.TextField("Applicant eligibility",blank=True,default="")
#     beneficiary_eligibility = models.TextField("Beneficiary eligibility",blank=True,default="")
#     credentials_documentation = models.TextField("Credentials / documentation",blank=True,default="")
#     preapplication_coordination = models.TextField("Preapplication coordination",blank=True,default="")
#     application_procedure = models.TextField("Application procedure",blank=True,default="")
#     award_procedure = models.TextField("Award procedure",blank=True,default="")
#     deadlines = models.TextField("Deadlines",blank=True,default="")
#     range_of_approval_disapproval_time = models.TextField("Range of approval / disapproval time",blank=True,default="")
#     appeals = models.TextField("Appeals",blank=True,default="")
#     renewals = models.TextField("Renewals",blank=True,default="")
#     formula_and_matching_requirements = models.TextField("Formula and matching requirements",blank=True,default="")
#     length_and_time_phasing_of_assistance = models.TextField("Length and time phasing of assistance",blank=True,default="")
#     reports = models.TextField("Reports",blank=True,default="")
#     audits = models.TextField("Audits",blank=True,default="")
#     records = models.TextField("Records",blank=True,default="")
#     account_identification = models.ManyToManyField(ProgramAccount)
#     range_and_average_of_financial_assistance = models.TextField("Range and average of financial assistance",blank=True,default="")
#     program_accomplishments = models.TextField("Program accomplishments",blank=True,default="")
#     regulations_guidelines_and_literature = models.TextField("Regulations guidelines and literature",blank=True,default="")
#     regional_or_local_office = models.TextField("Regional or local office",blank=True,default="")
#     headquarters_office = models.TextField("Headquarters office",blank=True,default="")
#     web_site_address = models.TextField("Web site address",blank=True,default="")
#     related_programs = models.TextField("Related programs",blank=True,default="")
#     examples_of_funded_projects = models.TextField("Examples of funded projects",blank=True,default="")
#     criteria_for_selecting_proposals = models.TextField("Criteria for selecting proposals",blank=True,default="")
#     published_date = models.TextField("Published Date", blank=True, default="")
#     parent_shortname = models.TextField("Parent Shortname", blank=True, default="")
#     url = models.TextField("URL on CFDA website", blank=True, default="")
#     recovery = models.BooleanField(default=False)
# 
#     cfda_edition = models.IntegerField("CFDA Edition", blank=True, null=True)
#     load_date = models.DateTimeField("Load Date", auto_now=True)    
#     caveat = models.TextField("Caveats about the spending of this program", blank=True, null=True)


import datetime
from haystack import indexes
from haystack.sites import site
from cfda.models import Program



class ProgramIndex(indexes.SearchIndex):
    
    type = 'cfda'
    program_number = indexes.CharField(model_attr='program_number') 
    program_title = indexes.CharField(document=True, model_attr='program_title')
    
   
#    def prepare_text(self, object):
        
#       text = getattr(object, 'objectives')
#limit to just program title. Objectives produces a lot of noise
#        text = getattr(object, 'program_title')

 #       return text

    def prepare_program_title(self, object):
        return str(object.program_title.replace('_', ' ').encode('ascii', 'ignore'))
                 
    def get_queryset(self):
        "Used when the entire index for model is updated."
        

# Path: cfda/models.py
# class Program(models.Model):
# 
#     def __unicode__(self):
#         return "%s %s" % (self.program_number, self.program_title)
# 
#     program_number = models.CharField("Program number", max_length=7)
#     program_title = models.CharField("Program title", max_length=255)
#     federal_agency = models.TextField("Federal agency", blank=True, default="")
#     agency = models.ForeignKey('Agency', blank=True, null=True)
#     authorization = models.TextField("Authorization",blank=True,default="")
#     objectives = models.TextField("Objectives",blank=True,default="")
#     types_of_assistance = models.ManyToManyField(AssistanceType)
#     uses_and_use_restrictions = models.TextField("Uses and use restrictions",blank=True,default="")
#     applicant_eligibility = models.TextField("Applicant eligibility",blank=True,default="")
#     beneficiary_eligibility = models.TextField("Beneficiary eligibility",blank=True,default="")
#     credentials_documentation = models.TextField("Credentials / documentation",blank=True,default="")
#     preapplication_coordination = models.TextField("Preapplication coordination",blank=True,default="")
#     application_procedure = models.TextField("Application procedure",blank=True,default="")
#     award_procedure = models.TextField("Award procedure",blank=True,default="")
#     deadlines = models.TextField("Deadlines",blank=True,default="")
#     range_of_approval_disapproval_time = models.TextField("Range of approval / disapproval time",blank=True,default="")
#     appeals = models.TextField("Appeals",blank=True,default="")
#     renewals = models.TextField("Renewals",blank=True,default="")
#     formula_and_matching_requirements = models.TextField("Formula and matching requirements",blank=True,default="")
#     length_and_time_phasing_of_assistance = models.TextField("Length and time phasing of assistance",blank=True,default="")
#     reports = models.TextField("Reports",blank=True,default="")
#     audits = models.TextField("Audits",blank=True,default="")
#     records = models.TextField("Records",blank=True,default="")
#     account_identification = models.ManyToManyField(ProgramAccount)
#     range_and_average_of_financial_assistance = models.TextField("Range and average of financial assistance",blank=True,default="")
#     program_accomplishments = models.TextField("Program accomplishments",blank=True,default="")
#     regulations_guidelines_and_literature = models.TextField("Regulations guidelines and literature",blank=True,default="")
#     regional_or_local_office = models.TextField("Regional or local office",blank=True,default="")
#     headquarters_office = models.TextField("Headquarters office",blank=True,default="")
#     web_site_address = models.TextField("Web site address",blank=True,default="")
#     related_programs = models.TextField("Related programs",blank=True,default="")
#     examples_of_funded_projects = models.TextField("Examples of funded projects",blank=True,default="")
#     criteria_for_selecting_proposals = models.TextField("Criteria for selecting proposals",blank=True,default="")
#     published_date = models.TextField("Published Date", blank=True, default="")
#     parent_shortname = models.TextField("Parent Shortname", blank=True, default="")
#     url = models.TextField("URL on CFDA website", blank=True, default="")
#     recovery = models.BooleanField(default=False)
# 
#     cfda_edition = models.IntegerField("CFDA Edition", blank=True, null=True)
#     load_date = models.DateTimeField("Load Date", auto_now=True)    
#     caveat = models.TextField("Caveats about the spending of this program", blank=True, null=True)


# Path: cfda/search_indexes.py
import datetime
from haystack import indexes
from haystack.sites import site
from cfda.models import Program



class ProgramIndex(indexes.SearchIndex):
    
    type = 'cfda'
    program_number = indexes.CharField(model_attr='program_number') 
    program_title = indexes.CharField(document=True, model_attr='program_title')
    
   
#    def prepare_text(self, object):
        
#       text = getattr(object, 'objectives')
#limit to just program title. Objectives produces a lot of noise
#        text = getattr(object, 'program_title')

 #       return text

    def prepare_program_title(self, object):
        return str(object.program_title.replace('_', ' ').encode('ascii', 'ignore'))
                 
    def get_queryset(self):
        "Used when the entire index for model is updated."
        

        return Program.objects.filter(types_of_assistance__financial=True ).distinct()
