We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Link to latests shared program is empty
![image](https://user-images.githubusercontent.com/1003685/130991189-31b89162-19a0-4e12-8f31-0862fe7dcef4.png)

(see link at the bottom)

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `website/teacher.py`
Content:
```
1 from website.auth import requires_login, is_teacher, current_user
2 import utils
3 import uuid
4 from flask import request, jsonify, redirect
5 from flask_helpers import render_template
6 import os
7 import hedyweb
8 TRANSLATIONS = hedyweb.Translations ()
9 from config import config
10 cookie_name     = config ['session'] ['cookie_name']
11 
12 def routes (app, database, requested_lang):
13     global DATABASE
14     DATABASE = database
15 
16     from app import render_main_menu
17 
18     @app.route('/class/<class_id>', methods=['GET'])
19     @requires_login
20     def get_class (user, class_id):
21         if not is_teacher (request):
22             return 'Only teachers can retrieve classes', 403
23         Class = DATABASE.get_class (class_id)
24         if not Class or Class ['teacher'] != user ['username']:
25             return 'No such class', 404
26         students = []
27         for student_username in Class.get ('students', []):
28             student = DATABASE.user_by_username (student_username)
29             programs = DATABASE.programs_for_user(student_username)
30             highest_level = max(program['level'] for program in programs) if len(programs) else 0
31             sorted_public_programs = list(sorted([program for program in programs if program.get ('public')], key=lambda p: p['date']))
32             latest_shared = sorted_public_programs[-1] if sorted_public_programs else None
33             students.append ({'username': student_username, 'last_login': utils.mstoisostring (student ['last_login']), 'programs': len (programs), 'highest_level': highest_level, 'latest_shared': latest_shared})
34 
35         if utils.is_testing_request (request):
36             return jsonify ({'students': students, 'link': Class ['link'], 'name': Class ['name'], 'id': Class ['id']})
37         return render_template ('class-overview.html', lang=requested_lang (), auth=TRANSLATIONS.get_translations (requested_lang (), 'Auth'), menu=render_main_menu('my-profile'), username=current_user (request) ['username'], current_page='my-profile', class_info={'students': students, 'link': os.getenv ('BASE_URL') + '/hedy/l/' + Class ['link'], 'name': Class ['name'], 'id': Class ['id']})
38 
39     @app.route('/class', methods=['POST'])
40     @requires_login
41     def create_class (user):
42         if not is_teacher (request):
43             return 'Only teachers can create classes', 403
44 
45         body = request.json
46         # Validations
47         if not isinstance(body, dict):
48             return 'body must be an object', 400
49         if not isinstance(body.get('name'), str):
50             return 'name must be a string', 400
51 
52         Class = {
53             'id': uuid.uuid4().hex,
54             'date': utils.timems (),
55             'teacher': user ['username'],
56             'link': utils.random_id_generator (7),
57             'name': body ['name']
58         }
59 
60         DATABASE.store_class (Class)
61 
62         return {}, 200
63 
64     @app.route('/class/<class_id>', methods=['PUT'])
65     @requires_login
66     def update_class (user, class_id):
67         if not is_teacher (request):
68             return 'Only teachers can update classes', 403
69 
70         body = request.json
71         # Validations
72         if not isinstance(body, dict):
73             return 'body must be an object', 400
74         if not isinstance(body.get('name'), str):
75             return 'name must be a string', 400
76 
77         Class = DATABASE.get_class (class_id)
78         if not Class or Class ['teacher'] != user ['username']:
79             return 'No such class', 404
80 
81         Class = DATABASE.update_class (class_id, body ['name'])
82 
83         return {}, 200
84 
85     @app.route('/class/<class_id>', methods=['DELETE'])
86     @requires_login
87     def delete_class (user, class_id):
88         Class = DATABASE.get_class (class_id)
89         if not Class or Class ['teacher'] != user ['username']:
90             return 'No such class', 404
91 
92         DATABASE.delete_class (Class)
93 
94         return {}, 200
95 
96     @app.route('/class/<class_id>/prejoin/<link>', methods=['GET'])
97     def prejoin_class (class_id, link):
98         Class = DATABASE.get_class (class_id)
99         if not Class or Class ['link'] != link:
100             return 'No such class', 404
101         user = {}
102         if request.cookies.get (cookie_name):
103             token = DATABASE.get_token(request.cookies.get (cookie_name))
104             if token:
105                 user = DATABASE.user_by_username(token ['username'])
106 
107         return render_template ('class-prejoin.html', lang=requested_lang (), auth=TRANSLATIONS.get_translations (requested_lang (), 'Auth'), menu=render_main_menu('my-profile'), username=current_user (request) ['username'], current_page='my-profile', class_info={'link': os.getenv ('BASE_URL') + '/class/' + Class ['id'] + '/join/' + Class ['link'] + '?lang=' + requested_lang (), 'name': Class ['name']})
108 
109     @app.route('/class/<class_id>/join/<link>', methods=['GET'])
110     @requires_login
111     def join_class (user, class_id, link):
112         Class = DATABASE.get_class (class_id)
113         if not Class or Class ['link'] != link:
114             return 'No such class', 404
115 
116         DATABASE.add_student_to_class (Class ['id'], user ['username'])
117 
118         return redirect(request.url.replace('/class/' + class_id + '/join/' + link, '/my-profile'), code=302)
119 
120     @app.route('/class/<class_id>/student/<student_id>', methods=['DELETE'])
121     @requires_login
122     def leave_class (user, class_id, student_id):
123 
124         Class = DATABASE.get_class (class_id)
125         if not Class or Class ['teacher'] != user ['username']:
126             return 'No such class', 404
127 
128         DATABASE.remove_student_from_class (Class ['id'], student_id)
129 
130         return {}, 200
131 
132     @app.route('/hedy/l/<link_id>', methods=['GET'])
133     def resolve_class_link (link_id):
134         Class = DATABASE.resolve_class_link (link_id)
135         if not Class:
136             return 'Invalid link', 404
137         return redirect(request.url.replace('/hedy/l/' + link_id, '/class/' + Class ['id'] + '/prejoin/' + link_id), code=302)
138
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/website/teacher.py b/website/teacher.py
--- a/website/teacher.py
+++ b/website/teacher.py
@@ -29,7 +29,11 @@
             programs = DATABASE.programs_for_user(student_username)
             highest_level = max(program['level'] for program in programs) if len(programs) else 0
             sorted_public_programs = list(sorted([program for program in programs if program.get ('public')], key=lambda p: p['date']))
-            latest_shared = sorted_public_programs[-1] if sorted_public_programs else None
+            if sorted_public_programs:
+                latest_shared = sorted_public_programs[-1]
+                latest_shared['link'] = os.getenv ('BASE_URL') + f"hedy/{latest_shared['id']}/view"
+            else:
+                latest_shared = None
             students.append ({'username': student_username, 'last_login': utils.mstoisostring (student ['last_login']), 'programs': len (programs), 'highest_level': highest_level, 'latest_shared': latest_shared})
 
         if utils.is_testing_request (request):

{"golden_diff": "diff --git a/website/teacher.py b/website/teacher.py\n--- a/website/teacher.py\n+++ b/website/teacher.py\n@@ -29,7 +29,11 @@\n             programs = DATABASE.programs_for_user(student_username)\n             highest_level = max(program['level'] for program in programs) if len(programs) else 0\n             sorted_public_programs = list(sorted([program for program in programs if program.get ('public')], key=lambda p: p['date']))\n-            latest_shared = sorted_public_programs[-1] if sorted_public_programs else None\n+            if sorted_public_programs:\n+                latest_shared = sorted_public_programs[-1]\n+                latest_shared['link'] = os.getenv ('BASE_URL') + f\"hedy/{latest_shared['id']}/view\"\n+            else:\n+                latest_shared = None\n             students.append ({'username': student_username, 'last_login': utils.mstoisostring (student ['last_login']), 'programs': len (programs), 'highest_level': highest_level, 'latest_shared': latest_shared})\n \n         if utils.is_testing_request (request):\n", "issue": "Link to latests shared program is empty\n![image](https://user-images.githubusercontent.com/1003685/130991189-31b89162-19a0-4e12-8f31-0862fe7dcef4.png)\r\n\r\n(see link at the bottom)\n", "before_files": [{"content": "from website.auth import requires_login, is_teacher, current_user\nimport utils\nimport uuid\nfrom flask import request, jsonify, redirect\nfrom flask_helpers import render_template\nimport os\nimport hedyweb\nTRANSLATIONS = hedyweb.Translations ()\nfrom config import config\ncookie_name     = config ['session'] ['cookie_name']\n\ndef routes (app, database, requested_lang):\n    global DATABASE\n    DATABASE = database\n\n    from app import render_main_menu\n\n    @app.route('/class/<class_id>', methods=['GET'])\n    @requires_login\n    def get_class (user, class_id):\n        if not is_teacher (request):\n            return 'Only teachers can retrieve classes', 403\n        Class = DATABASE.get_class (class_id)\n        if not Class or Class ['teacher'] != user ['username']:\n            return 'No such class', 404\n        students = []\n        for student_username in Class.get ('students', []):\n            student = DATABASE.user_by_username (student_username)\n            programs = DATABASE.programs_for_user(student_username)\n            highest_level = max(program['level'] for program in programs) if len(programs) else 0\n            sorted_public_programs = list(sorted([program for program in programs if program.get ('public')], key=lambda p: p['date']))\n            latest_shared = sorted_public_programs[-1] if sorted_public_programs else None\n            students.append ({'username': student_username, 'last_login': utils.mstoisostring (student ['last_login']), 'programs': len (programs), 'highest_level': highest_level, 'latest_shared': latest_shared})\n\n        if utils.is_testing_request (request):\n            return jsonify ({'students': students, 'link': Class ['link'], 'name': Class ['name'], 'id': Class ['id']})\n        return render_template ('class-overview.html', lang=requested_lang (), auth=TRANSLATIONS.get_translations (requested_lang (), 'Auth'), menu=render_main_menu('my-profile'), username=current_user (request) ['username'], current_page='my-profile', class_info={'students': students, 'link': os.getenv ('BASE_URL') + '/hedy/l/' + Class ['link'], 'name': Class ['name'], 'id': Class ['id']})\n\n    @app.route('/class', methods=['POST'])\n    @requires_login\n    def create_class (user):\n        if not is_teacher (request):\n            return 'Only teachers can create classes', 403\n\n        body = request.json\n        # Validations\n        if not isinstance(body, dict):\n            return 'body must be an object', 400\n        if not isinstance(body.get('name'), str):\n            return 'name must be a string', 400\n\n        Class = {\n            'id': uuid.uuid4().hex,\n            'date': utils.timems (),\n            'teacher': user ['username'],\n            'link': utils.random_id_generator (7),\n            'name': body ['name']\n        }\n\n        DATABASE.store_class (Class)\n\n        return {}, 200\n\n    @app.route('/class/<class_id>', methods=['PUT'])\n    @requires_login\n    def update_class (user, class_id):\n        if not is_teacher (request):\n            return 'Only teachers can update classes', 403\n\n        body = request.json\n        # Validations\n        if not isinstance(body, dict):\n            return 'body must be an object', 400\n        if not isinstance(body.get('name'), str):\n            return 'name must be a string', 400\n\n        Class = DATABASE.get_class (class_id)\n        if not Class or Class ['teacher'] != user ['username']:\n            return 'No such class', 404\n\n        Class = DATABASE.update_class (class_id, body ['name'])\n\n        return {}, 200\n\n    @app.route('/class/<class_id>', methods=['DELETE'])\n    @requires_login\n    def delete_class (user, class_id):\n        Class = DATABASE.get_class (class_id)\n        if not Class or Class ['teacher'] != user ['username']:\n            return 'No such class', 404\n\n        DATABASE.delete_class (Class)\n\n        return {}, 200\n\n    @app.route('/class/<class_id>/prejoin/<link>', methods=['GET'])\n    def prejoin_class (class_id, link):\n        Class = DATABASE.get_class (class_id)\n        if not Class or Class ['link'] != link:\n            return 'No such class', 404\n        user = {}\n        if request.cookies.get (cookie_name):\n            token = DATABASE.get_token(request.cookies.get (cookie_name))\n            if token:\n                user = DATABASE.user_by_username(token ['username'])\n\n        return render_template ('class-prejoin.html', lang=requested_lang (), auth=TRANSLATIONS.get_translations (requested_lang (), 'Auth'), menu=render_main_menu('my-profile'), username=current_user (request) ['username'], current_page='my-profile', class_info={'link': os.getenv ('BASE_URL') + '/class/' + Class ['id'] + '/join/' + Class ['link'] + '?lang=' + requested_lang (), 'name': Class ['name']})\n\n    @app.route('/class/<class_id>/join/<link>', methods=['GET'])\n    @requires_login\n    def join_class (user, class_id, link):\n        Class = DATABASE.get_class (class_id)\n        if not Class or Class ['link'] != link:\n            return 'No such class', 404\n\n        DATABASE.add_student_to_class (Class ['id'], user ['username'])\n\n        return redirect(request.url.replace('/class/' + class_id + '/join/' + link, '/my-profile'), code=302)\n\n    @app.route('/class/<class_id>/student/<student_id>', methods=['DELETE'])\n    @requires_login\n    def leave_class (user, class_id, student_id):\n\n        Class = DATABASE.get_class (class_id)\n        if not Class or Class ['teacher'] != user ['username']:\n            return 'No such class', 404\n\n        DATABASE.remove_student_from_class (Class ['id'], student_id)\n\n        return {}, 200\n\n    @app.route('/hedy/l/<link_id>', methods=['GET'])\n    def resolve_class_link (link_id):\n        Class = DATABASE.resolve_class_link (link_id)\n        if not Class:\n            return 'Invalid link', 404\n        return redirect(request.url.replace('/hedy/l/' + link_id, '/class/' + Class ['id'] + '/prejoin/' + link_id), code=302)\n", "path": "website/teacher.py"}], "after_files": [{"content": "from website.auth import requires_login, is_teacher, current_user\nimport utils\nimport uuid\nfrom flask import request, jsonify, redirect\nfrom flask_helpers import render_template\nimport os\nimport hedyweb\nTRANSLATIONS = hedyweb.Translations ()\nfrom config import config\ncookie_name     = config ['session'] ['cookie_name']\n\ndef routes (app, database, requested_lang):\n    global DATABASE\n    DATABASE = database\n\n    from app import render_main_menu\n\n    @app.route('/class/<class_id>', methods=['GET'])\n    @requires_login\n    def get_class (user, class_id):\n        if not is_teacher (request):\n            return 'Only teachers can retrieve classes', 403\n        Class = DATABASE.get_class (class_id)\n        if not Class or Class ['teacher'] != user ['username']:\n            return 'No such class', 404\n        students = []\n        for student_username in Class.get ('students', []):\n            student = DATABASE.user_by_username (student_username)\n            programs = DATABASE.programs_for_user(student_username)\n            highest_level = max(program['level'] for program in programs) if len(programs) else 0\n            sorted_public_programs = list(sorted([program for program in programs if program.get ('public')], key=lambda p: p['date']))\n            if sorted_public_programs:\n                latest_shared = sorted_public_programs[-1]\n                latest_shared['link'] = os.getenv ('BASE_URL') + f\"hedy/{latest_shared['id']}/view\"\n            else:\n                latest_shared = None\n            students.append ({'username': student_username, 'last_login': utils.mstoisostring (student ['last_login']), 'programs': len (programs), 'highest_level': highest_level, 'latest_shared': latest_shared})\n\n        if utils.is_testing_request (request):\n            return jsonify ({'students': students, 'link': Class ['link'], 'name': Class ['name'], 'id': Class ['id']})\n        return render_template ('class-overview.html', lang=requested_lang (), auth=TRANSLATIONS.get_translations (requested_lang (), 'Auth'), menu=render_main_menu('my-profile'), username=current_user (request) ['username'], current_page='my-profile', class_info={'students': students, 'link': os.getenv ('BASE_URL') + '/hedy/l/' + Class ['link'], 'name': Class ['name'], 'id': Class ['id']})\n\n    @app.route('/class', methods=['POST'])\n    @requires_login\n    def create_class (user):\n        if not is_teacher (request):\n            return 'Only teachers can create classes', 403\n\n        body = request.json\n        # Validations\n        if not isinstance(body, dict):\n            return 'body must be an object', 400\n        if not isinstance(body.get('name'), str):\n            return 'name must be a string', 400\n\n        Class = {\n            'id': uuid.uuid4().hex,\n            'date': utils.timems (),\n            'teacher': user ['username'],\n            'link': utils.random_id_generator (7),\n            'name': body ['name']\n        }\n\n        DATABASE.store_class (Class)\n\n        return {}, 200\n\n    @app.route('/class/<class_id>', methods=['PUT'])\n    @requires_login\n    def update_class (user, class_id):\n        if not is_teacher (request):\n            return 'Only teachers can update classes', 403\n\n        body = request.json\n        # Validations\n        if not isinstance(body, dict):\n            return 'body must be an object', 400\n        if not isinstance(body.get('name'), str):\n            return 'name must be a string', 400\n\n        Class = DATABASE.get_class (class_id)\n        if not Class or Class ['teacher'] != user ['username']:\n            return 'No such class', 404\n\n        Class = DATABASE.update_class (class_id, body ['name'])\n\n        return {}, 200\n\n    @app.route('/class/<class_id>', methods=['DELETE'])\n    @requires_login\n    def delete_class (user, class_id):\n        Class = DATABASE.get_class (class_id)\n        if not Class or Class ['teacher'] != user ['username']:\n            return 'No such class', 404\n\n        DATABASE.delete_class (Class)\n\n        return {}, 200\n\n    @app.route('/class/<class_id>/prejoin/<link>', methods=['GET'])\n    def prejoin_class (class_id, link):\n        Class = DATABASE.get_class (class_id)\n        if not Class or Class ['link'] != link:\n            return 'No such class', 404\n        user = {}\n        if request.cookies.get (cookie_name):\n            token = DATABASE.get_token(request.cookies.get (cookie_name))\n            if token:\n                user = DATABASE.user_by_username(token ['username'])\n\n        return render_template ('class-prejoin.html', lang=requested_lang (), auth=TRANSLATIONS.get_translations (requested_lang (), 'Auth'), menu=render_main_menu('my-profile'), username=current_user (request) ['username'], current_page='my-profile', class_info={'link': os.getenv ('BASE_URL') + '/class/' + Class ['id'] + '/join/' + Class ['link'] + '?lang=' + requested_lang (), 'name': Class ['name']})\n\n    @app.route('/class/<class_id>/join/<link>', methods=['GET'])\n    @requires_login\n    def join_class (user, class_id, link):\n        Class = DATABASE.get_class (class_id)\n        if not Class or Class ['link'] != link:\n            return 'No such class', 404\n\n        DATABASE.add_student_to_class (Class ['id'], user ['username'])\n\n        return redirect(request.url.replace('/class/' + class_id + '/join/' + link, '/my-profile'), code=302)\n\n    @app.route('/class/<class_id>/student/<student_id>', methods=['DELETE'])\n    @requires_login\n    def leave_class (user, class_id, student_id):\n\n        Class = DATABASE.get_class (class_id)\n        if not Class or Class ['teacher'] != user ['username']:\n            return 'No such class', 404\n\n        DATABASE.remove_student_from_class (Class ['id'], student_id)\n\n        return {}, 200\n\n    @app.route('/hedy/l/<link_id>', methods=['GET'])\n    def resolve_class_link (link_id):\n        Class = DATABASE.resolve_class_link (link_id)\n        if not Class:\n            return 'Invalid link', 404\n        return redirect(request.url.replace('/hedy/l/' + link_id, '/class/' + Class ['id'] + '/prejoin/' + link_id), code=302)\n", "path": "website/teacher.py"}]}