#!/usr/bin/python2.5
#
# Copyright 2008 the Melange authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Document viewers.

public: how the general public sees a Document
"""

__authors__ = [
  '"Todd Larsen" <tlarsen@google.com>',
  ]


from google.appengine.api import users

from soc.logic import document
from soc.logic import out_of_band
from soc.views import helper
from soc.views import simple

import soc.views.helper.responses
import soc.views.helper.templates


DEF_DOCS_PUBLIC_TMPL = 'soc/docs/public.html'

def public(request, partial_path=None, link_name=None,
           template=DEF_DOCS_PUBLIC_TMPL):
  """How the "general public" sees a Document.

  Args:
    request: the standard django request object
    partial_path: the Document's site-unique "path" extracted from the URL,
      minus the trailing link_name
    link_name: the last portion of the Document's site-unique "path"
      extracted from the URL
    template: the "sibling" template (or a search list of such templates)
      from which to construct the public.html template name (or names)

  Returns:
    A subclass of django.http.HttpResponse which either contains the form to
    be filled out, or a redirect to the correct view in the interface.
  """
  # create default template context for use with any templates
  context = helper.responses.getUniversalContext(request)

  # TODO: there eventually needs to be a call to some controller logic that
  #   implements some sort of access controls, based on the currently
  #   logged-in User's Roles, etc.

  # TODO: based on the User's Roles, Documents that the User can edit
  #   should display a link to a document edit form

  # try to fetch User entity corresponding to link_name if one exists
  try:
    doc = document.getDocumentIfPath(partial_path, link_name=link_name)
  except out_of_band.ErrorResponse, error:
    # show custom 404 page when Document path doesn't exist in Datastore
    return simple.errorResponse(request, error, template, context)

  doc.content = helper.templates.unescape(doc.content)
  context['document'] = doc

  return helper.responses.respond(request, template, context)

@@ -744,42 +744,36 @@
 rom 
-google.appengine.api import users%0A
+soc.logic import out_of_band
 %0Afro
@@ -791,24 +791,30 @@
  import 
-document
+path_link_name
 %0Afrom so
@@ -816,32 +816,39 @@
 om soc.logic
+.models
  import 
 out_of_band%0A
@@ -831,35 +831,32 @@
 dels import 
-out_of_band
+document
 %0Afrom soc.vi
@@ -2167,16 +2167,32 @@
 dit form
+%0A  %0A  doc = None
 %0A%0A  # tr
@@ -2261,50 +2261,217 @@
 s%0A  
-try:%0A    doc = document.getDocumentIfPath(
+path = path_link_name.combinePath(%5Bpartial_path, link_name%5D)%0A%0A  # try to fetch Document entity corresponding to path if one exists    %0A  try:%0A    if path:%0A      doc = document.logic.getFromFields(partial_path=
 part
@@ -2471,32 +2471,73 @@
 th=partial_path,
+%0A                                        
  link_name=link_

Fix not working docs show view. Document show view wasn't updated when the logic refactor was made.