app/soc/views/site/home.py
changeset 314 dfaf249c12b2
parent 311 a2121c1143b2
child 317 87215136c268
--- a/app/soc/views/site/home.py	Mon Oct 13 06:19:43 2008 +0000
+++ b/app/soc/views/site/home.py	Mon Oct 13 17:41:20 2008 +0000
@@ -28,13 +28,12 @@
 
 
 from google.appengine.api import users
+from google.appengine.ext import db
 
 from django import http
 from django import shortcuts
 from django import newforms as forms
 
-
-import soc.logic.models.settings
 from soc.logic import models
 from soc.logic import out_of_band
 from soc.logic import validate
@@ -43,14 +42,15 @@
 from soc.views import simple
 from soc.views import helper
 from soc.views.helper import access
-import soc.views.out_of_band
+
+import soc.logic.models.settings
+import soc.models.document
+import soc.models.site_settings
 import soc.views.helper.forms
 import soc.views.helper.responses
 import soc.views.helper.templates
 import soc.views.helper.widgets
-
-import soc.models.site_settings
-import soc.models.document
+import soc.views.out_of_band
 
 
 class DocumentForm(helper.forms.DbModelForm):
@@ -114,7 +114,12 @@
 
   if site_settings:
     context['site_settings'] = site_settings
-    site_doc = site_settings.home
+    
+    # check if ReferenceProperty to home Document is valid
+    try:
+      site_doc = site_settings.home
+    except db.Error:
+      site_doc = None
   
     if site_doc:
       site_doc.content = helper.templates.unescape(site_doc.content)
@@ -185,7 +190,13 @@
     if site_settings:
       # populate form with the existing SiteSettings entity
       settings_form = SiteSettingsForm(instance=site_settings)
-      site_doc = site_settings.home
+      
+      # check if ReferenceProperty to home Document is valid
+      try:
+        site_doc = site_settings.home
+      except db.Error:
+        site_doc = None
+    
     else:
       # no SiteSettings entity exists for this key_name, so show a blank form
       settings_form = SiteSettingsForm()