Beispiel #1
0
def get_speakers():
    if 'lecture_id' in request.args:
        _lecture_id = int(request.args['lecture_id'])
        _lecture = Lecture.get(_lecture_id)
        if _lecture:
            _speaker = _lecture.speaker
            if _speaker:
                return jsonify({'speaker': _speaker, 'lecture': _lecture})
            else:
                abort(404)
        else:
            abort(404)
    return jsonify({'speakers': speakers})
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
    })
Beispiel #3
0
def setup_database_contents():
    if not Speaker.query.all():
        print 'speakers db rebuilt'
        for s in Speaker.get():
            db.session.add(s)
        db.session.commit()

    if not Lecture.query.all():
        print 'lectures db rebuilt'
        for l in Lecture.get():
            db.session.add(l)
        db.session.commit()

    if not Sponsor.query.all():
        print 'sponsors db rebuilt'
        for l in Sponsor.get():
            db.session.add(l)
        db.session.commit()
Beispiel #4
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 } )    
Beispiel #5
0
def get_lecture(lecture_id):
    lecture = Lecture.get(lecture_id)
    if not lecture:
        abort(404)
    return jsonify({'lecture': lecture})
Beispiel #6
0
 def getLecture(self):
     from lecture import Lecture
     return Lecture.get( self.lecture_id )