예제 #1
0
 def test_amend(self):
     computer = Amender()
     spannifier = Spannifier()
     
     for input, comments, expectedResult in tests_input :
         res = computer.amend(input, comments)
         res = spannifier.unspannify_new(res)
         self.assertEqual(unicode(res),unicode(expectedResult))
예제 #2
0
파일: client.py 프로젝트: cc-archive/coment
def apply_amendments(request, version_id):
     location = "#"
     
     text_version = TextVersion.objects.get(id=version_id)
     spanned_content = text_version.get_spanned_content()
     
     # looking for comments with amendment state :
     amendment_comments, amendment_dis = text_version.get_amendments() 
     amendments = [(comment.start_word, comment.end_word, comment.content) for comment in amendment_comments] 
     amendments.extend([(di.comment.start_word, di.comment.end_word, di.content) for di in amendment_dis])

     if amendments :
         # apply amendments to compute new spanned content
         amender = Amender()
         modified_spanned_content = amender.amend(spanned_content, amendments)
    
         # unspan new content
         spannifier = Spannifier()
         new_content = unicode(spannifier.unspannify_new(modified_spanned_content))
         new_version = TextVersion.objects.duplicate(text_version, request.user, keep_comments=True, keep_dates = False)
         
         # remove amendments from new version :
         amendment_comments, amendment_dis = new_version.get_amendments() 
         amendment_dis.delete()
         amendment_comments.delete()
         
         # call edit to input new content and manage coment positioning
         new_version.edit(new_title = new_version.title, 
                     new_note = _(u'amended version'),
                     new_tags = new_version.tags, 
                     new_content = new_content,
                     keep_comments=True
                     )
         location = reverse('text-viewandcomment',args=[text_version.text_id])
     if amendments :
         success_message = _(u"amendments were applied with success")
     else :
         success_message = _(u"there are no amendments on this text")
     return True, location, success_message