app/soc/views/models/group.py
author Pawel Solyga <Pawel.Solyga@gmail.com>
Sat, 24 Jan 2009 11:07:16 +0000
changeset 949 07fdadbd6dc7
parent 858 e79e7a22326f
child 989 f52654ea6350
permissions -rw-r--r--
Check if timeline exists and when somebody tries to edit non existing timelime display error message. Add TODO regarding error message customization for Timeline. Add support for calendar widget in timeline for both gsoc and ghop programs (gsoc was hardcoded before). Patch by: Pawel Solyga Review by: to-be-reviewed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     2
#
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     3
# Copyright 2008 the Melange authors.
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     4
#
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     8
#
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    10
#
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    16
658
9964b1571ef8 Factor out the Group part of Sponsor
Sverre Rabbelier <srabbelier@gmail.com>
parents: 656
diff changeset
    17
"""Views for Groups.
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    18
"""
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    19
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    20
__authors__ = [
429
e50e18936f06 Fixed typo in e-mail address
Sverre Rabbelier <srabbelier@gmail.com>
parents: 409
diff changeset
    21
    '"Sverre Rabbelier" <sverre@rabbelier.nl>',
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    22
  ]
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    23
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    24
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    25
from google.appengine.api import users
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    26
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    27
from django import forms
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    28
387
c55195361cb6 Addressed comments by Todd on r822
Sverre Rabbelier <srabbelier@gmail.com>
parents: 363
diff changeset
    29
from soc.logic import dicts
662
0e89b027b140 Make use of the new generic key_name by lookup up scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents: 658
diff changeset
    30
from soc.logic.models import user as user_logic
755
1ed041c0cdc6 Remove unused imports and variables in different soc.views.models modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 681
diff changeset
    31
from soc.views.helper import widgets
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    32
from soc.views.models import base
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    33
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    34
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    35
class View(base.View):
658
9964b1571ef8 Factor out the Group part of Sponsor
Sverre Rabbelier <srabbelier@gmail.com>
parents: 656
diff changeset
    36
  """View methods for the Group model.
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    37
  """
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    38
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 654
diff changeset
    39
  def __init__(self, params=None):
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    40
    """Defines the fields and methods required for the base View class
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    41
    to provide the user with list, public, create, edit and delete views.
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    42
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    43
    Params:
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 654
diff changeset
    44
      params: a dict with params for this View
658
9964b1571ef8 Factor out the Group part of Sponsor
Sverre Rabbelier <srabbelier@gmail.com>
parents: 656
diff changeset
    45
    """
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    46
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 654
diff changeset
    47
    new_params = {}
606
65d35584ee31 Make forms generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 605
diff changeset
    48
809
757cc13ecd39 Hide 'tos' pull-down selector from Group profile forms.
Todd Larsen <tlarsen@google.com>
parents: 755
diff changeset
    49
    new_params['extra_dynaexclude'] = ['founder',
757cc13ecd39 Hide 'tos' pull-down selector from Group profile forms.
Todd Larsen <tlarsen@google.com>
parents: 755
diff changeset
    50
      # TODO(tlarsen): these need to be enabled once a button to a list
757cc13ecd39 Hide 'tos' pull-down selector from Group profile forms.
Todd Larsen <tlarsen@google.com>
parents: 755
diff changeset
    51
      #   selection "interstitial" page is implemented, see:
757cc13ecd39 Hide 'tos' pull-down selector from Group profile forms.
Todd Larsen <tlarsen@google.com>
parents: 755
diff changeset
    52
      #     http://code.google.com/p/soc/issues/detail?id=151
757cc13ecd39 Hide 'tos' pull-down selector from Group profile forms.
Todd Larsen <tlarsen@google.com>
parents: 755
diff changeset
    53
      'home', 'tos', 'member_template']
668
77f9a6ea6e67 Some style and typo fixes in different modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 662
diff changeset
    54
    new_params['edit_extra_dynafields'] = {
755
1ed041c0cdc6 Remove unused imports and variables in different soc.views.models modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 681
diff changeset
    55
        'founded_by': forms.CharField(widget=widgets.ReadOnlyInput(),
606
65d35584ee31 Make forms generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 605
diff changeset
    56
                                   required=False),
65d35584ee31 Make forms generic
Sverre Rabbelier <srabbelier@gmail.com>
parents: 605
diff changeset
    57
        }
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    58
502
e1e24c0a4e82 Add new parameters to views: url_name which is name used in urls (instead of using lower entity names) and module_name which is used for constructing django urls. Append changes to all affected files. Fix some title names. Change urls that included underscores like "site_settings" into urls with slash "site/settings". Plus some other minor fixes.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 499
diff changeset
    59
    # TODO(tlarsen): Add support for Django style template lookup
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 654
diff changeset
    60
    new_params['public_template'] = 'soc/group/public.html'
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    61
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 654
diff changeset
    62
    new_params['list_row'] = 'soc/group/list/row.html'
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 654
diff changeset
    63
    new_params['list_heading'] = 'soc/group/list/heading.html'
493
6976c4d8d0ac Refactor the sidebar to use Django templates
Sverre Rabbelier <srabbelier@gmail.com>
parents: 492
diff changeset
    64
656
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 654
diff changeset
    65
    params = dicts.merge(params, new_params)
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 654
diff changeset
    66
a76f1b443ea4 Cleanups in the views module
Sverre Rabbelier <srabbelier@gmail.com>
parents: 654
diff changeset
    67
    super(View, self).__init__(params=params)
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    68
583
12960609a69c Fills in the Founded By box in edit sponsor with the user's public name
Lennard de Rijk <ljvderijk@gmail.com>
parents: 569
diff changeset
    69
  def _editGet(self, request, entity, form):
12960609a69c Fills in the Founded By box in edit sponsor with the user's public name
Lennard de Rijk <ljvderijk@gmail.com>
parents: 569
diff changeset
    70
    """See base.View._editGet().
12960609a69c Fills in the Founded By box in edit sponsor with the user's public name
Lennard de Rijk <ljvderijk@gmail.com>
parents: 569
diff changeset
    71
    """
658
9964b1571ef8 Factor out the Group part of Sponsor
Sverre Rabbelier <srabbelier@gmail.com>
parents: 656
diff changeset
    72
583
12960609a69c Fills in the Founded By box in edit sponsor with the user's public name
Lennard de Rijk <ljvderijk@gmail.com>
parents: 569
diff changeset
    73
    # fill in the founded_by with data from the entity
12960609a69c Fills in the Founded By box in edit sponsor with the user's public name
Lennard de Rijk <ljvderijk@gmail.com>
parents: 569
diff changeset
    74
    form.fields['founded_by'].initial = entity.founder.name
681
48983ecf4665 Cleanups in group and program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 668
diff changeset
    75
    super(View, self)._editGet(request, entity, form)
583
12960609a69c Fills in the Founded By box in edit sponsor with the user's public name
Lennard de Rijk <ljvderijk@gmail.com>
parents: 569
diff changeset
    76
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    77
  def _editPost(self, request, entity, fields):
402
021e86368600 Incorperated suggestions by Todd
Sverre Rabbelier <srabbelier@gmail.com>
parents: 399
diff changeset
    78
    """See base.View._editPost().
363
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    79
    """
d35ffa6ca643 Add a framework for generic views
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    80
583
12960609a69c Fills in the Founded By box in edit sponsor with the user's public name
Lennard de Rijk <ljvderijk@gmail.com>
parents: 569
diff changeset
    81
    if not entity:
12960609a69c Fills in the Founded By box in edit sponsor with the user's public name
Lennard de Rijk <ljvderijk@gmail.com>
parents: 569
diff changeset
    82
      # only if we are creating a new entity we should fill in founder
662
0e89b027b140 Make use of the new generic key_name by lookup up scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents: 658
diff changeset
    83
      account = users.get_current_user()
0e89b027b140 Make use of the new generic key_name by lookup up scope_path
Sverre Rabbelier <srabbelier@gmail.com>
parents: 658
diff changeset
    84
      user = user_logic.logic.getForFields({'account': account}, unique=True)
583
12960609a69c Fills in the Founded By box in edit sponsor with the user's public name
Lennard de Rijk <ljvderijk@gmail.com>
parents: 569
diff changeset
    85
      fields['founder'] = user
681
48983ecf4665 Cleanups in group and program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 668
diff changeset
    86
48983ecf4665 Cleanups in group and program
Sverre Rabbelier <srabbelier@gmail.com>
parents: 668
diff changeset
    87
    super(View, self)._editPost(request, entity, fields)
858
e79e7a22326f Add an export() view, and implement it as text/text for Document.
Todd Larsen <tlarsen@google.com>
parents: 809
diff changeset
    88