예제 #1
0
    def __call__(self, environ, start_response):
        form = get_post(environ)
        comment = form.getfirst('comment', '').strip()
        check = form.getfirst('comment-check')
        question = form.getfirst('comment-question', '').strip()
        request_uri = environ.request_uri()
        submit = True

        if check:
            # try and catch any spam bots as they usually fill in hidden fields
            msg_warn(environ, 'The comment failed the spam filter and was not submitted')
            submit = False
        if question.lower() != 'environmental':
            msg_warn(environ, 'Please answer the question correctly in order to submit your comment')
            submit = False
        if environ.get('HTTP_REFERER') != request_uri:
            msg_error(environ, 'The comment must be submitted from the appropriate page')
            submit = False
        if not comment:
            msg_warn(environ, 'You did not fill in the comment field')
            submit = False

        if submit:
            from ConfigParser import NoOptionError

            email = form.getfirst('comment-email')
            title = form.getfirst('comment-title', 'Unknown page')
            name = form.getfirst('comment-name', 'an anonymous user')
            ip = environ['REMOTE_ADDR']
            subject = 'Comment on ' + title

            msg = "The following comment was sent by %s (IP address %s) using the page at %s\n" % (name, ip, request_uri)
            if email:
                msg += "This user's email address is <%s> (you can contact them by replying to this message).\n\n" % email
            else:
                msg += "This user did not provide an email address.\n\n"
            msg += comment

            # get required variables from the configuration
            config = environ['config']
            to_addr = config.get('DEFAULT', 'email')
            try:
                server = config.get('SMTP', 'server')
            except NoOptionError:
                server = 'localhost'
            try:
                port = config.get('SMTP', 'port')
            except NoOptionError:
                port = 25

            if not email: from_addr = '"MEDIN Portal Comment" <%s>' % to_addr
            else: from_addr = email

            # email the comment
            self.sendComment(from_addr, to_addr, subject, msg, server, port)
            msg_info(environ, 'Thank you for your comment')

        # delegate to the wrapped app
        return self.app(environ, start_response)
예제 #2
0
    def prepareSOAP(self, environ):
        """
        The interface for generating a SOAPCaller
        """
        q = get_query(environ)
        errors = q.verify()
        if errors:
            for error in errors:
                msg_error(environ, error)

        return self.request.prepareCaller(q, self.result_type, environ['logging.logger'])
예제 #3
0
    def prepareSOAP(self, environ):
        """
        The interface for generating a SOAPCaller
        """
        q = get_query(environ)
        errors = q.verify()
        if errors:
            for error in errors:
                msg_error(environ, error)

        return self.request.prepareCaller(q, self.result_type,
                                          environ['logging.logger'])
예제 #4
0
    def prepareSOAP(self, environ):
        """
        The interface for generating a SOAPCaller
        """
        from medin.dws import RESULT_SIMPLE

        q = get_query(environ)
        errors = q.verify()
        if errors:
            for error in errors:
                msg_error(environ, error)

        q.setCount(0)                   # we only need one result

        # Get the results in descending order so the result can be
        # used in an etag (as it is the latest).
        sort = q.getSort(cast=False)
        q.setSort('updated,0')

        # generate the soap caller
        return self.request.prepareCaller(q, RESULT_SIMPLE, environ['logging.logger'])
예제 #5
0
    def prepareSOAP(self, environ):
        """
        The interface for generating a SOAPCaller
        """
        from medin.dws import RESULT_SIMPLE

        q = get_query(environ)
        errors = q.verify()
        if errors:
            for error in errors:
                msg_error(environ, error)

        q.setCount(0)  # we only need one result

        # Get the results in descending order so the result can be
        # used in an etag (as it is the latest).
        sort = q.getSort(cast=False)
        q.setSort('updated,0')

        # generate the soap caller
        return self.request.prepareCaller(q, RESULT_SIMPLE,
                                          environ['logging.logger'])
예제 #6
0
    def __call__(self, environ, start_response):
        form = get_post(environ)
        comment = form.getfirst('comment', '').strip()
        check = form.getfirst('comment-check')
        question = form.getfirst('comment-question', '').strip()
        request_uri = environ.request_uri()
        submit = True

        if check:
            # try and catch any spam bots as they usually fill in hidden fields
            msg_warn(
                environ,
                'The comment failed the spam filter and was not submitted')
            submit = False
        if question.lower() != 'environmental':
            msg_warn(
                environ,
                'Please answer the question correctly in order to submit your comment'
            )
            submit = False
        if environ.get('HTTP_REFERER') != request_uri:
            msg_error(
                environ,
                'The comment must be submitted from the appropriate page')
            submit = False
        if not comment:
            msg_warn(environ, 'You did not fill in the comment field')
            submit = False

        if submit:
            from ConfigParser import NoOptionError

            email = form.getfirst('comment-email')
            title = form.getfirst('comment-title', 'Unknown page')
            name = form.getfirst('comment-name', 'an anonymous user')
            ip = environ['REMOTE_ADDR']
            subject = 'Comment on ' + title

            msg = "The following comment was sent by %s (IP address %s) using the page at %s\n" % (
                name, ip, request_uri)
            if email:
                msg += "This user's email address is <%s> (you can contact them by replying to this message).\n\n" % email
            else:
                msg += "This user did not provide an email address.\n\n"
            msg += comment

            # get required variables from the configuration
            config = environ['config']
            to_addr = config.get('DEFAULT', 'email')
            try:
                server = config.get('SMTP', 'server')
            except NoOptionError:
                server = 'localhost'
            try:
                port = config.get('SMTP', 'port')
            except NoOptionError:
                port = 25

            if not email: from_addr = '"MEDIN Portal Comment" <%s>' % to_addr
            else: from_addr = email

            # email the comment
            self.sendComment(from_addr, to_addr, subject, msg, server, port)
            msg_info(environ, 'Thank you for your comment')

        # delegate to the wrapped app
        return self.app(environ, start_response)