app/soc/views/models/club.py
changeset 782 27924b0f13cd
child 790 19f8930592ed
equal deleted inserted replaced
781:35a2d07e04e8 782:27924b0f13cd
       
     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 Clubs.
       
    18 """
       
    19 
       
    20 __authors__ = [
       
    21     '"Lennard de Rijk" <ljvderijk@gmail.com>',
       
    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.logic.models import user as user_logic
       
    31 from soc.views.helper import widgets
       
    32 from soc.views.models import base
       
    33 
       
    34 import soc.logic.models.club
       
    35 
       
    36 
       
    37 class View(base.View):
       
    38   """View methods for the Club 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['logic'] = soc.logic.models.club.logic
       
    52 
       
    53     new_params['name'] = "Club"
       
    54     new_params['name_short'] = "Club"
       
    55     new_params['name_plural'] = "Clubs"
       
    56     new_params['url_name'] = "club"
       
    57     new_params['module_name'] = "club"
       
    58     
       
    59     new_params['extra_dynaexclude'] = ['founder', 'home']
       
    60     new_params['edit_extra_dynafields'] = {
       
    61         'founded_by': forms.CharField(widget=widgets.ReadOnlyInput(),
       
    62                                    required=False),
       
    63         }
       
    64 
       
    65     # TODO(tlarsen): Add support for Django style template lookup
       
    66     new_params['public_template'] = 'soc/club/public.html'
       
    67 
       
    68     new_params['list_row'] = 'soc/club/list/row.html'
       
    69     new_params['list_heading'] = 'soc/club/list/heading.html'
       
    70 
       
    71     params = dicts.merge(params, new_params)
       
    72 
       
    73     super(View, self).__init__(params=params)
       
    74 
       
    75   def _editGet(self, request, entity, form):
       
    76     """See base.View._editGet().
       
    77     """
       
    78 
       
    79     # fill in the founded_by with data from the entity
       
    80     form.fields['founded_by'].initial = entity.founder.name
       
    81     super(View, self)._editGet(request, entity, form)
       
    82 
       
    83   def _editPost(self, request, entity, fields):
       
    84     """See base.View._editPost().
       
    85     """
       
    86 
       
    87     if not entity:
       
    88       # only if we are creating a new entity we should fill in founder
       
    89       account = users.get_current_user()
       
    90       user = user_logic.logic.getForFields({'account': account}, unique=True)
       
    91       fields['founder'] = user
       
    92 
       
    93     super(View, self)._editPost(request, entity, fields)
       
    94 
       
    95 view = View()
       
    96 
       
    97 create = view.create
       
    98 delete = view.delete
       
    99 edit = view.edit
       
   100 list = view.list
       
   101 public = view.public