OLD | NEW |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import json | 5 import json |
6 | 6 |
7 from google.appengine.ext import blobstore | 7 from google.appengine.ext import blobstore |
8 from google.appengine.ext import ndb | 8 from google.appengine.ext import ndb |
9 | 9 |
10 | 10 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 if tag == json_obj['default_template']: | 63 if tag == json_obj['default_template']: |
64 default_key = tmpl_key | 64 default_key = tmpl_key |
65 if not tmpl_key.get(): | 65 if not tmpl_key.get(): |
66 # Template of the same content does not exist. | 66 # Template of the same content does not exist. |
67 template = Template(id=content_str, content=content) | 67 template = Template(id=content_str, content=content) |
68 template.put() | 68 template.put() |
69 | 69 |
70 return default_key | 70 return default_key |
71 | 71 |
72 | 72 |
| 73 def CreateTemplate(content): |
| 74 """Create Template entity for user to share.""" |
| 75 content_str = json.dumps(content) |
| 76 tmpl_key = ndb.Key('Template', content_str) |
| 77 if not tmpl_key.get(): |
| 78 # Template of the same content does not exist. |
| 79 template = Template(id=content_str, content=content) |
| 80 template.put() |
| 81 |
| 82 return tmpl_key |
| 83 |
| 84 |
73 def GetTemplate(tmpl_id): | 85 def GetTemplate(tmpl_id): |
74 """Get Template entity of given tmpl_id generated by ndb.Key.""" | 86 """Get Template entity of given tmpl_id generated by ndb.Key.""" |
75 # Get entity key. | 87 # Get entity key. |
76 template = ndb.Key(urlsafe=tmpl_id).get() | 88 template = ndb.Key(urlsafe=tmpl_id).get() |
77 return json.dumps(template.content) | 89 return json.dumps(template.content) |
OLD | NEW |