Esempio n. 1
0
    def handle_submit(self, converted):
        context = self.context
        request = self.request
        parent = context.__parent__
        creator = authenticated_userid(request)
        comment = create_content(
            IComment,
            'Re: %s' % parent.title,
            converted['add_comment'],
            extract_description(converted['add_comment']),
            creator,
        )
        next_id = parent['comments'].next_id
        parent['comments'][next_id] = comment
        workflow = get_workflow(IComment, 'security', context)
        if workflow is not None:
            workflow.initialize(comment)
            if 'security_state' in converted:
                workflow.transition_to_state(comment, request,
                                             converted['security_state'])

        if support_attachments(comment):
            upload_attachments(converted['attachments'], comment, creator,
                               request)
        relocate_temp_images(comment, request)

        if converted.get('sendalert'):
            alerts = queryUtility(IAlerts, default=Alerts())
            alerts.emit(comment, request)

        location = resource_url(parent, request)
        msg = 'Comment added'
        location = '%s?status_message=%s' % (location, urllib.quote(msg))
        self.filestore.clear()
        return HTTPFound(location=location)
Esempio n. 2
0
    def handle_submit(self, converted):
        request = self.request
        context = self.context
        workflow = self.workflow
        wikipage = create_content(
            IWikiPage,
            converted['title'],
            converted['text'],
            extract_description(converted['text']),
            authenticated_userid(request),
        )

        name = make_name(context, converted['title'])
        context[name] = wikipage

        if workflow is not None:
            workflow.initialize(wikipage)
            if 'security_state' in converted:
                workflow.transition_to_state(wikipage, request,
                                             converted['security_state'])

        # Save the tags on it.
        set_tags(wikipage, request, converted['tags'])

        relocate_temp_images(wikipage, request)

        if converted['sendalert']:
            alerts = queryUtility(IAlerts, default=Alerts())
            alerts.emit(wikipage, request)

        msg = '?status_message=Wiki%20Page%20created'
        location = resource_url(wikipage, request) + msg
        return HTTPFound(location=location)
Esempio n. 3
0
def digest(root, closer, registry, frequency):
    if not is_normal_mode(registry):
        log.info("Cannot send mails; running in maintenance mode.")
        sys.exit(1)
    alerts = Alerts()
    freq = frequency
    alerts.send_digests(root, freq)
Esempio n. 4
0
    def handle(self, message, info, text, attachments):
        """ See IMailinHandler.
        """
        entry = create_content(
            IBlogEntry,
            title=info['subject'],
            creator=info['author'],
            text=text,
            description=extract_description(text),
        )
        entry.created = info['date']

        if attachments:
            if 'attachments' not in entry:
                # XXX Not a likely code path, left here for safety
                entry['attachments'] = att_folder = AttachmentsFolder()
                att_folder.title = 'Attachments'
                att_folder.creator = info['author']
            else:
                att_folder = entry['attachments']
            _addAttachments(att_folder, info, attachments)

        entry_id = make_unique_name(self.context, entry.title)
        self.context[entry_id] = entry

        workflow = get_workflow(IBlogEntry, 'security', self.context)
        if workflow is not None:
            workflow.initialize(entry)

        alerts = queryUtility(IAlerts, default=Alerts())
        alerts.emit(entry, offline_request)
Esempio n. 5
0
    def handle(self, message, info, text, attachments):
        """ See IMailinHandler.
        """
        target = self.context['comments']
        reply = create_content(
            IComment,
            title=info['subject'],
            creator=info['author'],
            text=text,
            description=extract_description(text),
        )

        reply.title = info['subject']
        reply.creator = info['author']
        reply.created = info['date']
        reply.text = text

        target[target.next_id] = reply

        workflow = get_workflow(IComment, 'security', target)
        if workflow is not None:
            workflow.initialize(reply)

        if attachments:
            _addAttachments(reply, info, attachments)

        # Mailin always sends alerts
        alerts = queryUtility(IAlerts, default=Alerts())
        alerts.emit(reply, offline_request)
Esempio n. 6
0
File: forum.py Progetto: lslaz1/karl
    def handle_submit(self, converted):
        request = self.request
        context = self.context
        workflow = self.workflow

        forum = create_content(
            IForum,
            converted['title'],
            converted['description'],
            authenticated_userid(request),
        )

        name = make_unique_name(context, converted['title'])
        context[name] = forum

        # Set up workflow
        if workflow is not None:
            workflow.initialize(forum)
            if 'security_state' in converted:
                workflow.transition_to_state(forum, request,
                                             converted['security_state'])

        if 'sendalert' in converted and converted['sendalert']:
            alerts = queryUtility(IAlerts, default=Alerts())
            alerts.emit(forum, request)
        location = resource_url(forum, request)
        return HTTPFound(location=location)
Esempio n. 7
0
    def handle_submit(self, converted):
        context = self.context
        request = self.request
        workflow = self.workflow
        name = make_unique_name(context, converted['title'])

        creator = authenticated_userid(request)

        blogentry = create_content(
            IBlogEntry,
            converted['title'],
            converted['text'],
            extract_description(converted['text']),
            creator,
        )

        context[name] = blogentry

        # Set up workflow
        if workflow is not None:
            workflow.initialize(blogentry)
            if 'security_state' in converted:
                workflow.transition_to_state(blogentry, request,
                                             converted['security_state'])

        # Tags, attachments, alerts, images
        set_tags(blogentry, request, converted['tags'])
        attachments_folder = blogentry['attachments']
        upload_attachments(
            filter(lambda x: x is not None, converted['attachments']),
            attachments_folder, creator, request)
        relocate_temp_images(blogentry, request)

        if converted['sendalert']:
            alerts = queryUtility(IAlerts, default=Alerts())
            alerts.emit(blogentry, request)

        location = resource_url(blogentry, request)
        self.filestore.clear()
        return HTTPFound(location=location)
Esempio n. 8
0
File: digest.py Progetto: zagy/karl
def main():
    parser = optparse.OptionParser(description=__doc__)
    parser.add_option('-C', '--config', dest='config',
        default=None,
        help='Path to configuration file (defaults to $CWD/etc/karl.ini)',
        metavar='FILE')
    parser.add_option('-l', '--log-file', dest='log_file',
        default=None,
        help="log file name (default to stderr)")
    parser.add_option('--daemon', '-D', dest='daemon',
                      action='store_true', default=False,
                      help='Run in daemon mode.')
    parser.add_option('--interval', '-i', dest='interval', type='int',
                      default=6*3600,
                      help='Interval, in seconds, between executions when in '
                           'daemon mode.')

    options, args = parser.parse_args()

    if options.log_file:
        logging.basicConfig(filename=options.log_file)
    else:
        logging.basicConfig() # log to stderr

    config = options.config
    if config is None:
        config = get_default_config()
    app = loadapp('config:%s' % config, 'karl')
    alerts = queryUtility(IAlerts, default=Alerts())

    def run():
        set_subsystem('digest')
        root, closer = get_root(app)
        alerts.send_digests(root)
        closer()

    if options.daemon:
        run_daemon('digest', run, options.interval)
    else:
        run()
Esempio n. 9
0
File: forum.py Progetto: lslaz1/karl
    def handle_submit(self, converted):
        context = self.context
        request = self.request
        workflow = self.workflow

        name = make_unique_name(context, converted['title'])
        creator = authenticated_userid(request)

        topic = create_content(
            IForumTopic,
            converted['title'],
            converted['text'],
            creator,
        )

        topic.description = extract_description(converted['text'])
        context[name] = topic

        # Set up workflow
        if workflow is not None:
            workflow.initialize(topic)
            if 'security_state' in converted:
                workflow.transition_to_state(topic, request,
                                             converted['security_state'])

        # send the temp images to their final place
        relocate_temp_images(topic, request)

        # Tags and attachments
        set_tags(topic, request, converted['tags'])
        if support_attachments(topic):
            upload_attachments(converted['attachments'], topic['attachments'],
                               creator, request)

        if 'sendalert' in converted and converted['sendalert']:
            alerts = queryUtility(IAlerts, default=Alerts())
            alerts.emit(topic, request)
        location = resource_url(topic, request)
        return HTTPFound(location=location)
Esempio n. 10
0
 def _get_instance(self):
     from karl.utilities.alerts import Alerts
     return Alerts()