from flask.ext.login import current_user from galah.web.auth import account_type_required from bson.objectid import ObjectId from bson.errors import InvalidId from flask import abort, render_template, get_flashed_messages, request from galah.db.models import Assignment, Submission, TestResult, User from galah.base.pretty import pretty_time from galah.web.util import create_time_element, GalahWebAdapter import datetime import logging # Load Galah's configuration from galah.base.config import load_config config = load_config("web") logger = GalahWebAdapter(logging.getLogger("galah.web.views.view_assignment")) # Custom filter to output submission timestamp in ISO format def isoformat(datetime): import re # Date String is close enough, just replace three trailing zeroes with Z datestring = datetime.isoformat() return re.sub(r"000$", "Z", datestring) app.jinja_env.filters['isoformat'] = isoformat @app.route("/assignments/<assignment_id>/") @account_type_required(("student", "teacher", "teaching_assistant"))
from galah.web.auth import account_type_required from galah.db.models import Assignment, Submission, Archive from galah.base.filemagic import zipdir from bson.objectid import ObjectId from bson.errors import InvalidId from flask import send_file, abort from flask.ext.login import current_user from galah.web.util import GalahWebAdapter import os.path import subprocess import tempfile import datetime import logging import sys logger = \ GalahWebAdapter(logging.getLogger("galah.web.views.download_submission")) @app.route("/assignments/<assignment_id>/<submission_id>/download.zip") @account_type_required(("student", "teacher", "teaching_assistant")) def download_submission(assignment_id, submission_id): # Figure out which assignment the user asked for. try: assignment_id = ObjectId(assignment_id) assignment = Assignment.objects.get(id = assignment_id) except (InvalidId, Assignment.DoesNotExist) as e: logger.info("Could not retrieve assignment: %s.", str(e)) abort(404) # Figure out which submission the user is trying to download try:
from flask import Response, request import flask from galah.web import app, oauth_enabled from flask.ext.login import current_user from galah.web.api.commands import api_calls, UserError from galah.base.crypto.passcrypt import check_seal, deserialize_seal from galah.db.models import User from flask.ext.login import login_user from galah.web.auth import FlaskUser from galah.web.util import GalahWebAdapter import requests import logging logger = GalahWebAdapter(logging.getLogger("galah.web.views.api")) def get_many(dictionary, *args): return dict((i, dictionary.get(i)) for i in args) @app.route("/api/login", methods=["POST"]) def api_login(): def success(the_user): login_user(the_user) return Response(response="Successfully logged in.", headers={"X-CallSuccess": "True"}) def failure(): return Response(response="Incorrect email or password.", headers={"X-CallSuccess": "False"})
from bson.objectid import ObjectId from bson.errors import InvalidId from flask import abort, request, flash, redirect, url_for from flask.ext.login import current_user from galah.db.models import Submission, Assignment, TestResult from galah.shepherd.api import send_test_request from galah.web.util import is_url_on_site, GalahWebAdapter import datetime import logging # Load Galah's configuration from galah.base.config import load_config config = load_config("shepherd") logger = \ GalahWebAdapter(logging.getLogger("galah.web.views.upload_submissions")) @app.route("/assignments/<assignment_id>/resubmit/<submission_id>") @account_type_required(("student", "teacher", "teaching_assistant")) def resubmit_submission(assignment_id, submission_id): # Figure out which assignment the submission belongs to. try: assignment_id = ObjectId(assignment_id) assignment = Assignment.objects.get(id = assignment_id) except (InvalidId, Assignment.DoesNotExist) as e: logger.info("Could not retrieve assignment: %s", str(e)) abort(404) # Figure out where we should redirect the user to once we're done. redirect_to = request.args.get("next") or request.referrer
from galah.web import app from galah.web.auth import account_type_required from galah.db.models import Assignment, Submission, Archive from bson.objectid import ObjectId from bson.errors import InvalidId from flask import send_file, abort from flask.ext.login import current_user from galah.web.util import GalahWebAdapter import os.path import subprocess import tempfile import datetime import logging import sys logger = \ GalahWebAdapter(logging.getLogger("galah.web.views.download_submission")) @app.route("/assignments/<assignment_id>/<submission_id>/download.tar.gz") @account_type_required(("student", "teacher")) def download_submission(assignment_id, submission_id): # Figure out which assignment the user asked for. try: assignment_id = ObjectId(assignment_id) assignment = Assignment.objects.get(id = assignment_id) except (InvalidId, Assignment.DoesNotExist) as e: logger.info("Could not retrieve assignment: %s.", str(e)) abort(404) # Figure out which submission the user is trying to download try:
from galah.web.auth import account_type_required from galah.db.models import Assignment, Submission, Archive from galah.base.filemagic import zipdir from bson.objectid import ObjectId from bson.errors import InvalidId from flask import send_file, abort from flask.ext.login import current_user from galah.web.util import GalahWebAdapter import os.path import subprocess import tempfile import datetime import logging import sys logger = \ GalahWebAdapter(logging.getLogger("galah.web.views.download_submission")) @app.route("/assignments/<assignment_id>/<submission_id>/download.zip") @account_type_required(("student", "teacher", "teaching_assistant")) def download_submission(assignment_id, submission_id): # Figure out which assignment the user asked for. try: assignment_id = ObjectId(assignment_id) assignment = Assignment.objects.get(id=assignment_id) except (InvalidId, Assignment.DoesNotExist) as e: logger.info("Could not retrieve assignment: %s.", str(e)) abort(404) # Figure out which submission the user is trying to download
from galah.web import app from flask.ext.login import current_user from galah.web.auth import account_type_required from bson.objectid import ObjectId from galah.db.models import Class, Assignment, Submission from flask import render_template, request, abort import datetime from mongoengine import Q from galah.web.util import create_time_element, GalahWebAdapter import logging logger = \ GalahWebAdapter(logging.getLogger("galah.web.views.browse_assignments")) @app.route("/assignments") @account_type_required(("student", "teacher", "teaching_assistant")) def browse_assignments(): # Grab all the current user's classes classes = Class.objects(id__in=current_user.classes).only("name") # Get the current time so we don't have to do it over and over again. now = datetime.datetime.today() if "show_all" in request.args: assignments = list( Assignment.objects( Q(for_class__in=current_user.classes) & (Q(hide_until=None) | Q(hide_until__lt=now))).only( "name", "due", "due_cutoff", "for_class")) else:
from galah.web import app from flask.ext.login import current_user from galah.web.auth import FlaskUser from flask import ( redirect, url_for, request, abort, current_app, send_file, Response ) from galah.db.models import Archive from bson.objectid import ObjectId, InvalidId from galah.web.util import GalahWebAdapter import logging logger = GalahWebAdapter(logging.getLogger("galah.web.views.get_archive")) @app.route("/archives/<archive_id>") def get_archive(archive_id): archive = None try: archive = Archive.objects.get( id = ObjectId(archive_id), archive_type = "assignment_package" ) except InvalidId: logger.info("Invalid ID requested.") abort(500) except Archive.DoesNotExist: pass # If we can't find the archive return a 404 error. if archive is None: logger.info("Could not find archive with given ID.")
from galah.web.auth import account_type_required from bson.objectid import ObjectId from bson.errors import InvalidId from flask import abort, render_template, get_flashed_messages, request from galah.db.models import Assignment, Submission, TestResult, User from galah.base.pretty import pretty_time from galah.web.util import create_time_element, GalahWebAdapter import datetime import logging # Load Galah's configuration from galah.base.config import load_config config = load_config("web") logger = GalahWebAdapter(logging.getLogger("galah.web.views.view_snapshot")) # Custom filter to output submission timestamp in ISO format def isoformat(datetime): import re # Date String is close enough, just replace three trailing zeroes with Z datestring = datetime.isoformat() return re.sub(r"000$", "Z", datestring) app.jinja_env.filters['isoformat'] = isoformat @app.route("/assignments/<assignment_id>/snapshot/<student_email>") @account_type_required(("teacher", "teaching_assistant"))