Пример #1
0
def add_note(lessonid):
    """Route to render AddNoteForm or process AddNoteForm to create a Note

    **NOTE: This does not actually upload the file to S3. That is done via AJAX.**

    """
    form = AddNoteForm()
    if form.validate_on_submit():
        # TODO: Add error handling
        filename = form.filename.data
        month = datetime.now().month
        semester = Semester.current_semester()
        print(form.file.data)
        note = Note.create(filename=filename,
                           s3_filename=form.file_hash.data,
                           uploader=g.user.user_id,
                           description=form.description.data,
                           lesson=lessonid,
                           semester=semester.value,
                           year=datetime.now().year,
                           original_filename=form.file.data.filename)
        g.user.karma_points += KarmaPoints.upload_note.value
        g.user.save()

        return redirect(url_for(".view", lessonid=lessonid))
    return render_template('notes/add_note.html', form=form)
Пример #2
0
def add_exam(lessonid):
    """Route to either display the form to upload exams or create a new Exam object

    **NOTE: THIS DOES NOT ACTUALLY UPLOAD THE FILE. THAT IS DONE VIA AJAX**"""
    form = AddExamForm()
    try:
        lesson = Lesson.get(Lesson.id == lessonid)
    except:
        flash('Id not found', 'error')
        return redirect(url_for('auth_bp.profile'))
    if form.validate_on_submit():
        Exam.create(average_grade=-1,
                    filename=form.filename.data,
                    s3_filename=form.file_hash.data,
                    lesson=lesson.id,
                    publisher=g.user.user_id,
                    number_of_takers=-1,
                    year=datetime.now().year,
                    semester=Semester.current_semester().value,
                    description=form.description.data)
        g.user.karma_points += KarmaPoints.upload_exam.value
        g.user.save()

        return redirect(url_for(".view", lessonid=lesson.id))

    return render_template("exams/add-exam.html", form=form)
Пример #3
0
 def attend(cls, user_id, lesson_ids):
     """Class method to create LessonStudent objects for every lesson a user wants to attend"""
     users_school = User.get(User.user_id == user_id).school_id
     for lesson_id in lesson_ids:
         lesson = Lesson.get(Lesson.id == lesson_id)
         if lesson.school_id != users_school:
             raise ValueError(
                 "Lesson id {} does not corrospond to the same school as the user"
                 .format(lesson.school_id))
     for lesson_id in lesson_ids:
         semester = Semester.current_semester()
         LessonStudent.create(student_id=user_id,
                              lesson_id=lesson_id,
                              semester=semester.value,
                              year=datetime.now().year)