Example #1
0
    def invitePost(self, request, context, params, group_entity, **kwargs):
        """Handles the POST request concerning the view that creates an invite
    for attaining a certain Role.

    Args:
      request: the standard Django HTTP request object
      page_name: the page name displayed in templates as page and header title
      params: a dict with params for this View
      group_entity: Group entity which this invite is from
      kwargs: the Key Fields for the specified entity
    """

        # get the request view parameters and populate the form using POST data
        request_params = request_view.view.getParams()
        form = request_params['invite_form'](request.POST)

        if not form.is_valid():
            # return the invalid form response
            return self._constructResponse(request,
                                           entity=None,
                                           context=context,
                                           form=form,
                                           params=request_params)

        # collect the cleaned data from the valid form
        _, form_fields = soc.views.helper.forms.collectCleanedFields(form)

        # create the fields for the new request entity
        request_fields = {
            'user': form_fields['user_id'],
            'group': group_entity,
            'role': params['logic'].role_name,
            'status': 'group_accepted'
        }

        if not request_logic.isValidNewRequest(request_fields,
                                               params['logic']):
            # not a valid invite
            context['error_message'] = self.DEF_INVITE_ERROR_MSG_FMT % (params)
            return super(View, self)._constructResponse(request,
                                                        entity=None,
                                                        context=context,
                                                        form=form,
                                                        params=request_params)

        # create the request entity
        request_logic.updateOrCreateFromFields(request_fields)

        group_view = params.get('group_view')

        if not group_view:
            return http.HttpResponseRedirect('/')
        else:
            # redirect to the requests list
            return http.HttpResponseRedirect(
                redirects.getListRequestsRedirect(group_entity,
                                                  group_view.getParams()))
Example #2
0
    def requestPost(self, request, context, params, group_entity, **kwargs):
        """Handles the POST request concerning the creation of a request
    to attain a role.

    Args:
      request: the standard Django HTTP request object
      context: dictionary containing the context for this view
      params: a dict with params for this View
      group_entity: the Group entity this request is for
      kwargs: the Key Fields for the specified entity
    """

        # get the request view parameters and populate the form using POST data
        request_params = request_view.view.getParams()
        form = request_params['request_form'](request.POST)

        if not form.is_valid():
            # return the invalid form response
            return self._constructResponse(request,
                                           entity=None,
                                           context=context,
                                           form=form,
                                           params=request_params)

        _, fields = soc.views.helper.forms.collectCleanedFields(form)

        # set the fields for the new request
        user_entity = user_logic.logic.getForCurrentAccount()

        request_fields = {
            'user': user_entity,
            'group': group_entity,
            'message': fields['message'],
            'role': params['logic'].role_name,
            'status': 'new'
        }

        if not request_logic.isValidNewRequest(request_fields,
                                               params['logic']):
            # not a valid request
            context['error_message'] = self.DEF_REQUEST_ERROR_MSG_FMT % (
                params)
            return super(View, self)._constructResponse(request,
                                                        entity=None,
                                                        context=context,
                                                        form=form,
                                                        params=request_params)

        # create the request entity
        request_logic.updateOrCreateFromFields(request_fields)

        # redirect to requests overview
        return http.HttpResponseRedirect('/user/requests')
Example #3
0
  def invitePost(self, request, context, params, group_entity, **kwargs):
    """Handles the POST request concerning the view that creates an invite
    for attaining a certain Role.

    Args:
      request: the standard Django HTTP request object
      page_name: the page name displayed in templates as page and header title
      params: a dict with params for this View
      group_entity: Group entity which this invite is from
      kwargs: the Key Fields for the specified entity
    """

    # get the request view parameters and populate the form using POST data
    request_params = request_view.view.getParams()
    form = request_params['invite_form'](request.POST)

    if not form.is_valid():
      # return the invalid form response
      return self._constructResponse(request, entity=None, context=context,
          form=form, params=request_params)

    # collect the cleaned data from the valid form
    _, form_fields = soc.views.helper.forms.collectCleanedFields(form)

    # create the fields for the new request entity
    request_fields = {
        'user': form_fields['user_id'],
        'group': group_entity,
        'role': params['logic'].role_name,
        'status': 'group_accepted'}

    if not request_logic.isValidNewRequest(request_fields, params['logic']):
      # not a valid invite
      context['error_message'] = self.DEF_INVITE_ERROR_MSG_FMT % (
          params)
      return super(View, self)._constructResponse(request, entity=None,
          context=context, form=form, params=request_params)

    # create the request entity
    request_logic.updateOrCreateFromFields(request_fields)

    group_view = params.get('group_view')

    if not group_view:
      return http.HttpResponseRedirect('/')
    else:
      # redirect to the requests list
      return http.HttpResponseRedirect(
          redirects.getListRequestsRedirect(group_entity, 
                                            group_view.getParams()))
Example #4
0
  def requestPost(self, request, context, params, group_entity, **kwargs):
    """Handles the POST request concerning the creation of a request
    to attain a role.

    Args:
      request: the standard Django HTTP request object
      context: dictionary containing the context for this view
      params: a dict with params for this View
      group_entity: the Group entity this request is for
      kwargs: the Key Fields for the specified entity
    """

    # get the request view parameters and populate the form using POST data
    request_params = request_view.view.getParams()
    form = request_params['request_form'](request.POST)

    if not form.is_valid():
      # return the invalid form response
      return self._constructResponse(request, entity=None, context=context,
          form=form, params=request_params)

    _, fields = soc.views.helper.forms.collectCleanedFields(form)

    # set the fields for the new request
    user_entity = user_logic.logic.getCurrentUser()

    request_fields = {
        'user': user_entity,
        'group' : group_entity,
        'message': fields['message'],
        'role' : params['logic'].role_name,
        'status' : 'new'}

    if not request_logic.isValidNewRequest(request_fields, params['logic']):
      # not a valid request
      context['error_message'] = self.DEF_REQUEST_ERROR_MSG_FMT % (
          params)
      return super(View, self)._constructResponse(request, entity=None,
          context=context, form=form, params=request_params)

    # create the request entity
    request_logic.updateOrCreateFromFields(request_fields)

    # redirect to requests overview
    return http.HttpResponseRedirect('/user/requests')