Python alapú mobil backend GAE felett

Author: Gyuri Horak
Date: 2012-02-29

GAE Python

Példaproject

Flask

Flask microframework, @mitsuhiko

JSONView

ExceptionHandlerViewMeta

class ReferenceErrorMeta(MethodViewType):

  def __new__(mcs, name, bases, odict):

    if 'get' in odict:
      odict['get'] = mcs.wrapmethod(odict['get'])

    return MethodViewType.__new__(mcs, name, bases, odict)

  @staticmethod
  def wrapmethod(method):
    @wraps(method)
    def wrapper(self, *args, **kwargs):
      try:
        return method(self, *args, **kwargs)
      except db.ReferencePropertyResolveError:
    return self.failure(10, 'Reference object seems to be deleted.')

  return wrapper

DB: a lekérdezés pénz

CachedModel

class CachedModel(db.Model):

  @classmethod
  def get_from_cache(id):
    ...

  @classmethod
  def get(cls, key):
    obj = cls.get_from_cache(key.id())
    if not obj:
      obj = super(CachedModel, cls).get(key)
    return obj

  def put(self):
    super(CachedModel, self).put()
    self.update_in_cache()

  def delete(self):
    super(CachedModel, self).delete()
    self.remove_from_cache()

  def __eq__(self, other):
    return self.key() == other.key()

CachedReferenceProperty

class CachedReferenceProperty(db.ReferenceProperty):

  def __get__(self, model_instance, model_class):

    ...

      # instance = get(reference_id) # WTF?
      instance = self.reference_class.get(reference_id)

      if instance is None:

        # Feature check vs. isinstance
        if hasattr(model_instance, 'update_references'):
          model_instance.update_references()

        raise db.ReferencePropertyResolveError(...)

Aggregáció

Sérülhet, akár rajtunk kívül álló okok miatt is.

Képkezelés

Geomodel

localmind is ezt használja clustering

Kérdések?

Köszönöm a figyelmet!