Exemplo n.º 1
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)
Exemplo n.º 2
0
def view(lessonid):
    """Route to display all users and their options"""
    try:
        lesson = Lesson.get(Lesson.id == lessonid)
    except:
        flash('Id not found', 'error')
        return redirect(url_for('auth_bp.profile'))

    # Get all users in lesson
    query = LessonStudent.select().where(LessonStudent.lesson_id == lesson.id)
    data = []

    semsters = set()
    for ls in query:
        user_options = UserOption.select().where((UserOption.user == ls.student_id.user_id) & (UserOption.agreed == True))
        user_options_list = [uo.option.name for uo in user_options if uo.option.lesson.id == lesson.id]
        if len(user_options_list) < 1:
            continue
        user = User.get(User.user_id == ls.student_id.user_id)
        data.append({'name': user.first_name + " " + user.last_name,
                     'email': user.email,
                     'options': user_options_list,
                     'semester': ls.semester,
                     'year': ls.year})
        semsters.add((ls.year, ls.semester))
    print(sorted(semsters))
    return render_template('search/listing.html', lesson=lesson, users=data, semesters=sorted(semsters))
Exemplo n.º 3
0
def index(lessonid):
    """Route to render the chat template for a given lesson"""
    try:
        lesson = Lesson.get(Lesson.id == lessonid)
    except:
        flash('Id not found', 'error')
        return redirect(url_for('auth_bp.profile'))
    return render_template('chat/listing.html', lesson=lesson)
Exemplo n.º 4
0
def view(lessonid):
    """Route to display all the studygroups for a Lesson"""
    try:
        lesson = Lesson.get(Lesson.id == lessonid)
    except:
        flash('Id not found', 'error')
        return redirect(url_for('auth_bp.profile'))
    study_groups = [sg for sg in StudyGroup.select().where(StudyGroup.lesson == lessonid)]
    form = AddStudyGroupForm()
    lesson_ids = [ls.lesson_id for ls in LessonStudent.select().where(LessonStudent.student_id == g.user.user_id)]
    if len(lesson_ids) < 1:
        flash("You do not have any lessons", 'warning')
        return redirect(url_for("auth_bp.profile"))
    else:
        lessons = Lesson.select().where(Lesson.id << lesson_ids)
        form.lesson.choices = [(str(lesson.id), lesson.lesson_name) for lesson in lessons]
    contact_form = ContactOrganiserForm()
    studygroup_session_form = AddStudyGroupSessionForm()
    return render_template('studygroups/study_groups_listing.html', lesson=lesson, study_groups=study_groups,
                           form=form, contact_form=contact_form, studygroup_session_form=studygroup_session_form)
Exemplo n.º 5
0
 def get(self, requests, *args, **kwargs):
     INSERT_DATA = []
     results = make_requests()
     for result in results:
         username = result["login"]["username"]
         street = result["location"]["street"]
         INSERT_DATA.append(Lesson(name=username, detail=street))
     Lesson.objects.bulk_create(
         INSERT_DATA
     )  # her bir db kaydı için sorgu(insert) oluşturup işliyor
     queryset = Lesson.objects.all()  # dbdeki bütün verileri getir
     serializer = LessonSerializer(
         queryset, many=True)  # getirilen verileri serializera koy
     return HttpResponse("Created User Data")
Exemplo n.º 6
0
def view(lessonid):
    """Route to display the listing of Questions for a lesson"""
    try:
        lesson = Lesson.get(Lesson.id == lessonid)
    except:
        flash('Id not found', 'error')
        return redirect(url_for('auth_bp.profile'))

    questions = Question.select().where(Question.lesson == lessonid).limit(10)
    last_posts = {}
    semesters = set()

    for question in questions:
        semesters.add((question.year, question.semester))

        reply = Reply.select().where(Reply.question == question.id).order_by(
            Reply.datetime).limit(1)
        try:
            last_posts[question.name] = [r for r in reply][0]
        except:
            pass

    print(request.form)

    form = AddQuestionForm()

    # try:
    #     print("name", session['name'])
    #     if session['add_question_data']:
    #         session['add_question_data'] = False
    #         form.name.data = session['name']
    #         form.content.data = session['content']
    #         form.document.data = session['document']
    #         form.validate()
    #
    # except KeyError as e:
    #     print(e)

    comment_form = AddReplyForm()

    return render_template('qa/qa_listing.html',
                           lesson=lesson,
                           questions=questions,
                           form=form,
                           last_posts=last_posts,
                           semesters=sorted(semesters),
                           comment_form=comment_form)
Exemplo n.º 7
0
def view(lessonid):
    """Route that lists the exams for a lesson"""
    try:
        lesson = Lesson.get(Lesson.id == lessonid)
    except:
        flash('Id not found', 'error')
        return redirect(url_for('auth_bp.profile'))
    exams = Exam.select().where(Exam.lesson == lessonid)
    semesters = set()
    for exam in exams:
        semesters.add((exam.year, exam.semester))
    print(semesters)
    form = AddExamForm()

    return render_template('exams/exam_listing.html',
                           lesson=lesson,
                           exams=exams,
                           semesters=sorted(semesters),
                           form=form)
Exemplo n.º 8
0
def add_studygroup():
    """Route to either render the AddStudyGroupForm or to process it and create a new StudyGroup"""
    form = AddStudyGroupForm()
    lesson_ids = [ls.lesson_id for ls in LessonStudent.select().where(LessonStudent.student_id == g.user.user_id)]
    if len(lesson_ids) < 1:
        flash("You do not have any lessons", 'warning')
        return redirect(url_for("auth_bp.profile"))
    else:
        lessons = Lesson.select().where(Lesson.id << lesson_ids)
        form.lesson.choices = [(str(lesson.id), lesson.lesson_name) for lesson in lessons]

    if form.validate_on_submit():
        study_group = StudyGroup.create(
            location=form.location.data,
            lesson=form.lesson.data,
            founder=g.user.user_id
        )
        StudyGroupMembers.create(
            user=g.user.user_id,
            study_group=study_group
        )
        return redirect(url_for(".view", lessonid=form.lesson.data))
    return render_template('studygroups/add_studygroup.html', form=form)
Exemplo n.º 9
0
def options(lessonid):
    """Route to display the UserOptionsForm and handle its submission"""
    try:
        lesson = Lesson.get(Lesson.id == lessonid)
    except:
        flash('Id not found', 'error')
        return redirect(url_for('auth_bp.profile'))

    for option in Option.select().where(Option.lesson == lesson.id):
        user_option = UserOption.get_or_create(option=option.id, user=g.user.user_id)[0]
        print(user_option.agreed)
        setattr(UserOptionsForm, option.name, BooleanField(option.description, default=user_option.agreed))

    form = UserOptionsForm()

    if form.validate_on_submit():
        for key, value in form.data.items():
            option = Option.get(Option.name == key)
            user_option = UserOption.get(option=option.id, user=g.user.user_id)
            user_option.agreed = value
            user_option.save()
        return redirect(url_for("auth_bp.profile"))

    return render_template('search/options.html', form=form)
Exemplo n.º 10
0
def view(lessonid):
    """Route to display the notes listing for a particular lesson"""
    try:
        lesson = Lesson.get(Lesson.id == lessonid)
    except:
        flash('Id not found', 'error')
        return redirect(url_for('auth_bp.profile'))

    notes = Note.select().where(Note.lesson == lessonid).order_by(
        -Note.year, +Note.semester)
    semesters = set()
    for note in notes:
        semesters.add((note.year, note.semester))

    if g.user.has_permission('note_admin'):
        form = AdminAddNoteForm()
    else:
        form = AddNoteForm()

    return render_template('notes/notes_listing.html',
                           lesson=lesson,
                           notes=notes,
                           semesters=sorted(semesters),
                           form=form)
Exemplo n.º 11
0
import json
from app.auth.models import School
from app.lesson.models import Lesson, Professor

f = open("data2.json")
data = json.load(f)

school = School.get()

for key, value in data.items():
    if value["link"] is not None and "professors" in value.keys(
    ) and value["professors"][0] is not None:
        for p in value["professors"]:
            lesson = Lesson.create(code=key,
                                   lesson_name=value["title"],
                                   school_id=school.school_id)
            if p is not None:
                name = p.split(" ")
                Professor.create(lesson_id=lesson.id,
                                 first_name=name[0],
                                 last_name=name[1])
from app.lesson.models import Lesson, Professor
from playhouse.migrate import *
from app.models import DATABASE

for lesson in Lesson.select():
    professors = lesson.professor.split(" & ")
    for professor in professors:
        if professor == 'Unknown':
            Professor.create(lesson_id=lesson.id,
                             first_name='Unknown',
                             last_name='')
        elif professor == 'Instructor: TBA':
            Professor.create(lesson_id=lesson.id,
                             first_name='Instructor: TBA',
                             last_name='')
        else:
            names = professor.split(" ")
            Professor.create(lesson_id=lesson.id,
                             first_name=names[0],
                             last_name=names[1])

migrator = PostgresqlMigrator(DATABASE)

migrate(migrator.drop_column('TBL_LESSON', 'PROFESSOR'))