示例#1
0
  def __init__(self, params=None):
    """Defines the fields and methods required for the base View class
    to provide the user with list, public, create, edit and delete views.

    Params:
      params: a dict with params for this View
    """

    new_params = {}

    new_params['extra_dynaexclude'] = ['founder', 'home', 'tos',
                                       'member_template', 'status']
    new_params['edit_extra_dynaproperties'] = {
        'founded_by': forms.CharField(widget=widgets.ReadOnlyInput(),
                                   required=False),
        }

    #set the extra_django_patterns and include the one from params
    patterns = params.get('extra_django_patterns', [])

    patterns += [
        (r'^%(url_name)s/(?P<access_type>list_requests)/%(key_fields)s$',
        'soc.views.models.%(module_name)s.list_requests',
        'List of requests for %(name)s'),
        (r'^%(url_name)s/(?P<access_type>list_roles)/%(key_fields)s$',
        'soc.views.models.%(module_name)s.list_roles',
        'List of roles for %(name)s')]

    if params.get('group_applicant_url'):
      # add the applicant pattern
      patterns += [
          (r'^%(url_name)s/(?P<access_type>applicant)/%(key_fields)s$',
          'soc.views.models.%(module_name)s.applicant', 
          "%(name)s Creation via Accepted Application"),]

    new_params['extra_django_patterns'] = patterns

    # TODO(tlarsen): Add support for Django style template lookup
    new_params['public_template'] = 'soc/group/public.html'

    new_params['list_row'] = 'soc/group/list/row.html'
    new_params['list_heading'] = 'soc/group/list/heading.html'

    new_params['create_extra_dynaproperties'] = {
       'email': forms.fields.EmailField(required=True),
       'clean_phone': cleaning.clean_phone_number('phone'),
       'clean_contact_street': cleaning.clean_ascii_only('contact_street'),
       'clean_contact_city': cleaning.clean_ascii_only('contact_city'),
       'clean_contact_state': cleaning.clean_ascii_only('contact_state'),
       'clean_contact_postalcode': cleaning.clean_ascii_only(
          'contact_postalcode'),
       'clean_shipping_street': cleaning.clean_ascii_only('shipping_street'),
       'clean_shipping_city': cleaning.clean_ascii_only('shipping_city'),
       'clean_shipping_state': cleaning.clean_ascii_only('shipping_state'),
       'clean_shipping_postalcode': cleaning.clean_ascii_only(
          'shipping_postalcode'),
       }

    new_params['role_views'] = {}

    params = dicts.merge(params, new_params, sub_merge=True)

    super(View, self).__init__(params=params)
示例#2
0
  def __init__(self, params=None):
    """

    Args:
      params: This dictionary should be filled with the parameters
    """

    new_params = {}

    patterns = params.get('extra_django_patterns')

    if not patterns:
      patterns = []

    if params.get('allow_requests_and_invites'):
      # add patterns concerning requests and invites
      patterns += [(r'^%(url_name)s/(?P<access_type>invite)/%(scope)s$',
          'soc.views.models.%(module_name)s.invite',
          'Create invite for %(name)s'),
          (r'^%(url_name)s/(?P<access_type>accept_invite)/%(scope)s/%(lnp)s$',
          'soc.views.models.%(module_name)s.accept_invite',
          'Accept invite for %(name)s'),
          (r'^%(url_name)s/(?P<access_type>process_request)/%(scope)s/%(lnp)s$',
          'soc.views.models.%(module_name)s.process_request',
          'Process request for %(name)s'),
          (r'^%(url_name)s/(?P<access_type>request)/%(scope)s$',
          'soc.views.models.%(module_name)s.role_request',
          'Create a Request to become %(name)s')]
    elif params.get('allow_invites'):
      # add patterns concerning only invites
      patterns += [(r'^%(url_name)s/(?P<access_type>invite)/%(scope)s$',
          'soc.views.models.%(module_name)s.invite',
          'Create invite for %(name)s'),
          (r'^%(url_name)s/(?P<access_type>accept_invite)/%(scope)s/%(lnp)s$',
          'soc.views.models.%(module_name)s.accept_invite',
          'Accept invite for %(name)s'),
          (r'^%(url_name)s/(?P<access_type>process_request)/%(scope)s/%(lnp)s$',
          'soc.views.models.%(module_name)s.process_request',
          'Process request for %(name)s')]

    # add manage pattern
    patterns += [(r'^%(url_name)s/(?P<access_type>manage)/%(scope)s/%(lnp)s$',
        'soc.views.models.%(module_name)s.manage',
        'Manage a %(name)s'),]

    new_params['extra_django_patterns'] = patterns
    new_params['scope_redirect'] = redirects.getInviteRedirect
    new_params['manage_redirect'] = redirects.getListRolesRedirect

    new_params['create_template'] = 'soc/role/edit.html'
    new_params['edit_template'] = 'soc/role/edit.html'

    new_params['create_extra_dynaproperties'] = {
       'latitude':forms.fields.FloatField(widget=forms.HiddenInput,
                                          required=False),
       'longitude': forms.fields.FloatField(widget=forms.HiddenInput,
                                            required=False),
       'email': forms.fields.EmailField(required=True),
       'clean_link_id': cleaning.clean_existing_user('link_id'),
       'clean_phone': cleaning.clean_phone_number('phone'),
       'clean_res_street': cleaning.clean_ascii_only('res_street'),
       'clean_res_city': cleaning.clean_ascii_only('res_city'),
       'clean_res_state': cleaning.clean_ascii_only('res_state'),
       'clean_res_postalcode': cleaning.clean_ascii_only('res_postalcode'),
       'clean_ship_street': cleaning.clean_ascii_only('ship_street'),
       'clean_ship_city': cleaning.clean_ascii_only('ship_city'),
       'clean_ship_state': cleaning.clean_ascii_only('ship_state'),
       'clean_ship_postalcode': cleaning.clean_ascii_only('ship_postalcode'),
       'clean_home_page': cleaning.clean_url('home_page'),
       'clean_blog': cleaning.clean_url('blog'),
       'clean_photo_url': cleaning.clean_url('photo_url'),
       'scope_path': forms.CharField(widget=forms.HiddenInput,
                                  required=True),
       }

    new_params['extra_dynaexclude'] = ['user', 'status', 'agreed_to_tos_on']

    params = dicts.merge(params, new_params, sub_merge=True)

    super(View, self).__init__(params=params)

    # add manage template
    template = 'soc/%(module_name)s/manage.html' % self._params
    self._params['manage_template'] = template

    if self._params.get('show_in_roles_overview'):
      # add to roles overview
      addRole(self)