app/soc/views/models/club_app.py
changeset 791 30da180c4bca
child 797 0bc3f950d7cf
equal deleted inserted replaced
790:19f8930592ed 791:30da180c4bca
       
     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 Club App profiles.
       
    18 """
       
    19 
       
    20 __authors__ = [
       
    21     '"Sverre Rabbelier" <sverre@rabbelier.nl>',
       
    22   ]
       
    23 
       
    24 
       
    25 from django import forms
       
    26 from django.utils.translation import ugettext_lazy
       
    27 
       
    28 from soc.models import group_app as group_app_model
       
    29 from soc.logic import accounts
       
    30 from soc.logic import cleaning
       
    31 from soc.logic import dicts
       
    32 from soc.logic.models import user as user_logic
       
    33 from soc.views import helper
       
    34 from soc.views.models import group_app
       
    35 from soc.views.helper import access
       
    36 
       
    37 import soc.logic.dicts
       
    38 
       
    39 
       
    40 class View(group_app.View):
       
    41   """View methods for the Sponsor model.
       
    42   """
       
    43 
       
    44   def __init__(self, params=None):
       
    45     """Defines the fields and methods required for the base View class
       
    46     to provide the user with list, public, create, edit and delete views.
       
    47 
       
    48     Params:
       
    49       params: a dict with params for this View
       
    50     """    
       
    51 
       
    52     rights = {}
       
    53     rights['create'] = [access.checkIsUser]
       
    54     rights['delete'] = [access.checkIsMyApplication]
       
    55     rights['edit'] = [access.checkIsMyApplication]
       
    56     rights['list'] = [access.checkIsUser]
       
    57 
       
    58     new_params = {}
       
    59 
       
    60     new_params['rights'] = rights
       
    61 
       
    62     new_params['create_template'] = 'soc/models/twoline_edit.html'
       
    63     new_params['edit_template'] = 'soc/models/twoline_edit.html'
       
    64 
       
    65     new_params['extra_dynaexclude'] = ['applicant', 'backup_admin']
       
    66     new_params['create_extra_dynafields'] = {
       
    67         'backup_admin_link_id': forms.CharField(
       
    68               label=group_app_model.GroupApplication.backup_admin.verbose_name
       
    69               ),
       
    70         'clean_backup_admin_link_id': cleaning.clean_existing_user('backup_admin_link_id'),
       
    71         }
       
    72 
       
    73     new_params['name'] = "Club Application"
       
    74     new_params['name_short'] = "Club Application"
       
    75     new_params['name_plural'] = "Club Application"
       
    76     new_params['url_name'] = "club_app"
       
    77     new_params['module_name'] = "club_app"
       
    78 
       
    79     params = dicts.merge(params, new_params)
       
    80 
       
    81     super(View, self).__init__(params=params)
       
    82 
       
    83   def list(self, request, access_type,
       
    84            page_name=None, params=None, filter=None):
       
    85     """Lists all notifications that the current logged in user has stored.
       
    86 
       
    87     for parameters see base.list()
       
    88     """
       
    89 
       
    90     params = dicts.merge(params, self._params)
       
    91 
       
    92     # get the current user
       
    93     user_entity = user_logic.logic.getForCurrentAccount()
       
    94 
       
    95     is_developer = accounts.isDeveloper(user=user_entity)
       
    96 
       
    97     if is_developer:
       
    98       filter = {}
       
    99     else:
       
   100       # only select the applications for this user so construct a filter
       
   101       filter = {'applicant': user_entity}
       
   102 
       
   103     if is_developer:
       
   104       params['list_description'] = ugettext_lazy(
       
   105           "An overview all club applications.")
       
   106     else:
       
   107       params['list_description'] = ugettext_lazy(
       
   108           "An overview of your club applications.")
       
   109 
       
   110     # use the generic list method with the filter. The access check in this
       
   111     # method will trigger an errorResponse when user_entity is None
       
   112     return super(View, self).list(request, access_type,
       
   113         page_name, params, filter)
       
   114 
       
   115   def _editGet(self, request, entity, form):
       
   116     """See base.View._editGet().
       
   117     """
       
   118 
       
   119     form.fields['backup_admin_link_id'].initial = entity.backup_admin.link_id
       
   120 
       
   121   def _editPost(self, request, entity, fields):
       
   122     """See base.View._editPost().
       
   123     """
       
   124 
       
   125     fields['backup_admin'] = fields['backup_admin_link_id']
       
   126 
       
   127     if not entity:
       
   128       fields['applicant'] = user_logic.logic.getForCurrentAccount()
       
   129 
       
   130 
       
   131 view = View()
       
   132 
       
   133 create = view.create
       
   134 delete = view.delete
       
   135 edit = view.edit
       
   136 list = view.list
       
   137 public = view.public