Exemple #1
0
    def create_update_question(self):
        global db_timer
        if not self.user:
            self.redirect('/')

	ukey = self.user.key
        question = self.request.get('question').strip()
        question = question if question[-1:] == '?' else question+'?'
        
        #logging.error('NewQuestion.post question:'+question)
        #### form the url###
        new_question = re.sub('[^a-zA-Z0-9\n\.]', ' ', question)
	new_question = new_question[:-1]+'?'
        qurl = 'qs/'+new_question.replace(' ','-')
        
        logging.error('NewQuestion.post qurl:'+qurl)

        path = self.request.path
	isEdit = True if path[:6] == '/_edit' else False
	path = path[6:]+'?' if isEdit else path+'?'
	
	logging.error('NewQuestion.post path:'+path)
	logging.error(isEdit)
        if question:
	    qq = Question.getQuestionByPath(path)
	    logging.error(qq.count())
	    if qq and qq.count()>0:
	    	q = qq.fetch()[0]
	    	q.last_updated_by = ukey
	    else:
	    	q = Question()
	    	q.added_by = ukey
	    	
            q.question = question
            q.qurl = '/'+qurl
            
            q = q.put()
            search.Index(name=_Q_INDEX_NAME).add(CreateDocument(str(q.id()), question))

            self.redirect('/%s' % qurl)
            
        else:
            error = "question, please!"
            self.render("question.html", q=question, error=error)