Esempio n. 1
0
 def update_votes(self, username, vote=[1, -1]):
     ANSWERS_COLLECTION.find_one_and_update({'_id': ObjectId(self.ansID)},
                                            {'$inc': {
                                                'votes': vote
                                            }})
     usr = User(username)
     usr.update_karma(vote)
Esempio n. 2
0
def login():
    form = LoginForm()
    if request.method == 'POST' and form.validate_on_submit():
        user = USERS_COLLECTION.find_one({"_id": form.username.data})
        if user and User.validate_login(user['password'], form.password.data):
            user_obj = User(user['_id'])
            login_user(user_obj, remember=True)
            flash("Logged in successfully!", category='success')
            return redirect(url_for('home'))
        flash("Wrong username or password!", category='error')
    return render_template('login.html', title='HoverSpace | Login', form=form)
Esempio n. 3
0
 def post_question(self):
     quesID = QUESTIONS_COLLECTION.insert_one({
         'short_description': self.short_description,
         'long_description': self.long_description,
         'posetdBy': self.posetdBy,
         'timestamp': self.timestamp,
         'ansID': []
     }).inserted_id
     usr = User(self.posetdBy)
     usr.update_questions(str(quesID))
     return quesID
Esempio n. 4
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
Esempio n. 5
0
def setBookmark(quesID):
    usr = User(current_user.get_id())
    fl = usr.setBookmark(quesID)
    #print(fl)
    if fl:
        return json.dumps({
            'status':
            'true',
            'message':
            'This question has been successfully bookmarked'
        })
    else:
        return json.dumps({'status': 'false', 'message': 'Bookmark removed'})
Esempio n. 6
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"
Esempio n. 7
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
Esempio n. 8
0
 def postQuestion(self):
     quesID = QUESTIONS_COLLECTION.insert_one({
         'postedBy': self.postedBy,
         'short_description': self.short_description,
         'long_description': self.long_description,
         'timestamp': self.timestamp,
         'ansID': [],
         'commentID': [],
         'votes': 0,
         'accepted_ans': None,
         'flag': False
     }).inserted_id
     usr = User(self.postedBy)
     usr.update_questions(str(quesID))
     return quesID
Esempio n. 9
0
def signup():
    form = SignUpForm()
    if request.method == 'POST' and form.validate_on_submit():
        user = USERS_COLLECTION.find_one( {'email': form.email.data} )
        if user:
            flash("You have already signed up from this email id", category='error')
        else:
            user = USERS_COLLECTION.find_one( {'_id': form.username.data} )
            if user:
                flash("That username has already been taken", category='error')
            else:
                user_obj = User(form.username.data, form.email.data, form.firstname.data,
                        form.lastname.data, form.password.data, db=True)
                flash("SignUp successfull!", category='success')
                return redirect(url_for('login'))
    return render_template('signup.html', title='HoverSpace | Signup', form=form)
Esempio n. 10
0
def updateVotes(quesID):
    rd = (request.data).decode('utf-8')
    data = json.loads(rd)
    voteType = data['voteType']
    print(voteType)

    usr = User(current_user.get_id())
    status = usr.voteQues(quesID, voteType)
    print(status)

    ques_obj = QuestionMethods(quesID)
    votesCount = ques_obj.updateVotes(status['votesChange'])

    postedBy = (ques_obj.getQuestion())['postedBy']
    usr = User(postedBy)
    usr.update_karma(status['votesChange'])
    print(status['type'], votesCount)
    return json.dumps({'type': status['type'], 'count': votesCount})
Esempio n. 11
0
def updateAnsVotes(ansID):
    rd = (request.data).decode('utf-8')
    data = json.loads(rd)
    voteType = data['voteType']
    print(voteType)

    ans_obj = UpdateAnswers(ansID)
    postedBy = (ans_obj.getAnswer())['postedBy']

    if current_user.get_id() == postedBy:
        return json.dumps({'type': 'notAllowed'})

    usr = User(current_user.get_id())
    status = usr.voteAns(ansID, voteType)
    print(status)

    votesCount = ans_obj.updateVotes(postedBy, status['votesChange'])

    usr = User(postedBy)
    usr.update_karma(status['votesChange'])
    print(status['type'], votesCount)
    return json.dumps({'type': status['type'], 'count': votesCount})
Esempio n. 12
0
def load_user(username):
    u = USERS_COLLECTION.find_one({"_id": username})
    if not u:
        return None
    return User(u['_id'])