Пример #1
0
def push(record, channel_id=None):
    """Send a log record via channel API.
    
    record -- log record to push
    channel_id

    If channel_id is supplied, the message will only be sent to the
    corresponding channel.
    """

    template_values = {
        'message': cgi.escape(record.message),
        'filename': cgi.escape(record.filename),
        'funcname': cgi.escape(record.funcName),
        'levelname': cgi.escape(record.levelname),
        'lineno': str(record.lineno),
        }

    data = {
        'html' : render_to_string('log_record_li.html',
                                  template_values)
        }

    if channel_id:
        channel.send_message(channel_id, simplejson.dumps(data))
    else:
        [channel.send_message(channel_id, simplejson.dumps(data))
         for channel_id in _get_channels()]
Пример #2
0
    def _add_input_handler(self, message=None):
        """Interactive filter creation. The function populates a
        dictionary with the user's replies which is used to construct
        the RecordFilter object.
        """
        global _input_index, _is_input

        fields = len(_input_fields)

        if _input_index <= fields:
            # first question, no previous answer
            if _input_index > 0:
                # store answer for previous question
                _input_values[_input_fields[_input_index - 1]] = message.body

        if _input_index < fields:
            # show next message
            template_values = {'i': _input_index}
            message.reply(render_to_string('filter_add.plain',
                                           template_values))
            _input_index += 1

        elif _input_index == fields:
            # end of questions
            jid = _sender_jid(message)
            filters.add_filter(jid, **_input_values)
            _is_input = False
            _input_index = 0
            message.reply('Filter added')
Пример #3
0
    def get(self):
        self.response.headers['Content-Type'] = 'text/html'
        user = users.get_current_user()

        template_values = {
            'subscriber': filters.is_subscriber(user.email()),
            'token' : channel.register_channel(user.user_id()),
            'url_prefix': URL_PREFIX,
            }

        self.response.out.write(render_to_string('wall.html',
                                                 template_values))
Пример #4
0
    def get(self):
        """'Add filter' form"""
        template_values = {
            'filename': self.request.get('filename') or '^$',
            'funcname': self.request.get('funcname') or '^$',
            'levelname': self.request.get('levelname') or 'INFO',
            'lineno': self.request.get('lineno') or '^$',
            'message': self.request.get('message') or '^$',
            'url_prefix': URL_PREFIX,
            }

        self.response.out.write(render_to_string('filter_add.html',
                                                 template_values))
Пример #5
0
    def get(self):
        self.response.headers['Content-Type'] = 'text/html'

        template_values = {
            'subscriptions': {},
            'url_prefix': URL_PREFIX
            }

        jid = users.get_current_user().email()
        template_values['subscriptions'][jid] = filters.subscriptions()[jid]

        self.response.out.write(render_to_string('filters.html',
                                                 template_values))
Пример #6
0
    def filters_command(self, message=None):
        """Command handler for /filters
        
        Shows a list of the sender's filters.
        """
        jid = _sender_jid(message)

        template_values = {
            'jid' : jid,
            'filters' : filters.subscriptions()[jid]
            }

        message.reply(render_to_string('filters.plain',
                                       template_values))
Пример #7
0
    def get(self):
        self.response.headers['Content-Type'] = 'text/html'
        user = users.get_current_user()

        template_values = {
            'email': user.email(),
            'subscriber': filters.is_subscriber(user.email()),
            'logout_url': users.create_logout_url(URL_PREFIX),
            'login_url': users.create_login_url(URL_PREFIX),
            'url_prefix': URL_PREFIX,
            }
        
        self.response.out.write(render_to_string('landing.html',
                                                 template_values))
Пример #8
0
def send(record, jid):
    """Send a log record to the given jid"""
    if xmpp.get_presence(jid, FROM_JID):
        template_values = {
            'message': record.message,
            'filename': record.filename,
            'funcname': record.funcName,
            'levelname': record.levelname,
            'lineno' : record.lineno
            }

        xmpp.send_message(jid,
                          render_to_string('bot_log_record.plain',
                                           template_values),
                          FROM_JID)
Пример #9
0
 def unhandled_command(self, message=None):
     """Fallback handler"""
     message.reply(render_to_string('bot_usage.plain',
                                    {}))