(text, post, user)
return dobj
Compute and return Diff object for diff between text and post.content
Compute and return Diff object for diff between text and post.content
Compute and return Diff object for diff between text and post . content
def create_diff(text, post, user):
    """
    Compute and return Diff object for diff between text and post.content
    """

    # Skip on post creation
    if not post:
        return

    ratio = diff_ratio(text1=text, text2=post.content)

    # Skip no changes detected
    if ratio == 1:
        return

    # Compute diff between text and post.
    content = post.content.splitlines()
    text = text.splitlines()

    diff = unified_diff(content, text)
    diff = [f"{line}\n" if not line.endswith('\n') else line for line in diff]
    diff = ''.join(diff)

    # See if a diff has been made by this user in the past 10 minutes
    dobj = Diff.objects.filter(post=post, author=post.author).first()

    # 10 minute time frame between
    frame = 60 * 10
    delta = (util.now() - dobj.created).seconds if dobj else frame

    # Create diff object within time frame or the person editing is a mod.
    if delta >= frame or user != post.author:
        # Create diff object for this user.
        dobj = Diff.objects.create(diff=diff, post=post, author=user)
        post.has_diff = True
        # Only log when anyone but the author commits changes.
        if user != post.author:
            db_logger(user=user, action=Log.EDIT, text=f'edited post', target=post.author, post=post)

    Post.objects.filter(pk=post.pk).update(has_diff=post.has_diff)

    return dobj
def create_diff ( text , post , user ) : # Skip on post creation if not post : return ratio = diff_ratio ( text1 = text , text2 = post . content ) # Skip no changes detected if ratio == 1 : return # Compute diff between text and post. content = post . content . splitlines ( ) text = text . splitlines ( ) diff = unified_diff ( content , text ) diff = [ f"{line}\n" if not line . endswith ( '\n' ) else line for line in diff ] diff = '' . join ( diff ) # See if a diff has been made by this user in the past 10 minutes dobj = Diff . objects . filter ( post = post , author = post . author ) . first ( ) # 10 minute time frame between frame = 60 * 10 delta = ( util . now ( ) - dobj . created ) . seconds if dobj else frame # Create diff object within time frame or the person editing is a mod. if delta >= frame or user != post . author : # Create diff object for this user. dobj = Diff . objects . create ( diff = diff , post = post , author = user ) post . has_diff = True # Only log when anyone but the author commits changes. if user != post . author : db_logger ( user = user , action = Log . EDIT , text = f'edited post' , target = post . author , post = post ) Post . objects . filter ( pk = post . pk ) . update ( has_diff = post . has_diff ) return dobj