예제 #1
0
 def get_by_path(cls, path):
     cache_key = 'Post.' + path
     entity = dbhelper.deserialize_entities(memcache.get(cache_key))
     if not entity:
         entity = Post.all().filter('path = ', path).get()
         memcache.set(cache_key, dbhelper.serialize_entities(entity), CACHE_DURATION)
     return entity
예제 #2
0
 def get_latest(cls, count=20):
     cache_key = 'Post.get_latest(count=%d)' % count
     entities = deserialize_entities(memcache.get(cache_key))
     if not entities:
         entities = Post.all().filter('is_published = ', True).order('-when_published').fetch(count)
         memcache.set(cache_key, serialize_entities(entities), CACHE_DURATION)
     return entities
예제 #3
0
파일: models.py 프로젝트: yesudeep/cmc
 def get_latest(cls, count=100):
     cache_key = 'Celebrity.get_latest(count=%d)' % count
     celebrities = deserialize_entities(memcache.get(cache_key))
     if not celebrities:
         celebrities = Celebrity.all().order('-when_modified').fetch(count)
         memcache.set(cache_key, serialize_entities(celebrities), 10)
     return celebrities
예제 #4
0
 def get_all(cls, count=MAX_COUNT):
     cache_key = '%s.get_all()' % (cls.__name__,)
     entities = deserialize_entities(memcache.get(cache_key))
     if not entities:
         entities = Manager.all().order('rank').order('full_name').fetch(count)
         memcache.set(cache_key, serialize_entities(entities), CACHE_DURATION)
     return entities
예제 #5
0
 def get_by_slug(cls, slug):
     cache_key = 'Project.get_by_slug(%s)' % slug
     entity = deserialize_entities(memcache.get(cache_key))
     if not entity:
         entity = Project.all().filter('slug = ', slug).get()
         memcache.set(cache_key, serialize_entities(entity), CACHE_DURATION)
     return entity
예제 #6
0
 def get_all(cls, count=MAX_COUNT):
     cache_key = 'AnnualReport.get_all()'
     entities = deserialize_entities(memcache.get(cache_key))
     if not entities:
         entities = AnnualReport.all() \
             .order('end_year') \
             .fetch(count)
         memcache.set(cache_key, serialize_entities(entities), CACHE_DURATION)
     return entities
예제 #7
0
 def get_all(cls, count=MAX_COUNT):
     cache_key = 'VesselType.get_all()'
     entities = deserialize_entities(memcache.get(cache_key))
     if not entities:
         entities = VesselType.all() \
             .order('rank') \
             .order('vessel_type_name') \
             .fetch(count)
         memcache.set(cache_key, serialize_entities(entities), CACHE_DURATION)
     return entities
예제 #8
0
 def get_all(cls, count=MAX_COUNT):
     """
     Override.
     """
     cache_key = '%s.get_all()' % (cls.__name__,)
     entities = deserialize_entities(memcache.get(cache_key))
     if not entities:
         entities = SubscriptionPeriod.all().order('period_in_months').fetch(count)
         memcache.set(cache_key, serialize_entities(entities), CACHE_DURATION)
     return entities
예제 #9
0
 def get_all_ongoing(cls):
     cache_key = 'Project.get_all_ongoing()'
     entities = deserialize_entities(memcache.get(cache_key))
     if not entities:
         entities = Project.all() \
             .filter('development_status = ', 'ongoing') \
             .order('title') \
             .fetch(MAX_COUNT)
         memcache.set(cache_key, serialize_entities(entities), CACHE_DURATION)
     return entities
예제 #10
0
 def get_all(cls, count=MAX_COUNT):
     """
     Override.
     """
     cache_key = '%s.get_all()' % (cls.__name__,)
     entities = deserialize_entities(memcache.get(cache_key))
     if not entities:
         entities = db.GqlQuery('SELECT * FROM %s' % cls.__name__).fetch(count)
         memcache.set(cache_key, serialize_entities(entities), CACHE_DURATION)
     return entities
예제 #11
0
 def get_by_period(cls, period_in_months):
     """
     Fetches a subscription period entity for the given period in months.
     """
     cache_key = unicode(period_in_months)
     subscription_period = deserialize_entities(memcache.get(cache_key))
     if not subscription_period:
         subscription_period = SubscriptionPeriod.all() \
             .filter('period_in_months = ', period_in_months) \
             .get()
         memcache.set(cache_key, serialize_entities(subscription_period), CACHE_DURATION)
     return subscription_period
예제 #12
0
 def get_all(cls, count=MAX_COUNT):
     cache_key = '%s.get_all()_' % (cls.__name__,)
     entities = deserialize_entities(memcache.get(cache_key))
     if not entities:
         entities = Vessel.all() \
             .filter('is_deleted = ', False) \
             .order('when_delivered') \
             .order('when_expected_year') \
             .order('when_expected') \
             .order('name') \
             .fetch(count)
         memcache.set(cache_key, serialize_entities(entities), CACHE_DURATION)
     return entities
예제 #13
0
 def get_all_vessels(self, count=MAX_COUNT):
     cache_key = 'VesselType.get_all_vessels(%s,%d)' % (str(self), count)
     entities = deserialize_entities(memcache.get(cache_key))
     if not entities:
         entities = Vessel.all() \
             .filter('vessel_type =', self) \
             .order('when_delivered') \
             .order('when_expected_year') \
             .order('when_expected') \
             .order('name') \
             .fetch(count)
         memcache.set(cache_key, serialize_entities(entities), CACHE_DURATION)
     return entities
예제 #14
0
 def get_by_product_and_period(cls, product, period_in_months):
     """
     Fetches a subscription for the given product and period in months.
     """
     cache_key = str(product.key()) + str(period_in_months)
     subscription = deserialize_entities(memcache.get(cache_key))
     if not subscription:
         subscription = Subscription.all() \
             .filter('product = ', product) \
             .filter('period_in_months = ', period_in_months) \
             .get()
         memcache.set(cache_key, serialize_entities(subscription), CACHE_DURATION)
     return subscription
예제 #15
0
 def get_all_for_customer_and_machine_id(cls, customer, machine_id, count=MAX_COUNT):
     """
     Obtains a list of all the activation credentials for a given customer
     and machine ID.
     """
     cache_key = unicode(customer.key()) + machine_id
     entities = deserialize_entities(memcache.get(cache_key))
     if not entities:
         entities = ActivationCredentials.all() \
             .filter('customer = ', customer) \
             .filter('machine_id = ', machine_id) \
             .fetch(count)
         memcache.set(cache_key, serialize_entities(entities), CACHE_DURATION)
     return entities
예제 #16
0
 def get_all_drilling(cls):
     cache_key = 'Vessel.get_all_drilling()'
     entities = deserialize_entities(memcache.get(cache_key))
     if not entities:
         entities = Vessel.all() \
             .filter('is_deleted = ', False) \
             .filter('is_drilling = ', True) \
             .order('when_delivered') \
             .order('when_expected_year') \
             .order('when_expected') \
             .order('name') \
             .fetch(MAX_COUNT)
         memcache.set(cache_key, serialize_entities(entities), CACHE_DURATION)
     return entities
예제 #17
0
 def get_under_construction_vessels(cls):
     cache_key = 'Vessel.get_under_construction_vessels()'
     entities = deserialize_entities(memcache.get(cache_key))
     if not entities:
         entities = Vessel.all() \
             .filter('is_deleted = ', False) \
             .filter('operational_status = ', VESSEL_STATUS_UNDER_CONSTRUCTION) \
             .order('rank') \
             .order('when_delivered') \
             .order('when_expected_year') \
             .order('when_expected') \
             .order('name') \
             .fetch(MAX_COUNT)
         memcache.set(cache_key, serialize_entities(entities), CACHE_DURATION)
     return entities
예제 #18
0
 def get_operating_rigs(cls):
     cache_key = 'Vessel.get_operating_rigs()'
     entities = deserialize_entities(memcache.get(cache_key))
     if not entities:
         entities = Vessel.all() \
             .filter('is_deleted = ', False) \
             .filter('operational_status = ', VESSEL_STATUS_OPERATIONAL) \
             .filter('generic_type = ', VESSEL_GENERIC_TYPE_RIG) \
             .order('rank') \
             .order('when_delivered') \
             .order('when_expected_year') \
             .order('when_expected') \
             .order('name') \
             .fetch(MAX_COUNT)
         memcache.set(cache_key, serialize_entities(entities), CACHE_DURATION)
     return entities
예제 #19
0
 def get_all_active_for_customer(cls, customer, count=MAX_COUNT):
     """
     Obtains all the active activation credentials which have an activation
     code but do not have a deactivation code, which essentially means
     the customer will have these products activated but not deinstalled them
     as per the Website.
     """
     cache_key = unicode(customer.key()) + 'all_active_for_customer'
     entities = deserialize_entities(memcache.get(cache_key))
     if not entities:
         entities = ActivationCredentials.all() \
             .filter('customer = ', customer) \
             .filter('deactivation_code = ', None) \
             .filter('activation_code != ', None) \
             .fetch(count)
         memcache.set(cache_key, serialize_entities(entities), CACHE_DURATION)
     return entities