Ejemplo n.º 1
0
def signup():
    dbrows = db.getCompetitions()
    competition = request.args.get("competition")
    return render_template("registration.html",
                           competitionselected=competition,
                           registrationmessage="",
                           dbrows=dbrows)
Ejemplo n.º 2
0
def account(accountmessage=""):
    try:
        accountmessage = accountmessage
        competition = ""
        dbrows = {}
        dbcompetitions = []

        playerid = session.get("mobileno")

        if playerid is not None:
            dbcompetitions = db.getCompetitions()
            dbrows = db.getAccount(playerid)

            if len(dbrows) > 0:
                competition = dbrows["competitionname"]
            else:
                accountmessage = "Account data not found"
        else:
            accountmessage = "Please login before accessing account."

        return render_template("account.html",
                               accountmessage=accountmessage,
                               competitionselected=competition,
                               dbrows=dbrows,
                               dbcompetitions=dbcompetitions)
    except Exception as ex:
        print(ex)
        loginmessage = "Please login before changing account settings."

        return render_template("account.html",
                               accountmessage=ex,
                               competitionselected="",
                               dbrows=dbrows,
                               dbcompetitions=dbcompetitions)
Ejemplo n.º 3
0
def home():
    dbrows = db.getCompetitions()

    return render_template("home.html", dbrows=dbrows)
Ejemplo n.º 4
0
def uploadassessment():
    dbclassrows = []

    try:
        userid = session.get("admno")
        if userid is None:
            flash("Please Login as teacher / admin.")
            return redirect(url_for('home'))

        #if db.authorize(player_id, utility.Authorization.TEACHER):
        if not db.isTeacher(userid):
            flash("Please Login as teacher.")
            return redirect(url_for('home'))

        if request.method == 'GET':
            dbclassrows = db.getClasses()
            dbassessmentrows = db.getAssessmentToRemove(userid)
            dbassessmentrowschangedate = db.getCompetitions()
            return render_template(
                "assessmentupload.html",
                dbclassrows=dbclassrows,
                dbassessmentrows=dbassessmentrows,
                dbassessmentrowschangedate=dbassessmentrowschangedate,
                isloggedin=True)
        elif request.method == 'POST':
            # check if the post request has the file part
            if 'qpfile' not in request.files:
                flash('No question paper file')
                return redirect(request.url)

            if 'akfile' not in request.files:
                flash('No answer-key paper file')
                return redirect(request.url)

            qpfile = request.files['qpfile']
            qpjpgfiles = ""

            akfile = request.files['akfile']
            # if user does not select file, browser also
            # submit an empty part without filename
            if qpfile.filename == '' or akfile.filename == '':
                flash('File not selected')
                return redirect(request.url)

            if qpfile and utility.allowed_qpaperfile_extensions(
                    qpfile.filename):
                folder_name = config.get("QPAPER", "UPLOAD_FOLDER_NAME")
                folder_path = config.get("QPAPER", "UPLOAD_FOLDER")
                secfilename = secure_filename(qpfile.filename)

                fnsplit = secfilename.split(".")
                qpfilename = fnsplit[0] + datetime.datetime.now().strftime(
                    "_%Y%m%d_%I-%M-%S_%p") + "." + fnsplit[1]

                qpfile.save(os.path.join(folder_path, qpfilename))

                qpjpgfiles = utility.convert_qpaper(folder_path, qpfilename,
                                                    folder_path, folder_name)

                if akfile and utility.allowed_answerkeyfile_extensions(
                        akfile.filename):
                    folder_path = config.get("QPAPER", "UPLOAD_FOLDER")
                    secfilename = secure_filename(akfile.filename)

                    fnsplit = secfilename.split(".")
                    akfilename = fnsplit[0] + datetime.datetime.now().strftime(
                        "_%Y%m%d_%I-%M-%S_%p") + "." + fnsplit[1]

                    akfile.save(os.path.join(folder_path, akfilename))
                else:
                    flash("Please select a CSV file")
                    return redirect(request.url)

                dtformat = "%d-%m-%Y %H:%M:%S"
                classname = request.form.get("classid")
                assesementname = request.form.get("assessmentname")
                description = request.form.get("description")

                startson = request.form.get("startson")
                startson = datetime.datetime.strptime(startson, dtformat)

                endson = request.form.get("endson")
                endson = datetime.datetime.strptime(endson, dtformat)

                note = request.form.get("note")

                isAssessmentSaved = db.createAssessmentWithFile(
                    classname, assesementname, description, startson, endson,
                    note, qpfilename, qpjpgfiles)
                if isAssessmentSaved:
                    isanswerkeysaved = db.import_csv_data(
                        folder_path + "/" + akfilename, "QuestionBank", True)
                    if isanswerkeysaved:
                        flash("Assessment created successfully")
                    else:
                        flash(
                            "Unable to save Answer-Key. Please contact your administrator"
                        )
                else:
                    flash(
                        "Unable to create Assessment. Please contact your adminstrator"
                    )

                return redirect(request.url)
            else:
                flash("Please select a PDF file")
                return redirect(request.url)
    except Exception as ex:
        print("uploadassessment()", ex)

    return