Example #1
0
def join_class_info_update(data):
    user = db.course_users.find_one({'username': session['username']})
    if user == None:
        user = {'username': session['username'], 'course_id': []}
        db.course_users.insert_one(user)
        user = db.course_users.find_one({'username': session['username']})

    courses = user['course_id']
    if data['course_id'] not in courses:
        user['course_id'].append(data['course_id'])
        # db.courses.replace_one({'_id': ObjectId(self.course_id)}, course)
        db.course_users.replace_one({'username': session['username']}, user)

    course_id = data['course_id']
    if len(course_id) != 24:
        return -1
    got_ret = space_check(str(course_id))
    if got_ret == -1:
        return -1
    course = db.courses.find_one({'_id': ObjectId(course_id)})
    if course == None:
        return -1
    users = course['enrolled']
    if session['username'] not in users:
        NotificationSender.Sender(course_id,
                                  "").register_observer(session['username'])
    else:
        return 2

    return 1
Example #2
0
def update_post(data , course_id):
    # postdetails=post(data['message'],data['files'],session['username'], course_id)
    postdetails=Post.PostBuilder(course_id)\
        .with_author(session['username'])\
        .with_text(data['message'])\
        .with_links(data['links'])\
        .build()
    post_id=save_to_database1(postdetails)
    # print(session['username'])
    course = db.courses.find_one({'_id': ObjectId(course_id)})
    course_name = course['course_name']
    notification = {"course_id":course_id, "course_name":course_name,"notification_type": "post", "username": session['username']}
    NotificationSender.Sender(course_id, notification).notify_observer()
    return
def update_post(data, course_id):

    postdetails = post(data['message'], data['files'], session['username'],
                       course_id)
    post_id = save_to_database(postdetails)
    #print(session['username'])
    course = db.courses.find_one({'_id': ObjectId(course_id)})
    course_name = course['course_name']
    notification = {
        "course_id": course_id,
        "course_name": course_name,
        "username": session['username']
    }
    NotificationSender.Sender(course_id, notification).notify_observer()
    return
Example #4
0
def show_news_feed(course_id):
    pymongo_cursor = db.classroom_newsfeed.find({'course_id':course_id})
    all_data = list(pymongo_cursor)
    data = all_data
    # print(data)
    data.reverse()
    # print(data)
    course = db.courses.find_one({'_id':ObjectId(course_id)})
    users = course['enrolled']
    if session['username'] not in users:
        NotificationSender.Sender(course_id, "").register_observer(session['username'])
    notifications = db.notifications.find_one({'username': session['username']})
    if notifications == None:
        notifications = []
    else:
        notifications = notifications['notifications']
    notifications.reverse()
    return course, data, users, notifications
Example #5
0
def leave_class_info_update(course_id):
    course = db.courses.find_one({'_id': ObjectId(course_id)})
    if course is None:
        return
    NotificationSender.Sender(course_id,
                              "").remove_observer(session['username'])
    user_info = db.course_users.find_one({'username': session['username']})
    if user_info is None:
        # print(user_info)
        # print(session['username'])
        return
    # print(user_info['course_id'])
    if course_id in user_info['course_id']:
        user_info['course_id'].remove(course_id)
    if ObjectId(course_id) in user_info['course_id']:
        user_info['course_id'].remove(ObjectId(course_id))
    # print(user_info['course_id'])
    db.course_users.replace_one({'username': session['username']}, user_info)
    return