コード例 #1
0
ファイル: handlers.py プロジェクト: WsanjaW/BikeTrips
 def get(self):
     
     user,id,url,url_linktext = self.get_user()
     
     #parameter mytrips = True if only users trips should be shown  
     mytrips = self.request.get('mytrips')
     
     if mytrips == 'True':
         trips_query = Trip.query(ancestor=helper.trip_key(id)).order(-Trip.creation_date)
     else:
         trips_query = Trip.query(Trip.visibility==True).order(-Trip.creation_date)
           
     trips, next_curs, more = trips_query.fetch_page(PAGE_SIZE)
     
     #return index page
     template_values = {'user': user, 'url': url, 'url_linktext': url_linktext,'trips':trips,'cursor':next_curs,
                        'more':more,'mytrips':mytrips}
     template = JINJA_ENVIRONMENT.get_template('templates/new/alltrips.html')
     self.response.write(template.render(template_values))
コード例 #2
0
ファイル: handlers.py プロジェクト: WsanjaW/BikeTrips
 def get_all_tags(self,id):
     '''
     Returns all tags for specified user
     '''
     #get users tags
     tags_query = Tags.query(ancestor=helper.trip_key(id))
     tags = tags_query.fetch(1)
     if tags:
         tags = tags[0]
         location = [str(x) for x in tags.location]
         type = [str(x) for x in tags.type]
         season = [str(x) for x in tags.season]
     else:
         location = []
         type = []
         season = []
     tags = []
     tags.append(location)
     tags.append(type)
     tags.append(season)
     return tags
コード例 #3
0
ファイル: handlers.py プロジェクト: WsanjaW/BikeTrips
 def post(self):
     
     _,id,_,_ = self.get_user()
     
     #get specific trip     
     trip_key = self.request.get('trip_id')
     tripk = ndb.Key(urlsafe=trip_key)
     trip = tripk.get()    
     
     #get new values
     new_name = self.request.get('trip_name')
     if new_name:         
         trip.trip_name = new_name
     new_description = self.request.get('description')
     if new_description:
         trip.description = new_description
         
     new_cities =  self.get_cities(self.request.get('cities'))
     if new_cities:
         trip.cities = new_cities
         
     new_avatar = self.request.get('img')
     if  new_avatar:
         trip.trip_avatar = new_avatar
     
     new_from_date = self.request.get('from_date') 
     if new_from_date:
         try:
             new_from_date = datetime.strptime( new_from_date, '%d/%m/%Y')  
         except:
             try:
                 new_from_date = datetime.strptime( new_from_date, '%Y-%m-%d')  
             except:
                     new_from_date = datetime.strptime( '2000-01-01', '%Y-%m-%d')  
         trip.from_date = new_from_date
     
     new_to_date = self.request.get('to_date')
     if new_to_date:
         try:
             new_to_date = datetime.strptime( new_to_date, '%d/%m/%Y')  
         except:
             try:
                 new_to_date = datetime.strptime( new_to_date, '%Y-%m-%d')  
             except:
                 new_to_date = datetime.strptime( '2000-01-01', '%Y-%m-%d')  
         trip.to_date = new_to_date
     
     if self.request.get('visibility') == 'True':
         trip.visibility = True
     else:
         trip.visibility = False 
     
     #crete tags for trip
     locationl = helper.creatList(self.request.get('location'))
     typel = helper.creatList(self.request.get('type'))
     seasonl = helper.creatList(self.request.get('season'))
     trip.trip_tags = Tags(location=locationl,type=typel,season=seasonl)
     
     #put new tags in users tags
     tags_query = Tags.query(ancestor=helper.trip_key(id))
     tags = tags_query.fetch(1)
     if tags:
         tags = tags[0]
         tags.location = helper.union(tags.location,locationl)
         tags.type = helper.union(tags.type,typel)
         tags.season = helper.union(tags.season,seasonl)
                   
     else:
         new_loc_tags = locationl
         new_type_tags = typel
         new_seasion_tags = seasonl
         tags = Tags(parent=helper.trip_key(id),location=new_loc_tags,type=new_type_tags,season=new_seasion_tags)
     
     tags.put()
     
     trip.put()
     
    
     self.redirect('/tripmanager/onetrip?trip_id='+ tripk.urlsafe())
コード例 #4
0
ファイル: handlers.py プロジェクト: WsanjaW/BikeTrips
 def post(self):
     '''
     Adds trip to datastore
     '''
     
     _,id,_,_ = self.get_user()
     
     #TODO some checking      
     trip = Trip(parent=helper.trip_key(id))
     trip.trip_name = self.request.get('trip_name')
     
     trip.description = self.request.get('description')
     trip.cities =  self.get_cities(self.request.get('cities'))
     avatar = self.request.get('img')
     if  avatar:
         trip.trip_avatar = avatar
     
     
     try:
         trip.from_date = datetime.strptime( self.request.get('from_date'), '%d/%m/%Y')  
         trip.to_date = datetime.strptime(self.request.get('to_date'), '%d/%m/%Y')
     except:
         try:
             trip.from_date = datetime.strptime( self.request.get('from_date'), '%Y-%m-%d')  
             trip.to_date = datetime.strptime(self.request.get('to_date'), '%Y-%m-%d')
         except:
             trip.from_date = datetime.strptime( '2000-01-01', '%Y-%m-%d')  
             trip.to_date = datetime.strptime('2000-01-01', '%Y-%m-%d')
     
     if self.request.get('visibility') == 'True':
         trip.visibility = True
     else:
         trip.visibility = False
     
     #create statistic for trip 
     trip.trip_statistic = TrackStatistic(name="Trip Stat",total_distance=0,total_time="",
                                          avr_speed=0,total_climb=0,max_elev=-100)
     
     #crete tags for trip
     locationl = helper.creatList(self.request.get('location'))
     typel = helper.creatList(self.request.get('type'))
     seasonl = helper.creatList(self.request.get('season'))
     trip.trip_tags = Tags(location=locationl,type=typel,season=seasonl)
     
     trip.put()
            
     #put new tags in users tags
     tags_query = Tags.query(ancestor=helper.trip_key(id))
     tags = tags_query.fetch(1)
     if tags:
         tags = tags[0]
         tags.location = helper.union(tags.location,locationl)
         tags.type = helper.union(tags.type,typel)
         tags.season = helper.union(tags.season,seasonl)
                   
     else:
         new_loc_tags = locationl
         new_type_tags = typel
         new_seasion_tags = seasonl
         tags = Tags(parent=helper.trip_key(id),location=new_loc_tags,type=new_type_tags,season=new_seasion_tags)
     
     tags.put()
     
     #redirect to mytrips because showing all tips will only be consistent in scope of user
     # and only eventually consistent for whole datastore  
     self.redirect('/tripmanager')