Example #1
0
def places(name=None):

    if request.method == 'POST':
        title = request.form.get('place_title', '')
        info = request.form.get('place_info', '')
        if title:
            p = Place()
            p.title = title
            p.info = info
            p.put()

    qs = Place.all()
    qs.order('added_at')

    return render_template('places.html', places=qs)
Example #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)