Ejemplo n.º 1
0
  def admin(self, request, access_type,
             page_name=None, params=None, **kwargs):
    """Displays the admin page for the entity specified by **kwargs.

    Params usage:
      rights: The rights dictionary is used to check if the user has
        the required rights to view the admin page for this entity.
        See checkAccess for more details on how the rights dictionary
        is used to check access rights.
      name: The name value is used to set the entity_type in the
        context so that the template can refer to it.
      public_template: The public_template value is used as template
        to display the public page of the found entity.

    Args:
      request: the standard Django HTTP request object
      access_type : the name of the access type which should be checked
      page_name: the page name displayed in templates as page and header title
      params: a dict with params for this View
      kwargs: the Key Fields for the specified entity
    """

    # create default template context for use with any templates
    context = helper.responses.getUniversalContext(request)
    helper.responses.useJavaScript(context, params['js_uses_all'])
    context['page_name'] = page_name
    logic = params['logic']

    try:
      entity = logic.getFromKeyFieldsOr404(kwargs)
    except out_of_band.Error, error:
      return helper.responses.errorResponse(error, request, context=context)
Ejemplo n.º 2
0
  def acceptedProjects(self, request, access_type,
                       page_name=None, params=None, filter=None, **kwargs):
    """See base.View.list.
    """
    contents = []
    logic = params['logic']

    program_entity = logic.getFromKeyFieldsOr404(kwargs)

    filter = {
        'status': 'accepted',
        'program': program_entity}

    fmt = {'name': program_entity.name}
    description = self.DEF_ACCEPTED_PROJECTS_MSG_FMT % fmt

    from soc.views.models import student_project as sp_view

    ap_params = sp_view.view.getParams().copy() # accepted projects
    ap_params['list_action'] = (redirects.getPublicRedirect, ap_params)
    ap_params['list_description'] = description
    ap_params['list_heading'] = 'soc/student_project/list/heading_all.html'
    ap_params['list_row'] = 'soc/student_project/list/row_all.html'

    return self.list(request, access_type, page_name=page_name,
                     params=ap_params, filter=filter)
Ejemplo n.º 3
0
    def assignTaskQuotasGet(self, request, context, org_params, page_name,
                            params, entity, **kwargs):
        """Handles the GET request for the task quota allocation page.

    Args:
        entity: the program entity
        rest see base.View.public()
    """

        from soc.modules.ghop.views.models.organization import view as org_view

        logic = params['logic']
        program_entity = logic.getFromKeyFieldsOr404(kwargs)

        org_params['list_template'] = ('modules/ghop/program/'
                                       'allocation/allocation.html')
        org_params['list_heading'] = ('modules/ghop/program/'
                                      'allocation/heading.html')
        org_params['list_row'] = 'modules/ghop/program/allocation/row.html'
        org_params['list_pagination'] = 'soc/list/no_pagination.html'

        description = self.DEF_TASK_QUOTA_ALLOCATION_MSG

        content = self._getOrgsWithProfilesList(program_entity, org_view,
                                                description, False)

        contents = [content]

        return self._list(request, org_params, contents, page_name, context)
Ejemplo n.º 4
0
    def acceptedOrgs(self,
                     request,
                     access_type,
                     page_name=None,
                     params=None,
                     filter=None,
                     **kwargs):
        """List all the accepted orgs for the given program.
    """

        from soc.modules.ghop.views.models.organization import view as org_view

        logic = params['logic']

        program_entity = logic.getFromKeyFieldsOr404(kwargs)

        fmt = {'name': program_entity.name}
        description = self.DEF_PARTICIPATING_ORGS_MSG_FMT % fmt

        ao_list = self._getOrgsWithProfilesList(program_entity, org_view,
                                                description, False)

        params = params.copy()
        params['list_msg'] = program_entity.accepted_orgs_msg

        return self._list(request, params, [ao_list], page_name)
Ejemplo n.º 5
0
  def admin(self, request, access_type,
             page_name=None, params=None, **kwargs):
    """Displays the admin page for the entity specified by **kwargs.

    Params usage:
      rights: The rights dictionary is used to check if the user has
        the required rights to view the admin page for this entity.
        See checkAccess for more details on how the rights dictionary
        is used to check access rights.
      name: The name value is used to set the entity_type in the
        context so that the template can refer to it.
      public_template: The public_template value is used as template
        to display the public page of the found entity.

    Args:
      request: the standard Django HTTP request object
      access_type : the name of the access type which should be checked
      page_name: the page name displayed in templates as page and header title
      params: a dict with params for this View
      kwargs: the Key Fields for the specified entity
    """

    # create default template context for use with any templates
    context = helper.responses.getUniversalContext(request)
    helper.responses.useJavaScript(context, params['js_uses_all'])
    context['page_name'] = page_name
    logic = params['logic']

    try:
      entity = logic.getFromKeyFieldsOr404(kwargs)
    except out_of_band.Error, error:
      return helper.responses.errorResponse(error, request, context=context)
Ejemplo n.º 6
0
    def edit(self,
             request,
             access_type,
             page_name=None,
             params=None,
             seed=None,
             **kwargs):
        """Displays the edit page for the entity specified by **kwargs.

    Params usage:
      The params dictionary is passed on to either editGet or editPost
      depending on the method type of the request. See the docstring
      for editGet and editPost on how they use it.

      rights: The rights dictionary is used to check if the user has
        the required rights to edit (or create) a new entity.
        See checkAccess for more details on how the rights dictionary
        is used to check access rights.
      name: The name value is used to construct the message_fmt of the
        raised error when there key_values do not define an existing
        entity. See DEF_CREATE_NEW_ENTITY_MSG_FMT on how the name
        (and the lower() version of it) is used.
      missing_redirect: The missing_redirect value is also used to
        construct the message_fmt mentioned above.
      error_public: The error_public value is used as the template for
        the error response mentioned above.

    Args:
      request: the standard Django HTTP request object
      access_type : the name of the access type which should be checked
      page_name: the page name displayed in templates as page and header title
      params: a dict with params for this View
      kwargs: The Key Fields for the specified entity
    """

        logic = params['logic']

        context = helper.responses.getUniversalContext(request)
        helper.responses.useJavaScript(context, params['js_uses_all'])
        context['page_name'] = page_name

        try:
            entity = logic.getFromKeyFieldsOr404(kwargs)
        except out_of_band.Error, error:
            msg = self.DEF_CREATE_NEW_ENTITY_MSG_FMT % {
                'entity_type_lower': params['name'].lower(),
                'entity_type': params['name'],
                'create': params['missing_redirect']
            }
            error.message_fmt = error.message_fmt + msg
            return helper.responses.errorResponse(error,
                                                  request,
                                                  context=context)
Ejemplo n.º 7
0
  def acceptedOrgs(self, request, access_type,
                   page_name=None, params=None, filter=None, **kwargs):
    """See base.View.list.
    """

    contents = []
    logic = params['logic']

    program_entity = logic.getFromKeyFieldsOr404(kwargs)

    fmt = {'name': program_entity.name}
    description = self.DEF_ACCEPTED_ORGS_MSG_FMT % fmt

    filter = {
        'status': 'accepted',
        'scope': program_entity,
        }

    from soc.views.models import org_app as org_app_view
    aa_params = org_app_view.view.getParams().copy() # accepted applications

    # define the list redirect action to show the notification
    del aa_params['list_key_order']
    aa_params['list_action'] = (redirects.getHomeRedirect, aa_params)
    aa_params['list_description'] = description

    aa_list = lists.getListContent(request, aa_params, filter, idx=0,
                                   need_content=True)

    if aa_list:
      contents.append(aa_list)

    use_cache = not aa_list # only cache if there are no aa's left
    description = self.DEF_CREATED_ORGS_MSG_FMT % fmt

    filter['status'] = ['new', 'active']

    from soc.views.models.organization import view as org_view
    ao_params = org_view.getParams().copy() # active orgs
    ao_list = self._getAcceptedOrgsList(description, ao_params, 
        filter, use_cache)

    contents.append(ao_list)

    params = params.copy()
    params['list_msg'] = program_entity.accepted_orgs_msg

    return self._list(request, params, contents, page_name)
Ejemplo n.º 8
0
    def export(self,
               request,
               access_type,
               page_name=None,
               params=None,
               **kwargs):
        """Displays the export page for the entity specified by **kwargs.

    Params usage:
      rights: The rights dictionary is used to check if the user has
        the required rights to view the export page for this entity.
        See checkAccess for more details on how the rights dictionary
        is used to check access rights.
      error_export: The error_export value is used as template when
        the key values (as defined by the page's url) do not
        correspond to an existing entity.
      Params is passed to download, refer to it's docstring for more
      details on how it uses it.

    Args:
      request: the standard Django HTTP request object
      access_type : the name of the access type which should be checked
      page_name: the page name displayed in templates as page and header title
      params: a dict with params for this View
      kwargs: the Key Fields for the specified entity
    """

        if not ('export_content_type' in params) and ('export_function'
                                                      in params):
            return self.public(request,
                               access_type,
                               page_name=page_name,
                               params=params,
                               **kwargs)

        # create default template context for use with any templates
        entity = None
        logic = params['logic']

        if not all(kwargs.values()):
            #TODO: Change this into a proper redirect
            return http.HttpResponseRedirect('/')

        try:
            entity = logic.getFromKeyFieldsOr404(kwargs)
        except out_of_band.Error, error:
            return helper.responses.errorResponse(
                error, request, template=params['error_export'])
Ejemplo n.º 9
0
  def edit(self, request, access_type,
           page_name=None, params=None, seed=None, **kwargs):
    """Displays the edit page for the entity specified by **kwargs.

    Params usage:
      The params dictionary is passed on to either editGet or editPost
      depending on the method type of the request. See the docstring
      for editGet and editPost on how they use it.

      rights: The rights dictionary is used to check if the user has
        the required rights to edit (or create) a new entity.
        See checkAccess for more details on how the rights dictionary
        is used to check access rights.
      name: The name value is used to construct the message_fmt of the
        raised error when there key_values do not define an existing
        entity. See DEF_CREATE_NEW_ENTITY_MSG_FMT on how the name
        (and the lower() version of it) is used.
      missing_redirect: The missing_redirect value is also used to
        construct the message_fmt mentioned above.
      error_public: The error_public value is used as the template for
        the error response mentioned above.

    Args:
      request: the standard Django HTTP request object
      access_type : the name of the access type which should be checked
      page_name: the page name displayed in templates as page and header title
      params: a dict with params for this View
      kwargs: The Key Fields for the specified entity
    """

    logic = params['logic']

    context = helper.responses.getUniversalContext(request)
    helper.responses.useJavaScript(context, params['js_uses_all'])
    context['page_name'] = page_name

    try:
      entity = logic.getFromKeyFieldsOr404(kwargs)
    except out_of_band.Error, error:
      msg = self.DEF_CREATE_NEW_ENTITY_MSG_FMT % {
          'entity_type_lower' : params['name'].lower(),
          'entity_type' : params['name'],
          'create' : params['missing_redirect']
          }
      error.message_fmt = error.message_fmt + msg
      return helper.responses.errorResponse(
          error, request, context=context)
Ejemplo n.º 10
0
    def delete(self,
               request,
               access_type,
               page_name=None,
               params=None,
               **kwargs):
        """Shows the delete page for the entity specified by **kwargs.

    Args:
      request: the standard Django HTTP request object
      access_type : the name of the access type which should be checked
      page_name: the page name displayed in templates as page and header title
      params: a dict with params for this View
      kwargs: The Key Fields for the specified entity

    Params usage:
      rights: The rights dictionary is used to check if the user has
        the required rights to delete the specified entity. See checkAccess
        for more details on how the rights dictionary is used to check access
        rights.
      name: used in the same way as in edit(), see it's docstring for
        a more detailed explanation on how it is used.
      missing_redirect: see name
      error_edit: see name
      delete_redirect: The delete_redirect value is used as the url to
        redirect to after having successfully deleted the entity.
    """

        logic = params['logic']

        try:
            entity = logic.getFromKeyFieldsOr404(kwargs)
        except out_of_band.Error, error:
            error.message_fmt = (
                error.message_fmt + self.DEF_CREATE_NEW_ENTITY_MSG_FMT % {
                    'entity_type_lower': params['name'].lower(),
                    'entity_type': params['name'],
                    'create': params['missing_redirect']
                })
            return responses.jsonErrorResponse(request,
                                               "No such %s" % params['name'])
Ejemplo n.º 11
0
  def export(self, request, access_type,
             page_name=None, params=None, **kwargs):
    """Displays the export page for the entity specified by **kwargs.

    Params usage:
      rights: The rights dictionary is used to check if the user has
        the required rights to view the export page for this entity.
        See checkAccess for more details on how the rights dictionary
        is used to check access rights.
      error_export: The error_export value is used as template when
        the key values (as defined by the page's url) do not
        correspond to an existing entity.
      Params is passed to download, refer to it's docstring for more
      details on how it uses it.

    Args:
      request: the standard Django HTTP request object
      access_type : the name of the access type which should be checked
      page_name: the page name displayed in templates as page and header title
      params: a dict with params for this View
      kwargs: the Key Fields for the specified entity
    """

    if not ('export_content_type' in params) and ('export_function' in params):
      return self.public(request, access_type, page_name=page_name,
                         params=params, **kwargs)

    # create default template context for use with any templates
    entity = None
    logic = params['logic']

    if not all(kwargs.values()):
      #TODO: Change this into a proper redirect
      return http.HttpResponseRedirect('/')

    try:
      entity = logic.getFromKeyFieldsOr404(kwargs)
    except out_of_band.Error, error:
      return helper.responses.errorResponse(
          error, request, template=params['error_export'])
Ejemplo n.º 12
0
  def acceptedProjects(self, request, access_type,
		       page_name=None, params=None, filter=None, **kwargs):
    """See base.View.list.
    """
    contents = []
    logic = params['logic']

    program_entity = logic.getFromKeyFieldsOr404(kwargs)

    filter = {
	'status': 'accepted',
	'program': program_entity }

    fmt = {'name': program_entity.name}
    description = self.DEF_ACCEPTED_PROJECTS_MSG_FMT % fmt

    from soc.views.models import student_project as sp_view

    ap_params = sp_view.view.getParams().copy() # accepted projects

    fun =  soc.cache.logic.cache(self._getData)
    ap_logic = ap_params['logic']
    entities = fun(logic.getModel(), filter, order=None, logic=ap_logic)
    
    ap_list = dicts.rename(ap_params, ap_params['list_params'])
    ap_list['action'] = (redirects.getPublicRedirect, ap_params)
    ap_list['description'] = description
    ap_list['pagination'] = 'soc/list/no_pagination.html'
    ap_list['heading'] = 'soc/student_project/list/heading_all.html'
    ap_list['row'] = 'soc/student_project/list/row_all.html'
    ap_list['data'] = entities

    contents.append(ap_list)

    params = params.copy()

    return self._list(request, params, contents, page_name)
Ejemplo n.º 13
0
  def delete(self, request, access_type,
             page_name=None, params=None, **kwargs):
    """Shows the delete page for the entity specified by **kwargs.

    Args:
      request: the standard Django HTTP request object
      access_type : the name of the access type which should be checked
      page_name: the page name displayed in templates as page and header title
      params: a dict with params for this View
      kwargs: The Key Fields for the specified entity

    Params usage:
      rights: The rights dictionary is used to check if the user has
        the required rights to delete the specified entity. See checkAccess
        for more details on how the rights dictionary is used to check access
        rights.
      name: used in the same way as in edit(), see it's docstring for
        a more detailed explanation on how it is used.
      missing_redirect: see name
      error_edit: see name
      delete_redirect: The delete_redirect value is used as the url to
        redirect to after having successfully deleted the entity.
    """

    logic = params['logic']

    try:
      entity = logic.getFromKeyFieldsOr404(kwargs)
    except out_of_band.Error, error:
      error.message_fmt = (
        error.message_fmt + self.DEF_CREATE_NEW_ENTITY_MSG_FMT % {
          'entity_type_lower' : params['name'].lower(),
          'entity_type' : params['name'],
          'create' : params['missing_redirect']})
      return helper.responses.errorResponse(
          error, request, template=params['error_edit'])