アクティビティ タイプの添付ファイル

これは Classroom アドオンに関する 5 番目のチュートリアルです 説明します。

このチュートリアルでは、前のステップの例を変更します activity-type のアタッチメントを生成します。これらの添付ファイルは 生徒の提出物を必要とする場合(書面による回答、テスト、 アーティファクトです。

コンテンツ タイプとアクティビティ タイプの添付ファイルの違いは重要です。 アクティビティ タイプの添付ファイルは、以下の点でコンテンツ タイプと異なります。

  • 「提出」[生徒表示] iframe の右上に表示されます。
  • 生徒の提出物に一意の ID を提供します。
  • Classroom の採点担当者の UI に生徒の添付ファイル カードが表示されます。
  • 生徒は、担当する課題の成績を設定できます。

採点については、次のチュートリアルをご覧ください。このコースでは、 次の作業を行います。

  • 以前の添付ファイル作成リクエストを Classroom API を使用して、アクティビティ タイプの添付ファイルを作成します。
  • 生徒の提出物用に永続ストレージを実装する。
  • 生徒からの入力を受け入れるには、前の生徒表示ルートを変更します。
  • 生徒の提出物の確認 iframe を提供するルートを指定します。

完了したら、 教師としてログインすると、Google Classroom の UI を使用できます。クラスの生徒は iframe でアクティビティを完了し、レスポンスを送信します。この教師は Classroom の採点 UI で生徒の提出物を確認する。

この例では、添付ファイルのテンプレートを 前のチュートリアルでは、有名なランドマークの画像とキャプションが表示されています。 名前が付けられます。アクティビティでは、生徒に次の指示を出します。 ランドマークの名前を指定します

添付ファイル作成リクエストを変更する

コード内で、コンテンツ タイプを作成したセクションに移動します。 先ほど説明しましたここでの重要な項目は、VM インスタンスを AddOnAttachment オブジェクト(以前に teacherViewUri を指定していました)は、 studentViewUri、アタッチメントの title

どのアドオンの添付ファイルにもこれら 3 つのフィールドが必要ですが、 studentWorkReviewUri がない場合、アタッチメントが activity-type または content-type です。値が入力されている CREATE リクエスト studentWorkReviewUri はアクティビティ タイプのアタッチメントになり、CREATE はアクティビティ タイプのアタッチメントになります。 studentWorkReviewUri のないリクエストは、コンテンツ タイプの添付ファイルになります。

このリクエストに加える唯一の変更は、 studentWorkReviewUri フィールド。適切な名前のルートをここに追加します。 実装します。

Python

こちらの例では、create_attachments メソッドの webapp/attachment_routes.py ファイル。

attachment = {
    # Specifies the route for a teacher user.
    "teacherViewUri": {
        "uri":
            flask.url_for(
                "load_activity_attachment",
                _scheme='https',
                _external=True),
    },
    # Specifies the route for a student user.
    "studentViewUri": {
        "uri":
            flask.url_for(
                "load_activity_attachment",
                _scheme='https',
                _external=True)
    },
    # Specifies the route for a teacher user when the attachment is
    # loaded in the Classroom grading view.
    # The presence of this field marks this as an activity-type attachment.
    "studentWorkReviewUri": {
        "uri":
            flask.url_for(
                "view_submission", _scheme='https', _external=True)
    },
    # The title of the attachment.
    "title": f"Attachment {attachment_count}",
}

コンテンツ タイプの添付ファイル用の永続ストレージを追加する

アクティビティに対する生徒の回答を記録します。後で検索できます。 教師が [生徒の提出物の確認] iframe で提出物を表示します。

Submission のデータベース スキーマを設定します。この例では、 画像に表示されているランドマークの名前を入力します。Submission 次の属性が含まれています。

  • attachment_id: アタッチメントの一意の識別子。割り当て元 メッセージの作成時にレスポンスで返される 添付します。
  • submission_id: 生徒の提出物の識別子。割り当て元 Classroom 内の getAddOnContext 応答で返される 生徒用のビューです。
で確認できます。
  • student_response: 生徒から提供された解答。
で確認できます。

Python

前のステップの SQLite と flask_sqlalchemy の実装を拡張します。

前のテーブルを定義したファイルに移動します。 (上記の例の場合は models.py)。次のコードを 追加します。

# Database model to represent a student submission.
class Submission(db.Model):
    # The attachmentId is the unique identifier for the attachment.
    submission_id = db.Column(db.String(120), primary_key=True)

    # The unique identifier for the student's submission.
    attachment_id = db.Column(db.String(120), primary_key=True)

    # The student's response to the question prompt.
    student_response = db.Column(db.String(120))

新しい Submission クラスを、添付ファイルを含むサーバー ファイルにインポートします。 ルートの処理。

生徒表示ルートを変更する

次に、前の [Student View] のルートに変更を加え、小さなフォームを表示して承諾する 入力できます。前のモジュールで作成したコードのほとんどは 説明します。

生徒用ビューへのルートを提供するサーバーコードを特定します。これは、 アタッチメントの作成時に studentViewUri フィールドに指定されたルート。 最初に行う変更は、Terraform から submissionId を抽出することです。 getAddOnContext レスポンス

Python

こちらの例では、load_activity_attachment メソッドの webapp/attachment_routes.py ファイル。

# Issue a request to the courseWork.getAddOnContext endpoint
addon_context_response = classroom_service.courses().courseWork(
).getAddOnContext(
    courseId=flask.session["courseId"],
    itemId=flask.session["itemId"]).execute()

# One of studentContext or teacherContext will be populated.
user_context = "student" if addon_context_response.get(
    "studentContext") else "teacher"

# If the user is a student...
if user_context == "student":
    # Extract the submissionId from the studentContext object.
    # This value is provided by Google Classroom.
    flask.session["submissionId"] = addon_context_response.get(
            "studentContext").get("submissionId")

また、生徒の提出状況を取得するリクエストを発行することもできます。 レスポンスには、次のような状態を示す SubmissionState 値が含まれます。 生徒が添付ファイルを開いたか提出したかを示すものです。考えられる原因 提出物の編集を禁止する場合や、 生徒の学習状況について教師に分析情報を提供することにprogress:

Python

こちらの例では、 上記の load_activity_attachment メソッド。

# Issue a request to get the status of the student submission.
submission_response = classroom_service.courses().courseWork(
).addOnAttachments().studentSubmissions().get(
    courseId=flask.session["courseId"],
    itemId=flask.session["itemId"],
    attachmentId=flask.session["attachmentId"],
    submissionId=flask.session["submissionId"]).execute()

最後に、データベースから添付ファイル情報を取得して、入力を提供します。 フォームに入力します。この例のフォームは、文字列の入力フィールドと 送信ボタンを使用できます。ランドマークの画像を表示して、生徒に名前を入力するように促します。 回答したら、データベースに記録します。

Python

こちらの例では、 上記の load_activity_attachment メソッド。

# Look up the attachment in the database.
attachment = Attachment.query.get(flask.session["attachmentId"])

message_str = f"I see that you're a {user_context}! "
message_str += (
    f"I've loaded the attachment with ID {attachment.attachment_id}. "
    if user_context == "teacher" else
    "Please complete the activity below.")

form = activity_form_builder()

if form.validate_on_submit():
    # Record the student's response in our database.

    # Check if the student has already submitted a response.
    # If so, update the response stored in the database.
    student_submission = Submission.query.get(flask.session["submissionId"])

    if student_submission is not None:
        student_submission.student_response = form.student_response.data
    else:
        # Store the student's response by the submission ID.
        new_submission = Submission(
            submission_id=flask.session["submissionId"],
            attachment_id=flask.session["attachmentId"],
            student_response=form.student_response.data)
        db.session.add(new_submission)

    db.session.commit()

    return flask.render_template(
        "acknowledge-submission.html",
        message="Your response has been recorded. You can close the " \
            "iframe now.",
        instructions="Please Turn In your assignment if you have " \
            "completed all tasks."
    )

# Show the activity.
return flask.render_template(
    "show-activity-attachment.html",
    message=message_str,
    image_filename=attachment.image_filename,
    image_caption=attachment.image_caption,
    user_context=user_context,
    form=form,
    responses=response_strings)

ユーザーを区別するために、送信を無効にすることを検討してください 教師用の画面に正解が表示されます。

Student Work Review iframe のルートを追加する

最後に、生徒の提出物の確認の iframe を提供するルートを追加します。名前 ルートは、作成時に studentWorkReviewUri に指定したものと一致する必要があります。 表示されます。このルートは、教師が生徒の提出物を確認すると開きます。 Classroom の採点機能 UI。

Classroom で submissionId クエリ パラメータを受け取る 生徒の提出物の確認の iframe を開きます。これを使用して生徒の課題を ローカル データベースを使用します。

Python

上記の例では、webapp/attachment_routes.py ファイル内にあります。

@app.route("/view-submission")
def view_submission():
    """
    Render a student submission using the show-student-submission.html template.
    """

    # Save the query parameters passed to the iframe in the session, just as we did
    # in previous routes. Abbreviated here for readability.
    add_iframe_query_parameters_to_session(flask.request.args)

    # For the sake of brevity in this example, we'll skip the conditional logic
    # to see if we need to authorize the user as we have done in previous steps.
    # We can assume that the user that reaches this route is a teacher that has
    # already authorized and created an attachment using the add-on.

    # In production, we recommend fully validating the user's authorization at
    # this stage as well.

    # Look up the student's submission in our database.
    student_submission = Submission.query.get(flask.session["submissionId"])

    # Look up the attachment in the database.
    attachment = Attachment.query.get(student_submission.attachment_id)

    # Render the student's response alongside the correct answer.
    return flask.render_template(
        "show-student-submission.html",
        message=f"Loaded submission {student_submission.submission_id} for "\
            f"attachment {attachment.attachment_id}.",
        student_response=student_submission.student_response,
        correct_answer=attachment.image_caption)

アドオンをテストする

前のチュートリアルのアドオンの手順をテストするを繰り返します。すべきこと 生徒が開くことができる添付ファイルがある。

アクティビティのアタッチメントをテストする手順は次のとおりです。

  • Google Classroom にログインします。 教師のテストユーザーと同じクラスの生徒テストユーザー。
  • [授業] タブに移動し、テスト用の [課題] を開きます。
  • アドオン添付ファイルカードをクリックして生徒用ビューを開き、 返されます。
  • アクティビティが完了したら iframe を閉じます。必要に応じて、[曲がる In ボタン。

完了しても Classroom に変更はありません できます。Student Work Review iframe をテストします。

  • 教師のテストユーザーとして Classroom にログインします。
  • [成績] タブで、テストの課題の列を見つけます。[ テストの課題の名前。
  • テスト学生ユーザーのカードを見つけます。カードの添付ファイルをクリックします。

生徒に対して正しい提出物が表示されていることを確認します。

これで、次のステップ(添付ファイルの同期)に進む準備が整いました 評価します