Esempio n. 1
0
            submission.user != current_user.id:
        logger.info("User tried to download submission they can't access.")

        abort(404)

    # Find any expired archives and remove them
    deleted_files = []
    for i in Archive.objects(expires__lt = datetime.datetime.today()).limit(5):
        if i.file_location:
            deleted_files.append(i.file_location)

            try:
                os.remove(i.file_location)
            except OSError as e:
                logger.warning(
                    "Could not remove expired archive at %s: %s.",
                    i.file_location, str(e)
                )

        i.delete()

    if deleted_files:
        logger.info("Deleted archives %s.", str(deleted_files))

    new_archive = Archive(
        requester = current_user.id,
        archive_type = "single_submission"
    )

    new_archive.expires = \
        datetime.datetime.today() + app.config["STUDENT_ARCHIVE_LIFETIME"]
Esempio n. 2
0
    if current_user.account_type == "student" and \
            submission.user != current_user.id:
        logger.info("User tried to download submission they can't access.")

        abort(404)

    # Find any expired archives and remove them
    deleted_files = []
    for i in Archive.objects(expires__lt=datetime.datetime.today()).limit(5):
        if i.file_location:
            deleted_files.append(i.file_location)

            try:
                os.remove(i.file_location)
            except OSError as e:
                logger.warning("Could not remove expired archive at %s: %s.",
                               i.file_location, str(e))

        i.delete()

    if deleted_files:
        logger.info("Deleted archives %s.", str(deleted_files))

    new_archive = Archive(requester=current_user.id,
                          archive_type="single_submission")

    new_archive.expires = \
        datetime.datetime.today() + app.config["STUDENT_ARCHIVE_LIFETIME"]

    archive_file_name = ""
    try:
        # Create the actual archive file.