示例#1
0
def strip_school_name(school):
    """
    Strips invalid characters from the school name for nicer URLs
    :param school: a School object whose name we want stripped
    :return: the name of the school without any invalid characters
    """
    return strip_invalid_chars(school.name)
示例#2
0
def strip_school_name(school):
    """
    Strips invalid characters from the school name for nicer URLs
    :param school: a School object whose name we want stripped
    :return: the name of the school without any invalid characters
    """
    return strip_invalid_chars(school.name)
示例#3
0
def student_school_link(student):
    """
    Gets the link for the school of a supplied student
    :param student: any Student object
    :return: the relative link to the page for the school if given a student
    """
    if type(student) is Student:
        sch = student.school
        return '/cern/%s/%s/%s' % (sch.state, sch.id, strip_invalid_chars(sch.name))
示例#4
0
def student_school_link(student):
    """
    Gets the link for the school of a supplied student
    :param student: any Student object
    :return: the relative link to the page for the school if given a student
    """
    if type(student) is Student:
        sch = student.school
        return '/cern/%s/%s/%s' % (sch.state, sch.id,
                                   strip_invalid_chars(sch.name))
示例#5
0
def my_school_link(context, user):
    """
    Gets the link for the school of the supplied student user
    :param user: a user who is also a student
    :return: the relative link to the page for the student's school
    """
    current_role = context['request'].current_role
    if current_role.entity_type == RoleController.ENTITY_STUDENT:
        sch = current_role.entity.school
        return '/cern/%s/%s/%s' % (sch.state, sch.id, strip_invalid_chars(sch.name))
    else:
        return ''
示例#6
0
def my_school_link(context, user):
    """
    Gets the link for the school of the supplied student user
    :param user: a user who is also a student
    :return: the relative link to the page for the student's school
    """
    current_role = context['request'].current_role
    if current_role.entity_type == RoleController.ENTITY_STUDENT:
        sch = current_role.entity.school
        return '/cern/%s/%s/%s' % (sch.state, sch.id,
                                   strip_invalid_chars(sch.name))
    else:
        return ''
示例#7
0
def edit_school_cover(request, school_id):
    """
    Edit cover template, customized for school
    :param request: any request
    :param school_id: valid ID of a school
    :return: the edit_cover_image template, customized for the school
    """
    sch = School.objects.get(id=school_id)
    return render(request, 'components/coverimage/edit_cover_image.html', {
        'name': sch.name,
        'return_url': "/cern/%s/%s/%s" %
                      (sch.state, sch.id, strip_invalid_chars(sch.name)),
        'post_url': '/cern/%s/save_school_cover' % sch.id,
        'reset_url': '/cern/%s/reset_school_cover' % sch.id
    })
示例#8
0
def edit_school_cover(request, school_id):
    """
    Edit cover template, customized for school
    :param request: any request
    :param school_id: valid ID of a school
    :return: the edit_cover_image template, customized for the school
    """
    sch = School.objects.get(id=school_id)
    return render(
        request, 'components/coverimage/edit_cover_image.html', {
            'name':
            sch.name,
            'return_url':
            "/cern/%s/%s/%s" %
            (sch.state, sch.id, strip_invalid_chars(sch.name)),
            'post_url':
            '/cern/%s/save_school_cover' % sch.id,
            'reset_url':
            '/cern/%s/reset_school_cover' % sch.id
        })
示例#9
0
def school(request, state, school_id, name, referral_id=None):
    """
    Displays the school splash page

    :param request: request to render page
    :param state: standard state abbreviation of where school is
    :param school_id: the ID of the school
    :param name: name of school
        spaces may be replaced by _ in this param
    :param referral_id: optional param which indicates a referral
    :return: rendering of school page or error page if no School with
        name and state combination can be found
    """
    referrer = None

    if referral_id:
        try:
            referrer = Student.objects.get(id=referral_id)
        except ObjectDoesNotExist:
            return HttpResponseRedirect('/cern/%s/%s/%s/' % (state, school_id, name))

    try:
        sch = School.objects.get(id=school_id)
    except ObjectDoesNotExist:
        return render(request, 'spuddercern/pages/no-school.html')

    stripped_name = strip_invalid_chars(sch.name)
    if strip_invalid_chars(sch.name) != name:
        return HttpResponseRedirect('/cern/%s/%s/%s' % (state, school_id, stripped_name))

    try:
        head = sch.get_head_student()
    except ObjectDoesNotExist:
        head = None

    student = None
    if request.current_role and request.current_role.entity_type == RoleController.ENTITY_STUDENT:
        student = request.current_role.entity

    ranked_students = sorted(sch.get_students(), key=lambda s: s.rep(), reverse=True)
    if len(ranked_students) == 0:
        top_students = None
        remaining_students = None
    elif len(ranked_students) <= 5:
        top_students = ranked_students
        remaining_students = None
    else:
        top_students = ranked_students[:5]
        remaining_students = ranked_students[5:]

    if request.method == 'POST':
        sch.description = request.POST.get('description', '')
        sch.mascot = request.POST.get('mascot', '')
        sch.save()

    texts = {}
    if sch.description:
        texts['Description'] = sch.description
    imgs = {}
    if sch.logo:
        imgs['Logo'] = sch.logo.id
    if sch.cover_image:
        imgs['Cover Image'] = sch.cover_image.id

    return render(
        request,
        'spuddercern/pages/school_splash.html', {
            'school': sch,
            'student': student,
            'head': head,
            'user_is_team_member': bool(request.user in ranked_students),
            'referrer': referrer,
            'top_students': top_students,
            'remaining_students': remaining_students,
            'text_fields': texts,
            'img_fields': imgs,
            'base_url': 'spuddercern/base.html',
        })
示例#10
0
def school(request, state, school_id, name, referral_id=None):
    """
    Displays the school splash page

    :param request: request to render page
    :param state: standard state abbreviation of where school is
    :param school_id: the ID of the school
    :param name: name of school
        spaces may be replaced by _ in this param
    :param referral_id: optional param which indicates a referral
    :return: rendering of school page or error page if no School with
        name and state combination can be found
    """
    referrer = None

    if referral_id:
        try:
            referrer = Student.objects.get(id=referral_id)
        except ObjectDoesNotExist:
            return HttpResponseRedirect('/cern/%s/%s/%s/' %
                                        (state, school_id, name))

    try:
        sch = School.objects.get(id=school_id)
    except ObjectDoesNotExist:
        return render(request, 'spuddercern/pages/no-school.html')

    stripped_name = strip_invalid_chars(sch.name)
    if strip_invalid_chars(sch.name) != name:
        return HttpResponseRedirect('/cern/%s/%s/%s' %
                                    (state, school_id, stripped_name))

    try:
        head = sch.get_head_student()
    except ObjectDoesNotExist:
        head = None

    student = None
    if request.current_role and request.current_role.entity_type == RoleController.ENTITY_STUDENT:
        student = request.current_role.entity

    ranked_students = sorted(sch.get_students(),
                             key=lambda s: s.rep(),
                             reverse=True)
    if len(ranked_students) == 0:
        top_students = None
        remaining_students = None
    elif len(ranked_students) <= 5:
        top_students = ranked_students
        remaining_students = None
    else:
        top_students = ranked_students[:5]
        remaining_students = ranked_students[5:]

    if request.method == 'POST':
        sch.description = request.POST.get('description', '')
        sch.mascot = request.POST.get('mascot', '')
        sch.save()

    texts = {}
    if sch.description:
        texts['Description'] = sch.description
    imgs = {}
    if sch.logo:
        imgs['Logo'] = sch.logo.id
    if sch.cover_image:
        imgs['Cover Image'] = sch.cover_image.id

    return render(
        request, 'spuddercern/pages/school_splash.html', {
            'school': sch,
            'student': student,
            'head': head,
            'user_is_team_member': bool(request.user in ranked_students),
            'referrer': referrer,
            'top_students': top_students,
            'remaining_students': remaining_students,
            'text_fields': texts,
            'img_fields': imgs,
            'base_url': 'spuddercern/base.html',
        })