Skip to content

Commit

Permalink
left with new_assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
happi4 committed Jan 19, 2021
1 parent 8e78b26 commit 16f14d3
Show file tree
Hide file tree
Showing 50 changed files with 1,430 additions and 750 deletions.
Binary file modified .DS_Store
Binary file not shown.
3 changes: 0 additions & 3 deletions .idea/.gitignore

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/CVS/Entries

This file was deleted.

1 change: 0 additions & 1 deletion .idea/CVS/Repository

This file was deleted.

1 change: 0 additions & 1 deletion .idea/CVS/Root

This file was deleted.

Empty file removed .idea/CVS/Template
Empty file.
1 change: 0 additions & 1 deletion .idea/inspectionProfiles/CVS/Entries

This file was deleted.

1 change: 0 additions & 1 deletion .idea/inspectionProfiles/CVS/Repository

This file was deleted.

1 change: 0 additions & 1 deletion .idea/inspectionProfiles/CVS/Root

This file was deleted.

Empty file.
6 changes: 0 additions & 6 deletions .idea/inspectionProfiles/profiles_settings.xml

This file was deleted.

7 changes: 0 additions & 7 deletions .idea/misc.xml

This file was deleted.

8 changes: 0 additions & 8 deletions .idea/modules.xml

This file was deleted.

10 changes: 0 additions & 10 deletions .idea/onlineLearner.iml

This file was deleted.

Binary file removed __pycache__/__init__.cpython-39.pyc
Binary file not shown.
Binary file added __pycache__/app.cpython-38.pyc
Binary file not shown.
Binary file removed __pycache__/app.cpython-39.pyc
Binary file not shown.
Binary file removed __pycache__/connect.cpython-38.pyc
Binary file not shown.
Binary file removed __pycache__/connect.cpython-39.pyc
Binary file not shown.
Binary file added __pycache__/forms.cpython-38.pyc
Binary file not shown.
Binary file removed __pycache__/user.cpython-39.pyc
Binary file not shown.
Binary file removed __pycache__/userStore.cpython-39.pyc
Binary file not shown.
275 changes: 181 additions & 94 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
from flask import Flask, request, render_template, redirect, url_for, flash
from flask_caching import Cache
import dao.connect
import threading
import csv
import re
import beans.fach
import dao.application_dao
import dao.dao as dao
from beans import fach
import forms

"""For cache"""
configurations = {
"DEBUG": True,
"CACHE_TYPE": "simple",
"CACHE_DEFAULT_TIMEOUT": 300
}


app = Flask(__name__, template_folder='template')
app.secret_key = b'hdgsJ%82/"*dbh#'
#For cache
app.config.from_mapping(configurations)
cache = Cache(app)


def csv_reader(path):
Expand All @@ -23,117 +35,154 @@ def csv_reader(path):
config = csv_reader("properties.settings")


@app.route("/<bid>/", methods=['GET', 'POST'])
@app.route("/<bid>", methods=['GET', 'POST'])
@app.route("/<bid>/", methods=['GET', 'POST'])
#@cache.memoize()
def index(bid):
"""Erste Seite der Webseite: """
user_store = dao.application_dao.ApplicationDao()

meine_kurse = user_store.get_my_courses(bid)
verf_kurse = user_store.get_all_other_courses(bid)

#result = False
#if request.method == "POST":
# Form data
#name = request.form['course_name']
#enroll_key = request.form.get('schluessel')
#free_spots = request.form.get('freie_plaetze')
#desc = request.form.get('btext')

#print(name, bid, enroll_key, free_spots, desc)

#new_course = fach.Kurs(name, bid, free_spots, desc, enroll_key)

#course_store = dao.application_dao.ApplicationDao()

#course_id = course_store.add_course(new_course) # Muss eine valide kid zurückliefern
#print(course_id, bid)
#course_store.completion()
#course_store.close()

#if course_id is not None: #Wenn course_id nicht NULL ist, ist es valid #TODO
#with threading.Lock():
#user_store.einschreiben(bid, course_id, enroll_key) #Add owner to course, Fix

#user_store.completion()
#user_store.close()

# TODO res=result
return render_template('index.html', mkurse=meine_kurse, vkurse=verf_kurse, bid=bid)

"""
Erste Seite der Webseite
"""
user = dao.Dao()
title = "Hauptseite"
form = forms.CourseForm()
meine_kurse = user.get_my_courses(bid)
verf_kurse = user.get_available_courses(bid)

return render_template('index.html', mkurse=meine_kurse, vkurse=verf_kurse,
bid=bid, title=title, form=form)

@app.route("/<bid>/new_course", methods=['POST', 'GET'])
def new_course(bid):
return render_template("new_course.html", bid=bid)


@app.route("/<bid>/view_course", methods=['POST', 'GET'])
def view_course(bid):
info_store = dao.application_dao.ApplicationDao()
kname = str(request.form.get("kname"))
ersteller = str(request.form.get("ersteller"))
fp = request.form.get("fp")

#print(bid)

#Einschreibeschlüssel, wenn vorhanden. Wird benutzt zu prüfen, ob ein Schlüssel stimmt
reg_key = info_store.get_key(kname, ersteller)

#course owner
owner = info_store.get_course_owner(kname)
#print(owner)

desc = info_store.get_course_details(kname, ersteller)

# Read details for above data from database

#course id
kid = info_store.get_kid(kname, ersteller)
"""
Kurs erstellen
"""
course = dao.Dao()
title = "Kurs Erstellen"
#form = forms.AddCourseForm(name = "Klaus")
form = forms.AddCourseForm()
if form.validate_on_submit():
name = str(form.name.data)
desc = str(form.desc.data)
spaces = form.spaces.data
key = str(form.key.data)
#print(name, desc, spaces, bid, key)
error = course.add_course(name, desc, spaces, bid, key)
if error is None:
flash("Course successfully created")
else:
flash("Failed to create course.")
return redirect(url_for('index', bid=bid))
return render_template("new_course.html", title=title, bid=bid, form=form)

#print(ersteller)
#print(kid)
#print(bid)

#check resgistrstion status. Returns True or False
registered = info_store.is_registered(bid, kid)
@app.route("/<bid>/<kid>/view_course", methods=['POST', 'GET'])
#@cache.memoize()
def view_course(bid, kid):
info = dao.Dao()

#print(bid, kid)
#print(registered)
#form_get = forms.CourseForm(request.form)

exercises = None
title = "Kurs Details"
kurs = info.get_course_details(kid)
form = forms.CourseDetailForm()
registered = info.is_registered(bid, kid)

#Get exercises for kid retieved
exercises = info_store.get_ex_list(kid, int(bid))

# TODO: Different view for ersteller


return render_template("view_course.html", bid=bid, kname=kname, desc=desc, fp=fp,
ersteller=ersteller, schluessel=reg_key, owner=owner, exercises=exercises,
registered=registered, kid=kid)


@app.route('/<bid>/new_enroll', methods=['POST', 'GET'])
def new_enroll(bid):
kname = request.form.get("kname")
ersteller = request.form.get("ersteller")

form_ex = forms.ExercisesForm()
exercises = info.get_exercises(kid, bid)

#print(exercises)
# form has been posted and submission exists
if request.form.get("submission"):
flash("Das neues Einreichen ist nicht möglich")
return redirect(url_for('index', bid=bid))

#Einschreiben ohne Schlüssel
if request.method == 'POST' and request.form.get('status') == 'register': #status code for registration
status = info.add_to_course(bid, kid) # key is none
if status == True:
flash("Enrollment to course successfull")
elif status == False:
flash("An error occured while registering")
return redirect(url_for('view_course', bid=bid, kid=kid))

return render_template("view_course.html", bid=bid, exercises=exercises,
form_ex=form_ex, registered=registered, kid=kid, title=title, form=form, kurs=kurs)


@app.route('/<bid>/<kid>/new_enroll', methods=['POST', 'GET'])
def new_enroll(bid, kid):
"""
Ein Benutzer schreibt sich ein
"""
course = dao.Dao()
form = forms.EnrollmentForm(request.form)
kname = form.course_name.data
print(kname, kid)

# status code
#if request.method == 'POST' and course.get_course_key(kid) is None and request.form.get('status') == 'register':

if form.validate_on_submit():
status = course.add_to_locked_course(bid, kid, form.key.data)
if status == True:
flash("Enrollment to course successfull")
elif status == False:
flash("Enrollment failed because of wrong key")
elif status == None:
flash("An error occured")
return redirect(url_for('view_course', bid=bid, kid=kid))

return render_template('new_enroll.html', bid=bid, kname=kname, ersteller=ersteller)
return render_template('new_enroll.html', bid=bid, kid=kid, kname=kname, form=form)


@app.route('/<bid>/new_assignment', methods=['POST', 'GET'])
def new_assignment(bid):

store_submission = dao.application_dao.ApplicationDao()
title = "Abgabe Einreichen"

form_get = forms.ExercisesForm(request.form)
ex_name = form_get.ex_name_hidden.data
course_name = form_get.course_name.data
anummer = form_get.ex_id.data
kid = form_get.course_id.data

#print(form_get.ex_id.data)

form = forms.ExerciseSubmissionForm()
#form.course_name.data = form_get.course_name.data
#form.course_id.data = form_get.course_id.data
#form.user_id.data = bid
#form.ex_id.data = form_get.ex_id.data

new_submission = dao.Dao()

if request.method == "POST" and request.form.get("submit"):

#print(form.ex_name.data, form.course_name.data,
#form.course_id.data, form.user_id.data, form.sub_text.data)
text = form.sub_text.data
new_submission.add_sub_text(text) # Insert into abgabe
aid = new_submission.get_aid(text)
print(aid)
kid = form.course_id.data
anummer = form.ex_id.data
print(bid, kid, anummer, aid)
status = new_submission.add_sub_ref(int(bid), int(kid), int(anummer), int(aid)) #TODO
if status is True:
flash("Submission has been registered successfully")
else:
flash("Failed to submit your work")
return redirect(url_for("view_course", bid=bid))


kid = request.form.get('kid')
#kid = request.form.get('kid')

anummer = request.form.get('anummer')
#anummer = request.form.get('anummer')

kname = request.form.get('kname')
#kname = request.form.get('kname')

ex_name = request.form.get('ex_name')
#ex_name = request.form.get('ex_name')


#TODO: decription
Expand All @@ -147,7 +196,45 @@ def new_assignment(bid):

#print(is_duplicate) TODO

return render_template('new_assignment.html', kname=kname, ex_name=ex_name)
return render_template('new_assignment.html', ex_name=ex_name, form=form, title=title,
course_name=course_name, anummer=anummer, kid=kid)


@app.route('/<bid>/<kid>/delete', methods=['GET', 'POST'])
def delete(bid, kid):
"""
Kurs löschen. Nur der Ersteller kann einen Kurs löschen
"""
user = dao.Dao()
if request.method == "POST":
#Delete course
form_delete = forms.CourseDetailForm(request.form)
kname = form_delete.course_name.data
kid = form_delete.course_id.data
owner = form_delete.creator_id.data
print(kid, owner)
if owner == bid:
#print(kid, owner)
status = user.delete_course(kid)
print(status)
if status == True:
success = "Deleted course " + kname + " successfully"
flash(success)
return redirect(url_for("index", bid=bid))
else:
exception = "An error occured while deleting the course" + kname
return redirect(url_for("view_course", bid=bid, kid=kid))
else:
#Kurs Löschen für Nichtersteller
# status code for deletion
#if request.method == 'POST' and request.form.get('status') == 'delete':
failure = "Failed to delete " + kname + \
" because you are not the course creator!"
flash(failure)
return redirect(url_for("view_course", bid=bid, kid=kid))





@app.route('/onlineLearner', methods=['GET'])
Expand All @@ -166,8 +253,8 @@ def onlineLearn():





if __name__ == "__main__":
port = int("9" + re.match(r"([a-z]+)([0-9]+)", config["username"], re.I).groups()[1])
app.run(host='0.0.0.0', port=port, debug=True)
app.add_url_rule(
'/favicon.ico', redirect_to=url_for('static', filename='favicon.ico'))
Binary file added beans/__pycache__/benutzer.cpython-38.pyc
Binary file not shown.
Binary file added beans/__pycache__/fach.cpython-38.pyc
Binary file not shown.
Binary file added dao/__pycache__/connect.cpython-38.pyc
Binary file not shown.
Binary file added dao/__pycache__/dao.cpython-38.pyc
Binary file not shown.
Binary file added dao/__pycache__/queries.cpython-38.pyc
Binary file not shown.
Loading

0 comments on commit 16f14d3

Please sign in to comment.