Exemple #1
0
 def edit(self, new_title, new_note, new_tags, new_content, keep_comments):
     "Edit text version with new values, use clever algo to keep comments"
     old_content = self.content
     if not keep_comments :
         self.comment_set.all().delete()
     elif new_content != old_content:
         new_comments = self.comment_set.all() ;
         tomodify_comments, toremove_comments = compute_new_comment_positions(old_content, new_content, new_comments)
         [comment.save() for comment in tomodify_comments]
         [comment.delete() for comment in toremove_comments]
     self.title = new_title
     self.note = new_note
     self.tags = new_tags
     self.content = new_content
     self.save()
Exemple #2
0
def precreate_version(request, version_id):
    previous_version = get_object_or_404(TextVersion,pk = version_id)
    comments = previous_version.comment_set.all() ;
    new_content = request.POST['content']
    create_new_version = request.POST['create_new_version']
    tomodify_comments, toremove_comments = compute_new_comment_positions(previous_version.content, new_content, comments)
    nb_removed = len(toremove_comments)    
    if create_new_version :
        message = ungettext("%(nb_removed)s comment will be removed because its underlying text has been changed. Do you want to continue ?",
                            "%(nb_removed)s comments will be removed because their underlying text has been changed. Do you want to continue ?", 
                            nb_removed) % {'nb_removed' : nb_removed}
    else :
        message = ungettext("%(nb_removed)s comment will be removed because its underlying text has been changed. Since you chose not to create a new version these comments will be definitely lost, do you want to continue ?",
                            "%(nb_removed)s comments will be removed because their underlying text has been changed. Since you chose not to create a new version these comments will be definitely lost, do you want to continue ?", 
                            nb_removed) % {'nb_removed' : nb_removed}
                
    return HttpResponse(simplejson.dumps({"warning_message" : message, 'nb_removed' : nb_removed }))