Пример #1
0
def add_to_module1(file_id):
    # Check if the user logged in or not. if not logged in then redirect to login
    if session.get('email'):
        file = File.objects(id=file_id).first()
        # get the logged in user school
        # finally add the file to the module1 array
        user = User.objects().filter(email=session.get('email')).first()
        if user.user_type == 'instructor' or user.user_type == 'admin':
            user_school = School.objects(id=user.school.id).first()
            user_school_module1 = Module1.objects(
                id=user_school.module1.id).first()
            user_school_module1.files.append(file.id)
            user_school_module1.save()
            return redirect(url_for('files.file_list'))
    else:
        return redirect(url_for('login'))
Пример #2
0
def chat_create(module):
    if session.get('email'):
        form = ChatForm(request.form)
        user = User.objects().filter(email=session.get('email')).first()
        if user.user_type == 'instructor' or user.user_type == 'admin':
            if request.method == 'POST' and form.validate():
                # save the chat and it will return id of that chat
                chat = Chat()
                chat.user = user.id
                chat.description = form.description.data
                chat.save()
                user_school = School.objects(id=user.school.id).first()
                # finally push the id of the chat in the user_school module
                if module == 'module1':
                    flash('Chat Successfully Added to Module1 !')
                    # get the module 1 by it's user_school module1
                    user_school_module1 = Module1.objects(
                        id=user_school.module1.id).first()
                    user_school_module1.chats.append(chat.id)
                    user_school_module1.save()
                elif module == 'module2':
                    flash('Chat Successfully Added to Module2 !')
                    user_school_module2 = Module2.objects(
                        id=user_school.module2.id).first()
                    user_school_module2.chats.append(chat.id)
                    user_school_module2.save()
                elif module == 'module3':
                    flash('Chat Successfully Added to Module3 !')
                    user_school_module3 = Module3.objects(
                        id=user_school.module3.id).first()
                    user_school_module3.chats.append(chat.id)
                    user_school_module3.save()
                # save the user_school
                user_school.save()
                # Finally redirect the user to the chat-create
                # With a Flash Message that Chat Successfully Created
                return redirect(url_for('schools.chat_create', module=module))
        else:
            return redirect(url_for('students.profile'))
        return render_template('chat-create.html',
                               form=form,
                               user=user,
                               module=module)
    else:
        return redirect(url_for('login'))