Exemplo n.º 1
0
 def addFlaggedBy(self, userID, postedBy):
     ans_obj = ANSWERS_COLLECTION.find_one({'_id': ObjectId(self.ansID)})
     flags = ans_obj['flaggedBy']
     votes = ans_obj['votes']
     if userID in flags:
         return "alreadyFlagged"
     ANSWERS_COLLECTION.find_one_and_update({'_id': ObjectId(self.ansID)}, {'$addToSet': {'flaggedBy': userID}})
     if (len(flags)>=10):
         flag = "True"
         self.setFlag(userID, votes, flag)
         usr = User(postedBy)
         usr.update_karma(-votes)
         return "quesRemoved"
     return "flagged"
Exemplo n.º 2
0
 def get_answers(self, quesID):
     answers = []
     try:
         ans_obj = (QUESTIONS_COLLECTION.find_one({'_id': ObjectId(quesID)}))['ansID']
         for answer in ans_obj:
             answers.append(ANSWERS_COLLECTION.find_one({'_id': ObjectId(answer)}))
     except TypeError:
         answers = []
     return answers
Exemplo n.º 3
0
    def post_answer(self):
        ansID = ANSWERS_COLLECTION.insert_one({
                    'postedBy': self.postedBy, 'quesID': self.quesID,
                    'ansText': self.ansText, 'timestamp': self.timestamp,
                    'quesID': self.quesID, 'commentID': [], 'votes': 0,
                    'flaggedBy': [], 'flag': 'False'}).inserted_id

        usr = User(self.postedBy)
        usr.update_answers(str(ansID))
        ques = QuestionMethods(self.quesID)
        ques.insert_answers(str(ansID))
        return ansID
Exemplo n.º 4
0
    def post_answer(self):
        ansID = ANSWERS_COLLECTION.insert_one({
            'posetdBy': self.posetdBy,
            'quesID': self.quesID,
            'ansText': self.ansText,
            'timestamp': self.timestamp,
            'quesID': self.quesID
        }).inserted_id

        usr = User(self.posetdBy)
        usr.update_answers(str(ansID))
        ques = QuestionMethods(self.quesID)
        ques.update_answers(str(ansID))
        return ansID
Exemplo n.º 5
0
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)
Exemplo n.º 6
0
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)
Exemplo n.º 7
0
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)
Exemplo n.º 8
0
 def removeFlag(self, userID):
     ANSWERS_COLLECTION.find_one_and_update({'_id': ObjectId(self.ansID)}, {'$pull': {'flaggedBy': userID}})
Exemplo n.º 9
0
 def getFlag(self):
     return (ANSWERS_COLLECTION.find_one({'_id': ObjectId(self.quesID)}))['flag']
Exemplo n.º 10
0
 def setFlag(self, flag):
     ANSWERS_COLLECTION.find_one_and_update({'_id': ObjectId(self.quesID)}, {'$set': {'flag': flag}})
Exemplo n.º 11
0
 def updateVotes(self, username, vote):
     ANSWERS_COLLECTION.find_one_and_update({'_id': ObjectId(self.ansID)}, {'$inc' : {'votes': vote}})
     votes = (ANSWERS_COLLECTION.find_one({'_id': ObjectId(self.ansID)}))['votes']
     return votes
Exemplo n.º 12
0
 def update_comments(self, commentID):
     ANSWERS_COLLECTION.find_one_and_update({'_id': ObjectId(self.ansID)}, {'$addToSet': {'commentID': commentID}})
Exemplo n.º 13
0
 def getAnswer(self):
     return (ANSWERS_COLLECTION.find_one({'_id': ObjectId(self.ansID)}))