Skip to content

Commit 32fcf8c

Browse files
committed
add </head> tags and Module 20
1 parent 7bd35d9 commit 32fcf8c

File tree

31 files changed

+235
-0
lines changed

31 files changed

+235
-0
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ Memcache | [12 &rArr;] 13 | Moving off App Engine `memcache` makes your apps mor
8484
Cloud Functions | 11 | Cloud Functions does not support Python 2, so after the Module 1 migration, you need to upgrade your app to Python 3 before attempting this migration, recommended if you have a very small App Engine app, or it has only one function/feature.
8585
Cloud Run | 4 or 5 | **Module 4** covers migrating to Cloud Run with Docker. Those unfamiliar with containers or do not wish to create/maintain a `Dockerfile` should do **Module 5**. Those doing **Module 4** will get additional information about Cloud Run in **Module 5** not covered in **Module 4**.
8686
Blobstore | [15 &rArr;] 16 | Moving off App Engine `blobstore` makes your apps more portable, so the **Module 16** Cloud Storage migration is _recommended_ for those using `blobstore`. Those unfamiliar with `blobstore` should do **Module 15** first to add its usage to the sample app.
87+
Users | [20 &rArr;] 21 | Moving off App Engine `users` makes your apps more portable, so the **Module 21** Cloud Storage migration is _recommended_ for those using `users`. Those unfamiliar with `users` should do **Module 20** first to add its usage to the sample app.
8788
General migration | 6 &rArr; 10 &rArr; 14 | This series is more generic and not targeting a specific feature migration, but rather if you need to migrate your App Engine apps from one running project to another. It starts with **Module 6** if you need to migrate your code, say from Datastore to Firestore. **Module 10** is if you need to migrate your data from one project to another, and finally, **Module 14** is after you're done migrating your app, your data, or both, and need to migrate a running service on one GCP project to another.
8889

8990

@@ -116,6 +117,8 @@ Module | Topic | Video | Codelab | START here | FINISH here
116117
17|Migrate to Python 3 bundled services| _TBD_ | [link](http://codelabs.developers.google.com/codelabs/cloud-gae-python-migrate-17-bundled?utm_source=codelabs&utm_medium=et&utm_campaign=CDR_wes_aap-serverless_mgrwormhole_sms_202002&utm_content=-) | Module 1 [code](/mod1-flask) (2.x) | Module 1 [code](/mod1b-flask) (3.x)
117118
18|Add App Engine `taskqueue` pull tasks| _TBD_ | [link](https://codelabs.developers.google.com/codelabs/cloud-gae-python-migrate-18-gaepull?utm_source=codelabs&utm_medium=et&utm_campaign=CDR_wes_aap-serverless_mgrgaepull_sms_202013&utm_content=-) | Module 1 [code](/mod1-flask) (2.x) | Module 18 [code](/mod18-gaepull) (2.x)
118119
19|Migrate to Cloud Pub/Sub| _TBD_ | [link](https://codelabs.developers.google.com/codelabs/cloud-gae-python-migrate-19-pubsub?utm_source=codelabs&utm_medium=et&utm_campaign=CDR_wes_aap-serverless_mgrpubsub_sms_202016&utm_content=-) | Module 18 [code](/mod18-gaepull) (2.x) | Module 19 [code](/mod19-pubsub) (2.x & 3.x)
120+
20|Add App Engine `users` | _TBD_ | _TBD_ | Module 1 [code](/mod1-flask) (2.x) | Module 20 [code](/mod20-gaeusers) (2.x)
121+
21|Migrate to Cloud Identity Platform | _TBD_ | _TBD_ | Module 20 [code](/mod20-gaeusers) (2.x) | _TBD_
119122

120123

121124
### Table of contents

mod1-flask/templates/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<html>
33
<head>
44
<title>VisitMe Example</title>
5+
</head>
56
<body>
67

78
<h1>VisitMe example</h1>

mod11-functions/templates/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<html>
33
<head>
44
<title>VisitMe Example</title>
5+
</head>
56
<body>
67

78
<h1>VisitMe example</h1>

mod12-memcache/templates/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<html>
33
<head>
44
<title>VisitMe Example</title>
5+
</head>
56
<body>
67

78
<h1>VisitMe example</h1>

mod12b-memcache/templates/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<html>
33
<head>
44
<title>VisitMe Example</title>
5+
</head>
56
<body>
67

78
<h1>VisitMe example</h1>

mod13a-memorystore/templates/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<html>
33
<head>
44
<title>VisitMe Example</title>
5+
</head>
56
<body>
67

78
<h1>VisitMe example</h1>

mod13b-memorystore/templates/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<html>
33
<head>
44
<title>VisitMe Example</title>
5+
</head>
56
<body>
67

78
<h1>VisitMe example</h1>

mod15-blobstore/templates/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<html>
33
<head>
44
<title>VisitMe Example</title>
5+
</head>
56
<body>
67

78
<h1>VisitMe example</h1>

mod16-cloudstorage/templates/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<html>
33
<head>
44
<title>VisitMe Example</title>
5+
</head>
56
<body>
67

78
<h1>VisitMe example</h1>

mod18-gaepull/templates/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<html>
33
<head>
44
<title>VisitMe Example</title>
5+
</head>
56
<body>
67

78
<h1>VisitMe example</h1>

mod19-pubsub/templates/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<html>
33
<head>
44
<title>VisitMe Example</title>
5+
</head>
56
<body>
67

78
<h1>VisitMe example</h1>

mod1b-flask/templates/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<html>
33
<head>
44
<title>VisitMe Example</title>
5+
</head>
56
<body>
67

78
<h1>VisitMe example</h1>

mod20-gaeusers/.gcloudignore

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# This file specifies files that are *not* uploaded to Google Cloud Platform
2+
# using gcloud. It follows the same syntax as .gitignore, with the addition of
3+
# "#!include" directives (which insert the entries of the given .gitignore-style
4+
# file at that point).
5+
#
6+
# For more information, run:
7+
# $ gcloud topic gcloudignore
8+
#
9+
.gcloudignore
10+
11+
# Source code control files
12+
.git/
13+
.gitignore
14+
.hgignore
15+
.hg/
16+
17+
# README/text files
18+
LICENSE
19+
*.md
20+
21+
# Tests/results (not in .gitignore)
22+
noxfile.py
23+
pylintrc
24+
pylintrc.test
25+
26+
# most of .gitignore (except `lib`)
27+
#
28+
# Python
29+
*.py[cod]
30+
__pycache__/
31+
/setup.cfg
32+
33+
# C extensions
34+
*.so
35+
36+
# Packages
37+
*.egg
38+
*.egg-info
39+
dist
40+
build
41+
eggs
42+
.eggs
43+
parts
44+
bin
45+
var
46+
sdist
47+
develop-eggs
48+
.installed.cfg
49+
lib64
50+
*.tgz
51+
52+
# Installer logs
53+
pip-log.txt
54+
55+
# Tests/results
56+
.nox/
57+
.pytest_cache/
58+
.cache
59+
.pytype
60+
.coverage
61+
coverage.xml
62+
*sponge_log.xml
63+
system_tests/local_test_setup
64+
65+
# Mac
66+
.DS_Store
67+
68+
# IDEs/editors
69+
*.sw[op]
70+
*~
71+
.vscode
72+
.idea
73+
74+
# Built documentation
75+
docs/_build
76+
docs.metadata
77+
78+
# Virtual environment
79+
env/

mod20-gaeusers/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Module 20 - Add usage of App Engine `users` to Flask `ndb` sample app
2+
3+
This repo folder is the corresponding (Python 2) code to the _forthcoming_ Module 20 codelab. The tutorial STARTs with the Python 2 code in the [Module 1 repo folder](/mod1-flask) and leads developers through adding usage of the Users API via App Engine `users`, culminating in the code in this folder.

mod20-gaeusers/app.yaml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright 2021 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
runtime: python27
16+
threadsafe: yes
17+
api_version: 1
18+
19+
handlers:
20+
- url: /.*
21+
script: main.app

mod20-gaeusers/appengine_config.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright 2020 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from google.appengine.ext import vendor
16+
17+
# Set PATH to your libraries folder.
18+
PATH = 'lib'
19+
# Add libraries installed in the PATH folder.
20+
vendor.add(PATH)

mod20-gaeusers/main.py

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Copyright 2022 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from flask import Flask, render_template, request
16+
from google.appengine.api import app_identity, users
17+
from google.appengine.ext import ndb
18+
19+
app = Flask(__name__)
20+
21+
22+
class Visit(ndb.Model):
23+
'Visit entity registers visitor IP address & timestamp'
24+
visitor = ndb.StringProperty()
25+
timestamp = ndb.DateTimeProperty(auto_now_add=True)
26+
27+
def store_visit(remote_addr, user_agent):
28+
'create new Visit entity in Datastore'
29+
Visit(visitor='{}: {}'.format(remote_addr, user_agent)).put()
30+
31+
def fetch_visits(limit):
32+
'get most recent visits'
33+
return Visit.query().order(-Visit.timestamp).fetch(limit)
34+
35+
36+
@app.route('/')
37+
def root():
38+
'main application (GET) handler'
39+
store_visit(request.remote_addr, request.user_agent)
40+
visits = fetch_visits(10)
41+
42+
# put together users context for web template
43+
user = users.get_current_user()
44+
context = { # logged in
45+
'who': user.nickname(),
46+
'admin': '(admin)' if users.is_current_user_admin() else '',
47+
'sign': 'Logout',
48+
'link': '/_ah/logout?continue=https://%s/' % \
49+
app_identity.get_default_version_hostname()
50+
} if user else { # not logged in
51+
'who': 'user',
52+
'admin': '',
53+
'sign': 'Login',
54+
'link': users.create_login_url('/'),
55+
}
56+
57+
# add visits to context and render template
58+
context['visits'] = visits
59+
return render_template('index.html', **context)

mod20-gaeusers/requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
flask

mod20-gaeusers/templates/index.html

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<title>VisitMe Example</title>
5+
</head>
6+
7+
<body>
8+
<p>
9+
Welcome, {{ who }} <code>{{ admin }}</code> <button id="loginbtn">{{ sign }}</button>
10+
</p><hr>
11+
12+
<h1>VisitMe example</h1>
13+
<h3>Last 10 visits</h3>
14+
<ul>
15+
{% for visit in visits %}
16+
<li>{{ visit.timestamp.ctime() }} from {{ visit.visitor }}</li>
17+
{% endfor %}
18+
</ul>
19+
20+
<script>
21+
document.getElementById("loginbtn").onclick = () => {
22+
window.location.href = '{{ link }}';
23+
};
24+
</script>
25+
</body>
26+
</html>

mod2a-cloudndb/templates/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<html>
33
<head>
44
<title>VisitMe Example</title>
5+
</head>
56
<body>
67

78
<h1>VisitMe example</h1>

mod2b-cloudndb/templates/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<html>
33
<head>
44
<title>VisitMe Example</title>
5+
</head>
56
<body>
67

78
<h1>VisitMe example</h1>

mod3a-datastore/templates/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<html>
33
<head>
44
<title>VisitMe Example</title>
5+
</head>
56
<body>
67

78
<h1>VisitMe example</h1>

mod3b-datastore/templates/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<html>
33
<head>
44
<title>VisitMe Example</title>
5+
</head>
56
<body>
67

78
<h1>VisitMe example</h1>

mod4a-rundocker/templates/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<html>
33
<head>
44
<title>VisitMe Example</title>
5+
</head>
56
<body>
67

78
<h1>VisitMe example</h1>

mod4b-rundocker/templates/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<html>
33
<head>
44
<title>VisitMe Example</title>
5+
</head>
56
<body>
67

78
<h1>VisitMe example</h1>

mod5-runbldpks/templates/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<html>
33
<head>
44
<title>VisitMe Example</title>
5+
</head>
56
<body>
67

78
<h1>VisitMe example</h1>

mod6-firestore/templates/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<html>
33
<head>
44
<title>VisitMe Example</title>
5+
</head>
56
<body>
67

78
<h1>VisitMe example</h1>

mod7-gaetasks/templates/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<html>
33
<head>
44
<title>VisitMe Example</title>
5+
</head>
56
<body>
67

78
<h1>VisitMe example</h1>

0 commit comments

Comments
 (0)