Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from app.modules.examples.yaml_example import YamlExampleHandler
from app.modules.training.pipeline_training import PipelineTrainigHandler
from app.modules.training.http_training import HttpTrainingHandler
from app.modules.training.datastore_training import DatastoreTrainingHandler

def handlers():
return [
Expand All @@ -18,5 +19,6 @@ def handlers():
(r'/examples/datastore/([^\/]+)/([^\/]+)', DatastoreExampleHandler),
(r'/examples/yaml', YamlExampleHandler),
(r'/training/pipeline/(\d+)', PipelineTrainigHandler),
(r'/training/http/([\d\.]+)/([\d\.]+)', HttpTrainingHandler),
(r'/training/http/([-?\d\.]+)/([-?\d\.]+)', HttpTrainingHandler),
(r'/training/datastore', DatastoreTrainingHandler),
]
4 changes: 4 additions & 0 deletions app/modules/common/kinds.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from google.appengine.ext import ndb

class Example(ndb.Model):
value = ndb.StringProperty()
3 changes: 2 additions & 1 deletion app/modules/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ <h1>Home</h1>
<li><a href="/examples/datastore/key">Datastore example (load)</a></li>
<li><a href="/examples/yaml">Yaml example</a></li>
<li><a href="/training/pipeline/5">Pipeline training</a></li>
<li><a href="/training/http/30.05/31.25">Http training </a></li>
<li><a href="/training/http/{{lat}}/{{lng}}">Http training</a></li>
<li><a href="/training/datastore">Datastore training</a></li>
</ul>
<p>Logged in as : {{user_name}}</p>
</body>
Expand Down
15 changes: 13 additions & 2 deletions app/modules/home.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import webapp2
import logging
import os

import geocoder
from google.appengine.ext.webapp import template
from google.appengine.api import users

Expand All @@ -12,6 +12,17 @@ def get(self):
# get logged in user
user = users.get_current_user()

# get user coordinates via user ip
g = geocoder.ip(self.request.remote_addr)

if not g.latlng:
# if user coordinates is not detected locate in cairo
lat = 30.0355
lng = 31.223
else:
lat = g.latlng[0]
lng = g.latlng[1]

template_path = os.path.join(os.path.dirname(__file__), 'home.html')

self.response.write(template.render(template_path, {'user_name' : user.nickname() }))
self.response.write(template.render(template_path, {'user_name' : user.nickname() , 'lat' : lat , 'lng' : lng}))
14 changes: 14 additions & 0 deletions app/modules/training/datastore_training.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<html>
<body>
<h1>Datastore Training</h1>
<dl>
{% for entity in entities %}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a conditional so No entities found is displayed if no entities exist.

<dt><p>{{ entity.key }}</p></dt>
<dd><p>{{ entity.value }}</p></dd>
{% endfor %}
{% if not entities %}
No entities found
{% endif %}
</dl>
</body>
</html>
25 changes: 25 additions & 0 deletions app/modules/training/datastore_training.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import webapp2
import logging
import os
from google.appengine.ext.webapp import template
from app.modules.common.kinds import Example

class DatastoreTrainingHandler(webapp2.RequestHandler):
def get(self):
logging.info("DatastoreTrainingHandler")

LIST_DEFAULT_LIMIT = 20

# get entities
entities_for_example_kind = Example.query().fetch(LIST_DEFAULT_LIMIT)

# make a list of key value pairs
entities = []
for entity in entities_for_example_kind:
entities.append({'key':entity.key.string_id() , 'value':entity.value})

template_path = os.path.join(os.path.dirname(__file__), 'datastore_training.html')
self.response.write(template.render(template_path, {
'entities': entities,
}))

1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ GoogleAppEnginePipeline
GoogleAppEngineCloudStorageClient
requests
requests_toolbelt
geocoder