Skip to content

Commit

Permalink
add </head> tags and Module 20
Browse files Browse the repository at this point in the history
  • Loading branch information
wescpy committed Sep 20, 2022
1 parent 7bd35d9 commit 32fcf8c
Show file tree
Hide file tree
Showing 31 changed files with 235 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ Memcache | [12 &rArr;] 13 | Moving off App Engine `memcache` makes your apps mor
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.
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**.
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.
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.
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.


Expand Down Expand Up @@ -116,6 +117,8 @@ Module | Topic | Video | Codelab | START here | FINISH here
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)
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)
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)
20|Add App Engine `users` | _TBD_ | _TBD_ | Module 1 [code](/mod1-flask) (2.x) | Module 20 [code](/mod20-gaeusers) (2.x)
21|Migrate to Cloud Identity Platform | _TBD_ | _TBD_ | Module 20 [code](/mod20-gaeusers) (2.x) | _TBD_


### Table of contents
Expand Down
1 change: 1 addition & 0 deletions mod1-flask/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<html>
<head>
<title>VisitMe Example</title>
</head>
<body>

<h1>VisitMe example</h1>
Expand Down
1 change: 1 addition & 0 deletions mod11-functions/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<html>
<head>
<title>VisitMe Example</title>
</head>
<body>

<h1>VisitMe example</h1>
Expand Down
1 change: 1 addition & 0 deletions mod12-memcache/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<html>
<head>
<title>VisitMe Example</title>
</head>
<body>

<h1>VisitMe example</h1>
Expand Down
1 change: 1 addition & 0 deletions mod12b-memcache/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<html>
<head>
<title>VisitMe Example</title>
</head>
<body>

<h1>VisitMe example</h1>
Expand Down
1 change: 1 addition & 0 deletions mod13a-memorystore/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<html>
<head>
<title>VisitMe Example</title>
</head>
<body>

<h1>VisitMe example</h1>
Expand Down
1 change: 1 addition & 0 deletions mod13b-memorystore/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<html>
<head>
<title>VisitMe Example</title>
</head>
<body>

<h1>VisitMe example</h1>
Expand Down
1 change: 1 addition & 0 deletions mod15-blobstore/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<html>
<head>
<title>VisitMe Example</title>
</head>
<body>

<h1>VisitMe example</h1>
Expand Down
1 change: 1 addition & 0 deletions mod16-cloudstorage/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<html>
<head>
<title>VisitMe Example</title>
</head>
<body>

<h1>VisitMe example</h1>
Expand Down
1 change: 1 addition & 0 deletions mod18-gaepull/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<html>
<head>
<title>VisitMe Example</title>
</head>
<body>

<h1>VisitMe example</h1>
Expand Down
1 change: 1 addition & 0 deletions mod19-pubsub/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<html>
<head>
<title>VisitMe Example</title>
</head>
<body>

<h1>VisitMe example</h1>
Expand Down
1 change: 1 addition & 0 deletions mod1b-flask/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<html>
<head>
<title>VisitMe Example</title>
</head>
<body>

<h1>VisitMe example</h1>
Expand Down
79 changes: 79 additions & 0 deletions mod20-gaeusers/.gcloudignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# This file specifies files that are *not* uploaded to Google Cloud Platform
# using gcloud. It follows the same syntax as .gitignore, with the addition of
# "#!include" directives (which insert the entries of the given .gitignore-style
# file at that point).
#
# For more information, run:
# $ gcloud topic gcloudignore
#
.gcloudignore

# Source code control files
.git/
.gitignore
.hgignore
.hg/

# README/text files
LICENSE
*.md

# Tests/results (not in .gitignore)
noxfile.py
pylintrc
pylintrc.test

# most of .gitignore (except `lib`)
#
# Python
*.py[cod]
__pycache__/
/setup.cfg

# C extensions
*.so

# Packages
*.egg
*.egg-info
dist
build
eggs
.eggs
parts
bin
var
sdist
develop-eggs
.installed.cfg
lib64
*.tgz

# Installer logs
pip-log.txt

# Tests/results
.nox/
.pytest_cache/
.cache
.pytype
.coverage
coverage.xml
*sponge_log.xml
system_tests/local_test_setup

# Mac
.DS_Store

# IDEs/editors
*.sw[op]
*~
.vscode
.idea

# Built documentation
docs/_build
docs.metadata

# Virtual environment
env/
3 changes: 3 additions & 0 deletions mod20-gaeusers/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Module 20 - Add usage of App Engine `users` to Flask `ndb` sample app

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.
21 changes: 21 additions & 0 deletions mod20-gaeusers/app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

runtime: python27
threadsafe: yes
api_version: 1

handlers:
- url: /.*
script: main.app
20 changes: 20 additions & 0 deletions mod20-gaeusers/appengine_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from google.appengine.ext import vendor

# Set PATH to your libraries folder.
PATH = 'lib'
# Add libraries installed in the PATH folder.
vendor.add(PATH)
59 changes: 59 additions & 0 deletions mod20-gaeusers/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from flask import Flask, render_template, request
from google.appengine.api import app_identity, users
from google.appengine.ext import ndb

app = Flask(__name__)


class Visit(ndb.Model):
'Visit entity registers visitor IP address & timestamp'
visitor = ndb.StringProperty()
timestamp = ndb.DateTimeProperty(auto_now_add=True)

def store_visit(remote_addr, user_agent):
'create new Visit entity in Datastore'
Visit(visitor='{}: {}'.format(remote_addr, user_agent)).put()

def fetch_visits(limit):
'get most recent visits'
return Visit.query().order(-Visit.timestamp).fetch(limit)


@app.route('/')
def root():
'main application (GET) handler'
store_visit(request.remote_addr, request.user_agent)
visits = fetch_visits(10)

# put together users context for web template
user = users.get_current_user()
context = { # logged in
'who': user.nickname(),
'admin': '(admin)' if users.is_current_user_admin() else '',
'sign': 'Logout',
'link': '/_ah/logout?continue=https://%s/' % \
app_identity.get_default_version_hostname()
} if user else { # not logged in
'who': 'user',
'admin': '',
'sign': 'Login',
'link': users.create_login_url('/'),
}

# add visits to context and render template
context['visits'] = visits
return render_template('index.html', **context)
1 change: 1 addition & 0 deletions mod20-gaeusers/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
flask
26 changes: 26 additions & 0 deletions mod20-gaeusers/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!doctype html>
<html>
<head>
<title>VisitMe Example</title>
</head>

<body>
<p>
Welcome, {{ who }} <code>{{ admin }}</code> <button id="loginbtn">{{ sign }}</button>
</p><hr>

<h1>VisitMe example</h1>
<h3>Last 10 visits</h3>
<ul>
{% for visit in visits %}
<li>{{ visit.timestamp.ctime() }} from {{ visit.visitor }}</li>
{% endfor %}
</ul>

<script>
document.getElementById("loginbtn").onclick = () => {
window.location.href = '{{ link }}';
};
</script>
</body>
</html>
1 change: 1 addition & 0 deletions mod2a-cloudndb/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<html>
<head>
<title>VisitMe Example</title>
</head>
<body>

<h1>VisitMe example</h1>
Expand Down
1 change: 1 addition & 0 deletions mod2b-cloudndb/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<html>
<head>
<title>VisitMe Example</title>
</head>
<body>

<h1>VisitMe example</h1>
Expand Down
1 change: 1 addition & 0 deletions mod3a-datastore/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<html>
<head>
<title>VisitMe Example</title>
</head>
<body>

<h1>VisitMe example</h1>
Expand Down
1 change: 1 addition & 0 deletions mod3b-datastore/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<html>
<head>
<title>VisitMe Example</title>
</head>
<body>

<h1>VisitMe example</h1>
Expand Down
1 change: 1 addition & 0 deletions mod4a-rundocker/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<html>
<head>
<title>VisitMe Example</title>
</head>
<body>

<h1>VisitMe example</h1>
Expand Down
1 change: 1 addition & 0 deletions mod4b-rundocker/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<html>
<head>
<title>VisitMe Example</title>
</head>
<body>

<h1>VisitMe example</h1>
Expand Down
1 change: 1 addition & 0 deletions mod5-runbldpks/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<html>
<head>
<title>VisitMe Example</title>
</head>
<body>

<h1>VisitMe example</h1>
Expand Down
1 change: 1 addition & 0 deletions mod6-firestore/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<html>
<head>
<title>VisitMe Example</title>
</head>
<body>

<h1>VisitMe example</h1>
Expand Down
1 change: 1 addition & 0 deletions mod7-gaetasks/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<html>
<head>
<title>VisitMe Example</title>
</head>
<body>

<h1>VisitMe example</h1>
Expand Down
Loading

0 comments on commit 32fcf8c

Please sign in to comment.