# Path: gogogo/models/cache.py
# def getCachedObjectOr404(model = None,key=None,key_name=None,id = None , id_or_name = None):
#     """
#     Get a object from cache. If it is not existed in the cache, 
#     it will query from database directly and save it in cache.
# 
#     If the object is not existed in the cache and database , it 
#     will raise Http404 exception
#     """
# 
#     if id_or_name:
#         try:
#             id = int(id_or_name)
#         except ValueError:
#             key_name = id_or_name
# 
#     cache_key = getCacheObjectKey(model = model , key=key , key_name = key_name,id = id)
#     
#     #print cache_key
#     object = memcache.get(cache_key)
# 
#     if object == None:
#         if key:
#             object = get_object_or_404(model,key)
#         else:
#             object = get_object_or_404(model,key_name=key_name, id = id)
#         if not memcache.add(cache_key, object, _default_cache_time):
#             logging.error("Memcache set %s failed." % cache_key)
# 
#     return object
# 
# def getCachedEntityOr404(model = None,key=None,key_name=None , id = None , id_or_name = None):
# 	"""
# 	Get cached entity object generated by createEntity()
# 	"""
# 	
# 	if id_or_name:
# 		try:
# 			id = int(id_or_name)
# 		except ValueError:
# 			key_name = id_or_name	
# 	
# 	cache_key = getCacheEntityKey(model = model ,key=key , key_name = key_name, id = id)
# 	
# 	entity = memcache.get(cache_key)
# 
# 	if entity == None:
# 		object = getCachedObjectOr404(model, key=key,key_name=key_name, id = id)
# 		entity = createEntity(object)		
# 		
# 		if not memcache.add(cache_key, entity, _default_cache_time):
# 			logging.error("Memcache set %s failed." % cache_key)
# 	
# 	return entity


from django.http import HttpResponse
from django.http import Http404
from django.template import Context, loader , RequestContext
from django.conf import settings
from django.utils.translation import ugettext_lazy as _
from django import forms
from django.forms import ModelForm
from ragendja.auth.decorators import staff_only
from ragendja.template import render_to_response
from gogogo.models import *
from django.core.urlresolvers import reverse
from gogogo.models.cache import getCachedObjectOr404 , getCachedEntityOr404

#from gogogo.views.db import reverse as db_reverse

_default_cache_time = 3600

def browse(request,id):
	"""
	Browse the information of a shape
	"""

# Path: gogogo/models/cache.py
# def getCachedObjectOr404(model = None,key=None,key_name=None,id = None , id_or_name = None):
#     """
#     Get a object from cache. If it is not existed in the cache, 
#     it will query from database directly and save it in cache.
# 
#     If the object is not existed in the cache and database , it 
#     will raise Http404 exception
#     """
# 
#     if id_or_name:
#         try:
#             id = int(id_or_name)
#         except ValueError:
#             key_name = id_or_name
# 
#     cache_key = getCacheObjectKey(model = model , key=key , key_name = key_name,id = id)
#     
#     #print cache_key
#     object = memcache.get(cache_key)
# 
#     if object == None:
#         if key:
#             object = get_object_or_404(model,key)
#         else:
#             object = get_object_or_404(model,key_name=key_name, id = id)
#         if not memcache.add(cache_key, object, _default_cache_time):
#             logging.error("Memcache set %s failed." % cache_key)
# 
#     return object
# 
# def getCachedEntityOr404(model = None,key=None,key_name=None , id = None , id_or_name = None):
# 	"""
# 	Get cached entity object generated by createEntity()
# 	"""
# 	
# 	if id_or_name:
# 		try:
# 			id = int(id_or_name)
# 		except ValueError:
# 			key_name = id_or_name	
# 	
# 	cache_key = getCacheEntityKey(model = model ,key=key , key_name = key_name, id = id)
# 	
# 	entity = memcache.get(cache_key)
# 
# 	if entity == None:
# 		object = getCachedObjectOr404(model, key=key,key_name=key_name, id = id)
# 		entity = createEntity(object)		
# 		
# 		if not memcache.add(cache_key, entity, _default_cache_time):
# 			logging.error("Memcache set %s failed." % cache_key)
# 	
# 	return entity


# Path: gogogo/views/db/shape.py
from django.http import HttpResponse
from django.http import Http404
from django.template import Context, loader , RequestContext
from django.conf import settings
from django.utils.translation import ugettext_lazy as _
from django import forms
from django.forms import ModelForm
from ragendja.auth.decorators import staff_only
from ragendja.template import render_to_response
from gogogo.models import *
from django.core.urlresolvers import reverse
from gogogo.models.cache import getCachedObjectOr404 , getCachedEntityOr404


#from gogogo.views.db import reverse as db_reverse

_default_cache_time = 3600

def browse(request,id):
	"""
	Browse the information of a shape
	"""

	entity = getCachedEntityOr404(Shape,id_or_name = id)