Example #1
0
def oncreate_academic(form):
    import datetime
    cdate = datetime.datetime.now()
    import cpfecys  
    currentyear_period = cpfecys.current_year_period()

    #Search for user roles
    result = db(db.auth_membership.user_id==auth.user.id).select()
    roll_var = ''
    i = 0;
    for a in result:
        if i == 0:
            roll_var = a.group_id.role
            i = i+1
        else:
            roll_var = roll_var + ',' + a.group_id.role  

    db.academic_log.insert(user_name = auth.user.username, 
                                roll =  roll_var, 
                                operation_log = 'insert', 
                                after_carnet = form.vars.carnet, 
                                after_email = form.vars.email, 
                                id_academic = form.vars.id, 
                                id_period = str(currentyear_period.id),
                                description = 'Se agrego registro desde la pagina agregar estudiantes.')
Example #2
0
def ondelete_academic(table_involved, id_of_the_deleted_record):
    import datetime
    import cpfecys  
    currentyear_period = cpfecys.current_year_period()

    cdate = datetime.datetime.now()
    student_var = db.academic(id_of_the_deleted_record)    

    #Search for user roles
    result = db(db.auth_membership.user_id==auth.user.id).select()
    roll_var = ''
    i = 0;
    for a in result:
        if i == 0:
            roll_var = a.group_id.role
            i = i+1
        else:
            roll_var = roll_var + ',' + a.group_id.role        

    db.academic_log.insert(user_name = auth.user.username, 
                                roll =  str(roll_var), 
                                operation_log = 'delete', 
                                before_carnet = student_var.carnet, 
                                before_email = student_var.email, 
                                id_period = str(currentyear_period.id),
                                description = 'Se elimino el registro desde la pagina estudiantes.')
Example #3
0
def consult_quiz():
    area = db(db.area_level.name=='DTT Tutor Académico').select().first()
    ecys_var=False
    if request.vars['ecys'] == "True":
        ecys_var=True
    import cpfecys
    period = cpfecys.current_year_period()
    idperiodoc = request.vars['period']
    idproject = request.vars['project']
    print idproject
    project = db(db.project.id==idproject).select().first()  
    userid = auth.user.id
    cursoid = project.project_id
    cadena = 'uid:'+str(userid)+':curso:'+str(cursoid)+':quiz:*'
    import redis
    r = redis.StrictRedis()
    a = r.keys(cadena)
    cuestionarios = a
    lista = db(db.project.project_id==cursoid).select(
        db.tb_metadata_quiz.ALL, 
        db.auth_user.first_name, 
        db.auth_user.last_name, 
        db.project.name, 
        join=[
            db.auth_user.on(
                db.tb_metadata_quiz.creador == db.auth_user.id
                ), 
            db.project.on(
                db.project.project_id == db.tb_metadata_quiz.curso)]
                )
    #lista = db(db.tb_metadata_quiz.id == db.auth_user.id).select()
    print lista
    return dict(ecys_var = ecys_var, periodo = period, project=project, idperiodoc=idperiodoc, idproject=idproject,a=a,lista=lista)
Example #4
0
def courses():
    #requires parameter year_period if no one is provided then it is automatically detected
    #and shows the current period
    year_period = request.vars['year_period']
    max_display = 1
    currentyear_period = db.period_year(db.period_year.id == year_period)
    if not currentyear_period:
        import cpfecys
        currentyear_period = cpfecys.current_year_period()
    current_data = db((db.user_project.period <= currentyear_period.id)&
              ((db.user_project.period + db.user_project.periods) > currentyear_period.id)&
              (db.user_project.assigned_user == auth.user.id)).select()
    current_period_name = T(cpfecys.second_period_name)
    if currentyear_period.period == cpfecys.first_period.id:
        current_period_name = T(cpfecys.first_period_name)
    start_index = currentyear_period.id - max_display - 1
    if start_index < 1:
        start_index = 0
    end_index = currentyear_period.id + max_display
    periods_before = db(db.period_year).select(limitby=(start_index, currentyear_period.id - 1))
    periods_after = db(db.period_year).select(limitby=(currentyear_period.id, end_index))
    other_periods = db(db.period_year).select()
    return dict(current_data = current_data,
                currentyear_period = currentyear_period,
                current_period_name = current_period_name,
                periods_before = periods_before,
                periods_after = periods_after,
                other_periods = other_periods)
Example #5
0
def ondelete_academic_assignation(table_involved, id_of_the_deleted_record):
    import datetime
    cdate = datetime.datetime.now()
    student_assignation_var = db.academic_course_assignation(id_of_the_deleted_record)  
    import cpfecys  
    currentyear_period = cpfecys.current_year_period()

    #Search for user roles
    result = db(db.auth_membership.user_id==auth.user.id).select()
    roll_var = ''
    i = 0;
    for a in result:
        if i == 0:
            roll_var = a.group_id.role
            i = i+1
        else:
            roll_var = roll_var + ',' + a.group_id.role

    project_name_var = ''
    project_var = db(db.project.id == student_assignation_var.assignation).select()
    for a in project_var:
        project_name_var = a.name

    db.academic_course_assignation_log.insert(user_name = auth.user.username, 
                                                roll =  roll_var, 
                                                operation_log = 'delete', 
                                                before_carnet = student_assignation_var.carnet.carnet, 
                                                before_course = student_assignation_var.assignation.name,
                                                before_year = str(student_assignation_var.semester.yearp) ,
                                                before_semester = str(student_assignation_var.semester.period),
                                                before_laboratory = student_assignation_var.laboratorio,
                                                id_period = str(currentyear_period.id),
                                                description = 'Se elimino el registro desde la pagina Asignar Estudiantes')
Example #6
0
def event_editor():
    assignation = request.vars['assignation']
    #check assignation belongs to this user
    import cpfecys
    check = db.user_project(id = assignation, assigned_user = auth.user.id)
    if (check is None):
        #check if there is no assignation or if it is locked (shouldn't be touched)
        if (session.last_assignation is None):
            redirect(URL('default','index'))
            return
        else:
            check = db.user_project(id = session.last_assignation)
            if cpfecys.assignation_is_locked(check):
                redirect(URL('default','index'))
                return
    else:
        session.last_assignation = check.id
    cyearperiod = cpfecys.current_year_period()
    db.public_event.semester.default = cyearperiod.id
    db.public_event.semester.writable = False
    db.public_event.semester.readable = False
    db.public_event.assignation.default = check.id
    db.public_event.assignation.writable = False
    db.public_event.assignation.readable = False
    db.public_event_schedule.public_event.readable = False
    db.public_event_schedule.public_event.writable = False
    query = (db.public_event.assignation == check.id)
    return dict(year = cyearperiod.yearp, semester = cyearperiod.period.name,name = check.project.name,grid = SQLFORM.smartgrid(db.public_event, constraints = {'public_event' : query}))
Example #7
0
def reportes():
    import cpfecys
    period = cpfecys.current_year_period()
    periodo = request.vars['period']
    project = request.vars['project']
    #project = db(db.project.id==idproject).select().first()  

    myquery = (db.project.id==project) & (db.course_activity.semester==period)


    programaciones = db(myquery).select(
        db.tb_quiz_actividad.id,
		db.tb_quiz_actividad.id_actividad,
		db.tb_quiz_actividad.id_quiz,
		db.tb_quiz_actividad.fecha,
		db.tb_quiz_actividad.inicio,
		db.tb_quiz_actividad.duracion,
		db.tb_quiz_actividad.finalizado,
		db.tb_quiz_actividad.private,
		db.tb_quiz_actividad.keyword,
		db.tb_metadata_quiz.nombre,
		db.tb_metadata_quiz.fecha_creacion,
		db.tb_metadata_quiz.creador,
		db.tb_metadata_quiz.id,
		db.tb_metadata_quiz.curso, 
		db.project.name,
		db.auth_user.id,
		db.auth_user.first_name, 
        db.auth_user.last_name,
		db.course_activity_category.category,
		db.activity_category.description,
		db.course_activity.name,
		db.course_activity.semester,
        join=[
            db.tb_metadata_quiz.on(
                db.tb_metadata_quiz.id_quiz == db.tb_quiz_actividad.id_quiz    
            ),
            db.project.on(
                db.project.project_id == db.tb_metadata_quiz.curso    
            ),
            db.auth_user.on(
                db.auth_user.id == db.tb_metadata_quiz.creador    
            ),
            db.course_activity.on(
                db.course_activity.id == db.tb_quiz_actividad.id_actividad    
            ),
            db.course_activity_category.on(
                db.course_activity_category.id == db.course_activity.course_activity_category    
            ),
            db.activity_category.on(
                db.activity_category.id == db.course_activity_category.category    
            )
        ]
    )

    print programaciones
    return dict(periodo = period, course=project, period=periodo, programaciones=programaciones)
Example #8
0
def evaluation():
    query=db.evaluation
    import cpfecys
    cperiod = cpfecys.current_year_period()
    db.evaluation.period.default = cperiod.id
    db.evaluation.period.writable = False
    db.evaluation.period.readable = False
    grid = SQLFORM.smartgrid(query, csv=False)
    return dict(grid=grid)
Example #9
0
def evaluation():
    query = db.evaluation
    import cpfecys
    cperiod = cpfecys.current_year_period()
    db.evaluation.period.default = cperiod.id
    db.evaluation.period.writable = False
    db.evaluation.period.readable = False
    grid = SQLFORM.smartgrid(query, csv=False)
    return dict(grid=grid)
Example #10
0
def register_mail_notifications():
#db.user_project.assigned_user == auth.user.id
    #Obtain the current period of the system and all the register periods
    period = cpfecys.current_year_period()
    periods = db(db.period_year).select()

    #Check if the period is change
    if request.vars['period'] !=None:
        period = request.vars['period']
        period = db(db.period_year.id==period).select().first()

    #show the page resiter_mail_notifications.html
    response.view='notification/register_mail_notifications.html'

    #obtain the projects where the student is register and is of the select semester
    projects = db((db.user_project.period==period) & (db.user_project.assigned_user == auth.user.id)).select()
#    dest=[]
 #   for student in allProject:
  #      dest.append(student.project)
   # projects = db(db.project.id.belongs(dest)).select()

    #obtain the names of the projects that thas register the user
    def obtain_nameProjects(userP):
        p = db(db.project.id==userP).select()
        nameP = ''
        for p2 in p:
            nameP=p2.name
        return nameP

    def obtain_period(periodo):
        semester = db(db.period.id==periodo).select()
        nameS = ''
        for s in semester:
            nameS=s.name
        return nameS

    #obtain all the registers of the send notices of the student
    def obtain_notices(project):
        #name project
        n=obtain_nameProjects(project.project)

        #name of the year
        anio = db(db.period_year.id==project.period).select()
        nameY = ''
        idP = ''
        for a in anio:
            nameY=a.yearp
            idP = a.period

        #name of period
        nameS=obtain_period(idP)
        #obtain all the notices that has the user has register
        notices  = db((db.notification_general_log4.emisor==auth.user.username) & (db.notification_general_log4.course==n)&(db.notification_general_log4.period==nameS)&(db.notification_general_log4.yearp==nameY)).select()
        return notices

    return dict(obtain_nameProjects=obtain_nameProjects,periods=periods, projects=projects, obtain_notices=obtain_notices)
Example #11
0
def home_quiz():
    area = db(db.area_level.name=='DTT Tutor Académico').select().first()
    ecys_var=False
    if request.vars['ecys'] == "True":
        ecys_var=True
    import cpfecys
    period = cpfecys.current_year_period()
    periodo = request.vars['period']
    project = request.vars['project']
    return dict(ecys_var = ecys_var, periodo = period, course=project, period=periodo)
Example #12
0
 def aux_in_courses(project_id):
     import cpfecys
     period = cpfecys.current_year_period()
     return db((db.project.id == project_id)&\
             (db.user_project.project == db.project.id)&\
             (db.auth_user.id == db.user_project.assigned_user)&\
             ((db.user_project.period <= period.id) & ((db.user_project.period + db.user_project.periods) > period.id))&\
             (db.auth_membership.user_id == db.auth_user.id)&\
             (db.auth_membership.group_id == db.auth_group.id)&\
             (db.auth_group.role == 'Student')).select()
Example #13
0
def consultar_quiz():
    area = db(db.area_level.name=='DTT Tutor Académico').select().first()
    ecys_var=False
    if request.vars['ecys'] == "True":
        ecys_var=True
    import cpfecys
    period = cpfecys.current_year_period()
    idperiodoc = request.vars['period']
    idproject = request.vars['project']
    project = db(db.project.id==idproject).select().first()  
    idPregunta = 1
    return dict(ecys_var = ecys_var, periodo = period, project=project)
Example #14
0
def take_quiz():
    import cpfecys
    period = cpfecys.current_year_period()
    periodo = request.vars['period']
    project = request.vars['project']
    projecto = db(db.project.id==project).select().first()
    ##inicia codigo viejo
    ## termina codigo viejo
    myquery = (db.vw_quiz_actividad.id_project==int(project)) & (db.vw_quiz_actividad.semestre==int(period))
    
    programaciones = db(myquery).select(db.vw_quiz_actividad.ALL)
    print programaciones
    return dict(periodo = period, course=project, period=periodo, programaciones=programaciones, project=projecto)
Example #15
0
def event_editor():
    assignation = request.vars['assignation']
    #check assignation belongs to this user
    import cpfecys
    check =  db((db.user_project.assigned_user==auth.user.id)&\
            (db.user_project.id == assignation)&\
            ((db.user_project.period <= cpfecys.current_year_period().id) & \
            ((db.user_project.period + db.user_project.periods) > cpfecys.current_year_period().id))).select(db.user_project.ALL).first()

    if (check is None):
        redirect(URL('default','index'))
        
    cyearperiod = cpfecys.current_year_period()
    db.public_event.semester.default = cyearperiod.id
    db.public_event.semester.writable = False
    db.public_event.semester.readable = False
    db.public_event.assignation.default = check.id
    db.public_event.assignation.writable = False
    db.public_event.assignation.readable = False
    db.public_event_schedule.public_event.readable = False
    db.public_event_schedule.public_event.writable = False
    query = (db.public_event.assignation == check.id)
    return dict(year = cyearperiod.yearp, semester = cyearperiod.period.name,name = check.project.name,grid = SQLFORM.smartgrid(db.public_event, constraints = {'public_event' : query}))
Example #16
0
def user():
    """
    exposes:
    http://..../[app]/default/user/login
    http://..../[app]/default/user/logout
    http://..../[app]/default/user/register
    http://..../[app]/default/user/profile
    http://..../[app]/default/user/retrieve_password
    http://..../[app]/default/user/change_password
    http://..../[app]/default/user/manage_users (requires membership in
    use @auth.requires_login()
        @auth.requires_membership('group name')
        @auth.requires_permission('read','table name',record_id)
    to decorate functions that need access control
    """
    if request.args(0) == 'profile':
        if ((auth.has_membership('Super-Administrator') == False) & (auth.has_membership('Teacher') == False) & (auth.has_membership('Ecys-Administrator') == False)):
            db.auth_user.first_name.writable = False
            db.auth_user.last_name.writable = False
            db.auth_user.username.writable = False

            db.auth_user.email.writable = False

            import cpfecys
            currentyear_period = cpfecys.current_year_period()

            for date_var in db((db.student_control_period.period_name==T(str(currentyear_period.period.name))+" "+str(currentyear_period.yearp))).select():
                var_date_finish = date_var.date_finish
                from datetime import datetime
                if datetime.now() > date_var.date_start and datetime.now() < var_date_finish:
                    db.auth_user.email.writable = True
                pass
            pass          

            db.auth_user.photo.writable = True
            review = db((db.photo_review.user_id == auth.user.id)).select().first()
            if review is not None:
                if review.accepted == True:
                    db.auth_user.photo.writable = False
                pass
            pass
        pass 
        if (auth.has_membership('Teacher')):
            if str(request.vars["edit_foto"]) == "True":
                db.auth_user.photo.writable = True
            else:
                db.auth_user.photo.writable = False
            db.auth_user.username.writable = False
    pass
    return dict(form=auth())
Example #17
0
def user():
    """
    exposes:
    http://..../[app]/default/user/login
    http://..../[app]/default/user/logout
    http://..../[app]/default/user/register
    http://..../[app]/default/user/profile
    http://..../[app]/default/user/retrieve_password
    http://..../[app]/default/user/change_password
    http://..../[app]/default/user/manage_users (requires membership in
    use @auth.requires_login()
        @auth.requires_membership('group name')
        @auth.requires_permission('read','table name',record_id)
    to decorate functions that need access control
    """
    if request.args(0) == 'profile':
        if ((auth.has_membership('Super-Administrator') == False) & (auth.has_membership('Teacher') == False) & (auth.has_membership('Ecys-Administrator') == False)):
            db.auth_user.first_name.writable = False
            db.auth_user.last_name.writable = False
            db.auth_user.username.writable = False

            db.auth_user.email.writable = False

            import cpfecys
            currentyear_period = cpfecys.current_year_period()

            for date_var in db((db.student_control_period.period_name==T(str(currentyear_period.period.name))+" "+str(currentyear_period.yearp))).select():
                var_date_finish = date_var.date_finish
                from datetime import datetime
                if datetime.now() > date_var.date_start and datetime.now() < var_date_finish:
                    db.auth_user.email.writable = True
                pass
            pass

            db.auth_user.photo.writable = True
            review = db((db.photo_review.user_id == auth.user.id)).select().first()
            if review is not None:
                if review.accepted == True:
                    db.auth_user.photo.writable = False
                pass
            pass
        pass
        if (auth.has_membership('Teacher')):
            if str(request.vars["edit_foto"]) == "True":
                db.auth_user.photo.writable = True
            else:
                db.auth_user.photo.writable = False
            db.auth_user.username.writable = False
    pass
    return dict(form=auth())
Example #18
0
def event_editor():
    assignation = request.vars['assignation']
    #check assignation belongs to this user
    import cpfecys
    check =  db((db.user_project.assigned_user==auth.user.id)&\
            (db.user_project.id == assignation)&\
            ((db.user_project.period <= cpfecys.current_year_period().id) & \
            ((db.user_project.period + db.user_project.periods) > cpfecys.current_year_period().id))).select(db.user_project.ALL).first()

    if (check is None):
        redirect(URL('default','index'))

    cyearperiod = cpfecys.current_year_period()
    db.public_event.semester.default = cyearperiod.id
    db.public_event.semester.writable = False
    db.public_event.semester.readable = False
    db.public_event.assignation.default = check.id
    db.public_event.assignation.writable = False
    db.public_event.assignation.readable = False
    db.public_event_schedule.public_event.readable = False
    db.public_event_schedule.public_event.writable = False
    query = (db.public_event.assignation == check.id)
    return dict(year = cyearperiod.yearp, semester = cyearperiod.period.name,name = check.project.name,grid = SQLFORM.smartgrid(db.public_event, constraints = {'public_event' : query}))
Example #19
0
def programacion_test():
    x = tuple(request.args)
    y = str(''.join(x))
    ide = int(y)
    lista = db(db.tb_metadata_quiz.id_quiz==ide).select(
        db.tb_metadata_quiz.creador, 
        db.tb_metadata_quiz.curso)

    #OBTENGO LA METADA DEL QUIZ
    lista = db(db.tb_metadata_quiz.id_quiz==ide).select(
        db.tb_metadata_quiz.ALL, 
        db.auth_user.first_name, 
        db.auth_user.last_name, 
        db.project.name, 
        join=[
            db.auth_user.on(
                db.tb_metadata_quiz.creador == db.auth_user.id
                ), 
            db.project.on(
                db.project.project_id == db.tb_metadata_quiz.curso)]
                )

    #OBTENGO LOS CODIGOS DE ACTIVIDADES QUE PERENECEN A UN QUIZ

    categorias = db().select(
        db.activity_category.id,
        db.activity_category.category,
        join=[
            db.equivalencia_quiz_category.on(
                db.equivalencia_quiz_category.categorie == db.activity_category.id
            )
        ] 
    )

    period = cpfecys.current_year_period()
    idperiodoc = request.vars['period']
    idproject = request.vars['project']
    project = db(db.project.id==idproject).select().first() 

    #Si el periodo actual es igual al periodo recibido en la variable corresponde el quiz
    actual = False
    if(int(period)==int(idperiodoc)):
        actual = True
 


    print categorias
    return dict(metadata = lista.first(), categorias = categorias, periodo = period, project =project) 
Example #20
0
def resources():
    #Get the selected item_restriction id from parameter
    item_restriction_id = request.vars['r']
    #Get the items that belong to current semester
    import cpfecys
    period = cpfecys.current_year_period()
    def teachers_on_project(project_id):
        import cpfecys
        period = cpfecys.current_year_period()
        return db((db.project.id == project_id)&\
                (db.user_project.project == db.project.id)&\
                (db.auth_user.id == db.user_project.assigned_user)&\
                ((db.user_project.period <= period.id) & ((db.user_project.period + db.user_project.periods) > period.id))&\
                (db.auth_membership.user_id == db.auth_user.id)&\
                (db.auth_membership.group_id == db.auth_group.id)&\
                (db.auth_group.role == 'Teacher')).select()
    def aux_in_courses(project_id):
        import cpfecys
        period = cpfecys.current_year_period()
        return db((db.project.id == project_id)&\
                (db.user_project.project == db.project.id)&\
                (db.auth_user.id == db.user_project.assigned_user)&\
                ((db.user_project.period <= period.id) & ((db.user_project.period + db.user_project.periods) > period.id))&\
                (db.auth_membership.user_id == db.auth_user.id)&\
                (db.auth_membership.group_id == db.auth_group.id)&\
                (db.auth_group.role == 'Student')).select()
    return dict(teachers_on_project = teachers_on_project,
                aux_in_courses = aux_in_courses,
                semester = period,
                data = db((db.item.created == period)&
                          (db.item.item_restriction == item_restriction_id)&
                          (db.item.item_restriction == db.item_restriction.id)&
                          (db.item_restriction.is_public == True)&
                          ((db.item_restriction.period == period)|(db.item_restriction.permanent == True))&
                          (db.item.assignation == db.user_project.id)&
                          (db.user_project.project == db.project.id)&
                          (db.user_project.project == db.project.id)&\
                        (db.auth_user.id == db.user_project.assigned_user)&\
                        (db.user_project.assignation_status == None)&\
                        (db.auth_membership.user_id == db.auth_user.id)&\
                        (db.auth_membership.group_id == db.auth_group.id)&\
                        (db.auth_group.role == 'Student')&
                          (db.item.id > 0)).select(orderby=db.project.name))
Example #21
0
def onupdate_academic(form):
    import datetime
    import cpfecys  
    currentyear_period = cpfecys.current_year_period()
    cdate = datetime.datetime.now()
    #session.flash = T('hola-'+str(form.vars))
    #Search for user roles
    result = db(db.auth_membership.user_id==auth.user.id).select()
    roll_var = ''
    i = 0;
    for a in result:
        if i == 0:
            roll_var = a.group_id.role
            i = i+1
        else:
            roll_var = roll_var + ',' + a.group_id.role    

    student_var = db(db.academic_log.id_academic == form.vars.id).select(orderby=db.academic_log.id)
    carnet_var = ''
    email_var = ''
    for a in student_var:
        carnet_var = a.after_carnet
        email_var = a.after_email
    if form.vars.delete_this_record == None:
        db.academic_log.insert(user_name = auth.user.username, 
                                roll =  roll_var, 
                                operation_log = 'update', 
                                before_carnet = carnet_var, 
                                before_email = email_var, 
                                after_carnet = form.vars.carnet, 
                                after_email = form.vars.email, 
                                id_academic = form.vars.id, 
                                id_period = str(currentyear_period.id),
                                description = 'Se modifico registro desde la pagina estudiantes.')
    else:
        db.academic_log.insert(user_name = auth.user.username, 
                                roll =  str(roll_var), 
                                operation_log = 'delete', 
                                before_carnet = carnet_var, 
                                before_email = email_var, 
                                id_period = str(currentyear_period.id),
                                description = 'Se elimino el registro desde la pagina estudiantes.')
Example #22
0
    def get_current_reports(period):
        from datetime import datetime
        import cpfecys
        cperiod = cpfecys.current_year_period()
        year = str(cperiod.yearp)
        if period.period == 1:
            start = datetime.strptime(year + '-01-01', "%Y-%m-%d")
            end = datetime.strptime(year + '-06-01', "%Y-%m-%d")
        else:
            start = datetime.strptime(year + '-06-01', "%Y-%m-%d")
            end = datetime.strptime(year + '-12-31', "%Y-%m-%d")

        reports = db((db.report.assignation == final_practice.user_project.id)&
                        (db.report.status.name!='Grading')&
                        (db.report.created >= start)&
                        (db.report.created <= end))
        avg = reports.select((db.report.score.sum()/db.report.score.count()).\
                        with_alias('avg')).first()['avg'] or 0
        reports = reports.select(), avg
        return reports
Example #23
0
def academic_log():
    import cpfecys
    #assignation = request.vars['assignation']
    year_period = cpfecys.current_year_period()
    max_display = 1

    currentyear_period = db.period_year(db.period_year.id == year_period)

    query = ((
        db.academic_course_assignation.semester == currentyear_period.id))

    #db.academic_course_assignation.assignation.default = check.project
    db.academic_course_assignation.assignation.writable = False
    db.academic_course_assignation.assignation.readable = False
    db.academic_course_assignation.semester.default = currentyear_period.id
    db.academic_course_assignation.semester.writable = False
    db.academic_course_assignation.semester.readable = False

    grid = SQLFORM.grid(query)

    current_period_name = T(cpfecys.second_period.name)
    if currentyear_period.period == cpfecys.first_period.id:
        current_period_name = T(cpfecys.first_period.name)
    start_index = currentyear_period.id - max_display - 1
    if start_index < 1:
        start_index = 0
    end_index = currentyear_period.id + max_display
    periods_before = db(db.period_year).select(limitby=(start_index,  \
        currentyear_period.id - 1))
    periods_after = db(db.period_year).select(limitby=(currentyear_period.id, \
     end_index))
    other_periods = db(db.period_year).select()
    return dict(
        grid=grid,
        currentyear_period=currentyear_period,
        current_period_name=current_period_name,
        periods_before=periods_before,
        periods_after=periods_after,
        other_periods=other_periods,
    )
Example #24
0
def academic_log():
    import cpfecys
    #assignation = request.vars['assignation']
    year_period = cpfecys.current_year_period()
    max_display = 1
    
    currentyear_period = db.period_year(db.period_year.id == year_period)
    

    query = ((db.academic_course_assignation.semester == currentyear_period.id))

    #db.academic_course_assignation.assignation.default = check.project
    db.academic_course_assignation.assignation.writable = False
    db.academic_course_assignation.assignation.readable = False
    db.academic_course_assignation.semester.default = currentyear_period.id
    db.academic_course_assignation.semester.writable = False
    db.academic_course_assignation.semester.readable = False

    grid = SQLFORM.grid(query)

    current_period_name = T(cpfecys.second_period.name)
    if currentyear_period.period == cpfecys.first_period.id:
        current_period_name = T(cpfecys.first_period.name)
    start_index = currentyear_period.id - max_display - 1
    if start_index < 1:
        start_index = 0
    end_index = currentyear_period.id + max_display
    periods_before = db(db.period_year).select(limitby=(start_index,  \
        currentyear_period.id - 1))
    periods_after = db(db.period_year).select(limitby=(currentyear_period.id, \
     end_index))
    other_periods = db(db.period_year).select()
    return dict(grid = grid,
                currentyear_period = currentyear_period,
                current_period_name = current_period_name,
                periods_before = periods_before,
                periods_after = periods_after,
                other_periods = other_periods,
                )
Example #25
0
def sent_mails():        
    import cpfecys
    all_course = True
    if request.vars['period'] is None:
        cperiod = cpfecys.current_year_period()
    else:
        all_course = False
        cperiod = db.period_year(db.period_year.id == request.vars['period'])

    academic_var = db.academic(db.academic.id_auth_user==auth.user.id)        
    period_list = db(db.academic_course_assignation.carnet==academic_var.id).select(db.academic_course_assignation.semester,distinct=True)

    select_form = FORM(INPUT(_name='semester_id',_type='text'))

    if select_form.accepts(request.vars,formname='select_form'):
        assignations = db((db.academic_course_assignation.semester==str(select_form.vars.semester_id)) & (db.academic_course_assignation.carnet==academic_var.id)).select()
        period_id = str(select_form.vars.semester_id)
        all_course = True
    else:
        assignations = db((db.academic_course_assignation.semester==cperiod.id) & (db.academic_course_assignation.carnet==academic_var.id)).select()
        period_id = str(cperiod.id)

    return dict(assignations=assignations,email=auth.user.email,period_id=period_id,period_list=period_list,cperiod=cperiod.id, all_course = all_course)
Example #26
0
def sent_mails():
    import cpfecys
    all_course = True
    if request.vars['period'] is None:
        cperiod = cpfecys.current_year_period()
    else:
        all_course = False
        cperiod = db.period_year(db.period_year.id == request.vars['period'])

    academic_var = db.academic(db.academic.id_auth_user == auth.user.id)
    period_list = db(
        db.academic_course_assignation.carnet == academic_var.id).select(
            db.academic_course_assignation.semester, distinct=True)

    select_form = FORM(INPUT(_name='semester_id', _type='text'))

    if select_form.accepts(request.vars, formname='select_form'):
        assignations = db((db.academic_course_assignation.semester == str(
            select_form.vars.semester_id))
                          & (db.academic_course_assignation.carnet ==
                             academic_var.id)).select()
        period_id = str(select_form.vars.semester_id)
        all_course = True
    else:
        assignations = db(
            (db.academic_course_assignation.semester == cperiod.id)
            & (db.academic_course_assignation.carnet == academic_var.id)
        ).select()
        period_id = str(cperiod.id)

    return dict(assignations=assignations,
                email=auth.user.email,
                period_id=period_id,
                period_list=period_list,
                cperiod=cperiod.id,
                all_course=all_course)
Example #27
0
def evaluation_reply():
    import cpfecys
    cperiod = cpfecys.current_year_period()

    project = request.vars['project']
    period = request.vars['period']
    evaluation = request.vars['evaluation']
    evaluated = request.vars['evaluated']

    if db((db.auth_user.id==auth.user.id) & \
        (db.user_project.project==project) & \
        ((db.user_project.period <= period) & ((db.user_project.period + db.user_project.periods) > period))).select().first() is None:
        academic_var = db.academic(db.academic.id_auth_user == auth.user.id)
        if db((db.academic_course_assignation.carnet == academic_var.id)
              & (db.academic_course_assignation.semester == period)
              & (db.academic_course_assignation.assignation == project)
              ).select().first() is None:
            session.flash = T('Not authorized')
            redirect(URL('default', 'index'))

    evaluated = db((db.auth_user.id==evaluated) & \
        ((db.user_project.period <= period) & ((db.user_project.period + db.user_project.periods) > period))).select().first()
    if evaluated is None:
        session.flash = T('Not authorized')
        redirect(URL('default', 'index'))

    var_evaluation = db((db.evaluation.id == evaluation)).select().first()

    if (str(period) != str(cperiod.id)):
        session.flash = T('Not authorized')
        redirect(URL('default', 'index'))

    user_role = None
    if auth.has_membership('Student') or auth.has_membership('Teacher'):
        try:
            if db((db.user_project.assigned_user == auth.user.id) & \
                ((db.user_project.period <= period) & ((db.user_project.period + db.user_project.periods) > period))).select().first() is not None:
                if auth.has_membership('Student'):
                    user_role = 2
                else:
                    user_role = 3
        except:
            None
    if auth.has_membership('Academic'):
        try:
            academic_var = db.academic(
                db.academic.id_auth_user == auth.user.id)
            if db((db.academic_course_assignation.carnet == academic_var.id)
                  & (db.academic_course_assignation.semester == period)
                  ).select().first() is not None:
                user_role = 5
        except:
            None

    if var_evaluation.repository_evaluation.user_type_evaluator != user_role:
        session.flash = T('Not authorized')
        redirect(URL('default', 'index'))

    var_repository_evaluation = db(
        db.repository_evaluation.id ==
        var_evaluation.repository_evaluation).select().first()
    question_category = db(db.question_repository.repository_evaluation ==
                           var_evaluation.repository_evaluation).select(
                               db.question_repository.question_type_name,
                               distinct=True)

    evaluation_result = db((db.evaluation_result.repository_evaluation == var_evaluation.repository_evaluation) &\
                                (db.evaluation_result.evaluated == evaluated.auth_user.id) & \
                                (db.evaluation_result.period == period) & \
                                (db.evaluation_result.project == project) ).select().first()

    if (evaluation_result is not None) and \
        (db((db.evaluation_auth_user.evaluation_result == evaluation_result.id) &\
        (db.evaluation_auth_user.evaluator == auth.user.id) ).select().first() is not None):
        session.flash = T('Not authorized')
        redirect(URL('default', 'index'))

    if (request.args(0) == 'send'):

        if evaluation_result is None:
            evaluation_result_id = db.evaluation_result.insert(
                repository_evaluation=var_evaluation.repository_evaluation,
                evaluated=evaluated.auth_user.id,
                period=period,
                project=project)
        else:
            evaluation_result_id = evaluation_result.id

        evaluation_auth_user = db((db.evaluation_auth_user.evaluation_result == evaluation_result_id) &\
                                (db.evaluation_auth_user.evaluator == auth.user.id) ).select().first()
        if evaluation_auth_user is None:
            db.evaluation_auth_user.insert(
                evaluation_result=evaluation_result_id, evaluator=auth.user.id)

        question_query = db((db.question_repository.repository_evaluation ==
                             var_evaluation.repository_evaluation)).select()
        for question in question_query:
            answer_query = db(
                (db.repository_answer.question_repository == question.id
                 )).select()
            if len(answer_query) == 0:
                if (request.vars['group_' + str(question.id)] is not None) & (
                        request.vars['group_' + str(question.id)] != ""):
                    db.evaluation_solve_text.insert(
                        evaluation_result=evaluation_result_id,
                        question_repository=question.id,
                        answer=request.vars['group_' + str(question.id)])
            else:
                for answer in answer_query:
                    if answer.exclusive_one_answer == True:
                        if request.vars['group_' +
                                        str(question.id)] is not None:
                            if str(request.vars['group_' +
                                                str(question.id)]) == str(
                                                    answer.id):
                                evaluation_solve_detail = db((db.evaluation_solve_detail.evaluation_result == evaluation_result_id) &\
                                    (db.evaluation_solve_detail.question_repository == question.id) & \
                                    (db.evaluation_solve_detail.repository_answer == answer.id)).select().first()
                                if evaluation_solve_detail is None:
                                    db.evaluation_solve_detail.insert(
                                        evaluation_result=evaluation_result_id,
                                        question_repository=question.id,
                                        repository_answer=answer.id,
                                        total_count=1)
                                else:
                                    db(
                                        db.evaluation_solve_detail.id ==
                                        evaluation_solve_detail.id
                                    ).update(total_count=(
                                        evaluation_solve_detail.total_count +
                                        1))

        session.flash = T('The evaluation has been sent')
        redirect(
            URL('evaluation',
                'evaluation_list',
                vars=dict(period=period, project=project)))

    return dict(var_evaluation=var_evaluation,
                var_repository_evaluation=var_repository_evaluation,
                question_category=question_category,
                evaluated=evaluated)
Example #28
0
def resources():
    #Get the selected item_restriction id from parameter
    item_restriction_id = request.vars['r']
    #Get the items that belong to current semester
    import cpfecys

    #emarquez: por default, sigue igual, si envia  parametro d periodo, se cambia
    parameter_period = request.vars['period'] or False

    period = cpfecys.current_year_period()

    #emarquez
    if parameter_period:
        period = db(db.period_year.id == parameter_period).select().first()


    def teachers_on_project(project_id):
        import cpfecys
        #period = cpfecys.current_year_period()
        if cpfecys.is_semestre(period.id):
            return db((db.project.id == project_id)&\
                    (db.user_project.project == db.project.id)&\
                    (db.auth_user.id == db.user_project.assigned_user)&\
                    ((db.user_project.period <= period.id) & ((db.user_project.period + db.user_project.periods) > period.id))&\
                    (db.auth_membership.user_id == db.auth_user.id)&\
                    (db.auth_membership.group_id == db.auth_group.id)&\
                    (db.auth_group.role == 'Teacher')).select()
        else:
            return db((db.project.id == project_id)&\
                    (db.user_project.project == db.project.id)&\
                    (db.auth_user.id == db.user_project.assigned_user)&\
                    (db.user_project.period == period.id) &\
                    (db.auth_membership.user_id == db.auth_user.id)&\
                    (db.auth_membership.group_id == db.auth_group.id)&\
                    (db.auth_group.role == 'Teacher')).select()

    def aux_in_courses(project_id):
        import cpfecys
        #period = cpfecys.current_year_period()
	
	rowsi = db((db.period.id==db.period_detail.period)&(db.period_year.period==db.period.id)).select()

 	lst = []
    	for r in rowsi:
        	lst.append(r.period_year.id)


        return db((db.project.id == project_id)&\
                (db.user_project.project == db.project.id)&\
                (db.auth_user.id == db.user_project.assigned_user)&\
                ((~db.user_project.period.belongs(lst))&(db.user_project.period <= period.id) & ((db.user_project.period + db.user_project.periods) > period.id))&\
                (db.auth_membership.user_id == db.auth_user.id)&\
		(db.auth_membership.group_id == db.auth_group.id)&\
                (db.auth_group.role == 'Student')).select()
    return dict(teachers_on_project = teachers_on_project,
                aux_in_courses = aux_in_courses,
                semester = period,
                data = db((db.item.created == period)&
                          (db.item.item_restriction == item_restriction_id)&
                          (db.item.item_restriction == db.item_restriction.id)&
                          (db.item_restriction.is_public == True)&
                          ((db.item_restriction.period == period)|(db.item_restriction.permanent == True))&
                          (db.item.assignation == db.user_project.id)&
                          (db.user_project.project == db.project.id)&
                          (db.user_project.project == db.project.id)&\
                        (db.auth_user.id == db.user_project.assigned_user)&\
                        (db.user_project.assignation_status == None)&\
                        (db.auth_membership.user_id == db.auth_user.id)&\
                        (db.auth_membership.group_id == db.auth_group.id)&\
                        (db.auth_group.role == 'Student')&
                          (db.item.id > 0)).select(orderby=db.project.name),
                period =parameter_period)
Example #29
0
def check_student(check_carnet):
    svp=db(db.validate_student).select().first()
    if svp is not None:
        try:
            #CONSUME THE WEBSERVICE
            from gluon.contrib.pysimplesoap.client import SoapClient
            from gluon.contrib.pysimplesoap.client import SimpleXMLElement
            client = SoapClient(
                location = svp.supplier,
                action = svp.supplier+"/"+svp.action_service,
                namespace = svp.supplier,
                soap_ns=svp.type_service, trace = True, ns = False)

            import cpfecys
            year = cpfecys.current_year_period()
            sent="<"+svp.send+">"
            for svpf in db(db.validate_student_parameters).select():
                sent +="<"+svpf.parameter_name_validate+">"+svpf.parameter_value_validate+"</"+svpf.parameter_name_validate+">"
            sent += "<CARNET>"+str(check_carnet)+"</CARNET><CICLO>"+str(year.yearp)+"</CICLO></"+svp.send+">"
            back = client.call(svp.action_service,xmlDatos=sent)

            #PREPARE FOR RETURNED XML WEB SERVICE
            xml = back.as_xml()
            xml=xml.replace('&lt;','<')
            xml=xml.replace('&gt;','>')
            inicio = xml.find("<"+svp.receive+">")
            final = xml.find("</"+svp.receive+">")
            xml = xml[inicio:(final+17)]
            import xml.etree.ElementTree as ET
            root = ET.fromstring(xml)
            xml = SimpleXMLElement(xml)

            #VARIABLE TO CHECK THE CORRECT FUNCTIONING
            CARNET = xml.CARNET
            NOMBRES = xml.NOMBRES
            APELLIDOS= xml.APELLIDOS
            CORREO = xml.CORREO

            #Unicode Nombres
            try:
                str(NOMBRES)
            except:
                apellidos_var = unicode(NOMBRES).split(' ')
                appellidos_return = None
                for apellido in apellidos_var:
                    try:
                        if appellidos_return is None:
                            appellidos_return = str(apellido)
                        else:
                            appellidos_return = appellidos_return + " " + str(apellido)
                    except:
                        try:

                            temp = unicode(apellido).encode('utf-8').replace('á','á').replace('é','é').replace('í','í').replace('ó','ó').replace('ú','ú').replace('ñ','ñ').replace('Ã','Á').replace('É','É').replace('Í','Í').replace('Ó','Ó').replace('Ú','Ú').replace('Ñ','Ñ').replace('ü‘','ü')
                        except:
                            None

                        apellido = temp
                        if appellidos_return is None:
                            appellidos_return = str(apellido)
                        else:
                            appellidos_return = appellidos_return + " " + str(apellido)
                NOMBRES = appellidos_return
            #Unicode APELLIDOS
            try:
                str(APELLIDOS)
            except:
                apellidos_var = unicode(APELLIDOS).split(' ')
                appellidos_return = None
                for apellido in apellidos_var:
                    try:
                        if appellidos_return is None:
                            appellidos_return = str(apellido)
                        else:
                            appellidos_return = appellidos_return + " " + str(apellido)
                    except:
                        try:
                            temp = unicode(apellido).encode('utf-8').replace('á','á').replace('é','é').replace('í','í').replace('ó','ó').replace('ú','ú').replace('ñ','ñ').replace('Ã','Á').replace('É','É').replace('Í','Í').replace('Ó','Ó').replace('Ú','Ú').replace('Ñ','Ñ').replace('ü‘','ü')
                        except:
                            None

                        apellido = temp
                        if appellidos_return is None:
                            appellidos_return = str(apellido)
                        else:
                            appellidos_return = appellidos_return + " " + str(apellido)
                APELLIDOS = appellidos_return

            if (CARNET is None or CARNET=='') and (NOMBRES is None or NOMBRES=='') and (APELLIDOS is None or APELLIDOS=='') and (CORREO is None or CORREO==''):
                return dict(flag=False,error=False,message=T('The record was removed because the user is not registered to the academic cycle'))
            else:
                isStuden=False
                for c in root.findall('CARRERA'):
                    if c.find('UNIDAD').text=="08" and c.find('EXTENSION').text=="00" and (c.find('CARRERA').text=="05" or c.find('CARRERA').text=="09" or c.find('CARRERA').text=="07"):
                        isStuden=True

                if isStuden==False:
                    return dict(flag=False,error=False,message=T('The record was removed because students not enrolled in career allowed to use the system'))
                else:
                    return dict(flag=True, carnet=int(str(CARNET)), nombres=(NOMBRES), apellidos=(APELLIDOS), correo=str(CORREO),error=False)
        except:
            return dict(flag=False,error=True,message=T('Error with web service validation'))
    else:
        return dict(flag=False,error=True,message=T('Error with web service validation'))
Example #30
0
def inbox():
    import cpfecys
    cperiod = cpfecys.current_year_period()
    period_list = []
    period_list2 = []
    assignations = []
    coursesAdmin = []

    
    
    select_form = FORM(INPUT(_name='semester_id',_type='text'))

    
    if select_form.accepts(request.vars,formname='select_form'):
        if auth.has_membership('Academic'):
            assignations = db((db.academic_course_assignation.semester==str(select_form.vars.semester_id)) & (db.academic_course_assignation.carnet==academic_var.id)).select()
        period_id = str(select_form.vars.semester_id)
    else:
        if auth.has_membership('Academic'):
            assignations = db((db.academic_course_assignation.semester==cperiod.id) & (db.academic_course_assignation.carnet==academic_var.id)).select()
        period_id = str(cperiod.id)

    if (auth.has_membership('Student') or auth.has_membership('Teacher')):
        #coursesAdmin = db((db.user_project.assigned_user == auth.user.id) & (db.user_project.period == period_id) & (db.user_project.project==db.project.id) ).select()
        coursesAdmin = db((db.user_project.assigned_user==auth.user.id)&\
                        (db.user_project.project == db.project.id)&\
                        ((db.user_project.period <= period_id) & \
                        ((db.user_project.period + db.user_project.periods) > period_id))).select()          
        #temp = db((db.user_project.assigned_user == auth.user.id) & (db.user_project.project==db.project.id) ).select(db.user_project.period ,distinct=True)
        
        for t in db(db.period_year).select():
            assignation_temp = db((db.user_project.assigned_user==auth.user.id)&\
                        (db.user_project.project == db.project.id)&\
                        ((db.user_project.period <= t.id) & \
                        ((db.user_project.period + db.user_project.periods) > t.id))).select(db.user_project.ALL).first()
    
    periods_temp = db(db.period_year).select(orderby=~db.period_year.id)
    periods = []
    for period_temp in periods_temp:
        added = False
        if auth.has_membership('Student') or auth.has_membership('Teacher'):
            try:
                if db((db.user_project.assigned_user==auth.user.id)&\
                    (db.user_project.period == db.period_year.id)&\
                    ((db.user_project.period <= t.id) & \
                    ((db.user_project.period + db.user_project.periods) > period_temp.id))).select(db.user_project.ALL).first() is not None:
                    periods.append(period_temp)
                    added = True
            except:
                None
        if auth.has_membership('Academic'):
            try:
                if db((db.academic_course_assignation.carnet==academic_var.id)&(db.academic_course_assignation.semester==period_temp.id)).select().first() is not None:
                    if added == False:
                        periods.append(period_temp)

            except:
                None

    period_var = db(db.period_year.id == period_id).select().first()
        
    return dict(assignations=assignations,email=auth.user.email,period_var=period_var,period_id=period_id,period_list=periods,cperiod=cperiod.id,coursesAdmin=coursesAdmin)
Example #31
0
def graph():
    #Import DB
    import cpfecys
    from decimal import Decimal

    if auth.has_membership('Super-Administrator') or auth.has_membership(
            'Evaluator360') or auth.has_membership('Ecys-Administrator'):
        #Obtain the current period of the system and all the register periods
        period = cpfecys.current_year_period()
        periods = db(db.period_year).select()

        # 2=student; 3= teacher; 6=ecys-administrator
        group = db((db.auth_group.id == 2)|\
                    (db.auth_group.id == 3)|\
                    (db.auth_group.id == 6)).select(db.auth_group.id).first()

        groups = db((db.auth_group.id == 2)|\
                    (db.auth_group.id == 3)|\
                    (db.auth_group.id == 6)).select()

        #Check if the period has changed
        if request.vars['period'] is None:
            None
        else:
            if request.vars['period'] != '':
                period = request.vars['period']
                period = db(db.period_year.id == period).select().first()
            else:
                session.flash = T('Not valid Action.')
                redirect(URL('default', 'index'))

        #check for type of rol selected
        if request.vars['group'] is None:
            None
        else:
            if request.vars['group'] != '':
                group = request.vars['group']
                group = db(db.auth_group.id == group).select().first()
            else:
                session.flash = T('Not valid Action.')
                redirect(URL('default', 'index'))

        columnTotal = (
            (db.answer.grade * db.evaluation_solve_detail.total_count).sum() /
            (db.evaluation_solve_detail.total_count.sum())).with_alias('total')
        rows = db((db.auth_membership.user_id == db.auth_user.id)
                  & (db.auth_membership.group_id == db.auth_group.id)
                  & (db.evaluation_result.evaluated == db.auth_user.id)
                  & (db.evaluation_solve_detail.evaluation_result ==
                     db.evaluation_result.id)
                  & (db.evaluation_solve_detail.repository_answer ==
                     db.repository_answer.id)
                  & (db.evaluation_solve_detail.question_repository ==
                     db.question_repository.id)
                  & (db.repository_answer.question_repository ==
                     db.question_repository.id)
                  & (db.evaluation_result.repository_evaluation ==
                     db.repository_evaluation.id)
                  & (db.repository_answer.answer == db.answer.answer)
                  & (db.repository_evaluation.user_type_evaluated ==
                     db.auth_group.id) & (db.auth_group.id == group)
                  & (db.evaluation_result.period == period)).select(
                      db.question_repository.question,
                      columnTotal,
                      groupby=db.question_repository.id)

        constantCien = Decimal(100)
        graphVal = Decimal(0)
        resGraph = []
        labelGraph = []

        for row in rows:
            graphVal = row.total / constantCien
            resGraph.append("%.3f" % (graphVal))
            labelGraph.append(row.question_repository.question)
        pass

        gridAnswer = db(db.answer).select(db.answer.grade, db.answer.answer)

    else:
        session.flash = T('Not authorized')
        redirect(URL('default', 'index'))

    return dict(periods=periods,
                period=period,
                periodo=period,
                gridAnswer=gridAnswer,
                resGraph=resGraph,
                labelGraph=labelGraph,
                group=group,
                groups=groups,
                grupo=group)
Example #32
0
def results_search():
    #Import DB
    import cpfecys
    from decimal import Decimal

    if auth.has_membership('Super-Administrator') or auth.has_membership(
            'Evaluator360') or auth.has_membership('Ecys-Administrator'):
        #User information
        first_name = auth.user.first_name
        last_name = auth.user.last_name
        user_id = auth.user.id
        fullname = first_name + ' ' + last_name

        #Obtain the current period of the system and all the register periods
        period = cpfecys.current_year_period()
        periods = db(db.period_year).select()

        group = db((db.auth_group.id == 2)|\
                    (db.auth_group.id == 3)|\
                    (db.auth_group.id == 6)).select(db.auth_group.id).first()

        groups = db((db.auth_group.id == 2)|\
                    (db.auth_group.id == 3)|\
                    (db.auth_group.id == 6)).select()

        #Check if the period has changed
        if request.vars['period'] is None:
            None
        else:
            if request.vars['period'] != '':
                period = request.vars['period']
                period = db(db.period_year.id == period).select().first()
            else:
                session.flash = T('Not valid Action.')
                redirect(URL('default', 'index'))

        #check for type of rol selected
        if request.vars['group'] is None:
            None
        else:
            if request.vars['group'] != '':
                group = request.vars['group']
                group = db(db.auth_group.id == group).select().first()
            else:
                session.flash = T('Not valid Action.')
                redirect(URL('default', 'index'))

        columnTotal = (
            (db.answer.grade * db.evaluation_solve_detail.total_count).sum() /
            (db.evaluation_solve_detail.total_count.sum())).with_alias('total')
        rows = db((db.auth_membership.user_id == db.auth_user.id)
                  & (db.auth_membership.group_id == db.auth_group.id)
                  & (db.evaluation_result.evaluated == db.auth_user.id)
                  & (db.evaluation_solve_detail.evaluation_result ==
                     db.evaluation_result.id)
                  & (db.evaluation_solve_detail.repository_answer ==
                     db.repository_answer.id)
                  & (db.evaluation_solve_detail.question_repository ==
                     db.question_repository.id)
                  & (db.repository_answer.question_repository ==
                     db.question_repository.id)
                  & (db.evaluation_result.repository_evaluation ==
                     db.repository_evaluation.id)
                  & (db.repository_answer.answer == db.answer.answer)
                  & (db.repository_evaluation.user_type_evaluated ==
                     db.auth_group.id) & (db.auth_group.id == group)
                  & (db.evaluation_result.period == period)).select(
                      db.question_repository.question,
                      columnTotal,
                      groupby=db.question_repository.id)

        suma = Decimal(0)
        promedio = 0
        constantCien = Decimal(100)
        graphVal = Decimal(0)
        resGraph = []
        labelGraph = []

        if rows.first() is not None:
            for row in rows:
                suma = row.total + suma
                graphVal = row.total / constantCien
                resGraph.append("%.3f" % (graphVal))
                labelGraph.append(row.question_repository.question)

            avg = suma / len(rows)
            promedio = int(avg)

        gridAnswer = db(db.answer).select(db.answer.grade, db.answer.answer)

    else:
        session.flash = T('Not authorized')
        redirect(URL('default', 'index'))

    min_average = 40
    max_average = 60

    return dict(periods=periods,
                period=period,
                periodo=period,
                fullname=fullname,
                rows=rows,
                promedio=promedio,
                gridAnswer=gridAnswer,
                resGraph=resGraph,
                min_average=min_average,
                max_average=max_average,
                group=group,
                groups=groups,
                grupo=group)
Example #33
0
def graphs():
    #requires parameter of project if none is provided then redirected to courses
    project_id = request.vars['project']
    #This also validates the current user is assigned in the project
    if not project_id: redirect(URL('courses'))
    current_project = db((db.user_project.assigned_user == auth.user.id)&
                         (db.project.id == project_id)).select().first()
    if not current_project: redirect(URL('courses'))
    #requires parameter year_period if no one is provided then it is automatically detected
    #and shows the current period
    year_period = request.vars['year_period']
    max_display = 1
    currentyear_period = db.period_year(db.period_year.id == year_period)
    if not currentyear_period:
        import cpfecys
        currentyear_period = cpfecys.current_year_period()
    current_data = db((db.user_project.period <= currentyear_period.id)&
              ((db.user_project.period + db.user_project.periods) > currentyear_period.id)&
              (db.user_project.project == current_project.project.id)&
              (db.auth_group.role == 'Student')&
              (db.auth_membership.group_id == db.auth_group.id)&
              (db.user_project.assigned_user == db.auth_membership.user_id)).select()
    import cpfecys
    current_period_name = T(cpfecys.second_period_name)
    #if we are second semester then start is 1st july
    import datetime
    start_date = datetime.date(currentyear_period.yearp, 7, 7)
    end_date = datetime.date(currentyear_period.yearp, 12, 31)
    if currentyear_period.period == cpfecys.first_period.id:
        current_period_name = T(cpfecys.first_period_name)
        #else we are on first semester, start jan 1st
        start_date = datetime.date(currentyear_period.yearp, 1, 1)
        end_date = datetime.date(currentyear_period.yearp, 6, 30)
    # i need all reports delivered by students for this semester
    reports = db((db.user_project.period <= currentyear_period.id)&
              ((db.user_project.period + db.user_project.periods) > currentyear_period.id)&
              (db.user_project.project == current_project.project.id)&
              (db.auth_group.role == 'Student')&
              (db.auth_membership.group_id == db.auth_group.id)&
              (db.user_project.assigned_user == db.auth_membership.user_id)&
              (db.report_restriction.start_date >= start_date)&
              (db.report_restriction.start_date <= end_date)).select(db.report.ALL, db.report_restriction.ALL, db.user_project.ALL, db.auth_group.ALL, db.auth_membership.ALL, orderby=db.user_project.assigned_user|db.report_restriction.start_date|db.report_restriction.name, left=[db.report.on(db.user_project.id == db.report.assignation), db.report_restriction.on(db.report.report_restriction == db.report_restriction.id)])
    report_activities = db((db.user_project.period <= currentyear_period.id)&
              ((db.user_project.period + db.user_project.periods) > currentyear_period.id)&
              (db.user_project.project == current_project.project.id)&
              (db.auth_group.role == 'Student')&
              (db.auth_membership.group_id == db.auth_group.id)&
              (db.user_project.assigned_user == db.auth_membership.user_id)&
              (db.report_restriction.start_date >= start_date)&
              (db.report_restriction.start_date <= end_date)&
              (db.report.id == db.log_metrics.report)).select(db.log_metrics.ALL, db.report.ALL, db.report_restriction.ALL, db.user_project.ALL, db.auth_group.ALL, db.auth_membership.ALL, orderby=db.user_project.assigned_user|db.report_restriction.start_date|db.report_restriction.name|db.log_metrics.created, left=[db.report.on(db.user_project.id == db.report.assignation), db.report_restriction.on(db.report.report_restriction == db.report_restriction.id)])
    # A helper to display this code within js stuff
    def values_display(values):
        result = "["
        old_user = None
        for item in values:
            if old_user != item.user_project.assigned_user.username:
                if old_user is not None:
                    result += "]},"
                old_user = item.user_project.assigned_user.username
                result += "{ name: '" + item.user_project.assigned_user.username + " - " + item.user_project.assigned_user.first_name +"',"
                result += "data: ["
            #categories.add(item.report.report_restriction)
            result += str(item.report.desertion_continued or 0) + ','
        result += "]}]"
        return XML(result)
    # A helper to display this code within js stuff
    def values_display_activities(values):
        result = "["
        old_user = None
        for item in values:
            if old_user != item.user_project.assigned_user.username:
                if old_user is not None:
                    result += "]},"
                old_user = item.user_project.assigned_user.username
                result += "{ name: '" + item.user_project.assigned_user.username + " - " + item.user_project.assigned_user.first_name +"',"
                result += "data: ["
            #categories.add(item.report.report_restriction)
            result += str(item.log_metrics.mediana or 0) + ','
        result += "]}]"
        return XML(result)
    start_index = currentyear_period.id - max_display - 1
    if start_index < 1:
        start_index = 0
    end_index = currentyear_period.id + max_display
    periods_before = db(db.period_year).select(limitby=(start_index, currentyear_period.id - 1))
    periods_after = db(db.period_year).select(limitby=(currentyear_period.id, end_index))
    other_periods = db(db.period_year).select()
    return dict(current_project = current_project,
                current_data = current_data,
                currentyear_period = currentyear_period,
                current_period_name = current_period_name,
                current_reports = reports,
                values_display = values_display,
                values_display_activities = values_display_activities,
                report_activities = report_activities,
                periods_before = periods_before,
                periods_after = periods_after,
                other_periods = other_periods)
Example #34
0
def send_mail():
    import cpfecys
    cperiod = cpfecys.current_year_period()


    assigned = db((db.user_project.assigned_user == auth.user.id) & ((db.user_project.period <= cperiod.id) & \
                        ((db.user_project.period + db.user_project.periods + 1) > cperiod.id)) & (db.user_project.project==request.vars['project']) ).select(db.user_project.ALL).first()
    try:
        if assigned is None:
            carnet_var = db(
                db.academic.id_auth_user == auth.user.id).select().first()
            assigned_user_var = db(
                (db.academic_course_assignation.carnet == carnet_var.id)
                & (db.academic_course_assignation.assignation ==
                   request.vars['project'])).select().first()
            if (assigned_user_var.semester == cperiod.id) or (
                (assigned_user_var.semester + 1) == cperiod.id):
                None
            else:
                session.flash = T('Not authorized')
                redirect(URL('default', 'index'))
    except:
        session.flash = T('Not authorized')
        redirect(URL('default', 'index'))

    if (request.vars['semester_id'] is None) or (str(
            request.vars['semester_id']) == "None"):
        period_id = cperiod.id
    else:
        period_id = request.vars['semester_id']
    cperiod = db(db.period_year.id == period_id).select().first()

    period_list = []
    if (request.args(0) == 'send'):
        email = request.vars['mail']
        if email != None:
            name = request.vars['name']
            message = request.vars['message']
            subject = request.vars['subject']
            remessage = request.vars['remessage']
            resub = request.vars['resub']
            retime = request.vars['retime']
            var_project_name = request.vars['var_project_name']
            if message != '' and subject != '':
                fail = reply_mail_with_email(email, message, remessage, retime,
                                             resub, subject, cperiod,
                                             var_project_name)
                if fail > 0:
                    response.flash = T('Sent Error')
                else:
                    response.flash = T('Mail Sent')
            else:
                response.flash = T('Fill all fields of the mail')
            return dict(email=email,
                        name=name,
                        remessage=remessage,
                        retime=retime,
                        resub=resub,
                        var_project_name=var_project_name)
        else:
            list_users = request.vars['list_users']
            message = request.vars['message']
            subject = request.vars['subject']
            var_course = request.vars['var_course']

            if list_users != None and var_course != '' and message != '' and subject != '':
                fail = send_mail_to_users(list_users, message, subject,
                                          cperiod.period.name, cperiod.yearp,
                                          var_course)
                if fail > 0:
                    response.flash = T('Sent Error')
                else:
                    response.flash = T('Mail Sent')
            else:
                response.flash = T('Fill all fields of the mail')
            academic_var = db.academic(
                db.academic.id_auth_user == auth.user.id)

            assignations = []

            assignations = db(
                (db.academic_course_assignation.semester == period_id)
                & (db.academic_course_assignation.carnet == academic_var.id)
            ).select()
            period_list = db(db.academic_course_assignation.carnet ==
                             academic_var.id).select(
                                 db.academic_course_assignation.semester,
                                 distinct=True)
            return dict(email=None,
                        assignations=assignations,
                        cperiod=cperiod,
                        period_list=period_list,
                        period_id=period_id)

    else:
        if (request.args(0) == 'period'):
            period_id = subject = request.vars['semester_id']
        if request.vars['mail'] != None:
            email = request.vars['mail']
            name = request.vars['name']
            remessage = request.vars['remessage']
            retime = request.vars['retime']
            resub = request.vars['resub']
            project_var = db.project(db.project.id == request.vars['project'])
            var_project_name = project_var.name
            return dict(email=email,
                        name=name,
                        remessage=remessage,
                        retime=retime,
                        resub=resub,
                        var_project_name=var_project_name)
        else:
            academic_var = db.academic(
                db.academic.id_auth_user == auth.user.id)
            assignations = db(
                (db.academic_course_assignation.semester == period_id)
                & (db.academic_course_assignation.carnet == academic_var.id)
            ).select()
            period_list = db(db.academic_course_assignation.carnet ==
                             academic_var.id).select(
                                 db.academic_course_assignation.semester,
                                 distinct=True)
            return dict(email=None,
                        assignations=assignations,
                        cperiod=cperiod,
                        period_list=period_list,
                        period_id=period_id)
Example #35
0
def evaluation_reply():
    import cpfecys
    cperiod = cpfecys.current_year_period()

    project = request.vars['project']
    period = request.vars['period']
    evaluation = request.vars['evaluation']
    evaluated = request.vars['evaluated']

    if db((db.auth_user.id==auth.user.id) & \
        (db.user_project.project==project) & \
        ((db.user_project.period <= period) & ((db.user_project.period + db.user_project.periods) > period))).select().first() is None:
        academic_var = db.academic(db.academic.id_auth_user==auth.user.id)
        if db((db.academic_course_assignation.carnet==academic_var.id)&(db.academic_course_assignation.semester==period)&(db.academic_course_assignation.assignation==project)).select().first() is None:
            session.flash  =T('Not authorized')
            redirect(URL('default','index'))

    evaluated = db((db.auth_user.id==evaluated) & \
        ((db.user_project.period <= period) & ((db.user_project.period + db.user_project.periods) > period))).select().first() 
    if evaluated is None:
        session.flash  =T('Not authorized')
        redirect(URL('default','index'))

    var_evaluation = db((db.evaluation.id == evaluation)).select().first()

    if (str(period) != str(cperiod.id)):
        session.flash  =T('Not authorized')
        redirect(URL('default','index'))

    user_role = None
    if auth.has_membership('Student') or auth.has_membership('Teacher'):
        try:
            if db((db.user_project.assigned_user == auth.user.id) & \
                ((db.user_project.period <= period) & ((db.user_project.period + db.user_project.periods) > period))).select().first() is not None:
                if auth.has_membership('Student'):
                    user_role = 2
                else:
                    user_role = 3
        except:
            None
    if auth.has_membership('Academic'):
        try:
            academic_var = db.academic(db.academic.id_auth_user==auth.user.id)
            if db((db.academic_course_assignation.carnet==academic_var.id)&(db.academic_course_assignation.semester==period)).select().first() is not None:
                user_role = 5
        except:
            None

    if var_evaluation.repository_evaluation.user_type_evaluator != user_role:
        session.flash  =T('Not authorized')
        redirect(URL('default','index'))

    var_repository_evaluation = db(db.repository_evaluation.id == var_evaluation.repository_evaluation).select().first()
    question_category = db(db.question_repository.repository_evaluation == var_evaluation.repository_evaluation).select(db.question_repository.question_type_name,distinct=True) 
    
    evaluation_result = db((db.evaluation_result.repository_evaluation == var_evaluation.repository_evaluation) &\
                                (db.evaluation_result.evaluated == evaluated.auth_user.id) & \
                                (db.evaluation_result.period == period) & \
                                (db.evaluation_result.project == project) ).select().first()
                             
    if (evaluation_result is not None) and \
        (db((db.evaluation_auth_user.evaluation_result == evaluation_result.id) &\
        (db.evaluation_auth_user.evaluator == auth.user.id) ).select().first() is not None):
        session.flash  =T('Not authorized')
        redirect(URL('default','index'))

    if (request.args(0) == 'send'):
        
        if evaluation_result is None:
            evaluation_result_id = db.evaluation_result.insert(repository_evaluation = var_evaluation.repository_evaluation,
                                        evaluated = evaluated.auth_user.id,
                                        period = period,
                                        project = project)
        else:
            evaluation_result_id = evaluation_result.id

        evaluation_auth_user = db((db.evaluation_auth_user.evaluation_result == evaluation_result_id) &\
                                (db.evaluation_auth_user.evaluator == auth.user.id) ).select().first()
        if evaluation_auth_user is None:
            db.evaluation_auth_user.insert(evaluation_result = evaluation_result_id,
                                        evaluator = auth.user.id)

        question_query = db((db.question_repository.repository_evaluation == var_evaluation.repository_evaluation)).select()
        for question in question_query:
            answer_query = db((db.repository_answer.question_repository == question.id) ).select()
            if len(answer_query) == 0:
                if (request.vars['group_'+str(question.id)] is not None) & (request.vars['group_'+str(question.id)] != ""):
                    db.evaluation_solve_text.insert(evaluation_result = evaluation_result_id,
                                                question_repository = question.id,
                                                answer = request.vars['group_'+str(question.id)])
            else:
                for answer in answer_query:
                    if answer.exclusive_one_answer ==  True:
                        if request.vars['group_'+str(question.id)] is not None:
                            if str(request.vars['group_'+str(question.id)]) == str(answer.id):
                                evaluation_solve_detail = db((db.evaluation_solve_detail.evaluation_result == evaluation_result_id) &\
                                    (db.evaluation_solve_detail.question_repository == question.id) & \
                                    (db.evaluation_solve_detail.repository_answer == answer.id)).select().first()
                                if evaluation_solve_detail is None:
                                    db.evaluation_solve_detail.insert(evaluation_result = evaluation_result_id,
                                                            question_repository = question.id,
                                                            repository_answer = answer.id,
                                                            total_count = 1)
                                else:
                                    db(db.evaluation_solve_detail.id == evaluation_solve_detail.id).update(total_count = (evaluation_solve_detail.total_count + 1) )

        
        session.flash = T('The evaluation has been sent')            
        redirect(URL('evaluation','evaluation_list', vars=dict(period=period,project=project) ))

    return dict(var_evaluation = var_evaluation,
                var_repository_evaluation = var_repository_evaluation,
                question_category = question_category,
                evaluated = evaluated)
Example #36
0
def academic_assignation_upload():
    def files():
        f = db(db.uploaded_file.name=='CargaEstudiantes_TutoresAcademicos').select()
        nameP = ''
        for p2 in f:
            nameP=p2.file_data
        return nameP
        return dict(nameP=nameP)

    assignation = request.vars['assignation']
    check = db.user_project(id=assignation, assigned_user = auth.user.id)
    name = check.project.name
    import csv
    error_users = []
    aviso_users = []
    success = False
    import cpfecys
    import datetime
    cdate = datetime.datetime.now()
    current_period = cpfecys.current_year_period()
    if request.vars.csvfile != None:
        try:
            file = request.vars.csvfile.file
        except AttributeError:
            response.flash = T('Please upload a file.')
            return dict(success = False,
                file = False,
                periods = periods,
                current_period = current_period,
                name=name, files=files)
        try:
            cr = csv.reader(file, delimiter=',', quotechar='"')
            success = True
            header = next(cr)
            for row in cr:
                ## parameters
                rcarnet = row[0]
                remail = row[1]
                rlaboratorio = row[2]
                ## check if user exists                
                check = db.user_project(id =assignation, assigned_user = auth.user.id)                      
                usr = db.academic(db.academic.carnet == rcarnet)        
                if usr is None:
                    #Email validation        
                    if rcarnet == '':
                        row.append(T('Error: ') + T('El carnet es un campo obligatorio.'))
                        error_users.append(row)
                    else:            
                        if IS_EMAIL()(remail)[1]:
                            row.append(T('Error: ') + T('El correo ingresado no es correcto.'))
                            error_users.append(row)
                        else:
                            #T o F validation
                            if rlaboratorio != 'T' and rlaboratorio != 'F':
                                row.append(T('Error: ') + T('El tipo de laboratorio ingresado no es correcto. Este debe ser T o F.'))
                                error_users.append(row)
                            else:
                                #insert a new user with csv data
                                usr = db.academic.insert(carnet = rcarnet,
                                                              email = remail)
                                #Add log
                                db.academic_log.insert(user_name = auth.user.username, 
                                                        roll =  'Student', 
                                                        operation_log = 'insert', 
                                                        after_carnet = rcarnet, 
                                                        after_email = remail, 
                                                        id_academic = usr.id,
                                                        id_period = current_period.id,
                                                        description = 'Se inserto desde archivo CSV.')
                                #add user to the course
                                ingresado = db.academic_course_assignation.insert(carnet = usr.id, semester = current_period, assignation = check.project, laboratorio = rlaboratorio)
                                #Add to log
                                lab_var = ''
                                if rlaboratorio == 'T':
                                    lab_var = 'True'
                                else:
                                    lab_var = 'False'

                                #Search for user roles
                                result = db(db.auth_membership.user_id==auth.user.id).select()
                                roll_var = ''
                                i = 0;
                                for a in result:
                                    if i == 0:
                                        roll_var = a.group_id.role
                                        i = i+1
                                    else:
                                        roll_var = roll_var + ',' + a.group_id.role

                                db.academic_course_assignation_log.insert(user_name = auth.user.username, roll =  roll_var, 
                                                        operation_log = 'insert', 
                                                        after_carnet = rcarnet, 
                                                        after_course = str(check.project.name), 
                                                        after_year = str(current_period.yearp) ,
                                                        after_semester = str(current_period.period),
                                                        after_laboratory = lab_var,
                                                        id_academic_course_assignation = str(ingresado.id),
                                                        id_period = current_period.id,
                                                        description = 'Se inserto desde archivo CSV.')
                else:
                    #Agregar la advertencia que el usuario ya se encuentra registrado en el sistema
                    row.append(T('Aviso: ') + T('El estudiante ya se encuentra registrado en el sistema'))
                    usr2 = db.academic_course_assignation((db.academic_course_assignation.semester == current_period) & (db.academic_course_assignation.assignation == check.project) & (db.academic_course_assignation.carnet == usr.id))
                    if usr2 is None:
                        #T o F validation
                        if rlaboratorio != 'T' and rlaboratorio != 'F':
                            row.append(T('Error: ') + T('El tipo de laboratorio ingresado no es correcto. Este debe ser T o F.'))
                            error_users.append(row)
                        else:
                            lab_var = ''
                            if rlaboratorio == 'T':
                                lab_var = 'True'
                            else:
                                lab_var = 'False'

                            #Search for user roles
                            result = db(db.auth_membership.user_id==auth.user.id).select()
                            roll_var = ''
                            i = 0;
                            for a in result:
                                if i == 0:
                                    roll_var = a.group_id.role
                                    i = i+1
                                else:
                                    roll_var = roll_var + ',' + a.group_id.role

                            ingresado = db.academic_course_assignation.insert(carnet = usr.id, semester = current_period, assignation = check.project, laboratorio = rlaboratorio)
                            db.academic_course_assignation_log.insert(user_name = auth.user.username, roll =  roll_var, 
                                                        operation_log = 'insert', 
                                                        after_carnet = rcarnet, 
                                                        after_course = str(check.project.name), 
                                                        after_year = str(current_period.yearp) ,
                                                        after_semester = str(current_period.period),
                                                        after_laboratory = lab_var,
                                                        id_academic_course_assignation = str(ingresado.id),
                                                        id_period = current_period.id,
                                                        description = 'Se inserto desde archivo CSV.')
                            aviso_users.append(row)
                    else:
                        row.remove(T('Aviso: ') + T('El estudiante ya se encuentra registrado en el sistema'))
                        row.append(T('Error: ') + T('El estudiante ya se encuentra registrado en el sistema y asignado al curso'))
                        error_users.append(row)
                    continue
        except:
            response.flash = T('File doesn\'t seem properly encoded.')
            return dict(success = False,
                file = False,
                periods = periods,
                current_period = current_period,
                name=name, files=files)
        response.flash = T('Data uploaded')
        return dict(success = success,
                    errors = error_users,
                    avisos = aviso_users,
                    periods = periods,
                    current_period = current_period,
                    name=name, files=files)
    return dict(success = False,
                file = False,
                periods = periods,
                current_period = current_period,
                name=name, files=files)
Example #37
0
def auto_daily():
    ## Get current year period
    import cpfecys
    currentyear_period = cpfecys.current_year_period()
    ## Get all report_restriction of this period_year that end_date is beyond today
    import datetime
    current_date = datetime.datetime.now()
    #if it is the first semester then the restriction should be:
    #start date >= January 1 year 00:00:00
    #end date >= January 1 year 00:00:00
    #start date < July 1 year 00:00:00
    #end date < July 1 year 00:00:00
    #if it is the second semester then the restriction should be:
    #start date >= July 1 year 00:00:00
    #end date >= July 1 year 00:00:00
    #start date < Jan 1 year 00:00:00
    #end date < Jan 1 year 00:00:00
    if currentyear_period.period == cpfecys.first_period.id:
        date_min = datetime.datetime(currentyear_period.yearp, 1, 1)
        date_max = datetime.datetime(currentyear_period.yearp, 7, 1)
    else:
        date_min = datetime.datetime(currentyear_period.yearp, 7, 1)
        date_max = datetime.datetime(currentyear_period.yearp, 1, 1)
    expired_restrictions = db((db.report_restriction.end_date < current_date)&
                              (db.report_restriction.start_date >= date_min)&
                              (db.report_restriction.end_date >= date_min)&
                              (db.report_restriction.start_date < date_max)&
                              (db.report_restriction.end_date < date_max)&
                              (db.report_restriction.is_enabled == True)).select()
    ## Get all assignations for this period_year
    semester_assignations = db((db.user_project.period <= currentyear_period.id)&
                     ((db.user_project.period + db.user_project.periods) > currentyear_period.id)).select()
    # For every assignation and restriction
    ## This makes all missed assignations automatically not sent and set to failed reports :(
    missed_reports = 0
    status_acceptance = db.report_status(db.report_status.name == 'Acceptance')
    for assignation in semester_assignations:
        for restriction in expired_restrictions:
            reports = db((db.report.assignation == assignation.id)&
                         (db.report.report_restriction == restriction.id)).count()
            if not(reports > 0):
                missed_reports += 1
                db.report.insert(assignation = assignation.id,
                                 min_score = cpfecys.get_custom_parameters().min_score,
                                 report_restriction = restriction.id,
                                 created = current_date,
                                 score = 0,
                                 status = status_acceptance,
                                 never_delivered = True,
                                 teacher_comment =  T('The period of time to create the report finished and it was never completed; so automatically it is considered as failed.'))
    ## This makes all 'Draft' reports that have no delivered anything to be set to failed!
    drafties = db((db.report.status == db.report_status(name = 'Draft'))&
               (db.report_restriction.end_date < current_date)&
               (db.report.report_restriction == db.report_restriction.id)&
               (db.report.heading == None)&
               (db.report.footer == None)&
               (db.report.desertion_started == None)&
               (db.report.desertion_gone == None)&
               (db.report.desertion_continued == None)&
               (db.report.hours == None)).select()
    total_drafties_empty = len(drafties)
    for d in drafties:
        d.report.score = 0
        d.report.status = db.report_status(name = 'Acceptance')
        d.report.teacher_comment =  T('The period of time to create the report finished and it was never completed; so automatically it is considered as failed.')
        d.report.never_delivered = True
        d.report.min_score = cpfecys.get_custom_parameters().min_score
        d.report.update_record()
##

    ## This makes all 'Draft' reports that expired get to 'Grading'
    drafties = db((db.report.status == db.report_status(name = 'Draft'))&
               (db.report_restriction.end_date < current_date)&
               (db.report.report_restriction == db.report_restriction.id)).select()
    total_drafties = len(drafties)
    import cpfecys
    signature = (cpfecys.get_custom_parameters().email_signature or '')
    for d in drafties:
        d.report.status = db.report_status(name = 'Grading')
        d.report.min_score = cpfecys.get_custom_parameters().min_score
        d.report.update_record()
        ## TODO: Send Email according to assignation
        # Notification Message
        me_the_user = d.report.assignation.assigned_user
        message = '<html>' + T('The report') + ' ' \
        + '<b>' + XML(d.report_restriction['name']) + '</b><br/>' \
        + T('sent by student: ') + XML(me_the_user.username) + ' ' \
        + XML(me_the_user.first_name) + ' ' + XML(me_the_user.last_name) \
        + '<br/>' \
        + T('was sent to be checked.') + '<br/>' + T('Checking can be done in:') \
        + ' ' + cpfecys.get_domain() + '<br />' + signature + '</html>'
        # send mail to teacher and student notifying change.
        mails = []
        # retrieve teacher's email
        teachers = db((db.project.id == d.report.assignation.project)&
                      (db.user_project.project == db.project.id)&
                      (db.user_project.assigned_user == db.auth_user.id)&
                      (db.auth_membership.user_id == db.auth_user.id)&
                      (db.auth_membership.group_id == db.auth_group.id)&
                      (db.auth_group.role == 'Teacher')).select()
        for teacher in teachers:
            mails.append(teacher.auth_user.email)
        # retrieve student's email
        student_mail = me_the_user.email
        mails.append(student_mail)
        was_sent = mail.send(to=mails,
                  subject=T('[DTT]Automatic Notification - Report ready to be checked.'),
                  # If reply_to is omitted, then mail.settings.sender is used
                  reply_to = student_mail,
                  message=message)
        #MAILER LOG
        db.mailer_log.insert(sent_message = message,
                             destination = ','.join(mails),
                             result_log = str(mail.error or '') + ':' + str(mail.result),
                             success = was_sent)
    ## This makes all 'Recheck' reports that expired to 'Grading'
    import datetime
    recheckies = db((db.report_restriction.id == db.report.report_restriction)&
                    (db.report.status == db.report_status(name='Recheck'))&
                    (db.report.score_date <= (current_date - datetime.timedelta(days = cpfecys.get_custom_parameters().rescore_max_days)))).select()
    total_recheckies = len(recheckies)
    import cpfecys
    signature = cpfecys.get_custom_parameters().email_signature
    for rech in recheckies:
        rech.report.status = db.report_status(name = 'Grading')
        rech.report.update_record()
        ## TODO: Send Email according to assignation
        me_the_user = rech.report.assignation.assigned_user
        message = '<html>' + T('The report') + ' ' \
        + '<b>' + XML(rech.report_restriction['name']) + '</b><br/>' \
        + T('sent by student: ') + XML(me_the_user.username) + ' ' \
        + XML(me_the_user.first_name) + ' ' + XML(me_the_user.last_name) \
        + '<br/>' \
        + T('was sent to be checked.') + '<br/>' + T('Checking can be done in:') \
        + ' ' + cpfecys.get_domain() + '<br />' + signature + '</html>'
        # send mail to teacher and student notifying change.
        mails = []
        # retrieve teacher's email
        teachers = db((db.project.id == rech.report.assignation.project)&
                      (db.user_project.project == db.project.id)&
                      (db.user_project.assigned_user == db.auth_user.id)&
                      (db.auth_membership.user_id == db.auth_user.id)&
                      (db.auth_membership.group_id == db.auth_group.id)&
                      (db.auth_group.role == 'Teacher')).select()
        for teacher in teachers:
            mails.append(teacher.auth_user.email)
        # retrieve student's email
        student_mail = me_the_user.email
        mails.append(student_mail)
        was_sent = mail.send(to=mails,
                  subject=T('[DTT]Automatic Notification - Report ready to be checked.'),
                  # If reply_to is omitted, then mail.settings.sender is used
                  reply_to = student_mail,
                  message = message)
        #MAILER LOG
        db.mailer_log.insert(sent_message = message,
                             destination = ','.join(mails),
                             result_log = str(mail.error or '') + ':' + str(mail.result),
                             success = was_sent)
    db.commit()
    auto_freeze()
    return T('Total Updated Reports: ') + str(total_recheckies + total_drafties + missed_reports) + ' ' + \
            T('Automatically Updated Draft Reports: ') + str(total_drafties) + ' ' + \
            T('Automatically Updated Recheck Reports: ') + str(total_recheckies) + ' ' + \
            T('Reports Never Delivered: ') + str(missed_reports + total_drafties_empty)
Example #38
0
            T('Automatically Updated Draft Reports: ') + str(total_drafties) + ' ' + \
            T('Automatically Updated Recheck Reports: ') + str(total_recheckies) + ' ' + \
            T('Reports Never Delivered: ') + str(missed_reports + total_drafties_empty)

from gluon.scheduler import Scheduler
scheduler = Scheduler(db3, dict(auto_daily = auto_daily), heartbeat = 60)

import cpfecys
cpfecys.setup(db, auth, scheduler, auto_daily)
cpfecys.force_student_data_update(request.env.path_info,
                                  ['/student/update_data',
                                   '/default/user/logout'])

#resources menu
#import cpfecys
period = cpfecys.current_year_period()
data = db((db.item_restriction.is_public == True)&
          (db.item_restriction.period == period)).select()
mnu = []
for d in data:
    mnu.append((T(d.name), False, URL('default', 'resources', vars=dict(r=d.id))))
response.menu.extend([(T('Resources & Schedules'), False, URL(), mnu)])

#any user should be able to see this menu
#resources menu
response.menu.extend([
(T('Help'), False, URL(), [
   (T('Links'), False, URL('default', 'links'), []),
   (T('Files'), False, URL('default', 'files'), []),
])])
Example #39
0
def academic_assignation():
    #requires parameter year_period if no one is provided then it is 
    #automatically detected
    #and shows the current period
    assignation = request.vars['assignation']
    year_period = request.vars['year_period']
    max_display = 1
    import cpfecys
    currentyear_period = db.period_year(db.period_year.id == year_period)
    check = db.user_project(id=assignation, assigned_user = auth.user.id)

    if not currentyear_period:
        currentyear_period = cpfecys.current_year_period()
        changid = currentyear_period.id
    if (check is None):
        #check if there is no assignation or if it is locked (shouldn't be touched)
        if (session.last_assignation is None):
            redirect(URL('default','index'))
            return
        else:
            check = db.user_project(id = session.last_assignation)
            if cpfecys.assignation_is_locked(check):
                redirect(URL('default','index'))
                return
    else:
        session.last_assignation = check.id
    cyearperiod = cpfecys.current_year_period()

    if request.vars['search_var'] is None:
        query = ((db.academic_course_assignation.semester == currentyear_period.id) & (db.academic_course_assignation.assignation==check.project))
    else:
        query2 = db((db.academic_course_assignation.carnet == db.academic.id) & (db.academic_course_assignation.semester == currentyear_period.id) & (db.academic_course_assignation.assignation==check.project) & (db.academic.carnet.like('%'+request.vars['search_var']+'%')) ).select()
        dest = []
        query = None
        for q in query2:
            dest.append(q.academic.id)
            #consultar a la base de datos para obtener a los usuarios a los que enviaremos
        query = (db.academic_course_assignation.carnet.belongs(dest) & (db.academic_course_assignation.semester == currentyear_period.id) & (db.academic_course_assignation.assignation==check.project))
        

    fields = (db.academic_course_assignation.carnet, db.academic_course_assignation.laboratorio)

    #db.academic.id.readable = False
    #db.academic.id.writable = False
    #db.academic.carnet.readable = False    
    #db.academic.carnet.writable = False
    #db.academic.email.writable = False
    #db.academic.email.readable = False


    db.academic_course_assignation.assignation.default = check.project
    db.academic_course_assignation.assignation.writable = False
    db.academic_course_assignation.assignation.readable = False
    db.academic_course_assignation.semester.default = currentyear_period.id
    db.academic_course_assignation.semester.writable = False
    db.academic_course_assignation.semester.readable = False

    if (currentyear_period.id == cpfecys.current_year_period().id):
        grid = SQLFORM.grid(query, fields=fields, oncreate=oncreate_academic_assignation, onupdate=onupdate_academic_assignation, ondelete=ondelete_academic_assignation,csv=False)
    else:
        checkProject = db((db.user_project.project == check.project) & (db.user_project.assigned_user==check.assigned_user) & (db.user_project.period==currentyear_period.id)).select()
        b=0
        for a in checkProject:
            b=b+1
        if b!=0:
            grid = SQLFORM.grid(query, fields=fields, deletable=False, editable=False, create=False,csv=False)
        else:
            session.flash  =T('Not authorized')
            redirect(URL('default','index'))

    current_period_name = T(cpfecys.second_period.name)
    if currentyear_period.period == cpfecys.first_period.id:
        current_period_name = T(cpfecys.first_period.name)
    start_index = currentyear_period.id - max_display - 1
    if start_index < 1:
        start_index = 0
    end_index = currentyear_period.id + max_display
    periods_before = db(db.period_year).select(limitby=(start_index,  \
        currentyear_period.id - 1))
    periods_after = db(db.period_year).select(limitby=(currentyear_period.id, \
     end_index))
    other_periods = db(db.period_year).select()
    return dict(grid = grid,
                currentyear_period = currentyear_period,
                current_period_name = current_period_name,
                periods_before = periods_before,
                periods_after = periods_after,
                other_periods = other_periods,
                name = check.project.name,
                assignation = check.id)
Example #40
0
def onupdate_academic_assignation(form):
    import datetime
    import cpfecys

    cdate = datetime.datetime.now()
    assignation = request.vars['assignation']
    
    
    currentyear_period = cpfecys.current_year_period()

    check = db.user_project(id=assignation, assigned_user = auth.user.id)
    if (check is None):
        #check if there is no assignation or if it is locked (shouldn't be touched)
        if (session.last_assignation is None):
            redirect(URL('default','index'))
            return
        else:
            check = db.user_project(id = session.last_assignation)
            if cpfecys.assignation_is_locked(check):
                redirect(URL('default','index'))
                return
    else:
        session.last_assignation = check.id

    #Search for user roles
    result = db(db.auth_membership.user_id==auth.user.id).select()
    roll_var = ''
    i = 0;
    for a in result:
        if i == 0:
            roll_var = a.group_id.role
            i = i+1
        else:
            roll_var = roll_var + ',' + a.group_id.role

    #Search for carnet
    student_var = db(db.academic.id == form.vars.carnet).select()
    carnet_var = ''
    for a in student_var:
        carnet_var = a.carnet

    #Search for before values
    student_var2 = db(db.academic_course_assignation_log.id_academic_course_assignation == form.vars.id).select(orderby=db.academic_course_assignation_log.id)
    bef_carnet_var = ''
    course_var = ''
    year_var = ''
    semester_var = ''
    laboratory_var = ''
    for a in student_var2:
        bef_carnet_var = a.after_carnet
        course_var = a.after_course
        year_var = a.after_year
        semester_var = a.after_semester
        laboratory_var = a.after_laboratory
    if form.vars.delete_this_record != None:
        db.academic_course_assignation_log.insert(user_name = auth.user.username, 
                                                roll =  roll_var, 
                                                operation_log = 'delete', 
                                                before_carnet = bef_carnet_var, 
                                                before_course = course_var,
                                                before_year = year_var,
                                                before_semester = semester_var,
                                                before_laboratory = laboratory_var,
                                                id_period = str(currentyear_period.id),
                                                description = 'Se elimino el registro desde la pagina Asignar Estudiantes')
    else:
        #Check that there is not an assignation
        usr2 = db((db.academic_course_assignation.id != form.vars.id) & (db.academic_course_assignation.semester == currentyear_period.id) & (db.academic_course_assignation.assignation == check.project) & (db.academic_course_assignation.carnet == form.vars.carnet)).select()
        i = 0;
        for a in usr2:
            i = i+1

        if i == 0: 
            #If there is not an assignation update the log
            session.flash = T('Se realizó la modificacion')
            db.academic_course_assignation_log.insert(user_name = auth.user.username, 
                                                roll =  roll_var, 
                                                operation_log = 'update', 
                                                before_carnet = bef_carnet_var, 
                                                before_course = course_var,
                                                before_year = year_var,
                                                before_semester = semester_var,
                                                before_laboratory = laboratory_var,
                                                after_carnet = carnet_var, 
                                                after_course = check.project.name,
                                                after_year = str(currentyear_period.yearp) ,
                                                after_semester = str(currentyear_period.period),
                                                after_laboratory = form.vars.laboratorio,
                                                id_academic_course_assignation = form.vars.id,
                                                id_period = str(currentyear_period.id),
                                                description = 'Se modifico el registro desde la pagina Asignar Estudiantes')
        else:
            #If there is an assignation delete the last record
            #db(db.academic_course_assignation.id==form.vars.id).delete()
            temp_academic = db(db.academic.carnet==bef_carnet_var).select()
            id_academic = ''
            for a in temp_academic:
                id_academic = a.id
            db(db.academic_course_assignation.id==form.vars.id).update(carnet=id_academic,laboratorio=laboratory_var)
            session.flash = T('Error: Ya existe la asignacion, no se modifico el estudiante')
Example #41
0
def results():
    #Import DB
    import cpfecys
    from decimal import Decimal

    first_name = ''
    last_name = ''
    user_id = None
    fullname = ''
    periods = []
    group = ''
    nameperiod = ''

    if auth.has_membership('Student') or auth.has_membership('Teacher'):
        if auth.has_membership('Ecys-Administrator'):
            first_name = ''
            last_name = ''
            user_id = None
        else:
            #User information
            first_name = auth.user.first_name
            last_name = auth.user.last_name
            user_id = auth.user.id
            fullname = first_name + ' ' + last_name

            #Obtain the current period of the system and all the register periods
            period = cpfecys.current_year_period()

            periods_temp = db(
                db.period_year).select(orderby=~db.period_year.id)

            for period_temp in periods_temp:
                try:
                    if db((db.user_project.assigned_user==auth.user.id)&\
                        (db.user_project.period == db.period_year.id)&\
                        ((db.user_project.period <= period_temp.id) & \
                        ((db.user_project.period + db.user_project.periods) > period_temp.id))).select(db.user_project.ALL).first() is not None:
                        periods.append(period_temp)
                except:
                    None

            #Check if the period has changed
            if request.vars['period'] is None:
                None
            else:
                if request.vars['period'] != '':
                    period = request.vars['period']
                    period = db(db.period_year.id == period).select().first()
                else:
                    session.flash = T('Not valid Action.')
                    redirect(URL('default', 'index'))
        pass
    pass

    if first_name == '' and user_id is None:
        if request.vars['period'] is None:
            None
        else:
            if request.vars['period'] != '':
                period = request.vars['period']
                user_id = request.vars['user']
                group = request.vars['group']
                qFullname = db(db.auth_user.id == user_id).select(
                    db.auth_user.first_name, db.auth_user.last_name).first()
                fullname = qFullname.first_name + ' ' + qFullname.last_name
                nameperiod = db(db.period_year.id == period).select().first()
            else:
                session.flash = T('Not valid Action.')
                redirect(URL('default', 'index'))
    pass

    columnTotal = (
        (db.answer.grade * db.evaluation_solve_detail.total_count).sum() /
        (db.evaluation_solve_detail.total_count.sum())).with_alias('total')
    rows = db((db.evaluation_solve_detail.evaluation_result ==
               db.evaluation_result.id)
              & (db.evaluation_solve_detail.repository_answer ==
                 db.repository_answer.id)
              & (db.evaluation_solve_detail.question_repository ==
                 db.question_repository.id)
              & (db.repository_answer.question_repository ==
                 db.question_repository.id)
              & (db.evaluation_result.repository_evaluation ==
                 db.repository_evaluation.id)
              & (db.repository_answer.answer == db.answer.answer)
              & (db.evaluation_result.evaluated == db.auth_user.id)
              & (db.auth_user.id == user_id)
              & (db.evaluation_result.period == period)).select(
                  db.question_repository.question,
                  columnTotal,
                  groupby=db.question_repository.id)
    #print '********************LAST SQL'
    #print db._lastsql
    ##calcular el promedio de los resultados
    suma = Decimal(0)
    promedio = 0
    constantCien = Decimal(100)
    graphVal = Decimal(0)
    resGraph = []

    if rows.first() is not None:
        for row in rows:
            #print row.question_repository.question, row.total
            suma = row.total + suma
            graphVal = row.total / constantCien
            resGraph.append("%.3f" % (graphVal))
        pass

        avg = suma / len(rows)
        promedio = int(avg)
    pass

    gridAnswer = db(db.answer).select(db.answer.grade, db.answer.answer)
    #gridAnswer = SQLFORM.grid(query, fields = [db.answer.grade, db.answer.answer], csv=False,deletable=False,
    #editable=False, details=False, selectable=None, create=False, searchable=False,sortable=False,
    #links_in_grid=False, user_signature=False, showbuttontext=False, ignore_rw = True)

    min_average = 40
    max_average = 60

    return dict(periods=periods,
                period=period,
                periodo=period,
                fullname=fullname,
                rows=rows,
                promedio=promedio,
                gridAnswer=gridAnswer,
                resGraph=resGraph,
                min_average=min_average,
                max_average=max_average,
                group=group,
                nameperiod=nameperiod)
Example #42
0
def evaluacion():
    import cpfecys
    import redis
    r = redis.StrictRedis(host='127.0.0.1', port=6379, db=0)

    period = cpfecys.current_year_period()
    periodo = request.vars['period']
    projecto = request.vars['project']
    project = db(db.project.id==projecto).select().first()
    x = tuple(request.args)
    y = str(''.join(x))
    id_programacion = int(y)
    error = False
    msjError = ""
    privado = False
    activo = True

    JsonQuiz = ""

    programacion = db(db.vw_quiz_actividad.id==int(id_programacion)).select(db.vw_quiz_actividad.ALL).first()
    print "La programacion es:"
    print programacion
    if( int(period.id) != int(periodo)):
        error = True
        msjError = "El periodo actual no corresponde al periodo de la evaluacion"
    pass

    ##Verifico si es privado
    if (programacion.private == 1):
        privado = True
    pass

    ##Verifico si aun sigue estando activo
    if (programacion.Estado_actual == 'Inactivo'):
        activo = True
    else:
        activo = False
    pass

    ##Obtengo la metadata del quiz
    metadata = db(db.tb_metadata_quiz.id_quiz==programacion.id_quiz).select(
        db.tb_metadata_quiz.creador, 
        db.tb_metadata_quiz.curso).first()

    print "La metadata es:"
    print metadata

    cadenaRedis = 'uid:'+str(metadata.creador)+':curso:'+str(metadata.curso)+':quiz:'+str(programacion.id_quiz)
    print "La cadena conexion es:"
    print cadenaRedis
    datos = r.hget(cadenaRedis,'preguntas')
    datos = datos.replace('\n','')
    datos = datos.replace('}]}"','}]}')
    
    print 'El quiz es: ' + datos
    template_respuestas = ""
    template_str = ""
    
    JsonQuiz = datos.replace('{[','{"PREGUNTAS" : [')
    print 'El quiz json:'
    print JsonQuiz

    ##Si el quiz esta activo recupero el detalle
    if (activo == True):
        import json
        JsonQuiz = unicode(JsonQuiz, 'utf-8')
        template_respuestas=json.loads(JsonQuiz)

        for pregunta in template_respuestas["PREGUNTAS"]:
            if(pregunta["tipo"] =="multiple"):
                for respuesta in pregunta["respuesta"]:
                    respuesta["correcta"] ="false"
                pass
            elif (pregunta["tipo"]=="veracidad"):
                pregunta["respuesta"] = None
            else:
                pregunta["respuesta"] = None
            pass
        pass

    #   template_str = json.dumps(template_respuestas)

    pass
    if not session.respuestas:
        session.respuestas = template_respuestas
    print "template de respuestas session:"
    print session.respuestas

    if (privado == True):
        session.bloqueado = True
    else:
        session.bloqueado = False
    pass

    return dict(period=period, project=project,programacion = programacion, error=error, msjError=msjError, privado = privado, activo=activo, JsonQuiz=JsonQuiz, metadata=metadata, bloqueado=session.bloqueado)
Example #43
0
def search():
    #Import DB
    import cpfecys
    from decimal import Decimal

    if auth.has_membership('Super-Administrator') or auth.has_membership(
            'Evaluator360') or auth.has_membership('Ecys-Administrator'):
        #Obtain the current period of the system and all the register periods
        period = cpfecys.current_year_period()
        periods = db(db.period_year).select()

        # 2=student; 3= teacher; 6=ecys-administrator
        group = db((db.auth_group.id == 2)|\
                    (db.auth_group.id == 3)|\
                    (db.auth_group.id == 6)).select(db.auth_group.id).first()

        groups = db((db.auth_group.id == 2)|\
                    (db.auth_group.id == 3)|\
                    (db.auth_group.id == 6)).select()

        #Check if the period has changed
        if request.vars['period'] is None:
            None
        else:
            if request.vars['period'] != '':
                period = request.vars['period']
                period = db(db.period_year.id == period).select().first()
            else:
                session.flash = T('Not valid Action.')
                redirect(URL('default', 'index'))

        #check for type of rol selected
        if request.vars['group'] is None:
            None
        else:
            if request.vars['group'] != '':
                group = request.vars['group']
                group = db(db.auth_group.id == group).select().first()
            else:
                session.flash = T('Not valid Action.')
                redirect(URL('default', 'index'))

        rows = db((db.auth_membership.user_id == db.auth_user.id)
                  & (db.auth_membership.group_id == db.auth_group.id)
                  & (db.evaluation_result.evaluated == db.auth_user.id)
                  & (db.auth_group.id == group)
                  & (db.evaluation_result.period == period)).select(
                      db.evaluation_result.period,
                      db.auth_user.id,
                      db.auth_group.id,
                      db.auth_user.username,
                      db.auth_user.username,
                      db.auth_user.first_name,
                      db.auth_user.last_name,
                      groupby=db.auth_user.id)

    else:
        session.flash = T('Not authorized')
        redirect(URL('default', 'index'))

    return dict(periods=periods,
                period=period,
                periodo=period,
                rows=rows,
                group=group,
                groups=groups,
                grupo=group)
Example #44
0
def inbox():
    import cpfecys
    cperiod = cpfecys.current_year_period()
    period_list = []
    period_list2 = []
    assignations = []
    coursesAdmin = []

    select_form = FORM(INPUT(_name='semester_id', _type='text'))

    if select_form.accepts(request.vars, formname='select_form'):
        if auth.has_membership('Academic'):
            #RGUARAN:se agregó academic_var
            academic_var = db.academic(
                db.academic.id_auth_user == auth.user.id)
            assignations = db((db.academic_course_assignation.semester == str(
                select_form.vars.semester_id))
                              & (db.academic_course_assignation.carnet ==
                                 academic_var.id)).select()
        period_id = str(select_form.vars.semester_id)
    else:
        if auth.has_membership('Academic'):
            #se agregó academic_var
            academic_var = db.academic(
                db.academic.id_auth_user == auth.user.id)
            assignations = db(
                (db.academic_course_assignation.semester == cperiod.id)
                & (db.academic_course_assignation.carnet == academic_var.id)
            ).select()
        period_id = str(cperiod.id)

    if (auth.has_membership('Student') or auth.has_membership('Teacher')):
        #coursesAdmin = db((db.user_project.assigned_user == auth.user.id) & (db.user_project.period == period_id) & (db.user_project.project==db.project.id) ).select()
        coursesAdmin = db((db.user_project.assigned_user==auth.user.id)&\
                        (db.user_project.project == db.project.id)&\
                        ((db.user_project.period <= period_id) & \
                        ((db.user_project.period + db.user_project.periods) > period_id))).select()
        #temp = db((db.user_project.assigned_user == auth.user.id) & (db.user_project.project==db.project.id) ).select(db.user_project.period ,distinct=True)

        for t in db(db.period_year).select():
            assignation_temp = db((db.user_project.assigned_user==auth.user.id)&\
                        (db.user_project.project == db.project.id)&\
                        ((db.user_project.period <= t.id) & \
                        ((db.user_project.period + db.user_project.periods) > t.id))).select(db.user_project.ALL).first()

    periods_temp = db(db.period_year).select(orderby=~db.period_year.id)
    periods = []
    for period_temp in periods_temp:
        added = False
        if auth.has_membership('Student') or auth.has_membership('Teacher'):
            try:
                if db((db.user_project.assigned_user==auth.user.id)&\
                    (db.user_project.period == db.period_year.id)&\
                    ((db.user_project.period <= t.id) & \
                    ((db.user_project.period + db.user_project.periods) > period_temp.id))).select(db.user_project.ALL).first() is not None:
                    periods.append(period_temp)
                    added = True
            except:
                None
        if auth.has_membership('Academic'):
            try:
                if db(
                    (db.academic_course_assignation.carnet == academic_var.id)
                        & (db.academic_course_assignation.semester ==
                           period_temp.id)).select().first() is not None:
                    if added == False:
                        periods.append(period_temp)

            except:
                None

    period_var = db(db.period_year.id == period_id).select().first()

    return dict(assignations=assignations,
                email=auth.user.email,
                period_var=period_var,
                period_id=period_id,
                period_list=periods,
                cperiod=cperiod.id,
                coursesAdmin=coursesAdmin)
Example #45
0
def courses_mail_notifications():
    #show all assignations of current user
    import cpfecys
    def split_name(project):
        try:
            (nameP, projectSection) = str(project).split('(')
        except:
            nameP = project
        return nameP

    def split_section(project):
        try:
            projectSection = None
            nameS = None
            (nameP, projectSection) = str(project).split('(')
            (nameS,garbage) = str(projectSection).split(')')
        except:
            nameS = '--------'
        return nameS
    return dict(assignations = db((db.user_project.assigned_user == auth.user.id) & (db.user_project.period == cpfecys.current_year_period().id)).select(), split_name=split_name, split_section=split_section)
Example #46
0
def send_mail():        
    import cpfecys
    cperiod = cpfecys.current_year_period()
    

    assigned = db((db.user_project.assigned_user == auth.user.id) & ((db.user_project.period <= cperiod.id) & \
                        ((db.user_project.period + db.user_project.periods + 1) > cperiod.id)) & (db.user_project.project==request.vars['project']) ).select(db.user_project.ALL).first()
    try:
        if assigned is None:
            carnet_var = db(db.academic.id_auth_user==auth.user.id).select().first()
            assigned_user_var = db((db.academic_course_assignation.carnet==carnet_var.id)&(db.academic_course_assignation.assignation==request.vars['project'])).select().first()
            if (assigned_user_var.semester == cperiod.id) or ((assigned_user_var.semester + 1) == cperiod.id):
                None
            else:
                session.flash  =T('Not authorized')
                redirect(URL('default','index'))
    except:
        session.flash  =T('Not authorized')
        redirect(URL('default','index'))

    if (request.vars['semester_id'] is None) or (str(request.vars['semester_id']) == "None"):
            period_id = cperiod.id
    else:
        period_id = request.vars['semester_id']
    cperiod =  db(db.period_year.id==period_id).select().first()
    
    
    
    period_list = []
    if (request.args(0) == 'send'):
        email = request.vars['mail']
        if email != None:
            name = request.vars['name']
            message = request.vars['message']
            subject = request.vars['subject']
            remessage = request.vars['remessage']
            resub = request.vars['resub']
            retime = request.vars['retime']
            var_project_name = request.vars['var_project_name']
            if message != '' and subject != '':
                fail = reply_mail_with_email(email,message, remessage, retime, resub, subject, cperiod, var_project_name)
                if fail > 0:
                    response.flash = T('Sent Error')
                else:
                    response.flash = T('Mail Sent')                
            else:
                response.flash = T('Fill all fields of the mail')
            return dict(email=email,name=name,remessage=remessage,retime=retime,resub=resub,var_project_name=var_project_name)
        else:
            list_users = request.vars['list_users']
            message = request.vars['message']
            subject = request.vars['subject']
            var_course = request.vars['var_course']
            
            if list_users!= None and var_course != '' and message != '' and subject != '':
                fail = send_mail_to_users(list_users, message, subject, cperiod.period.name, cperiod.yearp, var_course)
                if fail > 0:
                    response.flash = T('Sent Error')
                else:
                    response.flash = T('Mail Sent')                
            else:
                response.flash = T('Fill all fields of the mail')
            academic_var = db.academic(db.academic.id_auth_user==auth.user.id) 
            
            assignations = []
             
            assignations = db((db.academic_course_assignation.semester==period_id) & (db.academic_course_assignation.carnet==academic_var.id)).select()
            period_list = db(db.academic_course_assignation.carnet==academic_var.id).select(db.academic_course_assignation.semester,distinct=True)
            return dict(email=None,assignations=assignations,cperiod=cperiod,period_list = period_list, period_id = period_id)
        
    else:
        if (request.args(0) == 'period'):
            period_id = subject = request.vars['semester_id']
        if request.vars['mail'] != None:
            email = request.vars['mail']          
            name = request.vars['name']       
            remessage = request.vars['remessage']
            retime = request.vars['retime']
            resub = request.vars['resub']
            project_var = db.project(db.project.id==request.vars['project'])
            var_project_name = project_var.name
            return dict(email=email,name=name,remessage=remessage,retime=retime,resub=resub,var_project_name=var_project_name)
        else:
            academic_var = db.academic(db.academic.id_auth_user==auth.user.id)        
            assignations = db((db.academic_course_assignation.semester==period_id) & (db.academic_course_assignation.carnet==academic_var.id)).select()
            period_list = db(db.academic_course_assignation.carnet==academic_var.id).select(db.academic_course_assignation.semester,distinct=True)
            return dict(email=None,assignations=assignations,cperiod=cperiod,period_list = period_list, period_id = period_id)