def show(lecture_id):
    """Zobrazení a odevzdávání zadání """

    usr = getUser()
    lec = Lecture.get(lecture_id)

    if not lec: return HTTPError(404, "Cvičení nebylo nalezeno")

    if not lec.isActive():
        msg("Cvičení není aktivní", "error")
        redirect("/assigments")

    assigment = Assigment.getUnique(lecture_id, usr.login)

    if not assigment:
        assigment = Assigment.create(lec.lecture_id, lec.generate(), usr.login)
        msg("Cvičení bylo vygenerováno", "success")

    if request.method == 'POST' and request.files.response:
        try:
            assigment.respond(request.files.response.file.read())
            msgTxt = "Řešení bylo úspěšně odesláno"

            if request.is_xhr:
                return HTTPResponse({
                    "type": "success",
                    "msg": msgTxt
                })
            msg(msgTxt, "success")

        except Exception as e:
            msgTxt = "Chyba při odesílání řešení - %s" % e

            if request.is_xhr:
                return HTTPResponse({
                    "type": "error",
                    "msg": msgTxt
                })

            msg(msgTxt, "error")

        redirect(request.path)

    return template("assigments_show", {
        "assigment": assigment,
        "lecture": lec
    })
Example #2
0
def show(lecture_id):
    """Zobrazení a odevzdávání zadání """
                  
    usr = getUser()
    lec = Lecture.get( lecture_id );
    
    if not lec: return HTTPError(404, "Cvičení nebylo nalezeno")

    if not lec.isActive():
        msg("Cvičení není aktivní", "error")
        redirect("/assigments");
                      
    assigment = Assigment.getUnique( lecture_id, usr.login ) 
    
    if not assigment:
        assigment = Assigment.create( lec.lecture_id, lec.generate(), usr.login )
        msg("Cvičení bylo vygenerováno", "success")
        
    if request.method == 'POST' and request.files.response:
        try:        
            assigment.respond( request.files.response.file.read() )
            msgTxt = "Řešení bylo úspěšně odesláno";

            if request.is_xhr:
                 return HTTPResponse({"type": "success", "msg": msgTxt});
            msg(msgTxt ,"success")
            
        except Exception as e:
           msgTxt = "Chyba při odesílání řešení - %s" % e 
           
           if request.is_xhr:
                 return HTTPResponse({"type": "error", "msg": msgTxt});
                 
           msg(msgTxt, "error")
        
        redirect(request.path)
            
    return template("assigments_show", {"assigment" : assigment, "lecture": lec } )