app/soc/views/models/group.py
changeset 658 9964b1571ef8
parent 656 a76f1b443ea4
child 662 0e89b027b140
equal deleted inserted replaced
657:c781de4f6d39 658:9964b1571ef8
       
     1 #!/usr/bin/python2.5
       
     2 #
       
     3 # Copyright 2008 the Melange authors.
       
     4 #
       
     5 # Licensed under the Apache License, Version 2.0 (the "License");
       
     6 # you may not use this file except in compliance with the License.
       
     7 # You may obtain a copy of the License at
       
     8 #
       
     9 #   http://www.apache.org/licenses/LICENSE-2.0
       
    10 #
       
    11 # Unless required by applicable law or agreed to in writing, software
       
    12 # distributed under the License is distributed on an "AS IS" BASIS,
       
    13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       
    14 # See the License for the specific language governing permissions and
       
    15 # limitations under the License.
       
    16 
       
    17 """Views for Groups.
       
    18 """
       
    19 
       
    20 __authors__ = [
       
    21     '"Sverre Rabbelier" <sverre@rabbelier.nl>',
       
    22   ]
       
    23 
       
    24 
       
    25 from google.appengine.api import users
       
    26 
       
    27 from django import forms
       
    28 
       
    29 from soc.logic import dicts
       
    30 from soc.views import helper
       
    31 from soc.views.models import base
       
    32 
       
    33 import soc.views.helper
       
    34 import soc.views.helper.widgets
       
    35 
       
    36 
       
    37 class View(base.View):
       
    38   """View methods for the Group model.
       
    39   """
       
    40 
       
    41   def __init__(self, params=None):
       
    42     """Defines the fields and methods required for the base View class
       
    43     to provide the user with list, public, create, edit and delete views.
       
    44 
       
    45     Params:
       
    46       params: a dict with params for this View
       
    47     """
       
    48 
       
    49     new_params = {}
       
    50 
       
    51     new_params['extra_dynaexclude'] = ['founder', 'home']
       
    52     params['edit_extra_dynafields'] = {
       
    53         'founded_by': forms.CharField(widget=helper.widgets.ReadOnlyInput(),
       
    54                                    required=False),
       
    55         }
       
    56 
       
    57     # TODO(tlarsen): Add support for Django style template lookup
       
    58     new_params['public_template'] = 'soc/group/public.html'
       
    59 
       
    60     new_params['list_row'] = 'soc/group/list/row.html'
       
    61     new_params['list_heading'] = 'soc/group/list/heading.html'
       
    62 
       
    63     params = dicts.merge(params, new_params)
       
    64 
       
    65     super(View, self).__init__(params=params)
       
    66 
       
    67   def _editGet(self, request, entity, form):
       
    68     """See base.View._editGet().
       
    69     """
       
    70 
       
    71     # fill in the founded_by with data from the entity
       
    72     form.fields['founded_by'].initial = entity.founder.name
       
    73 
       
    74   def _editPost(self, request, entity, fields):
       
    75     """See base.View._editPost().
       
    76     """
       
    77 
       
    78     account = users.get_current_user()
       
    79     user = soc.logic.models.user.logic.getForFields({'account': account},
       
    80                                                     unique=True)
       
    81     if not entity:
       
    82       # only if we are creating a new entity we should fill in founder
       
    83       fields['founder'] = user