コード例 #1
0
ファイル: cravel.py プロジェクト: ujjalcal/cravel98
    def create_update_trip(self):
        global db_timer
        if not self.user:
            self.redirect('/')

        ukey = self.user.key
        tname = self.request.get('tname')
        tdescription = self.request.get('tdescription')
        tdetails = self.request.get('tdetails')
        tlinks = self.request.get('tlinks')
        linkList = striplist(tlinks.split(','))
        ttags = self.request.get('ttags')
	taglist = striplist(ttags.split(','))
	
        tdestinations = self.request.get('tdestinations').strip()
        d = []
        destinationList = striplist(tdestinations.split(','))
        if len(destinationList)>0:
		for dest in destinationList:
			#TODO add exception handling - trim spaces
			dest = Destination1.getDestinationByName(dest.strip())
			logging.error(dest.count())
			if dest and dest.count() > 0:
				d.append(dest.fetch()[0].key)

        #logging.error('NewTrip.post tname:'+tname)
        turl = 'trip/'+tname.replace(' ','-')

        path = self.request.path
	isEdit = True if path[:6] == '/_edit' else False
	path = path[6:] if isEdit else path

		
        logging.error('NewTrip.post turl:'+turl)
	
        if tname:
	    tq = Trip.getTripByPath(path)	
    	    if tq and tq.count()>0:
		t = tq.fetch()[0]
		t.last_updated_by = ukey
	    else:
	        t = Trip()
	        t.added_by = ukey
	    
	    t.name = tname
	    t.turl = '/'+turl
	    t.description=tdescription
	    t.details=tdetails
	    t.destinations = d
	    t.tags = taglist
	    t.links=linkList
	    
            t = t.put()
	    search.Index(name=_T_INDEX_NAME).add(CreateDocument(str(t.id()), tname))
            self.redirect('/%s' % turl)
            
        else:
            error = "trip, please!"
            self.render("trip-edit.html", t=trip, error=error)