from pages.models import Page, Language, Content
from pages.utils import auto_render
from django.contrib.admin.views.decorators import staff_member_required
from django import forms
from django.http import Http404
import settings

@auto_render
def details(request, page_id=None):
    template = None
    lang = Language.get_from_request(request)
    pages = Page.objects.filter(parent__isnull=True).order_by("tree_id")
    if len(pages) > 0:
        if page_id:
            try:
                current_page = Page.objects.get(id=int(page_id), status=1)
            except Page.DoesNotExist:
                raise Http404
        else:
            # get the first root page
            current_page = pages[0]
        template = current_page.get_template()
    else:
        template = settings.DEFAULT_PAGE_TEMPLATE
    
    return template, locals()

from pages.models import Page, Language, Content
from pages.utils import auto_render
from django.contrib.admin.views.decorators import staff_member_required
from django import forms
from django.http import Http404
import settings

@auto_render
def details(request, page_id=None):
    template = None
    lang = Language.get_from_request(request)
    pages = Page.objects.filter(parent__isnull=True).order_by("tree_id")
    if len(pages) > 0:
        if page_id:
            try:
                current_page = Page.objects.get(id=int(page_id), status=1)
            except Page.DoesNotExist:
                raise Http404
        else:
            # get the first root page
            current_page = pages[0]
        template = current_page.get_template()
    else:
        current_page = None
        template = settings.DEFAULT_PAGE_TEMPLATE
    
    return template, locals()

Fix a bug with an empty database
Fix a bug with an empty database

git-svn-id: 54fea250f97f2a4e12c6f7a610b8f07cb4c107b4@138 439a9e5f-3f3e-0410-bc46-71226ad0111b

  from pages.models import Page, Language, Content
  from pages.utils import auto_render
  from django.contrib.admin.views.decorators import staff_member_required
  from django import forms
  from django.http import Http404
  import settings
  
  @auto_render
  def details(request, page_id=None):
      template = None
      lang = Language.get_from_request(request)
      pages = Page.objects.filter(parent__isnull=True).order_by("tree_id")
      if len(pages) > 0:
          if page_id:
              try:
                  current_page = Page.objects.get(id=int(page_id), status=1)
              except Page.DoesNotExist:
                  raise Http404
          else:
              # get the first root page
              current_page = pages[0]
          template = current_page.get_template()
      else:
+         current_page = None
          template = settings.DEFAULT_PAGE_TEMPLATE
      
      return template, locals()
  
Fix a bug with an empty database
## Code Before:
from pages.models import Page, Language, Content
from pages.utils import auto_render
from django.contrib.admin.views.decorators import staff_member_required
from django import forms
from django.http import Http404
import settings

@auto_render
def details(request, page_id=None):
    template = None
    lang = Language.get_from_request(request)
    pages = Page.objects.filter(parent__isnull=True).order_by("tree_id")
    if len(pages) > 0:
        if page_id:
            try:
                current_page = Page.objects.get(id=int(page_id), status=1)
            except Page.DoesNotExist:
                raise Http404
        else:
            # get the first root page
            current_page = pages[0]
        template = current_page.get_template()
    else:
        template = settings.DEFAULT_PAGE_TEMPLATE
    
    return template, locals()

## Instruction:
Fix a bug with an empty database
## Code After:
from pages.models import Page, Language, Content
from pages.utils import auto_render
from django.contrib.admin.views.decorators import staff_member_required
from django import forms
from django.http import Http404
import settings

@auto_render
def details(request, page_id=None):
    template = None
    lang = Language.get_from_request(request)
    pages = Page.objects.filter(parent__isnull=True).order_by("tree_id")
    if len(pages) > 0:
        if page_id:
            try:
                current_page = Page.objects.get(id=int(page_id), status=1)
            except Page.DoesNotExist:
                raise Http404
        else:
            # get the first root page
            current_page = pages[0]
        template = current_page.get_template()
    else:
        current_page = None
        template = settings.DEFAULT_PAGE_TEMPLATE
    
    return template, locals()
