示例#1
0
  def process_exception(self, request, exception):
    """Called when an uncaught exception is raised.

    See the Django middleware documentation for an explanation of
    the method signature.
    """

    template = None
    context = responses.getUniversalContext(request)

    if isinstance(exception, DeadlineExceededError):
      template = 'soc/deadline_exceeded.html'
    if isinstance(exception, MemoryError):
      template = 'soc/memory_error.html'
    if isinstance(exception, AssertionError):
      template = 'soc/assertion_error.html'
    if isinstance(exception, out_of_band.Error):
      return responses.errorResponse(exception, request)

    if template:
      logging.exception(exception)
      return responses.respond(request, template, context=context)

    # let Django handle it
    return None
示例#2
0
    def process_exception(self, request, exception):
        """Called when an uncaught exception is raised.

    See the Django middleware documentation for an explanation of
    the method signature.
    """

        template = None
        context = responses.getUniversalContext(request)

        if isinstance(exception, DeadlineExceededError):
            template = 'soc/deadline_exceeded.html'
        if isinstance(exception, MemoryError):
            template = 'soc/memory_error.html'
        if isinstance(exception, AssertionError):
            template = 'soc/assertion_error.html'
        if isinstance(exception, out_of_band.Error):
            return responses.errorResponse(exception, request)

        if template:
            logging.exception(exception)
            return responses.respond(request, template, context=context)

        # let Django handle it
        return None
示例#3
0
    def listProjects(self,
                     request,
                     access_type,
                     page_name=None,
                     params=None,
                     **kwargs):
        """View that lists all of the current user's Student Projects for the
    Program given as Scope.
    """

        from soc.modules.gsoc.views.models import student_project as project_view

        user_entity = user_logic.getCurrentUser()

        # pylint: disable=E1103
        fields = {
            'link_id': user_entity.link_id,
            'scope_path': kwargs['scope_path']
        }

        try:
            student_entity = student_logic.getFromKeyFieldsOr404(fields)
        except out_of_band.Error, error:
            return responses.errorResponse(error,
                                           request,
                                           template=params['error_public'])
示例#4
0
    def editRecord(self,
                   request,
                   access_type,
                   page_name=None,
                   params=None,
                   **kwargs):
        """View in which a GradingRecord can be edited.

    For args see base.View.public().
    """

        survey_group_logic = params['logic']
        record_logic = survey_group_logic.getRecordLogic()

        get_dict = request.GET

        record_id = get_dict.get('id')

        if not (record_id and record_id.isdigit()):
            # no valid record_id specified showing the list of GradingRecords
            return self._showEditRecordList(request, params, page_name,
                                            **kwargs)

        # retrieve the wanted GradingRecord
        try:
            record_entity = record_logic.getFromIDOr404(int(record_id))
        except out_of_band.Error, error:
            return responses.errorResponse(error,
                                           request,
                                           template=params['error_public'])
示例#5
0
  def viewRecord(self, request, access_type, page_name=None,
                       params=None, **kwargs):
    """Read-Only View of Survey Form

    For params see base.View.public()
    """
    try:
      entity = params['logic'].getFromKeyFieldsOr404(kwargs)
    except out_of_band.Error, error:
      return responses.errorResponse(
          error, request, template=params['error_public'])
示例#6
0
    def take(self, request, access_type, page_name=None, params=None, **kwargs):
        """View for taking a Survey.

    For Args see base.View().public().
    """

        survey_logic = params["logic"]

        try:
            entity = survey_logic.getFromKeyFieldsOr404(kwargs)
        except out_of_band.Error, error:
            return responses.errorResponse(error, request, template=params["error_public"])
示例#7
0
  def manage(self, request, access_type,
             page_name=None, params=None, **kwargs):
    """View that allows Organization Admins to manage their Student Projects.

    For params see base.View().public()
    """

    try:
      entity = self._logic.getFromKeyFieldsOr404(kwargs)
    except out_of_band.Error, error:
      return responses.errorResponse(
          error, request, template=params['error_public'])
示例#8
0
  def stEdit(self, request, access_type,
             page_name=None, params=None, **kwargs):
    """View that allows students to edit information about their project.

    For params see base.View().public()
    """

    try:
      entity = self._logic.getFromKeyFieldsOr404(kwargs)
    except out_of_band.Error, error:
      return responses.errorResponse(
          error, request, template=params['error_public'])
示例#9
0
  def manage(self, request, access_type,
             page_name=None, params=None, **kwargs):
    """View that allows Organization Admins to manage their Student Projects.

    For params see base.View().public()
    """

    try:
      entity = self._logic.getFromKeyFieldsOr404(kwargs)
    except out_of_band.Error, error:
      return responses.errorResponse(
          error, request, template=params['error_public'])
示例#10
0
  def stEdit(self, request, access_type,
             page_name=None, params=None, **kwargs):
    """View that allows students to edit information about their project.

    For params see base.View().public()
    """

    try:
      entity = self._logic.getFromKeyFieldsOr404(kwargs)
    except out_of_band.Error, error:
      return responses.errorResponse(
          error, request, template=params['error_public'])
示例#11
0
  def viewResults(self, request, access_type, page_name=None,
                  params=None, **kwargs):
    """View for SurveyRecords.

    For params see base.View.public().
    """

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

    try:
      entity = params['logic'].getFromKeyFieldsOr404(kwargs)
    except out_of_band.Error, error:
      return responses.errorResponse(
          error, request, template=params['error_public'])
示例#12
0
  def _showEditRecordList(self, request, params, page_name, **kwargs):
    """Returns a list containing GradingRecords that can be edited.

    For args see base.View.public().
    """

    survey_group_logic = params['logic']
    record_logic = survey_group_logic.getRecordLogic()

    try:
      survey_group = survey_group_logic.getFromKeyFieldsOr404(kwargs)
    except out_of_band.Error, error:
      return responses.errorResponse(
          error, request, template=params['error_public'])
示例#13
0
  def take(self, request, access_type, page_name=None,
           params=None, **kwargs):
    """View for taking a Survey.

    For Args see base.View().public().
    """

    survey_logic = params['logic']

    try:
      entity = survey_logic.getFromKeyFieldsOr404(kwargs)
    except out_of_band.Error, error:
      return responses.errorResponse(
          error, request, template=params['error_public'])
示例#14
0
  def exportSerialized(self, request, access_type, page_name=None,
                       params=None, **kwargs):
    """Exports Surveys in JSON format.

    For args see base.View.public().
    """

    survey_logic = params['logic']

    try:
      sur = survey_logic.getFromKeyFieldsOr404(kwargs)
    except out_of_band.Error, error:
      return responses.errorResponse(
          error, request, template=params['error_public'])
示例#15
0
  def viewRecord(self, request, access_type, page_name=None,
                 params=None, **kwargs):
    """View that allows the user to see the contents of a single SurveyRecord.

    For params see base.View.public()
    """

    survey_logic = params['logic']
    record_logic = survey_logic.getRecordLogic()

    try:
      survey_entity = survey_logic.getFromKeyFieldsOr404(kwargs)
    except out_of_band.Error, error:
      return responses.errorResponse(
          error, request, template=params['error_public'])
示例#16
0
    def _showEditRecordList(self, request, params, page_name, **kwargs):
        """Returns a list containing GradingRecords that can be edited.

    For args see base.View.public().
    """

        survey_group_logic = params['logic']
        record_logic = survey_group_logic.getRecordLogic()

        try:
            survey_group = survey_group_logic.getFromKeyFieldsOr404(kwargs)
        except out_of_band.Error, error:
            return responses.errorResponse(error,
                                           request,
                                           template=params['error_public'])
示例#17
0
  def review(self, request, access_type, page_name=None, params=None,
             **kwargs):
    """View that lists a OrgAppSurveyRecord to be reviewed.

    For Args see base.View().public().
    """

    survey_logic = params['logic']
    record_logic = survey_logic.getRecordLogic()

    try:
      survey_entity = survey_logic.getFromKeyFieldsOr404(kwargs)
    except out_of_band.Error, error:
      return responses.errorResponse(
          error, request, template=params['error_public'])
示例#18
0
    def sendReminder(self, request, access_type, page_name=None, params=None, **kwargs):
        """Starts the task to send out reminders for the Survey given in kwargs.

    For args see base.View.public().
    """

        from google.appengine.api.labs import taskqueue

        from django import http

        survey_logic = params["logic"]

        try:
            entity = survey_logic.getFromKeyFieldsOr404(kwargs)
        except out_of_band.Error, error:
            return responses.errorResponse(error, request, template=params["error_public"])
示例#19
0
  def review(self, request, access_type,
             page_name=None, params=None, **kwargs):
    """Handles the view containing the review of an application.

    accepted (true or false) in the GET data will mark
    the application accordingly.


    For params see base.View.public().
    """

    try:
      entity = self._logic.getFromKeyFieldsOr404(kwargs)
    except out_of_band.Error, error:
      return responses.errorResponse(
          error, request, template=params['error_public'])
示例#20
0
  def review(self, request, access_type,
             page_name=None, params=None, **kwargs):
    """Handles the view containing the review of an application.

    accepted (true or false) in the GET data will mark
    the application accordingly.


    For params see base.View.public().
    """

    try:
      entity = self._logic.getFromKeyFieldsOr404(kwargs)
    except out_of_band.Error, error:
      return responses.errorResponse(
          error, request, template=params['error_public'])
示例#21
0
  def viewResults(self, request, access_type, page_name=None,
                  params=None, **kwargs):
    """View that lists all SurveyRecords which are of interest to the user.

    For params see base.View.public().
    """

    # TODO: this view could also contain statistics for the Survey

    survey_logic = params['logic']
    record_logic = survey_logic.getRecordLogic()

    try:
      entity = survey_logic.getFromKeyFieldsOr404(kwargs)
    except out_of_band.Error, error:
      return responses.errorResponse(
          error, request, template=params['error_public'])
示例#22
0
文件: student.py 项目: jamslevy/gsoc
  def listProjects(self, request, access_type,
                   page_name=None, params=None, **kwargs):
    """View that lists all of the current user's Student Projects for the
    Program given as Scope.
    """

    from soc.views.models import student_project as project_view

    user_entity = user_logic.logic.getForCurrentAccount()

    fields = {'link_id': user_entity.link_id,
        'scope_path': kwargs['scope_path']}

    try:
      student_entity = student_logic.logic.getFromKeyFieldsOr404(fields)
    except out_of_band.Error, error:
      return responses.errorResponse(
          error, request, template=params['error_public'])
示例#23
0
  def sendReminder(self, request, access_type, page_name=None,
                   params=None, **kwargs):
    """Starts the task to send out reminders for the Survey given in kwargs.

    For args see base.View.public().
    """

    from google.appengine.api import taskqueue

    from django import http

    survey_logic = params['logic']

    try:
      entity = survey_logic.getFromKeyFieldsOr404(kwargs)
    except out_of_band.Error, error:
      return responses.errorResponse(
          error, request, template=params['error_public'])
示例#24
0
    def exportSerialized(self,
                         request,
                         access_type,
                         page_name=None,
                         params=None,
                         **kwargs):
        """Exports Surveys in JSON format.

    For args see base.View.public().
    """

        survey_logic = params['logic']

        try:
            sur = survey_logic.getFromKeyFieldsOr404(kwargs)
        except out_of_band.Error, error:
            return responses.errorResponse(error,
                                           request,
                                           template=params['error_public'])
示例#25
0
  def viewRecords(self, request, access_type, page_name=None, params=None,
                  **kwargs):
    """View which shows all collected records for a given GradingSurveyGroup.

    For args see base.View.public().
    """

    from google.appengine.api import taskqueue

    from soc.logic import lists as lists_logic

    survey_group_logic = params['logic']
    record_logic = survey_group_logic.getRecordLogic()

    try:
      entity = survey_group_logic.getFromKeyFieldsOr404(kwargs)
    except out_of_band.Error, error:
      return responses.errorResponse(
          error, request, template=params['error_public'])
示例#26
0
文件: survey.py 项目: ajaksu/Melange
  def getContextEntity(self, request, page_name, params, kwargs):
    context = responses.getUniversalContext(request)
    responses.useJavaScript(context, params['js_uses_all'])
    context['page_name'] = page_name
    entity = None

    # TODO(ajaksu): there has to be a better way in this universe to get these
    kwargs['prefix'] = 'program'
    kwargs['link_id'] = request.path.split('/')[-1]
    kwargs['scope_path'] = '/'.join(request.path.split('/')[4:-1])

    entity = survey_logic.getFromKeyFieldsOr404(kwargs)

    if not self._public(request, entity, context):
      error = out_of_band.Error('')
      error = responses.errorResponse(
          error, request, template=params['error_public'], context=context)
      return error, None

    return entity, context
示例#27
0
    def review(self,
               request,
               access_type,
               page_name=None,
               params=None,
               **kwargs):
        """View that lists a OrgAppSurveyRecord to be reviewed.

    For Args see base.View().public().
    """

        survey_logic = params['logic']
        record_logic = survey_logic.getRecordLogic()

        try:
            survey_entity = survey_logic.getFromKeyFieldsOr404(kwargs)
        except out_of_band.Error, error:
            return responses.errorResponse(error,
                                           request,
                                           template=params['error_public'])
示例#28
0
    def viewRecord(self,
                   request,
                   access_type,
                   page_name=None,
                   params=None,
                   **kwargs):
        """View that allows the user to see the contents of a single SurveyRecord.

    For params see base.View.public()
    """

        survey_logic = params['logic']
        record_logic = survey_logic.getRecordLogic()

        try:
            survey_entity = survey_logic.getFromKeyFieldsOr404(kwargs)
        except out_of_band.Error, error:
            return responses.errorResponse(error,
                                           request,
                                           template=params['error_public'])
示例#29
0
    def list_self(self,
                  request,
                  access_type,
                  page_name=None,
                  params=None,
                  **kwargs):
        """View that lists all the OrgRecords you have access to.

    For Args see base.View().public().
    """

        from soc.logic.models.user import logic as user_logic

        survey_logic = params['logic']
        record_logic = survey_logic.getRecordLogic()

        try:
            entity = survey_logic.getFromKeyFieldsOr404(kwargs)
        except out_of_band.Error, error:
            return responses.errorResponse(error,
                                           request,
                                           template=params['error_public'])
示例#30
0
    def viewResults(self,
                    request,
                    access_type,
                    page_name=None,
                    params=None,
                    **kwargs):
        """View that lists all SurveyRecords which are of interest to the user.

    For params see base.View.public().
    """

        # TODO: this view could also contain statistics for the Survey

        survey_logic = params['logic']
        record_logic = survey_logic.getRecordLogic()

        try:
            entity = survey_logic.getFromKeyFieldsOr404(kwargs)
        except out_of_band.Error, error:
            return responses.errorResponse(error,
                                           request,
                                           template=params['error_public'])
示例#31
0
  def editRecord(self, request, access_type, page_name=None, params=None,
                 **kwargs):
    """View in which a GradingRecord can be edited.

    For args see base.View.public().
    """

    survey_group_logic = params['logic']
    record_logic = survey_group_logic.getRecordLogic()

    get_dict = request.GET

    record_id = get_dict.get('id')

    if not (record_id and record_id.isdigit()):
      # no valid record_id specified showing the list of GradingRecords
      return self._showEditRecordList(request, params, page_name, **kwargs)

    # retrieve the wanted GradingRecord
    try:
      record_entity = record_logic.getFromIDOr404(int(record_id))
    except out_of_band.Error, error:
      return responses.errorResponse(
          error, request, template=params['error_public'])
示例#32
0
    def viewRecords(self,
                    request,
                    access_type,
                    page_name=None,
                    params=None,
                    **kwargs):
        """View which shows all collected records for a given GradingSurveyGroup.

    For args see base.View.public().
    """

        from google.appengine.api.labs import taskqueue

        from soc.logic import lists as lists_logic

        survey_group_logic = params['logic']
        record_logic = survey_group_logic.getRecordLogic()

        try:
            entity = survey_group_logic.getFromKeyFieldsOr404(kwargs)
        except out_of_band.Error, error:
            return responses.errorResponse(error,
                                           request,
                                           template=params['error_public'])
示例#33
0
            return func(request, *args, **kwds)
        except DeadlineExceededError, exception:
            logging.exception(exception)
            return http.HttpResponseRedirect("/soc/content/deadline_exceeded.html")
        except CapabilityDisabledError, exception:
            logging.exception(exception)
            # assume the site is in maintenance if we get CDE
            return http.HttpResponseRedirect("/maintenance")
        except MemoryError, exception:
            logging.exception(exception)
            return http.HttpResponseRedirect("/soc/content/memory_error.html")
        except AssertionError, exception:
            logging.exception(exception)
            return http.HttpResponseRedirect("/soc/content/assertion_error.html")
        except out_of_band.Error, error:
            return responses.errorResponse(error, request)

    return view_wrapper


def merge_params(func):
    """Decorator that merges 'params' with self._params.
  """

    @wraps(func)
    def wrapper(self, *args, **kwargs):
        """Decorator wrapper method.
    """
        params = kwargs.get("params", {})
        kwargs["params"] = dicts.merge(params, self._params)
        return func(self, *args, **kwargs)