def get_singleton(cls):
"""Return (and create if missing) the single Portal document"""
try:
portal = cls.objects.get()
log.debug("Loaded portal info from db.")
except me.DoesNotExist:
log.info("No portal info found in db, will try to initialize.")
try:
portal = cls()
portal.save()
log.info("Initialized portal info.")
except me.NotUniqueError:
log.warning("Probable race condition while initializing "
"portal info, will try to reload.")
portal = cls.objects.get()
log.debug("Loaded portal info from db.")
except me.MultipleObjectsReturned:
log.error("Multiple Portal info found in database.")
portal = cls.objects.first()
return portal
评论列表
文章目录