app/soc/views/models/club.py
changeset 989 f52654ea6350
parent 983 1bbf226ade8e
child 993 99c46908b4b6
equal deleted inserted replaced
988:e35b3d98d469 989:f52654ea6350
    25 
    25 
    26 from google.appengine.api import users
    26 from google.appengine.api import users
    27 
    27 
    28 from django import http
    28 from django import http
    29 from django import forms
    29 from django import forms
    30 from django.utils.translation import ugettext
       
    31 
    30 
    32 from soc.logic import dicts
    31 from soc.logic import dicts
    33 from soc.logic.models import user as user_logic
    32 from soc.logic.models import user as user_logic
    34 from soc.logic.models import club_app as club_app_logic
    33 from soc.logic.models import club_app as club_app_logic
    35 from soc.logic.models import club as club_logic
    34 from soc.logic.models import club as club_logic
    36 from soc.logic.models import request as request_logic
    35 from soc.logic.models import request as request_logic
    37 from soc.views import out_of_band
    36 from soc.views import out_of_band
    38 from soc.views.helper import access
    37 from soc.views.helper import access
    39 from soc.views.helper import decorators
    38 from soc.views.helper import decorators
    40 from soc.views.helper import dynaform
    39 from soc.views.helper import dynaform
    41 from soc.views.helper import lists as list_helper
       
    42 from soc.views.helper import redirects
       
    43 from soc.views.helper import responses
    40 from soc.views.helper import responses
    44 from soc.views.helper import widgets
    41 from soc.views.helper import widgets
    45 from soc.views.models import base
    42 from soc.views.models import group
    46 from soc.views.models.request import view as request_view
       
    47 
    43 
    48 import soc.logic.models.club
    44 import soc.logic.models.club
    49 import soc.views.helper
    45 import soc.views.helper
    50 
    46 
    51 
    47 
    52 class View(base.View):
    48 class View(group.View):
    53   """View methods for the Club model.
    49   """View methods for the Club model.
    54   """
    50   """
    55 
    51 
    56   def __init__(self, params=None):
    52   def __init__(self, params=None):
    57     """Defines the fields and methods required for the base View class
    53     """Defines the fields and methods required for the base View class
    76 
    72 
    77     patterns = []
    73     patterns = []
    78 
    74 
    79     patterns += [(r'^%(url_name)s/(?P<access_type>applicant)/%(key_fields)s$',
    75     patterns += [(r'^%(url_name)s/(?P<access_type>applicant)/%(key_fields)s$',
    80         'soc.views.models.%(module_name)s.applicant', 
    76         'soc.views.models.%(module_name)s.applicant', 
    81         "%(name)s Creation via Accepted Application"),
    77         "%(name)s Creation via Accepted Application"),]
    82         (r'^%(url_name)s/(?P<access_type>list_requests)/%(key_fields)s$',
       
    83         'soc.views.models.%(module_name)s.list_requests',
       
    84         'List of requests for %(name)s')]
       
    85 
    78 
    86     new_params['extra_django_patterns'] = patterns
    79     new_params['extra_django_patterns'] = patterns
    87 
    80 
    88     new_params['extra_dynaexclude'] = ['founder', 'home']
    81     new_params['extra_dynaexclude'] = ['founder', 'home']
    89     new_params['edit_extra_dynafields'] = {
    82     new_params['edit_extra_dynafields'] = {
    90         'founded_by': forms.CharField(widget=widgets.ReadOnlyInput(),
    83         'founded_by': forms.CharField(widget=widgets.ReadOnlyInput(),
    91                                    required=False),
    84                                    required=False),
    92         }
    85         }
    93 
    86 
       
    87     # set the role names for the request overview
       
    88     new_params['role_names'] =  ['club_admin', 'club_member']
       
    89 
    94     params = dicts.merge(params, new_params)
    90     params = dicts.merge(params, new_params)
    95 
    91 
    96     super(View, self).__init__(params=params)
    92     super(View, self).__init__(params=params)
    97 
    93 
    98     # create and store the special form for applicants
    94     # create and store the special form for applicants
   190     # create the club entity
   186     # create the club entity
   191     entity = self._logic.updateOrCreateFromKeyName(fields, key_name)
   187     entity = self._logic.updateOrCreateFromKeyName(fields, key_name)
   192 
   188 
   193     # redirect to notifications list to see the admin invite
   189     # redirect to notifications list to see the admin invite
   194     return http.HttpResponseRedirect('/notification/list')
   190     return http.HttpResponseRedirect('/notification/list')
   195 
       
   196 
       
   197   @decorators.merge_params
       
   198   @decorators.check_access
       
   199   def listRequests(self, request, access_type,
       
   200                 page_name=None, params=None, **kwargs):
       
   201     """Gives an overview of all the requests for a specific club.
       
   202 
       
   203     Args:
       
   204       request: the standard Django HTTP request object
       
   205       access_type : the name of the access type which should be checked
       
   206       page_name: the page name displayed in templates as page and header title
       
   207       params: a dict with params for this View
       
   208       kwargs: the Key Fields for the specified entity
       
   209     """
       
   210 
       
   211     # set the pagename to include the link_id
       
   212     page_name = '%s %s' %(page_name, kwargs['link_id'])
       
   213 
       
   214     club_roles = ['club_admin', 'club_member']
       
   215 
       
   216     # list all incoming requests
       
   217     filter = {
       
   218         'role': club_roles,
       
   219         'state': 'new'
       
   220         }
       
   221 
       
   222     # create the list parameters
       
   223     inc_req_params = request_view.getParams()
       
   224 
       
   225     # define the list redirect action to the request processing page
       
   226     inc_req_params['list_action'] = (redirects.getProcessRequestRedirect, None)
       
   227     inc_req_params['list_description'] = ugettext(
       
   228         "An overview of the club's incoming requests.")
       
   229     
       
   230     inc_req_content = list_helper.getListContent(
       
   231         request, inc_req_params, filter, 0)
       
   232 
       
   233     # list all outstanding invites
       
   234     filter = {
       
   235         'role': club_roles,
       
   236         'state': 'group_accepted'
       
   237         }
       
   238 
       
   239     # create the list parameters
       
   240     out_inv_params = request_view.getParams()
       
   241 
       
   242     # define the list redirect action to the request processing page
       
   243     out_inv_params['list_action'] = (redirects.getProcessRequestRedirect, None)
       
   244     out_inv_params['list_description'] = ugettext(
       
   245         "An overview of the club's outstanding invites.")
       
   246 
       
   247     out_inv_content = list_helper.getListContent(
       
   248         request, out_inv_params, filter, 1)
       
   249 
       
   250     # list all ignored requests
       
   251     filter = {
       
   252         'role': club_roles,
       
   253         'state': 'ignored'
       
   254         }
       
   255 
       
   256     # create the list parameters
       
   257     ignored_params = request_view.getParams()
       
   258 
       
   259     # define the list redirect action to the request processing page
       
   260     ignored_params['list_action'] = (redirects.getProcessRequestRedirect, None)
       
   261     ignored_params['list_description'] = ugettext(
       
   262         "An overview of the club's ignored requests.")
       
   263     
       
   264     ignored_content = list_helper.getListContent(
       
   265         request, ignored_params, filter, 2)
       
   266 
       
   267 
       
   268     contents = [inc_req_content, out_inv_content, ignored_content]
       
   269 
       
   270     return self._list(request, params, contents, page_name)
       
   271 
   191 
   272 
   192 
   273   def _editGet(self, request, entity, form):
   193   def _editGet(self, request, entity, form):
   274     """See base.View._editGet().
   194     """See base.View._editGet().
   275     """
   195     """