mirror of
https://github.com/google/blockly.git
synced 2026-01-04 15:40:08 +01:00
Simplify
This commit is contained in:
@@ -23,7 +23,6 @@ __author__ = "q.neutron@gmail.com (Quynh Neutron)"
|
|||||||
import cgi
|
import cgi
|
||||||
import hashlib
|
import hashlib
|
||||||
from random import randint
|
from random import randint
|
||||||
from datetime import timezone
|
|
||||||
from google.cloud import ndb
|
from google.cloud import ndb
|
||||||
|
|
||||||
|
|
||||||
@@ -31,8 +30,7 @@ class Xml(ndb.Model):
|
|||||||
# A row in the database.
|
# A row in the database.
|
||||||
xml_hash = ndb.IntegerProperty()
|
xml_hash = ndb.IntegerProperty()
|
||||||
xml_content = ndb.TextProperty()
|
xml_content = ndb.TextProperty()
|
||||||
last_accessed = ndb.DateTimeProperty(auto_now = true)
|
last_accessed = ndb.DateTimeProperty(auto_now=True)
|
||||||
|
|
||||||
|
|
||||||
def keyGen():
|
def keyGen():
|
||||||
# Generate a random string of length KEY_LEN.
|
# Generate a random string of length KEY_LEN.
|
||||||
@@ -74,19 +72,14 @@ def keyToXml(key_provided):
|
|||||||
client = ndb.Client()
|
client = ndb.Client()
|
||||||
with client.context():
|
with client.context():
|
||||||
result = Xml.get_by_id(key_provided)
|
result = Xml.get_by_id(key_provided)
|
||||||
|
|
||||||
if not result:
|
if not result:
|
||||||
xml = ""
|
xml = ""
|
||||||
else:
|
else:
|
||||||
xml = result.xml_content
|
# Put it back into the datastore immediately, which updates the last
|
||||||
# Update row to include last accessed time--because last_accessed is set to
|
# accessed time.
|
||||||
# auto_now, any write updates the time.
|
|
||||||
with client.context():
|
with client.context():
|
||||||
row = Xml(id = key_provided,
|
result.put()
|
||||||
xml_hash = result.xml_hash,
|
xml = result.xml_content
|
||||||
xml_content = result.xml_content)
|
|
||||||
row.put();
|
|
||||||
|
|
||||||
return xml
|
return xml
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user