def profile(userID): user = USERS_COLLECTION.find_one({'_id': userID}) quesPosted = user['quesPosted'] for i in range(len(quesPosted)): quesPosted[i] = ObjectId(quesPosted[i]) bookmarks = [] bques = user['bookmarks'] for i in range(0, len(bques)): bques[i] = ObjectId(bques[i]) for q in QUESTIONS_COLLECTION.find({'_id': {'$in': bques}}): bookmarks.append(q) ques = [] for q in QUESTIONS_COLLECTION.find({'_id': {'$in': quesPosted}}): ques.append(q) data = { 'userID': user['_id'], 'fname': user['firstname'], 'lname': user['lastname'], 'email': user['email'], 'karma': user['karma'], 'quesPosted': ques } return render_template('profile.html', title='HoverSpace | Profile', data=data, bookmarks=bookmarks)
def home(): question = QUESTIONS_COLLECTION.find() answer = list() for record in question: try: for ansID in record['ansID']: for ans in ANSWERS_COLLECTION.find({'_id': ObjectId(ansID)}): answer.append(record['short_description']) answer.append(record['long_description']) answer.append(ans['ansText']) break except KeyError: pass return render_template('home.html', title='HoverSpace | Home', short_description=answer)
def home(): questions = QUESTIONS_COLLECTION.find().sort('timestamp', pymongo.DESCENDING) feed = list() for record in questions: try: story = { 'short_description': record['short_description'], 'long_description': record['long_description'], 'ques_url': url_for('viewQuestion', quesID=str(record['_id'])) } if record['accepted_ans']: story['answer'] = ANSWERS_COLLECTION.find_one( {'_id': ObjectId(accepted_ans)}) feed.append(story) except KeyError: pass return render_template('home.html', title='HoverSpace | Home', feed=feed)
def home(): form = SearchForm() if request.method == "POST": l = [] for selected in srch.search(form.srch_term.data): q = QuestionMethods(selected) l.append(q.getQuestion()) return render_template('search.html', title='HoverSpace | Search', result=l) questions = QUESTIONS_COLLECTION.find({ 'flag': 'False' }).sort('timestamp', pymongo.DESCENDING) feed = list() for record in questions: try: story = { 'short_description': record['short_description'], 'long_description': record['long_description'], 'ques_url': url_for('viewQuestion', quesID=str(record['_id'])), 'postedBy': record['postedBy'], 'ansCount': len(record['ansID']), 'votes': record['votes'], 'timestamp': record['timestamp'] } if record['accepted_ans']: story['answer'] = ANSWERS_COLLECTION.find_one( {'_id': ObjectId(record['accepted_ans'])}) feed.append(story) topcontributors = USERS_COLLECTION.find().sort( 'karma', pymongo.DESCENDING).limit(10) tags = [] for tag in TAGS_COLLECTION.find(): tags.append(tag['_id']) except KeyError: pass return render_template('home.html', title='HoverSpace | Home', feed=feed, form=form, tags=tags, topcontributors=topcontributors)
def add_all(self): for entry in QUESTIONS_COLLECTION.find(): self.add_string(str(entry['_id']), entry['short_description'])