Example #1
0
def update_scholarship(name):
    '''For GET requests, this method allows the administrator to edit the named
    document. For POST requests, this method saves the edits made by the
    administrator and then reloads/redisplays the document administration page.
    Non-authenticated users are redirected to the login page. documents that
    don't exist can't be edited. Because we don't show individual documents,
    all redirects go to the documents administration page.
    '''
    form = Scholarships()
    if form.is_submitted():
        if form.validate() and request.form.get('submit'):
            Scholarships.update_unit(form)
            return redirect(url_for('web.display_scholarship',
                            name=form.getName()))
    else:
        scholarship = Scholarships.read_unit(name)
        if scholarship:
            form.initialize(name=name, action='update',
                            scholarship=scholarship)
            return display_content(
                form=form,
                title='Edit: ' + name,
                breadcrumbs=get_breadcrumbs('scholarships', name, 'edit')
            )
    return redirect(url_for('web.display_admin_scholarships'))
Example #2
0
def login():
    '''This routine verifies that the user is an administrator and, if so,
    puts them in admin mode and redirects them to the admin resource they
    originally requested. It sends them back to the main page if their
    requested URL is unsafe. The username and password are stored in
    the database.
    '''
    if is_logged_in():
        return redirect(url_for('web.display_admin'))
    target_url = request.values.get('next') or url_for('web.display_admin')
    if not is_safe_url(target_url):
        return redirect(url_for('web.display_index'))
    form = Users()
    if form.is_submitted():
        # Check if the cancel button has been pressed; the form value will be
        # 'Cancel' but this doesn't need to be checked.
        if request.form.get('cancel'):
            return redirect(url_for('web.display_index'))
        if form.validate():
            user = Users.read_unit(form.nameField.data)
            if (user is not None) and \
                   (custom_app_context.verify(form.passwordField.data,
                                          user['password'])):
                session['logged_in'] = True
                return redirect(target_url)
        flash('invalid login...', 'error')
    return display_content(
        form=form,
        next=target_url,
        title='Login',
        breadcrumbs=get_breadcrumbs('login')
    )
Example #3
0
def contact():
    '''Configure and display the contact us page, with its input form and
    email feature.
    '''
    form = Contacts()
    if form.is_submitted():
        if request.form.get('cancel'):
            return redirect(url_for('web.display_index'))
        if form.validate():
            Contacts.send_email(mail, form)
            return redirect(url_for('web.display_index'))
        flash('All fields are required.')
    department = Departments.read_unit('cs')
    return display_content(
        form=form,
        title='Contact Us',
        primary=department.get('contact'),
        sideTitle='Admissions at Calvin',
        sideContent='''<p>Interested in what Calvin has to offer?<br>
    <a href="http://www.calvin.edu/admissions/visit/">Schedule a visit</a>
    or <br><a href="http://www.calvin.edu/admissions/contact/request/">request
    more information</a>.</p>''',
        breadcrumbs=get_breadcrumbs('contact'),
        editable=True,
        editableUrl=url_for('web.update_department', name='cs')
    )
Example #4
0
def update_department(name):
    '''Configure the editing for the about page, which must edit the long
    description of the department. There is only one department, name==cs.

    For GET requests, this method allows the administrator to edit the named
    document. For POST requests, this method saves the edits made by the
    administrator and then reloads/redisplays the document administration page.
    Non-authenticated users are redirected to the login page. documents that
    don't exist can't be edited. Because we don't show individual documents,
    all redirects go to the documents administration page.
    '''
    form = Departments()
    if form.is_submitted():
        if form.validate() and request.form.get('submit'):
            Departments.update_unit(form)
    else:
        department = Departments.read_unit(name)
        if department:
            form.initialize(name=name, action='update', department=department)
            return display_content(
                form=form,
                title='Edit: ' + name,
                breadcrumbs=get_breadcrumbs('departments', name, 'edit')
            )
    return redirect(url_for('web.display_about'))
Example #5
0
def display_news():
    '''This routine displays the main news list page.'''
    return display_content(
        breadcrumbs=get_breadcrumbs('news'),
        title='Computing News',
        primaryList=create_full_news_list(News.read_units()),
        primaryListHr=True,
        editable=True,
        editableUrl=url_for('web.display_admin_news')
    )
Example #6
0
def display_people():
    '''Configure and display a list of faculty members.'''
    return display_content(
        breadcrumbs=get_breadcrumbs('people'),
        image=Images.read_tagged_unit('people'),
        title='Faculty and Staff',
        primaryList=create_people_list(People.read_units()),
        primaryListHr=True,
        editable=False
    )
Example #7
0
def display_admin_resources():
    '''This routine displays the administration tools for resource units. It is
    password protected because the listing page allows administrative features.
    '''
    return display_content(
        breadcrumbs=get_breadcrumbs('admin', 'resources'),
        title='Administration: Resources',
        primaryList=create_admin_resources_list(Resources.read_units()),
        primaryListHr=True,
        editable=False
    )
Example #8
0
def display_research():
    '''Configure and display the research overview page.'''
    department = check_unit(Departments.read_unit('cs'))
    return display_content(
        breadcrumbs=get_breadcrumbs('research'),
        image=Images.read_tagged_unit('research'),
        title='Research',
        primary=department.get('research'),
        editable=True,
        editableUrl=url_for('web.update_department', name='cs')
    )
Example #9
0
def display_honors():
    '''Display information on the honors program.'''
    department = check_unit(Departments.read_unit('cs'))
    return display_content(
        breadcrumbs=get_breadcrumbs('academics', 'honors'),
        image=Images.read_tagged_unit('academics.honors'),
        title='Graduating with Honors',
        primary=department.get('honors'),
        editable=True,
        editableUrl=url_for('web.update_department', name='cs')
    )
Example #10
0
def display_courses():
    '''Configure and display the courses list page.'''
    department = check_unit(Departments.read_unit('cs'))
    courses = check_unit(Courses.read_units())
    return display_content(
        breadcrumbs=get_breadcrumbs('academics', 'courses'),
        image=Images.read_tagged_unit('courses'),
        title='Courses &amp; Materials',
        tabList=create_course_tab_list(courses, department),
        editable=True,
        editableUrl=url_for('web.update_department', name='cs')
    )
Example #11
0
def display_resources():
    '''Configure and display the resources overview page.'''
    return display_content(
        breadcrumbs=get_breadcrumbs('resources'),
        image=Images.read_tagged_unit('resources'),
        title='Department Resources',
        primary='''The Department of Computer Science offers the following
                   resources.''',
        primaryList=create_resources_list(Resources.read_units()),
        primaryListHr=False,
        editable=False
    )
Example #12
0
def display_program(name=None):
    '''Configure and display a program page.'''
    program = check_unit(Programs.read_unit(name))
    return display_content(
        breadcrumbs=get_breadcrumbs('academics', program.get('name')),
        image=Images.read_tagged_unit(name),
        title=program.get('title'),
        primary=program.get('majorDescription'),
        tabList=create_program_tab_list(program),
        editable=True,
        editableUrl=url_for('web.update_program', name=name)
    )
Example #13
0
def display_news_article(name):
    '''This routine displays a single news article.'''
    article = check_unit(News.read_unit(name))
    return display_content(
        breadcrumbs=get_breadcrumbs('news', name),
        title=article.get('title'),
        subtitle=article.get('date').strftime('%B %d, %Y'),
        primary='<p>' + article.get('content') + '</p>',
        current=get_name('news', name),
        editable=True,
        editableUrl=url_for('web.update_news_article', name=name)
    )
Example #14
0
def display_admin_news():
    '''This routine displays the administration tools for news.
    We'll eventually use CIT's news tools.
    '''
    return display_content(
        breadcrumbs=get_breadcrumbs('admin', 'news'),
        title='Administration: News Articles',
        primary=create_hyperlink(url_for('web.create_news_article'),
                                 'Create a news article'),
        primaryList=create_newsarticle_list(News.read_units()),
        primaryListHr=True,
        editable=False
    )
Example #15
0
def display_about():
    '''Configure and display the about page, with an appropriate image and the
    department long description.
    '''
    department = check_unit(Departments.read_unit('cs'))
    return display_content(
        breadcrumbs=get_breadcrumbs('about'),
        image=Images.read_tagged_unit('about'),
        title='About Us',
        primary=department.get('longDescription'),
        editable=True,
        editableUrl=url_for('web.update_department', name='cs')
    )
Example #16
0
def display_admin_images():
    '''This routine displays the administration tools for images. It maps both
    web routes to support certain unused breadcrumb trails.
    '''
    return display_content(
        breadcrumbs=get_breadcrumbs('admin', 'images'),
        title='Administration: Images',
        primary=create_hyperlink(url_for('web.create_image'),
                                 'Create a new image'),
        primaryList=create_image_list(Images.read_units()),
        primaryListHr=True,
        editable=False
    )
Example #17
0
def display_admin_tech_news():
    '''This routine displays the administration tools for tech news from feeds.
    '''
    return display_content(
        breadcrumbs=get_breadcrumbs('admin', 'technews'),
        title='Administration: TechNews Articles',
        primary='<p>Thumbs up/down relevant news articles to adjust the list of articles. ' +
        '<a href = "/admin/technews/refresh" >Click here to refresh the page listings.</a></p>' +
        '<p>To see the current items <a href="/admin/news">click here.</a></p>',
        primaryList=create_techNewsarticle_list(TechNews.read_units(refreshList = False)),
        primaryListHr=True,
        editable=False
    )
Example #18
0
def display_admin_programs():
    '''This routine displays the administration tools for program units. It is
    password protected because the listing page allows administrative features.
    Only the model schedules can be edited; the rest of the data comes from
    CIT.
    '''
    return display_content(
        breadcrumbs=get_breadcrumbs('admin', 'programs'),
        title='Administration: Programs',
        primaryList=create_admin_programs_list(Programs.read_units()),
        primaryListHr=True,
        editable=False
    )
Example #19
0
def display_resource(name):
    '''This routine displays a given resource. It is not password protected
    because all resources are visible to all visitors.
    '''
    resource = check_unit(Resources.read_unit(name))
    return display_content(
        breadcrumbs=get_breadcrumbs('resources', name),
        title=resource.get('title'),
        primary=resource.get('content'),
        tabList=create_resource_tab_list(resource),
        editable=True,
        editableUrl=url_for('web.update_resource', name=name)
    )
Example #20
0
def display_document(name):
    '''This routine displays a given document. It is not password protected
    because all documents are visible to all visitors.
    '''
    document = check_unit(Documents.read_unit(name))
    return display_content(
        breadcrumbs=get_breadcrumbs('documents', name),
        title=document.get('title'),
        primary=document.get('content'),
        primaryListHr=False,
        editable=True,
        editableUrl=url_for('web.update_document', name=name)
    )
Example #21
0
def display_scholarships():
    '''This routine displays the administration tools for user documents. It is
    password protected because the listing page allows administrative features.
    Documents should be accessed as linked from existing pages.
    '''
    scholarships = Scholarships.read_units()
    return display_content(
        breadcrumbs=get_breadcrumbs('scholarships'),
        title='Scholarships &amp; Awards',
        primaryList=create_scholarships_list(scholarships),
        primaryListHr=False,
        editable=True,
        editableUrl=url_for('web.display_admin_scholarships')
    )
Example #22
0
def display_admin_documents():
    '''This routine displays the administration tools for user documents. It is
    password protected because the listing page allows administrative features.
    Documents should be accessed as linked from existing pages.
    '''
    return display_content(
        breadcrumbs=get_breadcrumbs('admin', 'documents'),
        title='Administration: Documents',
        primary=create_hyperlink(url_for('web.create_document'),
                                 'Create a new document'),
        primaryList=create_document_list(Documents.read_units()),
        primaryListHr=True,
        editable=False
    )
Example #23
0
def display_image(name):
    '''This routine displays a given image. We included only to support
    generally unused breadcrumb trails. It is password protected at the
    moment to ensure that users access raw images as part of actual pages.
    '''
    image = check_unit(Images.read_unit(name))
    return display_content(
        breadcrumbs=get_breadcrumbs('images', name),
        title=image.get('name'),
        primary='<img src="/static/images/' + image.get('filename') + '">',
        primaryListHr=False,
        editable=True,
        editableUrl=url_for('web.update_image', name=name)
    )
Example #24
0
def display_programs():
    '''Configure and display the academics overview page.'''
    return display_content(
        breadcrumbs=get_breadcrumbs('academics'),
        image=Images.read_tagged_unit('about'),
        title='Academics',
        primary='''The Department of Computer Science offers the following
                   academic programs. To learn more about our academics goals,
                   see our <a href="/administration/assessment/plan">program
                   outcomes</a>.''',
        primaryList=create_programs_list(Programs.read_units()),
        primaryListHr=False,
        editable=False
    )
Example #25
0
def display_index():
    '''Configure and display the main index page, with an appropriate image,
    the department short description and a list of current news articles.
    '''
    department = check_unit(Departments.read_unit('cs'))
    return display_content(
        image=Images.read_tagged_unit('departments.cs'),
        title=department.get('title'),
        subtitle=department.get('tagline'),
        primary=department.get('shortDescription'),
        sideTitle='Computing News',
        sideList=create_brief_news_list(News.read_units(limit=2 + TechNews.TECH_NEWS_LIMIT)),
        editable=True,
        editableUrl=url_for('web.update_department', name='cs')
    )
Example #26
0
def display_admin_scholarships():
    '''This routine displays the administration tools for user documents. It is
    password protected because the listing page allows administrative features.
    Documents should be accessed as linked from existing pages.
    '''
    scholarships = Scholarships.read_units()
    return display_content(
        breadcrumbs=get_breadcrumbs('admin', 'scholarships'),
        title='Administration: Scholarships',
        primary=create_hyperlink(url_for('web.create_scholarship'),
                                 '''Create a new scholarship
                                    (in the CS database only)'''),
        primaryList=create_admin_scholarships_list(scholarships),
        primaryListHr=True,
        editable=True
    )
Example #27
0
def display_admin():
    '''This routine displays the site administration page.'''
    return display_content(
        breadcrumbs=get_breadcrumbs('admin'),
        title='Administration',
        primary='''<p>
                   The program, course, faculty and news resources
                   used on this site are administered by CIT; change
                   them by emailing helpdesk. These other resources are
                   managed by the department content management system;
                   you can do the following things with them yourself.
                   </p>
                   ''',
        primaryList=create_admin_list(),
        primaryListHr=False,
        editable=False
    )
Example #28
0
def create_document():
    '''This routine displays an editing page for creating an document.'''
    form = Documents()
    if form.is_submitted():
        if form.validate() and request.form.get('submit'):
            Documents.create_unit(form)
            return redirect(url_for('web.display_document',
                            name=form.getName()))
        else:
            return redirect(url_for('web.display_admin_documents'))
    else:
        form.initialize(action='create')
        return display_content(
            form=form,
            title='Create document',
            breadcrumbs=get_breadcrumbs('documents', 'create')
        )
Example #29
0
def display_scholarship(name):
    '''This routine displays a given scholarship.'''
    scholarship = check_unit(Scholarships.read_unit(name))
    # Add scholarship details in side bar if they exist.
    sideContent = create_scholarship_side(scholarship)
    sideTitle = None
    if sideContent:
        sideTitle = 'Details'
    return display_content(
        breadcrumbs=get_breadcrumbs('scholarships', name),
        title=scholarship.get('title'),
        primary=create_scholarship_content(scholarship),
        sideTitle=sideTitle,
        sideContent=sideContent,
        primaryListHr=False,
        editable=True,
        editableUrl=url_for('web.update_scholarship', name=name)
    )
Example #30
0
def update_program(name):
    '''Configure the editing for the program pages. Because all of the program
    data except the model schedule comes from CIT, this routine will only
    support updates to the model schedule. The administrator cannot edit
    the name of the program.
    '''
    form = Programs()
    if form.is_submitted():
        if form.validate() and request.form.get('submit'):
            Programs.update_unit(form)
    else:
        program = Programs.read_unit(name)
        if program:
            form.initialize(name=name, action='update', document=program)
            return display_content(
                form=form,
                title='Edit: ' + name,
                breadcrumbs=get_breadcrumbs('academics', name, 'edit')
            )
    return redirect(url_for('web.display_program', name=name))