Ejemplo n.º 1
0
def indicators_view(context, request):
    
    indicators = context.indicators
    
    return dict(api=TemplateAPI(request),
                competence=context,
                indicators=indicators)
                
Ejemplo n.º 2
0
def view_pw_reset(context, request):

    # Second step: User is visiting reset url
    if 'key' in request.params:
        key = request.params['key']

        if 'form.submitted' in request.params:
            try:
                # FormEncode validation
                schema = PWResetSchema()
                form_result = schema.to_python(request.params)
            except formencode.validators.Invalid, why:
                form = render_template('templates/password_reset.pt',
                                       request=request,
                                       api=TemplateAPI(request))
                # FormEncode fills template with error messages
                form = htmlfill.render(form,
                                       defaults=request.params,
                                       errors=why.error_dict)
                return Response(form)
            else:
                session = DBSession()
                user = session.query(User).filter_by(
                    email=form_result['email']).one()
                if key == user.password_reset_key():
                    user.password = '******' % sha.new(
                        form_result['password'].encode('utf-8')).hexdigest()
                    # Login directly
                    headers = []
                    plugins = request.environ.get('repoze.who.plugins', {})
                    identifier = plugins.get('auth_tkt')
                    if identifier:
                        identity = {'repoze.who.userid': form_result['email']}
                        headers = identifier.remember(request.environ,
                                                      identity)
                    request.environ['repoze.who.userid'] = form_result['email']
                    return HTTPFound(location=model_url(context, request),
                                     headers=headers)
                else:
                    statusmessage.show(request, u"Retrieve request not valid.",
                                       u"error")

        return render_template_to_response('templates/password_reset.pt',
                                           request=request,
                                           api=TemplateAPI(request))
Ejemplo n.º 3
0
def comments_view(context, request):

    journal_entry = context.__parent__

    return render_template('templates/comments.pt',
                           api=TemplateAPI(request),
                           journal_entry=journal_entry,
                           number=journal_entry.comments.count(),
                           context=context)
Ejemplo n.º 4
0
def student_projects_view(context, request):

    student = context
    projects = student.projects

    return dict(student=context,
                request=request,
                projects=projects,
                api=TemplateAPI(request))
Ejemplo n.º 5
0
def members_view(context, request):

    session = DBSession()
    all_students = session.query(Student).all()
    all_students = [
        student for student in all_students if not student in context.students
    ]
    all_teachers = session.query(Teacher).all()
    all_teachers = [
        teacher for teacher in all_teachers if not teacher in context.teachers
    ]

    if 'form.submitted' in request.POST:
        student_id = request.POST.get('student_id', None)
        if student_id:
            student = session.query(Student).filter_by(id=student_id).first()
            if student:
                context.students.append(student)
        teacher_id = request.POST.get('teacher_id', None)
        if teacher_id:
            teacher = session.query(Teacher).filter_by(id=teacher_id).first()
            if teacher:
                context.teachers.append(teacher)

        return HTTPFound(location=model_url(context, request, 'members.html'))
    # This should be a post request, but it has to be finished today ...
    elif 'remove_student' in request.GET:
        student_id = request.GET.get('remove_student', None)
        if student_id:
            student = context.students.filter_by(id=student_id).first()
            if student:
                context.students.remove(student)
        return HTTPFound(location=model_url(context, request, 'members.html'))
    elif 'remove_teacher' in request.GET:
        teacher_id = request.GET.get('remove_teacher', None)
        if teacher_id:
            teacher = context.teachers.filter_by(id=teacher_id).first()
            if teacher:
                context.teachers.remove(teacher)
        return HTTPFound(location=model_url(context, request, 'members.html'))

    root = get_root(request)
    students = []
    for student in context.students:
        students.append(root['users'][student.id])

    teachers = []
    for teacher in context.teachers:
        teachers.append(root['users'][teacher.id])

    return dict(api=TemplateAPI(request),
                context=context,
                students=students,
                all_students=all_students,
                teachers=teachers,
                all_teachers=all_teachers)
Ejemplo n.º 6
0
def project_view(context, request):

    project = context
    competence_cloud = project_competence_cloud_view(context, request)

    return dict(api=TemplateAPI(request),
                project=project,
                request=request,
                comments_view=comments_view,
                competence_cloud=competence_cloud)
Ejemplo n.º 7
0
def objectives_pdf_view(context, request):

    project = context.__parent__

    result = render_template('templates/objectives_pdf.pt',
                             api=TemplateAPI(request),
                             project=project)

    response = Response(parseString(result.encode('utf-8')).read())
    response.content_type = "application/pdf"
    return response
Ejemplo n.º 8
0
def student_view(context, request):

    competence_cloud = student_competence_cloud_view(context, request)

    # Redirect if the student is accessed by a teacher (gives a nicer URL).
    if authenticated_user(request) != context:
        return HTTPFound(location=model_url(context, request, 'stats.html'))

    return dict(student=context,
                competence_cloud=competence_cloud,
                request=request,
                comments_view=comments_view,
                api=TemplateAPI(request))
Ejemplo n.º 9
0
def users_view(context, request):
    
    session = DBSession()
    students = session.query(Student).order_by(Student.last_name, Student.first_name).all()
    for student in students:
        student.__parent__ = context
        
    teachers = session.query(Teacher).order_by(Teacher.last_name, Teacher.first_name).all()
    for teacher in teachers:
        teacher.__parent__ = context
    
    return dict(context=context,
                students=students,
                teachers=teachers,
                api=TemplateAPI(request))
Ejemplo n.º 10
0
def projects_view(context, request):
      
    session = DBSession()
    projects = session.query(Project)
    today = datetime.date.today()
    
    # Projects need to be traversal wrapped to make the links work.
    current_projects = []
    for project in projects.filter(Project.end_date >= today).order_by(Project.end_date.desc()):
        current_projects.append(context[project.id])
        
    past_projects = []
    for project in projects.filter(Project.end_date < today).order_by(Project.end_date.desc()):
        past_projects.append(context[project.id])
    
    api = TemplateAPI(request)
    return dict(context=context, api=api,current_projects=current_projects,past_projects=past_projects)
Ejemplo n.º 11
0
def student_application_pdf_view(context, request):

    data = gained_competences(context)

    show_projects = request.GET.get('show_projects', False)
    show_journal = request.GET.get('show_journal', False)
    show_indcators = request.GET.get('show_indcators', False)

    result = render_template('templates/student_application_pdf.pt',
                             api=TemplateAPI(request),
                             student=context,
                             show_projects=show_projects,
                             show_journal=show_journal,
                             show_indcators=show_indcators,
                             data=data)
    response = Response(parseString(result.encode('utf-8')).read())
    response.content_type = "application/pdf"
    return response
Ejemplo n.º 12
0
def student_competence_cloud_view(context, request):
    session = DBSession()
    query = session.query(Competence.title, func.count(Competence.id))
    query = query.filter(Student.id == context.id)
    query = query.join(Student.journal_entries)
    query = query.join(JournalEntry.indicators)
    query = query.join(Indicator.indicator_set)
    query = query.join(IndicatorSet.competence)
    query = query.group_by(Competence.id, Competence.title)

    tags = query.all()
    if tags is not None:
        cloud = [{'name': x[0], 'count': x[1]} for x in tags]
        limited = list(reversed(sorted(cloud, key=lambda x: x['count'])))[:100]
        entries = sorted(_calculateTagWeights(limited),
                         key=lambda x: x['name'])
    else:
        entries = ()

    return render_template(
        'templates/competence_cloud.pt',
        api=TemplateAPI(request),
        entries=entries,
    )
Ejemplo n.º 13
0
def objectives_view(context, request):

    project = context.__parent__

    return dict(api=TemplateAPI(request), project=project)
Ejemplo n.º 14
0
def license_view(context, request):

    return dict(api=TemplateAPI(request), )
Ejemplo n.º 15
0
def teacher_view(context, request):
    
    return dict(teacher=context,
                api=TemplateAPI(request))
Ejemplo n.º 16
0
def competences_view(context, request):

    return dict(api=TemplateAPI(request))
Ejemplo n.º 17
0
def forbidden_view(context, request):

    return dict(api=TemplateAPI(request), referrer=request.referrer)
Ejemplo n.º 18
0
def student_application_view(context, request):

    data = gained_competences(context)

    return dict(student=context, api=TemplateAPI(request), data=data)
Ejemplo n.º 19
0
                if form_result[field_name] != getattr(objective, field_name):
                    setattr(objective, field_name, form_result[field_name])
                    changed = True
            # Add onjective if this is the add form
            if add_form:
                objective.project = project
                session.add(objective)
            return HTTPFound(location=model_url(context, request))
    elif 'form.cancel' in request.POST:
        return HTTPFound(location=model_url(context, request))

    else:
        if not add_form:
            for field_name in objective_schema.fields.keys():
                value = getattr(objective, field_name)
                if field_name == 'competences':
                    values = []
                    for competence in value:
                        values.append(competence.id)
                    value = values
                defaults[field_name] = value

    form = render_template('templates/objective_edit.pt',
                           objective=objective,
                           competences=competences,
                           add_form=add_form,
                           api=TemplateAPI(request))
    # FormEncode fills template with default values
    form = htmlfill.render(form, defaults=defaults, errors=errors)
    return Response(form)
Ejemplo n.º 20
0
def student_stats_view(context, request):

    session = DBSession()

    # Achievable competences
    query = session.query(Competence.id, Competence.title,
                          func.count(Competence.id))
    query = query.filter(Student.id == context.id)
    query = query.join(Student.projects)
    query = query.join(Project.objectives)
    query = query.join(Objective.competences)
    query = query.join(Competence.indicator_sets)
    query = query.join(IndicatorSet.indicators)
    query = query.group_by(Competence.id, Competence.title)
    achiveable = query.order_by(Competence.title).all()

    # Subquery in order to count each indicator only once
    subquery = session.query(Indicator.id.label('indicator_id'))
    subquery = subquery.filter(Student.id == context.id)
    subquery = subquery.join(Student.journal_entries)
    subquery = subquery.join(JournalEntry.indicators)
    subquery = subquery.distinct().subquery()

    # Achieved competences
    query = session.query(Competence.id, Competence.title,
                          func.count(Competence.id))
    query = query.filter(subquery.c.indicator_id == Indicator.id)
    query = query.join(Indicator.indicator_set)
    query = query.join(IndicatorSet.competence)
    query = query.group_by(Competence.id, Competence.title)
    achieved = query.order_by(Competence.title).all()

    # Combine the two lists into one
    numbers = []
    for element in achiveable:
        number = {'label': element[1], 'achievable': element[2], 'achieved': 0}
        if len(achieved) and achieved[0][0] == element[0]:
            number['achieved'] = achieved.pop(0)[2]
        numbers.append(number)

    localizer = get_localizer(request)

    graph_axis = []
    graph_data = []
    graph_data.append({
        'label':
        '&nbsp;%s&nbsp;' % localizer.translate(_('Achieved')),
        'data': []
    })
    graph_data.append({
        'label':
        '&nbsp;%s&nbsp;' % localizer.translate(_('Achievable')),
        'data': []
    })
    for index, number in enumerate(numbers):
        graph_axis.append([index, number['label']])
        graph_data[0]['data'].append([index, number['achieved']])
        graph_data[1]['data'].append(
            [index, number['achievable'] - number['achieved']])

    projects = []
    for project in context['projects']:
        project_data = {'title': project.title}
        # Collect all competences for the project
        competences = []
        for objective in project.objectives:
            for competence in objective.competences:
                achieved = False
                if not competence in competences:
                    competence_data = {
                        'title': competence.title,
                        'indicator_sets': [],
                        'achieved': False
                    }
                    for indicator_set in competence.indicator_sets:
                        indicator_set_data = {
                            'title': indicator_set.title,
                            'achieved': False
                        }
                        indicators = []
                        for indicator in indicator_set.indicators:
                            indicator_data = {
                                'title': indicator.title,
                                'achieved': False
                            }
                            # Check whether indicator has been achieved
                            query = session.query(Indicator)
                            query = query.filter(
                                JournalEntry.user_id == context.id)
                            query = query.filter(Indicator.id == indicator.id)
                            query = query.join(JournalEntry.indicators)
                            if query.first():
                                achieved = True
                                indicator_data['achieved'] = True
                            indicators.append(indicator_data)
                        indicator_set_data['indicators'] = indicators
                        if achieved:
                            indicator_set_data['achieved'] = True
                        competence_data['indicator_sets'].append(
                            indicator_set_data)

                    if achieved:
                        competence_data['achieved'] = True
                    competences.append(competence_data)
        project_data['competences'] = competences
        projects.append(project_data)

    return dict(api=TemplateAPI(request),
                projects=projects,
                graph_axis=simplejson.dumps(graph_axis),
                graph_data=simplejson.dumps(graph_data))
Ejemplo n.º 21
0
def meta_competences_view(context, request):

    return dict(api=TemplateAPI(request), meta_competences=context)
Ejemplo n.º 22
0
def login_view(context, request):

    return dict(api=TemplateAPI(request))
Ejemplo n.º 23
0
def dashboard_view(context, request):

    return dict(api=TemplateAPI(request))