app/soc/views/models/presence.py
author Lennard de Rijk <ljvderijk@gmail.com>
Tue, 28 Jul 2009 11:23:11 +0200
changeset 2685 506cda0463e8
parent 2388 eb1a6abdb056
child 2782 3944749338d3
permissions -rw-r--r--
Added columns to the manage project page that show the amount of evaluations. The total possible amount of evaluations that is shown is based on surveys which have at least one Record.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
446
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     2
#
1308
35b75ffcbb37 Partially reverted "Update the copyright notice for 2009."
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1307
diff changeset
     3
# Copyright 2008 the Melange authors.
446
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     4
#
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     8
#
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    10
#
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    16
534
c31cfbf1a20f Replace HomeSettings with Presence Model class. Replace SiteSettings with
Todd Larsen <tlarsen@google.com>
parents: 514
diff changeset
    17
"""Views for Models with a "presence" on a Melange site.
446
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    18
"""
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    19
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    20
__authors__ = [
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    21
    '"Sverre Rabbelier" <sverre@rabbelier.nl>',
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    22
  ]
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    23
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    24
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    25
from google.appengine.ext import db
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    26
970
8b5611d5b053 Use ugettext instead of ugettext_lazy
Sverre Rabbelier <srabbelier@gmail.com>
parents: 926
diff changeset
    27
from django.utils.translation import ugettext
446
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    28
1419
5d0f80ad7b9f Add caching to the homepage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1417
diff changeset
    29
from soc.cache import home
901
d580a057103d Presence is now a 'abstract' View, pull in members from program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 858
diff changeset
    30
from soc.logic import cleaning
446
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    31
from soc.logic import dicts
452
160c748988a2 Fixes to {Site,Home}Settings
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
    32
from soc.logic.models import document as document_logic
446
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    33
from soc.views import helper
710
edb5dbb1dea7 Add explicit access_types from the url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 662
diff changeset
    34
from soc.views.helper import access
921
e499cc2641f6 Create a new 'home' view for Presences
Sverre Rabbelier <srabbelier@gmail.com>
parents: 904
diff changeset
    35
from soc.views.helper import decorators
2384
71780864a5ed Now showing link to edit the home page document on the home page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
    36
from soc.views.helper import redirects
1229
ec3768cbf369 Refactored the picker so that it is more generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1218
diff changeset
    37
from soc.views.helper import widgets
446
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    38
from soc.views.models import base
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    39
534
c31cfbf1a20f Replace HomeSettings with Presence Model class. Replace SiteSettings with
Todd Larsen <tlarsen@google.com>
parents: 514
diff changeset
    40
import soc.models.presence
c31cfbf1a20f Replace HomeSettings with Presence Model class. Replace SiteSettings with
Todd Larsen <tlarsen@google.com>
parents: 514
diff changeset
    41
import soc.logic.models.presence
446
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    42
import soc.logic.dicts
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    43
import soc.views.helper
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    44
import soc.views.helper.widgets
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    45
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    46
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    47
class View(base.View):
844
b55c68d25b35 Make getToSLink() an actual method for re-use by others.
Todd Larsen <tlarsen@google.com>
parents: 807
diff changeset
    48
  """View methods for the Presence model.
446
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    49
  """
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    50
1303
08433090cff8 Add prefix filtering and refactored program field generation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1256
diff changeset
    51
  def __init__(self, params):
446
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    52
    """Defines the fields and methods required for the base View class
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    53
    to provide the user with list, public, create, edit and delete views.
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    54
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    55
    Params:
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 632
diff changeset
    56
      params: a dict with params for this View
446
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    57
    """
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    58
1007
3b66772d21a5 Major refactor of the access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 970
diff changeset
    59
    rights = access.Checker(params)
3b66772d21a5 Major refactor of the access module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 970
diff changeset
    60
    rights['home'] = ['allow']
926
390c8a98cdd0 Bugfixes to last commit
Sverre Rabbelier <srabbelier@gmail.com>
parents: 923
diff changeset
    61
901
d580a057103d Presence is now a 'abstract' View, pull in members from program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 858
diff changeset
    62
    new_params = {}
926
390c8a98cdd0 Bugfixes to last commit
Sverre Rabbelier <srabbelier@gmail.com>
parents: 923
diff changeset
    63
    new_params['rights'] = rights
901
d580a057103d Presence is now a 'abstract' View, pull in members from program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 858
diff changeset
    64
1256
375632e7ec21 Put the tos extra_dynaexclude in presence_with_tos.py where it belongs.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1241
diff changeset
    65
    new_params['extra_dynaexclude'] = ['home']
921
e499cc2641f6 Create a new 'home' view for Presences
Sverre Rabbelier <srabbelier@gmail.com>
parents: 904
diff changeset
    66
    new_params['home_template'] = 'soc/presence/home.html'
710
edb5dbb1dea7 Add explicit access_types from the url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 662
diff changeset
    67
1430
ff8cc6b15e6a Rename dynafields to dynaproperties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1419
diff changeset
    68
    new_params['create_extra_dynaproperties'] = {
901
d580a057103d Presence is now a 'abstract' View, pull in members from program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 858
diff changeset
    69
        # add cleaning of the link id and feed url
1079
be1aacb33b0f Changed clean_link_id to be in a wrapper form as well.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1051
diff changeset
    70
        'clean_link_id': cleaning.clean_link_id('link_id'),
901
d580a057103d Presence is now a 'abstract' View, pull in members from program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 858
diff changeset
    71
        'clean_feed_url': cleaning.clean_feed_url,
d580a057103d Presence is now a 'abstract' View, pull in members from program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 858
diff changeset
    72
        }
446
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    73
1430
ff8cc6b15e6a Rename dynafields to dynaproperties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1419
diff changeset
    74
    new_params['edit_extra_dynaproperties'] = {
1229
ec3768cbf369 Refactored the picker so that it is more generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1218
diff changeset
    75
        'home_link_id': widgets.ReferenceField(
1697
ffda5c32283b Set the proper filter for the home document
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1430
diff changeset
    76
            reference_url='document', filter=['__scoped__'],
1303
08433090cff8 Add prefix filtering and refactored program field generation
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1256
diff changeset
    77
            filter_fields={'prefix': params['document_prefix']},
1229
ec3768cbf369 Refactored the picker so that it is more generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1218
diff changeset
    78
            required=False, label=ugettext('Home page Document link ID'),
ec3768cbf369 Refactored the picker so that it is more generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1218
diff changeset
    79
            help_text=soc.models.work.Work.link_id.help_text),
ec3768cbf369 Refactored the picker so that it is more generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1218
diff changeset
    80
    }
ec3768cbf369 Refactored the picker so that it is more generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1218
diff changeset
    81
923
5a10f6db154b Hook up the 'home' view for site and program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 921
diff changeset
    82
    patterns = []
5a10f6db154b Hook up the 'home' view for site and program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 921
diff changeset
    83
5a10f6db154b Hook up the 'home' view for site and program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 921
diff changeset
    84
    page_name = "Home"
5a10f6db154b Hook up the 'home' view for site and program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 921
diff changeset
    85
    patterns += [(r'^%(url_name)s/(?P<access_type>home)/%(key_fields)s$',
5a10f6db154b Hook up the 'home' view for site and program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 921
diff changeset
    86
                  'soc.views.models.%(module_name)s.home',
5a10f6db154b Hook up the 'home' view for site and program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 921
diff changeset
    87
                  page_name)]
5a10f6db154b Hook up the 'home' view for site and program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 921
diff changeset
    88
5a10f6db154b Hook up the 'home' view for site and program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 921
diff changeset
    89
    new_params['extra_django_patterns'] = patterns
5a10f6db154b Hook up the 'home' view for site and program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 921
diff changeset
    90
901
d580a057103d Presence is now a 'abstract' View, pull in members from program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 858
diff changeset
    91
    params = dicts.merge(params, new_params, sub_merge=True)
446
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    92
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 632
diff changeset
    93
    super(View, self).__init__(params=params)
446
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    94
1419
5d0f80ad7b9f Add caching to the homepage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1417
diff changeset
    95
  @home.cache
921
e499cc2641f6 Create a new 'home' view for Presences
Sverre Rabbelier <srabbelier@gmail.com>
parents: 904
diff changeset
    96
  @decorators.check_access
e499cc2641f6 Create a new 'home' view for Presences
Sverre Rabbelier <srabbelier@gmail.com>
parents: 904
diff changeset
    97
  def home(self, request, access_type,
e499cc2641f6 Create a new 'home' view for Presences
Sverre Rabbelier <srabbelier@gmail.com>
parents: 904
diff changeset
    98
             page_name=None, params=None, **kwargs):
e499cc2641f6 Create a new 'home' view for Presences
Sverre Rabbelier <srabbelier@gmail.com>
parents: 904
diff changeset
    99
    """See base.View.public().
e499cc2641f6 Create a new 'home' view for Presences
Sverre Rabbelier <srabbelier@gmail.com>
parents: 904
diff changeset
   100
e499cc2641f6 Create a new 'home' view for Presences
Sverre Rabbelier <srabbelier@gmail.com>
parents: 904
diff changeset
   101
    Overrides public_template to point at 'home_template'.
e499cc2641f6 Create a new 'home' view for Presences
Sverre Rabbelier <srabbelier@gmail.com>
parents: 904
diff changeset
   102
    """
e499cc2641f6 Create a new 'home' view for Presences
Sverre Rabbelier <srabbelier@gmail.com>
parents: 904
diff changeset
   103
1992
6a476fb946c9 Redirect to show if there is no home document
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1991
diff changeset
   104
    key_name = self._logic.getKeyNameFromFields(kwargs)
6a476fb946c9 Redirect to show if there is no home document
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1991
diff changeset
   105
    redirect = '/%s/show/%s' % (self._params['url_name'], key_name)
6a476fb946c9 Redirect to show if there is no home document
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1991
diff changeset
   106
921
e499cc2641f6 Create a new 'home' view for Presences
Sverre Rabbelier <srabbelier@gmail.com>
parents: 904
diff changeset
   107
    new_params = {}
e499cc2641f6 Create a new 'home' view for Presences
Sverre Rabbelier <srabbelier@gmail.com>
parents: 904
diff changeset
   108
    new_params['public_template'] = self._params['home_template']
1992
6a476fb946c9 Redirect to show if there is no home document
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1991
diff changeset
   109
    new_params['public_redirect'] = redirect
921
e499cc2641f6 Create a new 'home' view for Presences
Sverre Rabbelier <srabbelier@gmail.com>
parents: 904
diff changeset
   110
e499cc2641f6 Create a new 'home' view for Presences
Sverre Rabbelier <srabbelier@gmail.com>
parents: 904
diff changeset
   111
    params = dicts.merge(params, new_params)
e499cc2641f6 Create a new 'home' view for Presences
Sverre Rabbelier <srabbelier@gmail.com>
parents: 904
diff changeset
   112
e499cc2641f6 Create a new 'home' view for Presences
Sverre Rabbelier <srabbelier@gmail.com>
parents: 904
diff changeset
   113
    return self.public(request, access_type,
e499cc2641f6 Create a new 'home' view for Presences
Sverre Rabbelier <srabbelier@gmail.com>
parents: 904
diff changeset
   114
                       page_name=page_name, params=params, **kwargs)
e499cc2641f6 Create a new 'home' view for Presences
Sverre Rabbelier <srabbelier@gmail.com>
parents: 904
diff changeset
   115
446
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   116
  def _public(self, request, entity, context):
710
edb5dbb1dea7 Add explicit access_types from the url
Sverre Rabbelier <srabbelier@gmail.com>
parents: 662
diff changeset
   117
    """See base.View._public().
446
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   118
    """
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   119
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   120
    if not entity:
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   121
      return
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   122
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   123
    try:
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   124
      home_doc = entity.home
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   125
    except db.Error:
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   126
      home_doc = None
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   127
1991
3aeda3007467 Make _public return True iff public page should be shown
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
   128
    if not home_doc:
3aeda3007467 Make _public return True iff public page should be shown
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
   129
      return False
3aeda3007467 Make _public return True iff public page should be shown
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
   130
3aeda3007467 Make _public return True iff public page should be shown
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
   131
    home_doc.content = helper.templates.unescape(home_doc.content)
3aeda3007467 Make _public return True iff public page should be shown
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
   132
    context['home_document'] = home_doc
3aeda3007467 Make _public return True iff public page should be shown
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1700
diff changeset
   133
2384
71780864a5ed Now showing link to edit the home page document on the home page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   134
    # check if the current user is allowed edit the home document
71780864a5ed Now showing link to edit the home page document on the home page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   135
    rights = self._params['rights']
71780864a5ed Now showing link to edit the home page document on the home page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   136
71780864a5ed Now showing link to edit the home page document on the home page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   137
    allowed_to_edit = False
71780864a5ed Now showing link to edit the home page document on the home page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   138
71780864a5ed Now showing link to edit the home page document on the home page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   139
    try:
71780864a5ed Now showing link to edit the home page document on the home page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   140
      # use the IsDocumentWritable check because we have no django args
71780864a5ed Now showing link to edit the home page document on the home page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   141
      rights.checkIsDocumentWritable({'key_name': home_doc.key().name(),
71780864a5ed Now showing link to edit the home page document on the home page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   142
                                      'prefix': home_doc.prefix,
71780864a5ed Now showing link to edit the home page document on the home page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   143
                                      'scope_path': home_doc.scope_path,
71780864a5ed Now showing link to edit the home page document on the home page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   144
                                      'link_id': home_doc.link_id},
2388
eb1a6abdb056 Small indentation fix.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2384
diff changeset
   145
                                     'key_name')
2384
71780864a5ed Now showing link to edit the home page document on the home page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   146
      allowed_to_edit = True
71780864a5ed Now showing link to edit the home page document on the home page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   147
    except:
71780864a5ed Now showing link to edit the home page document on the home page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   148
      pass
71780864a5ed Now showing link to edit the home page document on the home page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   149
71780864a5ed Now showing link to edit the home page document on the home page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   150
    if allowed_to_edit:
71780864a5ed Now showing link to edit the home page document on the home page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   151
      # put the link to edit to home document in context
71780864a5ed Now showing link to edit the home page document on the home page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   152
      context['home_document_edit_redirect'] = redirects.getEditRedirect(
71780864a5ed Now showing link to edit the home page document on the home page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   153
          home_doc, {'url_name': 'document'})
71780864a5ed Now showing link to edit the home page document on the home page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   154
71780864a5ed Now showing link to edit the home page document on the home page.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2076
diff changeset
   155
    return super(View, self)._public(request, entity, context)
446
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   156
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   157
  def _editGet(self, request, entity, form):
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   158
    """See base.View._editGet().
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   159
    """
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   160
0b479d573a4c Refactoring of {site/home}_settings to make them use base.View
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
   161
    try:
452
160c748988a2 Fixes to {Site,Home}Settings
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   162
      if entity.home:
807
b6db9fb1246d Hack in tos_scope_path and tos_link_id to select Terms of Service Document.
Todd Larsen <tlarsen@google.com>
parents: 799
diff changeset
   163
        form.fields['home_link_id'].initial = entity.home.link_id
901
d580a057103d Presence is now a 'abstract' View, pull in members from program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 858
diff changeset
   164
    except db.Error:
2076
1cd180cc56c9 Style fixes and removal of unused imports in soc.views.models.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1992
diff changeset
   165
      # TODO(Pawel.Solyga): use logging to log exception
1cd180cc56c9 Style fixes and removal of unused imports in soc.views.models.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1992
diff changeset
   166
      return
807
b6db9fb1246d Hack in tos_scope_path and tos_link_id to select Terms of Service Document.
Todd Larsen <tlarsen@google.com>
parents: 799
diff changeset
   167
662
0e89b027b140 Make use of the new generic key_name by lookup up scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents: 656
diff changeset
   168
    super(View, self)._editGet(request, entity, form)
0e89b027b140 Make use of the new generic key_name by lookup up scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents: 656
diff changeset
   169
452
160c748988a2 Fixes to {Site,Home}Settings
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   170
  def _editPost(self, request, entity, fields):
160c748988a2 Fixes to {Site,Home}Settings
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   171
    """See base.View._editPost().
160c748988a2 Fixes to {Site,Home}Settings
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   172
    """
160c748988a2 Fixes to {Site,Home}Settings
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   173
1229
ec3768cbf369 Refactored the picker so that it is more generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1218
diff changeset
   174
    if 'home_link_id' not in fields:
ec3768cbf369 Refactored the picker so that it is more generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1218
diff changeset
   175
      return super(View, self)._editPost(request, entity, fields)
ec3768cbf369 Refactored the picker so that it is more generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1218
diff changeset
   176
1417
8b9e256a3abe Set and unset the home_for property if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1308
diff changeset
   177
    if not fields['home_link_id'] and entity.home:
8b9e256a3abe Set and unset the home_for property if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1308
diff changeset
   178
      properties = {'home_for': None}
8b9e256a3abe Set and unset the home_for property if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1308
diff changeset
   179
      document_logic.logic.updateEntityProperties(entity.home, properties)
8b9e256a3abe Set and unset the home_for property if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1308
diff changeset
   180
1700
599a5ff8f422 Clean document references
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1697
diff changeset
   181
    home_doc = fields.get('resolved_home_link_id')
452
160c748988a2 Fixes to {Site,Home}Settings
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   182
    fields['home'] = home_doc
160c748988a2 Fixes to {Site,Home}Settings
Sverre Rabbelier <srabbelier@gmail.com>
parents: 446
diff changeset
   183
1417
8b9e256a3abe Set and unset the home_for property if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1308
diff changeset
   184
    if home_doc:
8b9e256a3abe Set and unset the home_for property if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1308
diff changeset
   185
      properties = {'home_for': entity}
8b9e256a3abe Set and unset the home_for property if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1308
diff changeset
   186
      document_logic.logic.updateEntityProperties(home_doc, properties)
8b9e256a3abe Set and unset the home_for property if appropriate
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1308
diff changeset
   187
662
0e89b027b140 Make use of the new generic key_name by lookup up scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents: 656
diff changeset
   188
    super(View, self)._editPost(request, entity, fields)