This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <form method='POST' action='http://upload.example.com' enctype='multipart/form-data' id='form'> | |
| <input type='file' /> | |
| <input type='submit' /> | |
| </form> | |
| <script> | |
| var io = new goog.net.IframeIo; | |
| goog.events.listen (io, goog.net.EventType.COMPLETE, | |
| function (event) { | |
| alert(event.target.getResponseText ()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class User (db.model): | |
| name = db.StringProperty () | |
| prop = db.IntergerPeroperty () | |
| class Presence (db.model): | |
| user = db.ReferenceProperty (User) | |
| last = db.DateTimeProperty () | |
| # Keys users onlines | |
| presences = Presence.all ().filter ('last >', date_considered_connected) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## Models.py | |
| class Message (MarkDeleted): | |
| uuid = db.StringProperty (required=True) | |
| owner = db.ReferenceProperty (Actor, collection_name="message_owner", required=True) | |
| target = db.ReferenceProperty (Actor, collection_name="message_target", required=True) | |
| entry = db.ReferenceProperty (Entry, required=True) | |
| reply = db.SelfReferenceProperty () | |
| label = db.StringProperty (choices=MESSAGE_LABEL, required=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def query_counter (q, cursor=None, limit=500): | |
| if cursor: | |
| q.with_cursor (cursor) | |
| count = q.count (limit=limit) | |
| if count == limit: | |
| return count + query_counter (q, q.cursor (), limit=limit) | |
| return count |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def prefetch_refprops(entities, *props): | |
| fields = [(entity, prop) for entity in entities for prop in props] | |
| ref_keys = [prop.get_value_for_datastore(x) for x, prop in fields] | |
| # Because if ref_keys has a None value, | |
| # db.get raise a BadArgumentError exception. | |
| for (i, v) in enumerate (ref_keys): | |
| if v is None: | |
| del ref_keys[i] | |
| del fields[i] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import logging | |
| from google.appengine.api import memcache | |
| from django.conf import settings | |
| from django import template | |
| class HTMLListNode (template.Node): | |
| """ Create or reuse all node of the template. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Largely inspired by: http://blog.notdot.net/2009/9/Efficient-model-memcaching | |
| def serialize(models): | |
| if isinstance(models, db.Model): | |
| return db.model_to_protobuf(models).Encode() | |
| elif isinstance(models, list): | |
| return [serialize(x) for x in models] | |
| elif isinstance(models, dict): | |
| return dict([(k, serialize(x)) for k, x in models.items()]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| import logging | |
| from google.appengine.ext import db | |
| from google.appengine.api import datastore | |
| from google.appengine.datastore import datastore_rpc | |
| def async_put(entities, **kwargs): | |
| config = datastore.CreateConfig(**kwargs) | |
| entities, _ = datastore.NormalizeAndTypeCheck(entities, db.Model) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import logging | |
| import time | |
| from google.appengine.runtime import apiproxy_errors | |
| from google.appengine.ext import db | |
| DATASTORE_NB_RETRY=5 | |
| DATASTORE_TIME_RETRY=.15 | |
| DATASTORE_DEFAULT_DEADLINE=5 | |
| DATASTORE_DEFAULT_CFG=db.create_config( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class CapabilityDatastore (object): | |
| def process_request (self, request): | |
| datastore_write = CapabilitySet('datastore_v3', capabilities=['write']) | |
| if not datastore_write.is_enabled(): | |
| return views.common_capability(request) |
OlderNewer