Beispiel #1
0
def index(project):
    """
    Home handler
    """
    thisfile = os.environ.get('SCRIPT_NAME',".")
    form = cgi.FieldStorage()

    userdir = 'users/'
    logintest = isloggedin(userdir)

    logint = form.getvalue("login",None)
    action = None

    if project: 
        try:    project=project.decode("utf-8")
        except: pass
    if len(config.projects)==1:project=config.projects[0]

    projectconfig=None
    try:    projectconfig = config.configProject(project) # read in the settings of the current project
    except: pass
    if logintest:
        userconfig = logintest[0]
    #action, userconfig = login(form, userdir, thisfile, action)
        adminLevel, username, realname = int(userconfig["admin"]),userconfig["username"],userconfig["realname"]
    else:
        #adminLevel, username, realname = 0,"guest","guest"
        adminLevel, username, realname = 0,None,None

    if logintest and logint != "logout": buttonname="Enter"# enter
    else: buttonname="Login"
    
        
    return render_template('home.html', project=project, config=config, projectconfig=projectconfig, asset="/static")
Beispiel #2
0
def project(project):
    if current_user.is_authenticated and current_user.project == project:
        print 'yes'
        sql = database.SQL(project)
        projectconfig = config.configProject(project)
        myassignments = printmyassignments(project,sql,projectconfig,current_user.id)
        alltext = printalltexts(project,sql, current_user.adminLevel,projectconfig)
        userassignments = printuserassignments(project,projectconfig,sql,current_user.adminLevel)
        menus = printmenues(project,sql, projectconfig)
        mate = printmate(project,projectconfig, sql, current_user.adminLevel)
        return render_template('project.html', project=project, \
            myassignments=myassignments,userassignments=userassignments, alltext=alltext,mate=mate, menus=menus, asset="/static")
    else:
        return flask.redirect(flask.url_for('ulogin', project=project))
Beispiel #3
0
def index():
    """
    Home handler
    """
    thisfile = os.environ.get('SCRIPT_NAME', ".")
    form = cgi.FieldStorage()

    userdir = 'users/'

    logint = form.getvalue("login", None)

    project = form.getvalue("project", None)
    if project:
        try:
            project = project.decode("utf-8")
        except:
            pass
    if len(config.projects) == 1: project = config.projects[0]

    projectconfig = None
    try:
        projectconfig = config.configProject(
            project)  # read in the settings of the current project
    except:
        pass

    if logintest and logint != "logout": buttonname = "Enter"  # enter
    else: buttonname = "Login"
    action, userconfig = login(form, userdir, thisfile + '?project=' + project,
                               action)
    adminLevel, username, realname = int(
        userconfig["admin"]), userconfig["username"], userconfig["realname"]

    return render_template('index.html',
                           project=project,
                           logint=logint,
                           config=config,
                           projectconfig=projectconfig,
                           buttonname=buttonname,
                           username=username,
                           realname=realname,
                           adminLevel)
Beispiel #4
0
def editor(project,text_id,opensentence):
    textid=int(text_id)
    from editor import printhtmlheader,printheadline,printmenues
    if current_user.is_authenticated and current_user.project == project:
        sql = database.SQL(project)
        projectconfig = config.configProject(project)
        txt = ""
        if not projectconfig:
        #print "Content-Type: text/html\n" # blank line: end of headers
            txt = "something went seriously wrong: can't read the configuration of the project",project.encode("utf-8")
        try:
            _,textname,_ = sql.getall(None, "texts",["rowid"],[text_id])[0]
        except:
            pass
            txt+= "something went seriously wrong: The text you are looking for does not seem to exist! project"
            textname="text not found!"
        todo = sql.gettodostatus(current_user.id,textid)
        validator=0
        if todo>0: validator=int(todo) # -1 and 0 => 0, 1 => 1
        projectEsc=project.replace("'","\\'").replace('"','\\"')
        validvalid=sql.validvalid(textid)
        
        exotype, exotoknum =sql.getExo(textid)
        addEmptyUser=None
        #print "uu",sql.exotypes[exotype],sql.exotypes[exotype]=="graphical feedback"
        if sql.exotypes[exotype] in ["teacher visible","graphical feedback", "percentage"] :
            addEmptyUser=current_user.username
        if sql.exotypes[exotype] in ["teacher visible"] :
            validvalid+=[sql.userid(sql.teacher)]
        if sql.exotypes[exotype]=="graphical feedback":
            graphical=1
        if exotoknum and not current_user.adminLevel:    quantityInfo = ">"+str(exotoknum)+" tokens"
        else:                   quantityInfo = str(sql.getnumber(None, "sentences",["textid"],[textid]))+" sentences"
        
        jsdef = config.jsDefPrinter(projectconfig)
        htmlheader = printhtmlheader(projectEsc,textname,current_user,textid,current_user.id,sql,todo,validator,addEmptyUser,validvalid,opensentence, projectconfig)
        headline  = printheadline(project,textname,quantityInfo,current_user)
        userid = current_user.id
        main = ""
        for snr,sid,s,tid in sql.getAllSentences(textid, current_user.username, current_user.id, current_user.adminLevel):
            #print adminLevel, validvalid, validator
            treelinks, firsttreeid, sentenceinfo=sql.links2AllTrees(sid,snr,current_user.username,current_user.adminLevel, todo, validvalid, validator,addEmptyUser=addEmptyUser)
            status=""
            if todo>=0:status=sql.gettreestatus(sid,userid)
            status="<span id='status{nr}' class='status' onClick='nexttreestatus({sid},{nr})'>{status}</span>".format(status=status,sid=sid, nr=snr)
            connectRight=""
            if current_user.adminLevel or (sql.validatorsCanConnect and validator):
                connectRight='''<img class="connectRight" src="/static/images/chain.png" border="0" align="bottom" id='connectRight{nr}' nr='{nr}' title="connect with next tree (+ctrl: split at selcted word)"> '''.format(nr=snr)
            exo=""
            if exotype>1: # 0: no exercise, 1: no feedback
                exo='''<img class="check" src="/static/images/check.png" border="0" align="bottom" id='check{nr}' nr='{nr}' title="check annotation" graphical={graphical}> '''.format(nr=snr, graphical=graphical)
            main += '''<div id='sentencediv{nr}' class='sentencediv' style="margin:10px;" sid={sid}  nr={nr}>
                    <a id='toggler{nr}' class="toggler" treeid="{firsttreeid}" nr="{nr}" >
                        {nr}: {sentence} &nbsp;
                    </a> 
                    <span id="othertrees{nr}" > {treelinks} </span>
                    <img class="saveimg" src="/static/images/save.png" border="0" align="bottom" id='save{nr}' title="save">
                    <img class="undoimg" src="/static/images/undo.png" border="0" align="bottom" id='undo{nr}'>
                    <img class="redoimg" src="/static/images/redo.png" border="0" align="bottom" id='redo{nr}'> 
                    {status}
                    <img class="exportimg" src="/static/images/export.png" border="0" align="bottom" id='export{nr}' nr='{nr}' title="export"> 
                    {connectRight}
                    {exo}
                </div><p><small>{sentenceinfo}</small></p>'''.format(sentence=s.encode("utf-8"),nr=snr, sid=sid, firsttreeid=firsttreeid, project=project.encode("utf-8"), userid=userid, treelinks=treelinks.encode("utf-8"), status=status,connectRight=connectRight,exo=exo,sentenceinfo=sentenceinfo.encode("utf-8"))
        menus = printmenues(projectconfig)
        return render_template('editor.html', project=project, \
            textname=textname,htmlheader=htmlheader,menus=menus, headline=headline,main=main.decode("utf-8"), jsdef=jsdef, asset="/static")
    else:
        return flask.redirect(flask.url_for('ulogin', project=project))
			print "Error in project.cgi! Can't read the user config files. Please check that the user files are readible and writable by the apache user "+action.encode("utf-8")
			import traceback
			print "traceback:",traceback.print_exc()
			print "Exception:",str(e)
			sys.exit("something's wrong")
	else:
		action, userconfig = login(form, userdir, thisfile, action)
	adminLevel, username, realname = int(userconfig["admin"]),userconfig["username"].decode("utf-8"),userconfig["realname"].decode("utf-8")
	
	print "Content-Type: text/html\n" # blank line: end of headers
	projectconfig=None
	if logint == "confirm":
		print "Your account has been confirmed. You can log on now." # blank line: end of headers
		print '<script type="text/javascript">setTimeout(window.location.href=".",10000);</script>'
	try:	
		projectconfig = config.configProject(project) # read in the settings of the current project
	except:
		print "Error! Can't read the configuration files. Please check that the files project.cfg, functions.cfg, and categories.cfg are present in the project folder	"
		sys.exit("something's wrong")
	if not projectconfig:
		##print "Content-Type: text/html\n" # blank line: end of headers
		print "something went seriously wrong: can't read the configuration of the project"
		if project: print project.encode("utf-8")
		##print "Content-Type: text/html\n" # blank line: end of headers
		print '<script type="text/javascript">window.location.href=".";</script>'
		sys.exit("something's wrong")
	#sql=database.SQL(project)
	#userid = sql.userid(username, realname)
	try:
		sql=database.SQL(project)
		userid = sql.userid(username, realname)