Exemplo n.º 1
0
    def add_things(self, user):

        # Add 10 Things
        things = [
            'read War and Peace',
            'sky dive',
            'learn to SCUBA dive',
            'get a university degree',
            'learn to sail',
            'learn to kite board',
            'learn to play guitar',
            'learn archery',
            'learn spanish',
            'learn chinese',
        ]
        
        self.response.out.write('<hr/>Adding things to do<hr/>')
        
        # Get all list items for the current user        
        query = UserListItems.gql('WHERE user = :user', user=user)
        user_list_items = query.get()

        if user_list_items is None:
            user_list_items = UserListItems(user=user)        
        
        for name in things:
            thing = Thing()
            thing.title = name
            thing.put()
            
            # Add Reference to the Thing from User
            user_list_item = UserListItem()
            user_list_item.user = user
            user_list_item.list_item = thing
            
            # Update the list of items the user has
            user_list_items.list_items.append(thing.key())
            
            # Add the specifics of the user list item linkage
            user_list_item = UserListItem()
            user_list_item.user = user
            user_list_item.list_item = thing
            one_year = datetime.timedelta(days=365)
            today = datetime.datetime.today()
            user_list_item.date_due = today + one_year
            user_list_item.put()            
            
            self.response.out.write('Added %s<br/>' % thing)
Exemplo n.º 2
0
    def add_places(self, user):
    
        # Add 10 Places
        places = [
            'the CN Tower',
            'the Eiffel Tower',
            'Athens Greece',
            'the Great Pyramids',
            'the Great Wall of China',
            'the Louvre',
            'the Palace of Versailles',
            'Sydney Australia',
            'the Grand Canyon',
            'Bora Bora'
        ]
        
        self.response.out.write('<hr/>Adding places to go<hr/>')
        
        # Get all list items for the current user        
        query = UserListItems.gql('WHERE user = :user', user=user)
        user_list_items = query.get()
        
        if user_list_items is None:
            user_list_items = UserListItems(user=user)        
        
        for name in places:
            place = Place()
            place.title = name
            place.put()
            
            # Add Reference to the Place from User
            user_list_item = UserListItem()
            user_list_item.user = user
            user_list_item.list_item = place
            
            # Update the list of items the user has
            user_list_items.list_items.append(place.key())
            
            # Add the specifics of the user list item linkage
            user_list_item = UserListItem()
            user_list_item.user = user
            user_list_item.list_item = place
            one_year = datetime.timedelta(days=365)
            today = datetime.datetime.today()
            user_list_item.date_due = today + one_year
            user_list_item.put()            

            self.response.out.write('Added %s<br/>' % place)
Exemplo n.º 3
0
    def add_people(self, user):
        # Add 10 People
        people = [
            'Nelson Mandella',
            'the Queen of England',
            'the Pope',
            'President Obama',
            'President Obama',
            'Richard Branson',
            'Bill Gates',
            'Warren Buffet',
            'Bon Jovi',
            'Jennifer Aniston'
        ]
        
        self.response.out.write('<hr/>Adding people to meet<hr/>')

        # Get all list items for the current user        
        query = UserListItems.gql('WHERE user = :user', user=user)
        user_list_items = query.get()
        
        if user_list_items is None:
            user_list_items = UserListItems(user=user)

        for name in people:
            # Add Person Entity
            query = Person.gql('WHERE title=:name', name=name)
            person = query.get()

            if person:
                self.response.out.write('Found %s in database<br/>' % person)
            
            if not person:
                person = Person()
                person.title = name
                person.put()
                self.response.out.write('Added %s<br/>' % person)                
            
            # Update the list of items the user has
            if person.key() not in user_list_items.list_items:
                user_list_items.list_items.append(person.key())
                self.response.out.write('Added %s to %s<br/>' % (person.key().to_path(), user_list_items.list_items))            

            # Add the specifics of the user list item linkage
            user_list_item = UserListItem()
            user_list_item.user = user
            user_list_item.list_item = person
            one_year = datetime.timedelta(days=365)
            today = datetime.datetime.today()
            user_list_item.date_due = today + one_year
            user_list_item.put()
            
            ListItemCounter.increment(user_list_item)
            
            self.response.out.write('------------------------------------<br/>')

        # Save the linkages from list items to the current user
        user_list_items.put();