当前位置: 首页>>代码示例>>Python>>正文


Python Person.save方法代码示例

本文整理汇总了Python中person.models.Person.save方法的典型用法代码示例。如果您正苦于以下问题:Python Person.save方法的具体用法?Python Person.save怎么用?Python Person.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在person.models.Person的用法示例。


在下文中一共展示了Person.save方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: save

# 需要导入模块: from person.models import Person [as 别名]
# 或者: from person.models.Person import save [as 别名]
    def save(self):
        data = self.cleaned_data
        person = Person(
            first_name=data['first_name'],
            last_name=data['last_name'],
            username=data['username'],
            email=data['email']
        )

        person.set_password(data['password'])
        person.save()

        # Send confirmation email
        TemplateEmail(
            subject='Registration',
            from_email='[email protected]',
            to_emails=person.email,
            template='email/confirmation_email.html',
            context={
                'user': person,
                'activation_link': absreverse('person:confirmation', kwargs={'key': person.confirmation})
            }
        ).send()

        return person
开发者ID:wgear,项目名称:vile-code,代码行数:27,代码来源:forms.py

示例2: CitationsTest

# 需要导入模块: from person.models import Person [as 别名]
# 或者: from person.models.Person import save [as 别名]
class CitationsTest(TestCase):

    def setUp(self):
        self.person1 = Person(full_name='João Carlos da Silva')
        self.person1.save()

        self.person2 = Person(full_name='Antonio da Silva')
        self.person2.save()

        self.person1_id = self.person1.pk
        self.person2_id = self.person2.pk

        citation2 = CitationName(person_id=self.person2_id, name='da Silva, A', default_name=True)
        citation2.save()

    def test_name_with_first_letters(self):

        result = name_with_first_letters(self.person1.full_name.split(), False)
        self.assertEqual(result, 'Silva, JC')

        result = name_with_first_letters(self.person1.full_name.split(), True)
        self.assertEqual(result, 'da Silva, JC')

    def test_names_without_last_name(self):

        result = names_without_last_name(self.person1.full_name.split(), False)
        self.assertEqual(result, 'Silva, João Carlos')

        result = names_without_last_name(self.person1.full_name.split(), True)
        self.assertEqual(result, 'da Silva, João Carlos')

    def test_first_name_and_first_letter(self):

        result = first_name_and_first_letter(self.person1.full_name.split(), False)
        self.assertEqual(result, 'Silva, João C')

        result = first_name_and_first_letter(self.person1.full_name.split(), True)
        self.assertEqual(result, 'da Silva, João C')

    def test_generate_citation_names(self):

        for person in Person.objects.all():
            generate_citation_names(person)

        citation = CitationName.objects.filter(person_id=self.person1_id, default_name=True)
        self.assertEqual('Silva, JC', citation[0].name)

        citation = CitationName.objects.filter(person_id=self.person2_id, default_name=True)
        self.assertEqual('da Silva, A', citation[0].name)

    def test_citation_names(self):
        response = self.client.get(reverse('citation_names'))
        self.assertEqual(response.status_code, 302)
开发者ID:neuromat,项目名称:nira,代码行数:55,代码来源:tests.py

示例3: make_person

# 需要导入模块: from person.models import Person [as 别名]
# 或者: from person.models.Person import save [as 别名]
def make_person(name, building, relation, address=None, city=None, website=None, phone=None):

    # now associate applicant with building:

    # first find/make person
    people = Person.objects.filter(city=city).filter(name=name)
    person = None
    # check if a previous building object in the db exists
    if people.exists():
        person = people[0]
        print "Already had Person: %s" % person.name
    else:
        # if not,
        # CREATE A NEW PERSON OBJECT HERE
        person = Person()

        person.name = name
        if city:
            person.city = city

        if address:
            person.address = address

        if website:
            person.website = website

        if phone:
            person.phone = phone

        person.save()

    # then find/make association:
    bpeople = BuildingPerson.objects.filter(building=building).filter(person=person)
    bperson = None
    # check if a previous building_person object in the db exists
    if bpeople.exists():
        bperson = bpeople[0]
        print "Already had BuildingPerson: %s with: %s" % (bperson.person.name, bperson.building.address)
    else:
        # if not,
        # CREATE A NEW BUILDING PERSON OBJECT HERE
        bperson = BuildingPerson()

        bperson.person = person
        bperson.building = building
        bperson.relation = relation
        bperson.save()

    return (person, bperson)
开发者ID:enerscore,项目名称:rentrocket,代码行数:51,代码来源:helpers.py

示例4: AccessRestrictedView

# 需要导入模块: from person.models import Person [as 别名]
# 或者: from person.models.Person import save [as 别名]
class AccessRestrictedView( UnifiView ):

    def __call__( self, request, *args, **kwargs ):
        """
        Due to security concerns, do not overload this function or
        any of its subclass overrides.
        """
        self.request = request
        self.args = args
        self.kwargs = kwargs
        
        if self.request.user.is_authenticated():
            self.user = self.request.user

            try:
                self.person = Person.objects.get( user=self.user )
            except Person.DoesNotExist:
                self.person = Person( user=self.user )
                self.person.save()
            return self.allow( *args, **kwargs )

        else:
            return self.deny()


    def deny( self ):
        client = Client( self.request )

        if client.is_banned():
            return HttpResponse( status=403 )
        else:
            return self.dialog(

                title       = "Not Authenticated",
                message     = "Velkommen til UNIFI, du er ikke pålogget. " + \
                              "For å logge deg på benytt universitetets " + \
                              "innloggingsportal."

            )

    def render( self, template_name, context ):
        context['person'] = self.person
        context['rules'] = rules
        return builtin_render( self.request, template_name, context )
开发者ID:ilyakh,项目名称:unifi-webfaction,代码行数:46,代码来源:views.py

示例5: setUp

# 需要导入模块: from person.models import Person [as 别名]
# 或者: from person.models.Person import save [as 别名]
    def setUp(self):
        logged, self.user, self.factory = system_authentication(self)
        self.assertEqual(logged, True)

        country = Country(id=31)
        country.save()

        city = City(country=country)
        city.save()

        person = Person(full_name="Fulano Testeiro")
        person.save()

        date_departure1 = datetime.date(2015, 1, 15)
        date_arrival1 = datetime.date(2015, 1, 16)

        date_departure2 = datetime.date(2014, 1, 15)
        date_arrival2 = datetime.date(2014, 1, 16)
        order_01 = 0
        order_02 = 1

        amount_paid = 666

        mission1 = scientific_mission(person, amount_paid)
        mission1.save()
        route1_mission1 = create_route(city, mission1, date_departure1, order_01)
        route2_mission1 = create_route(city, mission1, date_arrival1, order_02)
        route1_mission1.save()
        route2_mission1.save()

        mission2 = scientific_mission(person, amount_paid)
        mission2.save()
        route1_mission2 = create_route(city, mission2, date_departure2, order_01)
        route2_mission2 = create_route(city, mission2, date_arrival2, order_02)
        route1_mission2.save()
        route2_mission2.save()
开发者ID:neuromat,项目名称:nira,代码行数:38,代码来源:tests.py

示例6: read_csv

# 需要导入模块: from person.models import Person [as 别名]
# 或者: from person.models.Person import save [as 别名]
def read_csv(source_csv, city_tag, feed_date):
    #could also use city.models.find_by_city_state
    city_options = City.objects.filter(tag=city_tag)
    #print "Number of cities available: %s" % len(city_options)
    if not len(city_options):
        raise ValueError, "CITY NOT FOUND! run make_cities.py first"
    else:
        city = city_options[0]

    print city


    feeds = FeedInfo.objects.filter(city=city).filter(added=feed_date)
    if feeds.exists():
        feed = feeds[0]
        print "Already had feed: %s, %s" % (feed.city, feed.added)
    else:
        feed = FeedInfo()
        feed.city = city
        feed.added = feed_date
        feed.version = "0.1"
        feed.save()
        print "Created new feed: %s" % feed.city.name

    people = Person.objects.filter(name="Blank")
    if people.exists():
        person = people[0]
        print "Already had person: %s" % (person.name)
    else:
        person = Person()
        person.name = "Blank"
        person.save()
        print "Created new person: %s" % person.name

    sources = Source.objects.filter(feed=feed)
    if sources.exists():
        feed_source = sources[0]
        print "Already had source: %s, %s" % (feed_source.feed.city, feed_source.feed.added)
    else:
        feed_source = Source()
        feed_source.feed = feed
        feed_source.person = person
        feed_source.save()
        print "Created new source: %s" % feed_source.feed.city.name


    # ideally, should be able to use the database itself as the cache,
    # instead of using a local file
    # but it's also good to not have to repeat geo queries if going in bulk
    # the site code *will* make geo queries
    # so it's still a good idea to cache the coded address locally
    # even if using the site code for everything else.
    
    cache_file = "%s.json" % city.tag
    #print cache_file
    cache_destination = os.path.join(os.path.dirname(source_csv), cache_file)
    print cache_destination
    #keep a local copy of data we've processed...
    #this should help with subsequent calls
    #to make sure we don't need to duplicate calls to remote geolocation APIs:
    loaded_cache = load_json(cache_destination, create=True)

    #need to go through and load SearchResults separately
    local_cache = {}
    for key in loaded_cache.keys():
        #this is useful if there is a cached value 
        #that was not parsed correctly... this will remove it:
        #if key.strip() == "314 North Washington Street Apt. C":
        if key.strip() == "some address with bad cached data":
            print "not adding: ", key
            #exit()
            pass
        else:
            current = loaded_cache[key]
            results = current['results']
            #print results
            sr = SearchResults()
            #sr.from_dict(results, debug=True)
            sr.from_dict(results, debug=False)
            #print sr
            current['results'] = sr

            #print current['results']
            local_cache[key] = current
        
    #use street address as the key
    #for each address, store SearchResults object

    #reset skips for every run:
    skips = codecs.open("skips.txt", 'w', encoding='utf-8')
    skips.close()


    skips = 0
    #with codecs.open(source_csv, 'rb', encoding='utf-8') as csvfile:
    with open(source_csv) as csvfile:

        #reader = csv.reader(csvfile, delimiter=' ', quotechar='|')
        #reader = csv.reader(csvfile)
        #reader = unicodecsv.UnicodeReader(csvfile, encoding='utf-8')
#.........这里部分代码省略.........
开发者ID:City-of-Bloomington,项目名称:rentrocket,代码行数:103,代码来源:import_master_template.py

示例7: read_csv

# 需要导入模块: from person.models import Person [as 别名]
# 或者: from person.models.Person import save [as 别名]
def read_csv(source_csv, city_name, city_tag):
    city_options = City.objects.filter(tag=city_tag)
    print "Number of cities available: %s" % len(city_options)
    if not len(city_options):
        raise ValueError, "CITY NOT FOUND! run make_cities.py first"
        ## city = City()
        ## city.name = city_name
        ## city.tag = to_tag(city.name)
        ## city.save()
    else:
        city = city_options[0]

    print city

    feed_date = "2013-07-31"

    feeds = FeedInfo.objects.filter(city=city).filter(added=feed_date)
    if feeds.exists():
        feed = feeds[0]
        print "Already had feed: %s, %s" % (feed.city, feed.added)
    else:
        feed = FeedInfo()
        feed.city = city
        feed.added = feed_date
        feed.version = "0.1"
        feed.save()
        print "Created new feed: %s" % feed.city.name

    people = Person.objects.filter(name="Blank")
    if people.exists():
        person = people[0]
        print "Already had person: %s" % (person.name)
    else:
        person = Person()
        person.name = "Blank"
        person.save()
        print "Created new person: %s" % person.name

    sources = Source.objects.filter(feed=feed)
    if sources.exists():
        feed_source = sources[0]
        print "Already had source: %s, %s" % (feed_source.feed.city, feed_source.feed.added)
    else:
        feed_source = Source()
        feed_source.feed = feed
        feed_source.person = person
        feed_source.save()
        print "Created new source: %s" % feed_source.feed.city.name


    cache_file = "%s.json" % city.tag
    cache_destination = os.path.join(os.path.dirname(source_csv), cache_file)
    #keep a local copy of data we've processed...
    #this should help with subsequent calls
    #to make sure we don't need to duplicate calls to remote geolocation APIs:
    local_cache = load_json(cache_destination, create=True)
    if not local_cache.has_key('buildings'):
        local_cache['buildings'] = {}
    if not local_cache.has_key('parcels'):
        local_cache['parcels'] = {}
    
    locations = {}
    for key, value in local_cache['buildings'].items():
        locations[key] = Location(value)

    #geocoder helper:
    geo = Geo()

    skips = 0
    #with codecs.open(source_csv, 'rb', encoding='utf-8') as csvfile:
    with open(source_csv) as csvfile:
        #reader = csv.reader(csvfile, delimiter=' ', quotechar='|')
        #reader = csv.reader(csvfile)
        #reader = unicodecsv.UnicodeReader(csvfile, encoding='utf-8')

        reader = unicode_csv_reader(csvfile)

        #just print the first row:
        print '>, <'.join(reader.next())

        count = 0
        for row in reader:
            count += 1
            print "Looking at row: %s" % count
            
            #could exit out early here, if needed
            if count > 1000:
                #exit()
                pass
            
            address = row[0]

            #need to fix the number being at the end of the address
            parts = address.split(',')
            anumber = parts[-1]
            parts = parts[:-1]
            street = ",".join(parts)
            address = "%s %s" % (anumber, street)


#.........这里部分代码省略.........
开发者ID:City-of-Bloomington,项目名称:rentrocket,代码行数:103,代码来源:convert-evanston.py

示例8: read_csv

# 需要导入模块: from person.models import Person [as 别名]
# 或者: from person.models.Person import save [as 别名]
def read_csv(source_csv, city_name, city_tag):
    city_options = City.objects.filter(tag=city_tag)
    print "Number of cities available: %s" % len(city_options)
    if not len(city_options):
        raise ValueError, "CITY NOT FOUND! run make_cities.py first"
        ## city = City()
        ## city.name = city_name
        ## city.tag = to_tag(city.name)
        ## city.save()
    else:
        city = city_options[0]

    print city

    feed_date = "2013-10-16"

    feeds = FeedInfo.objects.filter(city=city).filter(added=feed_date)
    if feeds.exists():
        feed = feeds[0]
        print "Already had feed: %s, %s" % (feed.city, feed.added)
    else:
        feed = FeedInfo()
        feed.city = city
        feed.added = feed_date
        feed.version = "0.1"
        feed.save()
        print "Created new feed: %s" % feed.city.name

    people = Person.objects.filter(name="Blank")
    if people.exists():
        person = people[0]
        print "Already had person: %s" % (person.name)
    else:
        person = Person()
        person.name = "Blank"
        person.save()
        print "Created new person: %s" % person.name

    sources = Source.objects.filter(feed=feed)
    if sources.exists():
        feed_source = sources[0]
        print "Already had source: %s, %s" % (feed_source.feed.city, feed_source.feed.added)
    else:
        feed_source = Source()
        feed_source.feed = feed
        feed_source.person = person
        feed_source.save()
        print "Created new source: %s" % feed_source.feed.city.name


    cache_file = "%s.json" % city.tag
    cache_destination = os.path.join(os.path.dirname(source_csv), cache_file)
    #keep a local copy of data we've processed...
    #this should help with subsequent calls
    #to make sure we don't need to duplicate calls to remote geolocation APIs:
    local_cache = load_json(cache_destination, create=True)
    if not local_cache.has_key('buildings'):
        local_cache['buildings'] = {}
    if not local_cache.has_key('parcels'):
        local_cache['parcels'] = {}
    
    locations = {}
    for key, value in local_cache['buildings'].items():
        locations[key] = Location(value)

    #geocoder helper:
    geo = Geo()

    skips = 0
    #with codecs.open(source_csv, 'rb', encoding='utf-8') as csvfile:
    with open(source_csv) as csvfile:
        #reader = csv.reader(csvfile, delimiter=' ', quotechar='|')
        #reader = csv.reader(csvfile)
        #reader = unicodecsv.UnicodeReader(csvfile, encoding='utf-8')

        reader = unicode_csv_reader(csvfile)

        #just print the first row:
        print '>, <'.join(reader.next())

        count = 0

        #want to randomize the order... distribute options more evenly
        #print len(reader)
        #exit()
        #in order to randomize, should randomize the order in the csv
        for row in reader:
            count += 1
            print "Looking at row: %s" % count
            
            #could exit out early here, if needed
            if count > 10:
                #exit()
                pass

            print row
            address = row[0]


            ## no_units = row[12]
#.........这里部分代码省略.........
开发者ID:codeforbtv,项目名称:green-rental,代码行数:103,代码来源:convert-columbia.py

示例9: SeminarsTest

# 需要导入模块: from person.models import Person [as 别名]
# 或者: from person.models.Person import save [as 别名]
class SeminarsTest(TestCase):

    """
    The following tests are performed:
    1 - Seminars search;
    2 - Seminars report in latex and pdf;
    3 - Seminars report for internal with date;
    4 - Seminars report  without date;
    5 - Seminars report with invalid dates selected;
    6 - Seminars poster.
    """

    def setUp(self):
        logged, self.user, self.factory = system_authentication(self)
        self.assertEqual(logged, True)

        self.person = Person(full_name="Person Full Test")
        self.person.save()

        type1 = SeminarType(name="Testing 1")
        type1.save()

        type2 = SeminarType(name="Testing 2")
        type2.save()

        self.date1 = base_date1
        self.date2 = base_date2

        seminar1 = seminar('Seminar1', type1, self.date1)
        seminar1.save()

        seminar2 = seminar('Seminar2', type2, self.date2)
        seminar2.save()

    def test_report_status_code(self):
        response = self.client.get(reverse('seminars_report'))
        self.assertEqual(response.status_code, 200)

    def test_report_with_dates_and_all_categories(self):

        response = self.client.post(reverse('seminars_report'), {'start_date': '01/01/2015',
                                                                 'end_date': '03/05/2017',
                                                                 'category': '0'})
        cont = response.context['seminars']
        self.assertEqual(len(cont), 1)
        self.assertEqual(response.status_code, 200)

    def test_report_with_dates_and_specific_category(self):
        response = self.client.post(reverse('seminars_report'), {'start_date': '01/01/2015',
                                                                 'end_date': '03/05/2017',
                                                                 'category': 'All'})
        cont = response.context['seminars']
        self.assertEqual(len(cont), 1)
        self.assertEqual(response.status_code, 200)

    def test_report_without_dates(self):
        response = self.client.post(reverse('seminars_report'), {'start_date': '',
                                                                 'end_date': '',
                                                                 'category': '0'})
        cont = response.context['seminars']
        self.assertEqual(len(cont), 2)
        self.assertEqual(response.status_code, 200)

    def test_report_with_wrong_dates(self):
        response = self.client.post(reverse('seminars_report'), {'start_date': '01/01/2016',
                                                                 'end_date': '03/05/2015',
                                                                 'category': 'All'})
        self.assertEqual(response.status_code, 200)

    def test_poster(self):

        # Just load the page
        response = self.client.get(reverse('seminars_poster'))
        self.assertEqual(response.status_code, 200)

        # Test creation of seminar poster..
        response = self.client.post(reverse('seminars_poster'), {'title': ''})
        self.assertEqual(response.status_code, 200)

        response = self.client.post(reverse('seminars_poster'), {'title': 0})
        self.assertEqual(response.status_code, 404)

        # seminar_id = Seminar.objects.get(title='Seminar1')
        # seminar_id = seminar_id.pk
        #
        # response = self.client.post(reverse('seminars_poster'), {'title': seminar_id})
        # self.assertEqual(response.status_code, 200)

    def test_tex(self):
        response = self.client.get(reverse('seminars_file'), {'start_date': '2015-03-01',
                                                              'end_date': '2017-03-05',
                                                              'category': 'All',
                                                              'extension': '.tex'})
        self.assertEqual(response.status_code, 200)

    def test_pdf(self):
        response = self.client.get(reverse('seminars_file'), {'start_date': '2015-03-01',
                                                              'end_date': '2017-03-05',
                                                              'category': 'All',
                                                              'extension': '.pdf'})
#.........这里部分代码省略.........
开发者ID:neuromat,项目名称:nira,代码行数:103,代码来源:tests.py

示例10: MeetingsTest

# 需要导入模块: from person.models import Person [as 别名]
# 或者: from person.models.Person import save [as 别名]
class MeetingsTest(TestCase):

    """
    The following tests are performed:
    1 - Meetings report with date for each audience;
    2 - Meetings report without date;
    3 - Meetings report with invalid date.
    """

    def setUp(self):

        logged, self.user, self.factory = system_authentication(self)
        self.assertEqual(logged, True)

        self.person = Person(full_name="Person Full Test")
        self.person.save()

        self.date1 = base_date2
        self.date2 = base_date1
        self.date3 = base_date3

        meeting1 = meeting('First meeting', self.date1, self.date2, False)
        meeting1.save()

        meeting2 = meeting('Second meeting', self.date1, self.date3, True)
        meeting2.save()

        meeting3 = meeting('Third meeting', self.date1, self.date3, True)
        meeting3.save()

    def test_report_status_code(self):
        response = self.client.get(reverse('meetings_report'))
        self.assertEqual(response.status_code, 200)

    def test_report_with_valid_date(self):
        # With valid date, to each audience
        response = self.client.post(reverse('meetings_report'), {'start_date': '01/01/2014',
                                                                 'end_date': '03/05/2017',
                                                                 'broad_audience': 0})
        cont = response.context['meetings']
        self.assertEqual(len(cont), 3)
        self.assertEqual(response.status_code, 200)

        response = self.client.post(reverse('meetings_report'), {'start_date': '01/01/2014',
                                                                 'end_date': '03/05/2017',
                                                                 'broad_audience': 1})
        cont = response.context['meetings']
        self.assertEqual(len(cont), 2)
        self.assertEqual(response.status_code, 200)

        response = self.client.post(reverse('meetings_report'), {'start_date': '01/01/2014',
                                                                 'end_date': '03/05/2015',
                                                                 'broad_audience': 2})
        cont = response.context['meetings']
        self.assertEqual(len(cont), 1)
        self.assertEqual(response.status_code, 200)

    def test_report_without_date(self):
        # Without date, all categories. Should get all results.
        response = self.client.post(reverse('meetings_report'), {'start_date': '',
                                                                 'end_date': '',
                                                                 'broad_audience': 0})
        cont = response.context['meetings']
        self.assertEqual(len(cont), 3)
        self.assertEqual(response.status_code, 200)

    def test_report_wrong_date(self):
        response = self.client.post(reverse('meetings_report'), {'start_date': '01/01/2017',
                                                                 'end_date': '03/05/2015'})
        self.assertEqual(response.status_code, 200)
开发者ID:neuromat,项目名称:nira,代码行数:72,代码来源:tests.py

示例11: read_csv

# 需要导入模块: from person.models import Person [as 别名]
# 或者: from person.models.Person import save [as 别名]
def read_csv(source_csv):
    city_options = City.objects.filter(tag="bloomington_in")
    print "Number of cities available: %s" % len(city_options)
    if not len(city_options):
        raise ValueError, "CITY NOT FOUND! run make_cities.py first"
        ## city = City()
        ## city.name = "Bloomington"
        ## city.tag = to_tag(city.name)
        ## city.save()
    else:
        city = city_options[0]

    print city

    feed_date = "2013-08-29"

    feeds = FeedInfo.objects.filter(city=city).filter(added=feed_date)
    if feeds.exists():
        feed = feeds[0]
        print "Already had feed: %s, %s" % (feed.city, feed.added)
    else:
        feed = FeedInfo()
        feed.city = city
        feed.added = feed_date
        feed.version = "0.1"
        feed.save()
        print "Created new feed: %s" % feed.city

    people = Person.objects.filter(name="Blank")
    if people.exists():
        person = people[0]
        print "Already had person: %s" % (person.name)
    else:
        person = Person()
        person.name = "Blank"
        person.save()
        print "Created new person: %s" % person.name

    sources = Source.objects.filter(feed=feed)
    if sources.exists():
        feed_source = sources[0]
        print "Already had source: %s, %s" % (feed_source.feed.city, feed_source.feed.added)
    else:
        feed_source = Source()
        feed_source.feed = feed
        feed_source.person = person
        feed_source.save()
        print "Created new source: %s" % feed_source.feed.city

    cache_file = "%s.json" % city.tag
    cache_destination = os.path.join(os.path.dirname(source_csv), cache_file)
    # keep a local copy of data we've processed...
    # this should help with subsequent calls
    # to make sure we don't need to duplicate calls to remote geolocation APIs:
    local_cache = load_json(cache_destination, create=True)
    if not local_cache.has_key("buildings"):
        local_cache["buildings"] = {}
    if not local_cache.has_key("parcels"):
        local_cache["parcels"] = {}

    locations = {}
    for key, value in local_cache["buildings"].items():
        locations[key] = Location(value)

    # geocoder helper:
    geo = Geo()

    skips = 0
    with codecs.open(source_csv, "rb", encoding="utf-8") as csvfile:
        # reader = csv.reader(csvfile, delimiter=' ', quotechar='|')
        reader = csv.reader(csvfile)

        # just print the first row:
        print ">, <".join(reader.next())

        count = 0
        for row in reader:
            count += 1
            print "Looking at row: %s" % count

            # could exit out early here, if needed
            if count > 1000:
                # exit()
                pass

            bldg_id = row[0]
            print bldg_id

            address = row[1]
            print address

            owner = row[2]

            # skip this:
            ownder_contact = row[3]

            agent = row[4]

            bldg_units = row[9]
            print bldg_units
#.........这里部分代码省略.........
开发者ID:enerscore,项目名称:rentrocket,代码行数:103,代码来源:convert-bloomington.py

示例12: read_csv

# 需要导入模块: from person.models import Person [as 别名]
# 或者: from person.models.Person import save [as 别名]
def read_csv(source_csv, city_name, city_tag):
    city_options = City.objects.filter(tag=city_tag)
    print "Number of cities available: %s" % len(city_options)
    if not len(city_options):
        raise ValueError, "CITY NOT FOUND! run make_cities.py first"
        ## city = City()
        ## city.name = city_name
        ## city.tag = to_tag(city.name)
        ## city.save()
    else:
        city = city_options[0]

    print city

    feed_date = "2013-10-16"

    feeds = FeedInfo.objects.filter(city=city).filter(added=feed_date)
    if feeds.exists():
        feed = feeds[0]
        print "Already had feed: %s, %s" % (feed.city, feed.added)
    else:
        feed = FeedInfo()
        feed.city = city
        feed.added = feed_date
        feed.version = "0.1"
        feed.save()
        print "Created new feed: %s" % feed.city.name

    people = Person.objects.filter(name="Blank")
    if people.exists():
        person = people[0]
        print "Already had person: %s" % (person.name)
    else:
        person = Person()
        person.name = "Blank"
        person.save()
        print "Created new person: %s" % person.name

    sources = Source.objects.filter(feed=feed)
    if sources.exists():
        feed_source = sources[0]
        print "Already had source: %s, %s" % (feed_source.feed.city, feed_source.feed.added)
    else:
        feed_source = Source()
        feed_source.feed = feed
        feed_source.person = person
        feed_source.save()
        print "Created new source: %s" % feed_source.feed.city.name

    cache_file = "%s-20150525.json" % city.tag
    cache_destination = os.path.join(os.path.dirname(source_csv), cache_file)
    # keep a local copy of data we've processed...
    # this should help with subsequent calls
    # to make sure we don't need to duplicate calls to remote geolocation APIs:
    local_cache = load_json(cache_destination, create=True)
    if not local_cache.has_key("buildings"):
        local_cache["buildings"] = {}

    search_results = {}
    for key, value in local_cache["buildings"].items():
        # search_results[key] = Location(value)
        sr = SearchResults()
        sr.from_dict(value)
        # print
        # print sr
        # print
        search_results[key] = sr

    # geocoder helper:
    # geo = Geo()

    skips = 0
    with open(source_csv) as csvfile:

        reader = unicode_csv_reader(csvfile)

        # just print the first row:
        print ">, <".join(reader.next())

        count = 0

        # want to randomize the order... distribute options more evenly
        # print len(reader)
        # exit()
        # in order to randomize, should randomize the order in the csv
        for row in reader:
            count += 1
            print "Looking at row: %s" % count

            any_updated = False

            # could exit out early here, if needed
            if count > 10:
                # exit()
                pass

            # if you want to skip ahead more quickly:
            if count < 27187:
                pass
            else:
#.........这里部分代码省略.........
开发者ID:enerscore,项目名称:rentrocket,代码行数:103,代码来源:convert-columbia.py


注:本文中的person.models.Person.save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。