示例#1
0
 def get(self):
     user,_,url,url_linktext = self.get_user()
     
     #get filters from url
     location = helper.creatList(self.request.get("locationfilter"))
     type = helper.creatList(self.request.get("typefilter"))
     season = helper.creatList(self.request.get("seasonfilter"))
     
     #get all trips
     trips_query = Trip.query(Trip.visibility==True)
     if location != ['']:
         trips_query = trips_query.filter(Trip.trip_tags.location.IN(location))
     if type != ['']:
         trips_query = trips_query.filter(Trip.trip_tags.type.IN(type))
     if season != ['']:
         trips_query = trips_query.filter(Trip.trip_tags.season.IN(season))
 
     trips = trips_query.fetch()
     
     #create template
     template_values = {'user': user, 'url': url, 'url_linktext': url_linktext,
                       'location':location,'type':type,'season':season,'trips':trips}
     template = JINJA_ENVIRONMENT.get_template('templates/new/search.html')
  
     self.response.write(template.render(template_values))
示例#2
0
 def post(self):
     
     
     if self.request.get('locationfilter'):
         self.session['locationfilter'] = helper.creatList(self.request.get('locationfilter'))
     else:
         if self.session.get('locationfilter'):
             del self.session['locationfilter']
     if self.request.get('typefilter'):
         self.session['typefilter'] = helper.creatList(self.request.get('typefilter'))
     else:
         if self.session.get('typefilter'):
             del self.session['typefilter']
             
     if self.request.get('seasonfilter'):
         self.session['seasonfilter'] = helper.creatList(self.request.get('seasonfilter'))
     else:
         if self.session.get('seasonfilter'):
             del self.session['seasonfilter']
     
     self.redirect(self.request.referer)
示例#3
0
 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
 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')