def display_homework(page): if page == "index": hws = os.listdir(app_path("static", "hw")) hws.extend(os.listdir(app_path("templates", "hw"))) hws = [hw for hw in sorted(hws) if not hw == "index.mak"] else: hws = None return render_template("hw/{}.mak".format(page), name="mako", hws=hws)
def display_homework(page): if page == 'index': hws = os.listdir(app_path('static', 'hw')) hws.extend(os.listdir(app_path('templates', 'hw'))) hws = [hw for hw in sorted(hws) if not hw == "index.mak"] else: hws = None return render_template('hw/{}.mak'.format(page), name='mako', hws=hws)
def display_lecture(page): if page == "index": lecture_notes = os.listdir(app_path("templates", "lectures")) lecture_notes = [note for note in sorted(lecture_notes) if not note == "index.mak"] else: lecture_notes = None return render_template("lectures/{}.mak".format(page), name="mako", lectures=lecture_notes)
def resources(): res = dict() oer_links = [] oer_yaml = app_path("oer.yaml") with open(oer_yaml) as oer_data: oer_links = yaml.safe_load(oer_data) res['links'] = {} res['Decks'] = [] res['Books'] = [] res['Videos'] = [] if os.path.exists(app_path('static', 'decks')): res['Decks'] = os.listdir(app_path('static', 'decks')) if 'decks' in oer_links: res['links']['decks'] = oer_links['decks'] if os.path.exists(app_path('static', 'books')): res['Books'] = os.listdir(app_path('static', 'books')) if 'books' in oer_links: res['links']['books'] = oer_links['books'] if os.path.exists(app_path('static', 'videos')): res['Videos'] = os.listdir(app_path('static', 'videos')) if 'videos' in oer_links: res['links']['videos'] = oer_links['videos'] return render_template('resources.mak', name='mako', resources=res)
def resources(): res = dict() oer_links = [] oer_yaml = app_path("oer.yaml") with open(oer_yaml) as oer_data: oer_links = yaml.safe_load(oer_data) res["links"] = {} res["Decks"] = [] res["Books"] = [] res["Videos"] = [] if os.path.exists(app_path("static", "decks")): res["Decks"] = os.listdir(app_path("static", "decks")) if "decks" in oer_links: res["links"]["decks"] = oer_links["decks"] if os.path.exists(app_path("static", "books")): res["Books"] = os.listdir(app_path("static", "books")) if "books" in oer_links: res["links"]["books"] = oer_links["books"] if os.path.exists(app_path("static", "videos")): res["Videos"] = os.listdir(app_path("static", "videos")) if "videos" in oer_links: res["links"]["videos"] = oer_links["videos"] return render_template("resources.mak", name="mako", resources=res)
def resources(): res = dict() oer_links = [] oer_yaml = app_path("oer.yaml") with open(oer_yaml) as oer_data: oer_links = yaml.safe_load(oer_data) res['links'] = {} res['Decks'] = [] res['Books'] = [] res['Videos'] = [] if os.path.exists(app_path('static', 'decks')): res['Decks'] = os.listdir(app_path('static', 'decks')) if 'decks' in oer_links: res['links']['decks'] = oer_links['decks'] if os.path.exists(app_path('static', 'books')): res['Books'] = os.listdir(app_path('static', 'books')) if 'books' in oer_links: res['links']['books'] = oer_links['books'] if os.path.exists(app_path('static', 'videos')): res['Videos'] = os.listdir(app_path('static', 'videos')) if 'videos' in oer_links: res['links']['videos'] = oer_links['videos'] return render_template('resources', resources=res)
def display_homework(page): if page == "index": # Old way of generating list (for backwards compatibility) hws = os.listdir(app_path("static", "hw")) hws.extend(os.listdir(app_path("templates", "hw"))) hws = [hw for hw in sorted(hws) if not hw == "index.mak"] # New, cleaner-in-the-template way to do it hwd = [(hw, os.path.join("/static", "hw")) for hw in os.listdir(app_path("static", "hw"))] hwd.extend([(os.path.splitext(hw)[0], "/hw") for hw in os.listdir(app_path("templates", "hw"))]) hwd = { os.path.basename(hw): os.path.join(loc, hw) for hw, loc in hwd if os.path.splitext(os.path.basename(hw))[0] != "index" } else: hws = None hwd = None return render_template(os.path.join("hw", page), hws=hws, os=os, assignments=hwd)
def find_participant(nick): yaml_dir = app_path('people') for dirpath, dirnames, files in os.walk(yaml_dir): for fname in files: if (fname.lower().startswith(nick.lower()) and fname.endswith('.yaml')): participant = os.path.join(dirpath, fname).replace( yaml_dir, '') participant = participant.replace('.yaml', '') return 'participants' + participant
def find_participant(nick): yaml_dir = app_path('people') for dirpath, dirnames, files in os.walk(yaml_dir): for fname in files: if (fname.lower().startswith(nick.lower()) and fname.endswith('.yaml')): participant = os.path.join(dirpath, fname).replace(yaml_dir, '') participant = participant.replace('.yaml', '') return 'participants' + participant
def participant_page(year, term, username): """ Render a page that shows some stats about the selected participant """ participant_data = {} yaml_dir = app_path("people") participant_yaml = os.path.join(yaml_dir, year, term, username + ".yaml") with open(participant_yaml) as participant_file: participant_data = yaml.safe_load(participant_file) return render_template("participant.mak", name="mako", participant_data=participant_data, gravatar=gravatar)
def display_lecture(page): if page == 'index': lecture_notes = os.listdir(app_path('templates', 'lectures')) lecture_notes = [ note for note in sorted(lecture_notes) if not note == "index.mak" ] else: lecture_notes = None return render_template('lectures/{}.mak'.format(page), name='mako', lectures=lecture_notes)
def inject_yaml(): with open(app_path('site.yaml')) as site_yaml: site_config = yaml.safe_load(site_yaml) course_url = "http://localhost:5000/" if site_config['course'].get('public_url', None) is not None: course_url = site_config['course']['public_url'] elif os.environ.get('OPENSHIFT_GEAR_DNS', None) is not None: course_url = "https://" + os.environ['OPENSHIFT_GEAR_DNS'] site_config['course']['public_url'] = course_url return site_config
def inject_yaml(): with open(app_path("site.yaml")) as site_yaml: site_config = yaml.safe_load(site_yaml) course_url = "http://localhost:5000/" if site_config["course"].get("public_url", None) is not None: course_url = site_config["course"]["public_url"] elif os.environ.get("OPENSHIFT_GEAR_DNS", None) is not None: course_url = "https://" + os.environ["OPENSHIFT_GEAR_DNS"] site_config["course"]["public_url"] = course_url return site_config
def participant_page(year, term, username): """ Render a page that shows some stats about the selected participant """ participant_data = {} yaml_dir = app_path('people') participant_yaml = os.path.join(yaml_dir, year, term, username + '.yaml') with open(participant_yaml) as participant_file: participant_data = yaml.safe_load(participant_file) return render_template('participant', participant_data=participant_data, gravatar=gravatar)
def participants(root_dir): """ Render the participants page, which shows a directory of all the students with their forge links, blog posts, assignment links, and etc. """ yaml_dir = app_path('people', root_dir) student_data = [] for dirpath, dirnames, files in os.walk(yaml_dir): dirpath = dirpath.rstrip("/") for fname in sorted(files): if fname.endswith('.yaml'): with open(dirpath + '/' + fname) as students: contents = yaml.safe_load(students) contents['yaml'] = dirpath + '/' + fname year_term_data = dirpath.split('/') contents['participant_page'] = "{y}/{t}/{u}".format( y=year_term_data[-2], t=year_term_data[-1], u=os.path.splitext(fname)[0] ) for forge in contents['forges']: url = urlparse(forge) if "github.com" in url.netloc: contents['github'] = url.path[1:] contents['isActive'] = (currentYear in year_term_data and currentTerm in year_term_data) student_data.append(contents) assignments = get_hw_keys() elapsed = (datetime.today() - ofcourse.site.COURSE_START).total_seconds() target_number = int(elapsed / timedelta(weeks=1).total_seconds() + 1 + len(assignments)) return render_template( 'blogs.mak', name='mako', student_data=student_data, gravatar=ofcourse.site.gravatar, target_number=target_number, hw_keys=assignments )
def display_homework(page): if page == 'index': # Old way of generating list (for backwards compatibility) hws = os.listdir(app_path('static', 'hw')) hws.extend(os.listdir(app_path('templates', 'hw'))) hws = [hw for hw in sorted(hws) if not hw == "index.mak"] # New, cleaner-in-the-template way to do it hwd = [(hw, os.path.join('/static', 'hw')) for hw in os.listdir(app_path('static', 'hw'))] hwd.extend([(os.path.splitext(hw)[0], '/hw') for hw in os.listdir(app_path('templates', 'hw'))]) hwd = { os.path.basename(hw): os.path.join(loc, hw) for hw, loc in hwd if os.path.splitext(os.path.basename(hw))[0] != "index" } else: hws = None hwd = None return render_template(os.path.join("hw", page), hws=hws, os=os, assignments=hwd)
def display_lecture(page): if page == "index": lecture_list = os.listdir(app_path("templates", "lectures")) # Old way of generating list (for backwards compatibility) lectures = [note for note in sorted(lecture_list) if note != "index.mak"] # New, cleaner-in-the-template way to do it lecture_notes = [ (note, os.path.splitext(os.path.join("/lectures", note))[0]) for note in sorted(lecture_list) if os.path.splitext(note)[0] != "index" ] else: lecture_notes = None lectures = None return render_template(os.path.join("lectures", page), lecture_notes=lecture_notes, lectures=lectures)
def participant_page(year, term, username): """ Render a page that shows some stats about the selected participant """ participant_data = {} yaml_dir = app_path('people') participant_yaml = os.path.join(yaml_dir, year, term, username + '.yaml') with open(participant_yaml) as participant_data: participant_data = yaml.load(participant_data) return render_template( 'participant.mak', name='make', participant_data=participant_data, gravatar=gravatar )
def participants(root_dir): """ Render the participants page, which shows a directory of all the students with their forge links, blog posts, assignment links, and etc. """ yaml_dir = app_path('people', root_dir) student_data = [] for dirpath, dirnames, files in os.walk(yaml_dir): dirpath = dirpath.rstrip("/") for fname in sorted(files): if fname.endswith('.yaml'): with open(dirpath + '/' + fname) as students: contents = yaml.safe_load(students) contents['yaml'] = dirpath + '/' + fname year_term_data = dirpath.split('/') contents['participant_page'] = "{y}/{t}/{u}".format( y=year_term_data[-2], t=year_term_data[-1], u=os.path.splitext(fname)[0]) for forge in contents['forges']: url = urlparse(forge) if "github.com" in url.netloc: contents['github'] = url.path[1:] contents['isActive'] = (currentYear in year_term_data and currentTerm in year_term_data) student_data.append(contents) assignments = get_hw_keys() elapsed = (datetime.today() - ofcourse.site.COURSE_START).total_seconds() target_number = int(elapsed / timedelta(weeks=1).total_seconds() + 1 + len(assignments)) return render_template('blogs.mak', name='mako', student_data=student_data, gravatar=ofcourse.site.gravatar, target_number=target_number, hw_keys=assignments)
def display_lecture(page): if page == 'index': lecture_list = os.listdir(app_path('templates', 'lectures')) # Old way of generating list (for backwards compatibility) lectures = [ note for note in sorted(lecture_list) if note != "index.mak" ] # New, cleaner-in-the-template way to do it lecture_notes = [(note, os.path.splitext(os.path.join("/lectures", note))[0]) for note in sorted(lecture_list) if os.path.splitext(note)[0] != "index"] else: lecture_notes = None lectures = None return render_template(os.path.join('lectures', page), lecture_notes=lecture_notes, lectures=lectures)
import hashlib from datetime import datetime # flask dependencies from flask import Flask from flask import jsonify from flask.ext.mako import MakoTemplates, render_template from werkzeug.exceptions import NotFound # ofcourse from ofcourse.util import count_posts, app_path from ofcourse.blueprints import homework, lectures, quizzes from ofcourse.participants import participants_bp app = Flask(__name__) app.static_folder = app_path("static") app.templates_folder = app_path("templates") app.people_folder = app_path("people") mako = MakoTemplates(app) # Automatically include site config @app.context_processor def inject_yaml(): with open(app_path('site.yaml')) as site_yaml: site_config = yaml.safe_load(site_yaml) course_url = "http://localhost:5000/" if site_config['course'].get('public_url', None) is not None: course_url = site_config['course']['public_url']
import os from flask import Blueprint from flask.ext.mako import render_template from ofcourse.util import app_path homework = Blueprint('homework', __name__, template_folder=app_path('templates')) lectures = Blueprint('lectures', __name__, template_folder=app_path('templates')) quizzes = Blueprint('quizzes', __name__, template_folder=app_path('templates')) @homework.route('/', defaults={'page': 'index'}) @homework.route('/<page>') def display_homework(page): if page == 'index': hws = os.listdir(app_path('static', 'hw')) hws.extend(os.listdir(app_path('templates', 'hw'))) hws = [hw for hw in sorted(hws) if not hw == "index.mak"] else: hws = None return render_template('hw/{}.mak'.format(page), name='mako', hws=hws) @lectures.route('/', defaults={'page': 'index'}) @lectures.route('/<page>')
from __future__ import print_function import os from itertools import chain from flask import Blueprint from ofcourse.render import render_template from ofcourse.util import app_path homework = Blueprint('homework', __name__, template_folder=app_path('templates')) lectures = Blueprint('lectures', __name__, template_folder=app_path('templates')) quizzes = Blueprint('quizzes', __name__, template_folder=app_path('templates')) @homework.route('/', defaults={'page': 'index'}) @homework.route('/<page>') def display_homework(page): if page == 'index': # Old way of generating list (for backwards compatibility) hws = os.listdir(app_path('static', 'hw')) hws.extend(os.listdir(app_path('templates', 'hw'))) hws = [hw for hw in sorted(hws) if not hw == "index.mak"] # New, cleaner-in-the-template way to do it hwd = [(hw, os.path.join('/static', 'hw')) for hw in os.listdir(app_path('static', 'hw'))] hwd.extend([(os.path.splitext(hw)[0], '/hw') for hw in os.listdir(app_path('templates', 'hw'))])
import os from flask import Blueprint from flask.ext.mako import render_template from ofcourse.util import app_path homework = Blueprint("homework", __name__, template_folder=app_path("templates")) lectures = Blueprint("lectures", __name__, template_folder=app_path("templates")) quizzes = Blueprint("quizzes", __name__, template_folder=app_path("templates")) @homework.route("/", defaults={"page": "index"}) @homework.route("/<page>") def display_homework(page): if page == "index": hws = os.listdir(app_path("static", "hw")) hws.extend(os.listdir(app_path("templates", "hw"))) hws = [hw for hw in sorted(hws) if not hw == "index.mak"] else: hws = None return render_template("hw/{}.mak".format(page), name="mako", hws=hws) @lectures.route("/", defaults={"page": "index"}) @lectures.route("/<page>") def display_lecture(page): if page == "index": lecture_notes = os.listdir(app_path("templates", "lectures"))
import hashlib from datetime import datetime # flask dependencies from flask import Flask from flask import jsonify from werkzeug.exceptions import NotFound # ofcourse from .render import render_init, render_template from ofcourse.util import count_posts, app_path from ofcourse.blueprints import homework, lectures, quizzes from ofcourse.participants import participants_bp app = Flask(__name__) app.static_folder = app_path("static") app.templates_folder = app_path("templates") app.people_folder = app_path("people") render_init(app) # Automatically include site config @app.context_processor def inject_yaml(): with open(app_path('site.yaml')) as site_yaml: site_config = yaml.safe_load(site_yaml) course_url = "http://localhost:5000/" if site_config['course'].get('public_url', None) is not None: course_url = site_config['course']['public_url']
def inject_yaml(): with open(app_path('site.yaml')) as site_yaml: site_config = yaml.load(site_yaml) return site_config
import os from datetime import datetime, date, timedelta from urlparse import urlparse import yaml from flask import Blueprint, redirect from flask.ext.mako import render_template import ofcourse from ofcourse.util import app_path, get_hw_keys participants_bp = Blueprint('participants_bp', __name__, template_folder=app_path('templates')) currentYear = str(date.today().year) currentTerm = "fall" if date.today().month > 7 else "spring" @participants_bp.route('/') def participants_blank(): """ This is the default landing for the participants listing page. It will list all of the participants in the current term for HFOSS """ return participants_year_term(currentYear, currentTerm)