app/soc/views/models/presence.py
changeset 844 b55c68d25b35
parent 807 b6db9fb1246d
child 854 bb43b74c58f6
equal deleted inserted replaced
843:a086ff3888d3 844:b55c68d25b35
    30 from soc.logic import dicts
    30 from soc.logic import dicts
    31 from soc.logic import validate
    31 from soc.logic import validate
    32 from soc.logic.models import document as document_logic
    32 from soc.logic.models import document as document_logic
    33 from soc.views import helper
    33 from soc.views import helper
    34 from soc.views.helper import access
    34 from soc.views.helper import access
       
    35 from soc.views.helper import redirects
    35 from soc.views.models import base
    36 from soc.views.models import base
    36 
    37 
    37 import soc.models.presence
    38 import soc.models.presence
    38 import soc.logic.models.presence
    39 import soc.logic.models.presence
    39 import soc.logic.dicts
    40 import soc.logic.dicts
   113 
   114 
   114   pass
   115   pass
   115 
   116 
   116 
   117 
   117 class View(base.View):
   118 class View(base.View):
   118   """View methods for the Document model.
   119   """View methods for the Presence model.
   119   """
   120   """
   120 
   121 
   121   def __init__(self, params=None):
   122   def __init__(self, params=None):
   122     """Defines the fields and methods required for the base View class
   123     """Defines the fields and methods required for the base View class
   123     to provide the user with list, public, create, edit and delete views.
   124     to provide the user with list, public, create, edit and delete views.
   145     new_params['sidebar_defaults'] = []
   146     new_params['sidebar_defaults'] = []
   146 
   147 
   147     params = dicts.merge(params, new_params)
   148     params = dicts.merge(params, new_params)
   148 
   149 
   149     super(View, self).__init__(params=params)
   150     super(View, self).__init__(params=params)
       
   151 
       
   152   def getToSLink(self, entity):
       
   153     """Returns link to 'show' the ToS Document if it exists, None otherwise.
       
   154 
       
   155     Args:
       
   156       entity: Presence entity that may or may not have a tos property
       
   157     """
       
   158     if not entity:
       
   159       return None
       
   160 
       
   161     try:
       
   162       tos_doc = entity.tos
       
   163     except db.Error:
       
   164       return None
       
   165 
       
   166     return redirects.getPublicRedirect(tos_doc, {'url_name': 'document'})
   150 
   167 
   151   def _public(self, request, entity, context):
   168   def _public(self, request, entity, context):
   152     """See base.View._public().
   169     """See base.View._public().
   153     """
   170     """
   154 
   171 
   162 
   179 
   163     if home_doc:
   180     if home_doc:
   164       home_doc.content = helper.templates.unescape(home_doc.content)
   181       home_doc.content = helper.templates.unescape(home_doc.content)
   165       context['home_document'] = home_doc
   182       context['home_document'] = home_doc
   166 
   183 
   167     try:
   184     context['tos_link'] = self.getToSLink(entity)
   168       tos_doc = entity.tos
       
   169     except db.Error:
       
   170       tos_doc = None
       
   171 
       
   172     if tos_doc:
       
   173       # TODO(tlarsen): This may not be the correct way to do this...  Also,
       
   174       #   at some point, this needs to be a link to *all* of the various
       
   175       #   Terms of Service that might apply to the scope of this particular
       
   176       #   page (e.g. site-wide ToS, program ToS, group ToS, etc.).  See:
       
   177       #     http://code.google.com/p/soc/issues/detail?id=153
       
   178       #   So, this probably needs to be added to base.py, but these
       
   179       # overridden _public() methods do not seem to call it.
       
   180       context['tos_link'] = '/document/show/%s/%s' % (
       
   181         tos_doc.scope_path, tos_doc.link_id)
       
   182 
   185 
   183   def _editGet(self, request, entity, form):
   186   def _editGet(self, request, entity, form):
   184     """See base.View._editGet().
   187     """See base.View._editGet().
   185     """
   188     """
   186 
   189