Ejemplo n.º 1
0
 def __call__(self):
     kurs = getCourse(self.context)
     mongoclient = get_mongo_client()
     cdb = mongoclient[kurs.id]
     clc = cdb.checklist_collection
     studentid = ploneapi.user.get_current().getId()
     summe = None
     if self.context.summe:
         summe = self.calculate_summe()
     if self.request.form:
         checklistpost = {
             'studentid': studentid,
             'checkliste': self.context.UID(),
             'data': self.request.form,
             'summe': summe
         }
         clc_id = clc.insert_one(checklistpost).inserted_id
         if clc_id:
             ploneapi.portal.show_message(
                 message=
                 'Ihre Eingaben zu dieser Checkliste wurden erfolgreich gespeichert.',
                 request=self.request,
                 type='info')
     url = self.context.absolute_url()
     return self.request.response.redirect(url)
Ejemplo n.º 2
0
def getCourseData(kurs, studentid):
    """liest die Daten des Kurses aus dem aktuellen Kurs"""
    mongoclient = get_mongo_client()
    cdb = mongoclient[kurs.id]
    cc = cdb.course_collection
    coursedata = cc.find_one({"studentid": studentid})
    return coursedata
Ejemplo n.º 3
0
def getStudentData(kurs, studentid):
    """liest die Daten des Studenten aus dem aktuellen Kurs"""
    mongoclient = get_mongo_client()
    cdb = mongoclient[kurs.id]
    uc = cdb.user_collection
    studentdata = uc.find_one({"studentid": studentid})
    return studentdata
Ejemplo n.º 4
0
def resetUserData(kurs, studentid):
    """setzt die Daten eines bestimmten Benutzers zurück."""

    studentdata = getStudentData(kurs, studentid)
    objid = studentdata.get('_id')
    studentdata['visited'] = []
    studentdata['tests'] = {}
    mongoclient = get_mongo_client()
    cdb = mongoclient[kurs.id]
    uc = cdb.user_collection
    update = uc.update_one({"_id": objid}, {"$set": studentdata}, upsert=False)
    return update
Ejemplo n.º 5
0
 def get_data(self):
     data = {}
     kurs = getCourse(self.context)
     mongoclient = get_mongo_client()
     cdb = mongoclient[kurs.id]
     clc = cdb.checklist_collection
     studentid = ploneapi.user.get_current().getId()
     formdata = clc.find_one({'studentid':studentid, 'checkliste':self.context.UID()}, sort=[( '_id', pymongo.DESCENDING )])
     if formdata:
         data = formdata.get('data')
         data['summe'] = formdata.get('summe')
     return data
Ejemplo n.º 6
0
def resetComplete(kurs, studentid):
    """setzt alle Daten eines Benutzers komplett zurück"""

    mongoclient = get_mongo_client()
    cdb = mongoclient[kurs.id]
    cc = cdb.course_collection
    myquery = {'studentid': studentid}
    ret = cc.delete_one(myquery)
    studentdata = getStudentData(kurs, studentid)
    objid = studentdata.get('_id')
    cdb = mongoclient[kurs.id]
    uc = cdb.user_collection
    ret = uc.delete_one({"_id": objid})
    return True
Ejemplo n.º 7
0
def einschreiben(kurs, studentid):
    """schreibt einen Benutzer in den aktuellen Kurs ein"""
    mongoclient = get_mongo_client()
    cdb = mongoclient[kurs.id]
    cc = cdb.course_collection
    coursepost = {'studentid': studentid, 'date': datetime.now()}
    cc_id = cc.insert_one(coursepost).inserted_id
    uc = cdb.user_collection
    studentpost = {
        'studentid': studentid,
        'lastchange': datetime.now(),
        'visited': [],
        'tests': {}
    }
    uc_id = uc.insert_one(studentpost).inserted_id
    return (cc_id, uc_id)
Ejemplo n.º 8
0
def getResultsForQuiz(context):
    """ Hilfsfunktion fuer edi.quiz
    """
    retdict = {}
    kurs = getCourse(context)
    studentid = ploneapi.user.get_current().getId()
    quizuid = context.UID()
    mongoclient = get_mongo_client()
    cdb = mongoclient[kurs.id]
    uc = cdb.user_collection
    studentdata = uc.find_one({"studentid": studentid})
    if studentdata:
        tests = studentdata.get('tests')
        if tests:
            retdict = tests.get(quizuid, {})
    return retdict
Ejemplo n.º 9
0
def getGlobalStats(kurs):
    """sucht alle Dokumente eingetragener Studenten aus der Datenbank
    """
    mongoclient = get_mongo_client()
    cdb = mongoclient[kurs.id]
    cc = cdb.course_collection
    alldocs = []
    for doc in cc.find():
        entry = {}
        studentid = doc.get('studentid')
        if studentid:
            user = ploneapi.user.get(userid=studentid)
            entry['studentid'] = studentid
            entry['fullname'] = user.getProperty('fullname')
            entry['email'] = user.getProperty('email')
            entry['in'] = doc.get('date').strftime('%d.%m.%Y %H:%M')
            entry['fin'] = ''
            if doc.get('finished'):
                entry['fin'] = doc.get('finished').strftime('%d.%m.%Y %H:%M')
            alldocs.append(entry)
    return alldocs
Ejemplo n.º 10
0
def updateVisitedData(kurs, studentid, uid, retdict, finished):
    """aktualisiert die Daten zu den besuchten Inhalten"""
    mongoclient = get_mongo_client()
    cdb = mongoclient[kurs.id]
    uc = cdb.user_collection
    cc = cdb.course_collection

    if finished:
        coursedata = getCourseData(kurs, studentid)
        objid = coursedata.get('_id')
        if not 'finished' in coursedata:
            coursedata['finished'] = datetime.now()
            courseupdate = cc.update_one({"_id": objid}, {"$set": coursedata},
                                         upsert=False)

    studentdata = getStudentData(kurs, studentid)
    if not studentdata:
        #Autoren und Redakteure arbeiten am Kurs
        return
    visited = studentdata.get('visited')
    tests = studentdata.get('tests')
    objid = studentdata.get('_id')
    if not visited:
        visited = []
        visited.append(uid)
    else:
        if not visited[-1] == uid:
            visited.append(uid)
    studentdata['visited'] = visited
    if not tests:
        tests = {}
    if retdict:
        tests[uid] = retdict
        studentdata['tests'] = tests
    studentdata['lastchange'] = datetime.now()
    update = uc.update_one({"_id": objid}, {"$set": studentdata}, upsert=False)
    return update