equal
deleted
inserted
replaced
139 value = self.request.get(arg) |
139 value = self.request.get(arg) |
140 if value: |
140 if value: |
141 queries.append(arg + '=' + urllib.quote_plus(self.request.get(arg))) |
141 queries.append(arg + '=' + urllib.quote_plus(self.request.get(arg))) |
142 return self.request.path + '?' + '&'.join(queries) |
142 return self.request.path + '?' + '&'.join(queries) |
143 |
143 |
|
144 def in_production(self): |
|
145 """Detects if app is running in production. |
|
146 |
|
147 Returns a boolean. |
|
148 """ |
|
149 server_software = os.environ['SERVER_SOFTWARE'] |
|
150 return not server_software.startswith('Development') |
|
151 |
144 |
152 |
145 class DefaultPageHandler(BaseRequestHandler): |
153 class DefaultPageHandler(BaseRequestHandler): |
146 """Redirects to the Datastore application by default.""" |
154 """Redirects to the Datastore application by default.""" |
147 |
155 |
148 PATH = '/' |
156 PATH = '/' |
307 else: |
315 else: |
308 values['writable'] = True |
316 values['writable'] = True |
309 |
317 |
310 if values['show_stats']: |
318 if values['show_stats']: |
311 memcache_stats = memcache.get_stats() |
319 memcache_stats = memcache.get_stats() |
|
320 if not memcache_stats: |
|
321 memcache_stats = {'hits': 0, 'misses': 0, 'byte_hits': 0, 'items': 0, |
|
322 'bytes': 0, 'oldest_item_age': 0} |
312 values['stats'] = memcache_stats |
323 values['stats'] = memcache_stats |
313 try: |
324 try: |
314 hitratio = memcache_stats['hits'] * 100 / (memcache_stats['hits'] |
325 hitratio = memcache_stats['hits'] * 100 / (memcache_stats['hits'] |
315 + memcache_stats['misses']) |
326 + memcache_stats['misses']) |
316 except ZeroDivisionError: |
327 except ZeroDivisionError: |
465 and execute the datastore query. |
476 and execute the datastore query. |
466 """ |
477 """ |
467 |
478 |
468 PATH = '/datastore' |
479 PATH = '/datastore' |
469 |
480 |
470 SCHEMA_CACHE_TIMEOUT = 60 |
481 def get_kinds(self): |
471 |
482 """Get sorted list of kind names the datastore knows about. |
472 def get_kinds(self, cache={}): |
483 |
473 """Return sorted list of kind names the datastore knows about. |
484 This should only be called in the development environment as GetSchema is |
474 |
485 expensive and no caching is done. |
475 The list of kinds is cached for a short time. |
|
476 """ |
486 """ |
477 server_software = os.environ['SERVER_SOFTWARE'] |
|
478 in_production = not server_software.startswith('Development') |
|
479 |
|
480 if in_production and ('kinds' in cache): |
|
481 if cache['kinds_timestamp'] + self.SCHEMA_CACHE_TIMEOUT > time.time(): |
|
482 return cache['kinds'] |
|
483 else: |
|
484 del cache['kinds'] |
|
485 schema = datastore_admin.GetSchema() |
487 schema = datastore_admin.GetSchema() |
486 kinds = [] |
488 kinds = [] |
487 for entity_proto in schema: |
489 for entity_proto in schema: |
488 kinds.append(entity_proto.key().path().element_list()[-1].type()) |
490 kinds.append(entity_proto.key().path().element_list()[-1].type()) |
489 kinds.sort() |
491 kinds.sort() |
490 if in_production: |
|
491 cache['kinds'] = kinds |
|
492 cache['kinds_timestamp'] = time.time() |
|
493 return kinds |
492 return kinds |
494 |
493 |
495 def get(self): |
494 def get(self): |
496 """Formats the results from execute_query() for datastore.html. |
495 """Formats the results from execute_query() for datastore.html. |
497 |
496 |
551 'number': page, |
550 'number': page, |
552 'start': (page - 1) * num, |
551 'start': (page - 1) * num, |
553 }) |
552 }) |
554 current_page += 1 |
553 current_page += 1 |
555 |
554 |
|
555 in_production = self.in_production() |
|
556 if in_production: |
|
557 kinds = None |
|
558 else: |
|
559 kinds = self.get_kinds() |
|
560 |
556 values = { |
561 values = { |
557 'request': self.request, |
562 'request': self.request, |
558 'kinds': self.get_kinds(), |
563 'in_production': in_production, |
|
564 'kinds': kinds, |
559 'kind': self.request.get('kind'), |
565 'kind': self.request.get('kind'), |
560 'order': self.request.get('order'), |
566 'order': self.request.get('order'), |
561 'headers': headers, |
567 'headers': headers, |
562 'entities': entities, |
568 'entities': entities, |
563 'message': self.request.get('msg'), |
569 'message': self.request.get('msg'), |