Example #1
0
    def process_request(self, request):
        """
        Called for every request. If the website is unavailable, or a request.method that would modify the database is
        invoked without a connection to a primary, returns an HTTP Service Unavailable response.
        """

        if settings.SERVICE_UNAVAILABLE or (request.method not in ("GET", "HEAD") and not mongoengine_is_primary()):
            # Can't use render because there is no context
            return response_service_unavailable()
Example #2
0
    def process_view(self, request, view_func, view_args, view_kwargs):
        """
        Called for every view, and catches database connection issues to serve the proper maintenance page.
        """
        try:
            return view_func(request, *view_args, **view_kwargs)
        except mongoengine.connection.ConnectionError as err:
            getLogger('app').error('Database access error: %s', err)

            return response_service_unavailable()
    def process_request(self, request):
        """
        Called for every request. If the website is unavailable, or a request.method that would modify the database is
        invoked, returns an HTTP Service Unavailable response.
        """

        if (settings.SERVICE_UNAVAILABLE
                or (settings.SITE_READ_ONLY
                    and request.method not in ("GET", "HEAD"))):
            # Can't use render because there is no context
            return response_service_unavailable()
    def process_view(self, request, view_func, view_args, view_kwargs):
        """
        Called for every view, and catches database connection issues to serve the proper maintenance page.
        """
        try:
            return view_func(request, *view_args, **view_kwargs)
        except (mongoengine.connection.ConnectionError, DatabaseWriteDenied) as err:
            # TODO: Raise a DatabaseWriteDenied exception when trying to write to the database when in readonly mode.
            # Currently we rely on the developer checking settings.SITE_READ_ONLY in GET views.
            getLogger('app').error('Database access error: %s' % err)

            return response_service_unavailable()
    def process_request(self, request):
        """
        Called for every request. If the website is unavailable, or a request.method that would modify the database is
        invoked, returns an HTTP Service Unavailable response.
        """

        if (
            settings.SERVICE_UNAVAILABLE
            or (settings.SITE_READ_ONLY and request.method not in ("GET", "HEAD"))
        ):
            # Can't use render because there is no context
            return response_service_unavailable()
    def process_view(self, request, view_func, view_args, view_kwargs):
        """
        Called for every view, and catches database connection issues to serve the proper maintenance page.
        """
        try:
            return view_func(request, *view_args, **view_kwargs)
        except (mongoengine.connection.ConnectionError,
                DatabaseWriteDenied) as err:
            # TODO: Raise a DatabaseWriteDenied exception when trying to write to the database when in readonly mode.
            # Currently we rely on the developer checking settings.SITE_READ_ONLY in GET views.
            getLogger('app').error('Database access error: %s' % err)

            return response_service_unavailable()
Example #7
0
 def test_unavailable(self):
     self.assertEquals(response_service_unavailable().status_code, HTTP_SERVICE_UNAVAILABLE)