Exemple #1
0
def blog_edit_item(item, **kwargs):
    typecheck(item, qon.blog.BlogItem)

    if kwargs.has_key('summary'):
        new_summary = _unicode_fix(kwargs['summary'])
    
        if item.title == 'comment':
            if not item.history:
                # start the history with the original message
                item.history = "---- Original Content from %s ----\n%s\n" % \
                    (format_datetime(item.date), item.get_summary())
    
            # append the diff from the current state to the new state to the history
            import difflib
            prev = item.get_summary().splitlines()
            current = new_summary.splitlines()
            diffs = list(difflib.unified_diff(prev, current, n=1, lineterm=''))
            date = format_datetime(datetime.utcnow())
            item.history = "%s\n---- Edit on %s ----\n%s\n" % (item.history, date, '\n'.join(diffs[2:]))

        # change the summary
        item.set_summary(new_summary)
        del kwargs['summary']

    _set_attributes(item, **kwargs)
    item.modified = datetime.utcnow()
    item._p_changed = 1
    
    transaction_commit(None, 'EditBlogItem')   # moved from blog/form.ptl/EditBlogItemForm.commit()

    if item.title == 'comment' or item.not_watchable:   # XXX hack to find comment
        assert(item.parent_blogitem)
        qon.search.searchengine.notify_edited_blog_comment(item)
    else:
        # handle edited blog entries
        qon.search.searchengine.notify_edited_blog_item(item)
Exemple #2
0
    def add_comment(self, user, category, priority, text, extra_header=''):
        """Add a comment to an existing ticket. Simply appends a separator
        line and text."""
        if text is None:
            text = ''
        self.modified = datetime.utcnow()

        from ui.blocks.util import format_datetime    
        date = format_datetime(self.modified)

        self.category = category
        self.priority = priority
        
        if self.text is None:
            self.text = ''
            
        self.text += '\n\n' + ('-' * 40) + '\n' + \
            'Comment by: %s\n' % user.display_name() + \
            'Date: %s\n' % date + \
            extra_header + \
            '\n' + \
            text.strip()
            
        user.karma_activity_credit()