def test_partial_accept(self): text1 = "Organisation de conferences lors de la Fete de la science" text2 = "Organisation mon texte de la Fete de la autre texte science" soup_wrapped, textdiff = html_diff_wrapper.render_html_diff( text1, text2, 'modif') correction_tags = soup_wrapped.find_all('span', {'id': "modif"}) descriminator = 0 for correction_tag in correction_tags: correction_tag['data-item'] = str(descriminator) descriminator += 1 result = html_diff_wrapper.soup_to_text(soup_wrapped) #2 modifs self.assertEqual( result, 'Organisation <span data-item="0" id="modif"><del>de conferences lors</del><ins>mon texte</ins></span> de la Fete de la <span data-item="1" id="modif"><ins>autre texte </ins></span>science' ) items = ['0'] corrections = [] for item in items: corrections.extend( soup_wrapped.find_all('span', { 'id': 'modif', 'data-item': item })) #resfuse the first modif soup = html_diff_wrapper.include_diffs(soup_wrapped, corrections, "ins", "del", None) result = html_diff_wrapper.soup_to_text(soup) self.assertEqual( result, 'Organisation de conferences lors de la Fete de la <span data-item="1" id="modif"><ins>autre texte </ins></span>science' ) items = ['1'] corrections = [] for item in items: corrections.extend( soup_wrapped.find_all('span', { 'id': 'modif', 'data-item': item })) #accept the last modif soup = html_diff_wrapper.include_diffs(soup_wrapped, corrections, "del", "ins", None) result = html_diff_wrapper.soup_to_text(soup) #the text with only the last modif self.assertEqual( result, 'Organisation de conferences lors de la Fete de la autre texte science' ) soup_wrapped, textdiff = html_diff_wrapper.render_html_diff( text1, result, 'modif') result = html_diff_wrapper.soup_to_text(soup_wrapped) #1 modif (accepted modif) self.assertEqual( result, 'Organisation de conferences lors de la Fete de la <span id="modif"><ins>autre texte </ins></span>science' )
def start(self, context, request, appstruct, **kw): user = get_current(request) user = context.working_group.get_member(user) correction = appstruct['_object_data'] correction.text = html_diff_wrapper.normalize_text(correction.text) old_text = correction.text correction.setproperty('author', user) version = context.get_version(user, (context, 'version')) context.addtoproperty('corrections', correction) correction.setproperty('current_version', version) context.setproperty('version', version.version) souptextdiff, textdiff = html_diff_wrapper.render_html_diff( getattr(context, 'text', ''), getattr(correction, 'text', ''), "correction") soupdescriptiondiff, descriptiondiff = html_diff_wrapper.render_html_diff( getattr(context, 'description', ''), getattr(correction, 'description', ''), "correction") souptitlediff, titlediff = html_diff_wrapper.render_html_diff( getattr(context, 'title', ''), getattr(correction, 'title', ''), "correction") descriminator = 0 descriminator = self._identify_corrections(souptitlediff, correction, descriminator, 'title', user) self._add_actions(correction, request, souptitlediff) descriminator = self._identify_corrections(soupdescriptiondiff, correction, descriminator, 'description', user) self._add_actions(correction, request, soupdescriptiondiff) self._identify_corrections(souptextdiff, correction, descriminator, 'text', user) self._add_actions(correction, request, souptextdiff) correction.text = html_diff_wrapper.soup_to_text(souptextdiff) correction.description = html_diff_wrapper.soup_to_text(soupdescriptiondiff) correction.title = html_diff_wrapper.soup_to_text(souptitlediff) if souptextdiff.find_all("span", id="correction") or \ soupdescriptiondiff.find_all("span", id="correction") or\ souptitlediff.find_all("span", id="correction"): correction.state.append('in process') alert('internal', [request.root], context.working_group.members, internal_kind=InternalAlertKind.working_group_alert, subjects=[context], alert_kind='correction_added') else: context.text = old_text return {}
def test_render_htmldiff(self): text_origin = "Organiser des <strong>animation</strong> lors de la Fete de la science." text = "Organiser des lors de la Fete de la science." soup, diff = html_diff_wrapper.render_html_diff(text_origin, text) self.assertEqual(diff, '<div class="diff">Organiser des <span id="diff_id"><del><strong>animation</strong> </del></span>lors de la Fete de la science.</div>') text_origin = "Organiser des <strong>animation</strong> lors de <strong>la Fete</strong> de la science." text = "Organiser des lors de <strong>la Fete</strong> de la science." soup, diff = html_diff_wrapper.render_html_diff(text_origin, text) self.assertEqual(diff, '<div class="diff">Organiser des <span id="diff_id"><del><strong>animation</strong> </del></span>lors de <strong><strong>la Fete</strong> de la science.</strong></div>')
def start(self, context, request, appstruct, **kw): user = get_current(request) user = context.working_group.get_member(user) correction = appstruct['_object_data'] correction.text = html_diff_wrapper.normalize_text(correction.text) old_text = correction.text correction.setproperty('author', user) version = context.get_version(user, (context, 'version')) context.addtoproperty('corrections', correction) correction.setproperty('current_version', version) context.setproperty('version', version.version) souptextdiff, textdiff = html_diff_wrapper.render_html_diff( getattr(context, 'text', ''), getattr(correction, 'text', ''), "correction") soupdescriptiondiff, descriptiondiff = html_diff_wrapper.render_html_diff( getattr(context, 'description', ''), getattr(correction, 'description', ''), "correction") souptitlediff, titlediff = html_diff_wrapper.render_html_diff( getattr(context, 'title', ''), getattr(correction, 'title', ''), "correction") descriminator = 0 descriminator = self._identify_corrections(souptitlediff, correction, descriminator, 'title', user) self._add_actions(correction, request, souptitlediff) descriminator = self._identify_corrections(soupdescriptiondiff, correction, descriminator, 'description', user) self._add_actions(correction, request, soupdescriptiondiff) self._identify_corrections(souptextdiff, correction, descriminator, 'text', user) self._add_actions(correction, request, souptextdiff) correction.text = html_diff_wrapper.soup_to_text(souptextdiff) correction.description = html_diff_wrapper.soup_to_text( soupdescriptiondiff) correction.title = html_diff_wrapper.soup_to_text(souptitlediff) if souptextdiff.find_all("span", id="correction") or \ soupdescriptiondiff.find_all("span", id="correction") or\ souptitlediff.find_all("span", id="correction"): correction.state.append('in process') alert('internal', [request.root], context.working_group.members, internal_kind=InternalAlertKind.working_group_alert, subjects=[context], alert_kind='correction_added') else: context.text = old_text return {}
def update(self): result = {} site = get_site_folder(True, self.request) user = get_current(self.request) is_manager = has_any_roles( user=user, roles=('Admin', ('SiteAdmin', site))) or\ is_site_moderator(self.request) duplicates = find_duplicates_artist(self.context, self.duplicates_state) diff_bodies = {} context_view = self.content( args={'object': self.context}, template=self.context.templates.get('diff', None))['body'] for duplicate in duplicates: duplicate_view = self.content( args={'object': duplicate}, template=duplicate.templates.get('diff', None))['body'] soupt, textdiff = html_diff_wrapper.render_html_diff( context_view, duplicate_view) diff_bodies[duplicate] = (textdiff, get_oid(duplicate)) values = {'context': self.context, 'oid': get_oid(self.context), 'context_view': context_view, 'contents': diff_bodies, 'row_len': math.ceil(len(diff_bodies)/2), 'is_manager': is_manager, 'view': self} body = self.content(args=values, template=self.template)['body'] item = self.adapt_item(body, self.viewid) result['coordinates'] = {self.coordinates: [item]} return result
def update(self): result = {} duplicates = get_duplicates(self.context) diff_bodies = {} context_view = self.content(args={'object': self.context}, template=self.context.templates.get( 'diff', None))['body'] for duplicate in duplicates: duplicate_view = self.content(args={'object': duplicate}, template=duplicate.templates.get( 'diff', None))['body'] soupt, textdiff = html_diff_wrapper.render_html_diff( context_view, duplicate_view) diff_bodies[duplicate] = (textdiff, get_oid(duplicate)) values = { 'context': self.context, 'oid': get_oid(self.context), 'context_view': context_view, 'contents': diff_bodies, 'view': self } body = self.content(args=values, template=self.template)['body'] item = self.adapt_item(body, self.viewid) result['coordinates'] = {self.coordinates: [item]} return result
def update(self): result = {} duplicates = get_duplicates(self.context) diff_bodies = {} context_view = self.content( args={'object': self.context}, template=self.context.templates.get('diff', None))['body'] for duplicate in duplicates: duplicate_view = self.content( args={'object': duplicate}, template=duplicate.templates.get('diff', None))['body'] soupt, textdiff = html_diff_wrapper.render_html_diff( context_view, duplicate_view) diff_bodies[duplicate] = (textdiff, get_oid(duplicate)) values = {'context': self.context, 'oid': get_oid(self.context), 'context_view': context_view, 'contents': diff_bodies, 'view': self} body = self.content(args=values, template=self.template)['body'] item = self.adapt_item(body, self.viewid) result['coordinates'] = {self.coordinates: [item]} return result
def test_different_treatments_in_one_sentence(self): text1 = "fete de la science.Organiser des animations lors de la Fete de la science qui se deroule au mois d'octobre. Programme: - conferences - expositions - autres" text2 = "Fete de la science. Organiser des animations lors de la Fete de la science qui se deroule au mois du 24/09/2014 au 19/10/2014. Programme: - conferences - expositions - autres" soup, textdiff = html_diff_wrapper.render_html_diff( text1, text2, 'modif') spanids_data = [] spans = soup.find_all('span', {'id': "modif"}) descriminator = 1 for span in spans: span['data-item'] = str(descriminator) descriminator += 1 fselection = self._include_spanids(spans[0:2], "del", "ins") for span in fselection: spanids_data.append(span) lselection = self._include_spanids(spans[2:], "ins", "del") for span in lselection: spanids_data.append(span) html_diff_wrapper.unwrap_diff(spanids_data, soup) soup_to_text = html_diff_wrapper.soup_to_text(soup) self.assertEqual( soup_to_text, "Fete de la science. Organiser des animations lors de la Fete de la science qui se deroule au mois d'octobre. Programme: - conferences - expositions - autres" )
def start(self, context, request, appstruct, **kw): user = get_current() source = appstruct['source'] targets = appstruct['targets'] if can_access(user, source) and all(can_access(user, target) for target in targets): diff_bodies = {} source_view = renderers.render( source.templates.get('diff', None), {'object': source}, request) for target in targets: target_view = renderers.render( target.templates.get('diff', None), {'object': target}, request) soupt, textdiff = html_diff_wrapper.render_html_diff( source_view, target_view) diff_bodies[target] = (textdiff, get_oid(target)) return {'context_view': source_view, 'contents': diff_bodies} return {}
def test_render_htmldiff(self): text_origin = "Organiser des <strong>animation</strong> lors de la Fete de la science." text = "Organiser des lors de la Fete de la science." soup, diff = html_diff_wrapper.render_html_diff(text_origin, text) self.assertEqual( diff, '<div class="diff">Organiser des <span id="diff_id"><del><strong>animation</strong> </del></span>lors de la Fete de la science.</div>' ) text_origin = "Organiser des <strong>animation</strong> lors de <strong>la Fete</strong> de la science." text = "Organiser des lors de <strong>la Fete</strong> de la science." soup, diff = html_diff_wrapper.render_html_diff(text_origin, text) self.assertEqual( diff, '<div class="diff">Organiser des <span id="diff_id"><del><strong>animation</strong> </del></span>lors de <strong><strong>la Fete</strong> de la science.</strong></div>' )
def get_explanation_diff(self, context, request): proposal = context.proposal souptextdiff, textdiff = html_diff_wrapper.render_html_diff( getattr(proposal, 'text', ''), getattr(context, 'text', ''), "explanation") descriminator = 1 explanations = self._identify_explanations(context, request, souptextdiff, descriminator) return souptextdiff, explanations
def get_explanation_diff(self, context, request): proposal = context.proposal souptextdiff, textdiff = html_diff_wrapper.render_html_diff( getattr(proposal, 'text', ''), getattr(context, 'text', ''), "explanation") descriminator = 1 explanations = self._identify_explanations(context, request, souptextdiff, descriminator) return souptextdiff, explanations
def update(self): version = self.params('version') titlediff = '' textdiff = '' descriptiondiff = '' keywordsdiff = [] versionobj = None if version is not None: versionobj = get_obj(int(version)) soupt, textdiff = html_diff_wrapper.render_html_diff( getattr(versionobj, 'text', ''), getattr(self.context, 'text', '')) soupd, descriptiondiff = html_diff_wrapper.render_html_diff( '<div>'+getattr(versionobj, 'description', '')+'</div>', '<div>'+getattr(self.context, 'description', '')+'</div>') soupt, titlediff = html_diff_wrapper.render_html_diff( getattr(versionobj, 'title', ''), getattr(self.context, 'title', '')) for k in versionobj.keywords: if k in self.context.keywords: keywordsdiff.append({'title': k, 'state': 'nothing'}) else: keywordsdiff.append({'title': k, 'state': 'del'}) [keywordsdiff.append({'title': k, 'state': 'ins'}) for k in self.context.keywords if k not in versionobj.keywords] result = {} values = { 'version': versionobj, 'idee': self.context, 'textdiff': textdiff, 'titlediff': titlediff, 'descriptiondiff': descriptiondiff, 'keywordsdiff': keywordsdiff } body = self.content(args=values, template=self.template)['body'] item = self.adapt_item(body, self.viewid) result['coordinates'] = {self.coordinates: [item]} return result
def test_partial_accept(self): text1 = "Organisation de conferences lors de la Fete de la science" text2 = "Organisation mon texte de la Fete de la autre texte science" soup_wrapped, textdiff = html_diff_wrapper.render_html_diff(text1, text2, 'modif') correction_tags = soup_wrapped.find_all('span', {'id': "modif"}) descriminator = 0 for correction_tag in correction_tags: correction_tag['data-item'] = str(descriminator) descriminator += 1 result = html_diff_wrapper.soup_to_text(soup_wrapped) #2 modifs self.assertEqual(result, 'Organisation <span data-item="0" id="modif"><del>de conferences lors</del><ins>mon texte</ins></span> de la Fete de la <span data-item="1" id="modif"><ins>autre texte </ins></span>science') items = ['0'] corrections = [] for item in items: corrections.extend(soup_wrapped.find_all('span', {'id':'modif', 'data-item': item})) #resfuse the first modif soup = html_diff_wrapper.include_diffs(soup_wrapped, corrections, "ins", "del", None) result = html_diff_wrapper.soup_to_text(soup) self.assertEqual(result, 'Organisation de conferences lors de la Fete de la <span data-item="1" id="modif"><ins>autre texte </ins></span>science') items = ['1'] corrections = [] for item in items: corrections.extend(soup_wrapped.find_all('span', {'id':'modif', 'data-item': item})) #accept the last modif soup = html_diff_wrapper.include_diffs(soup_wrapped, corrections, "del", "ins", None) result = html_diff_wrapper.soup_to_text(soup) #the text with only the last modif self.assertEqual(result, 'Organisation de conferences lors de la Fete de la autre texte science') soup_wrapped, textdiff = html_diff_wrapper.render_html_diff(text1, result, 'modif') result = html_diff_wrapper.soup_to_text(soup_wrapped) #1 modif (accepted modif) self.assertEqual(result, 'Organisation de conferences lors de la Fete de la <span id="modif"><ins>autre texte </ins></span>science')
def start(self, context, request, appstruct, **kw): user = get_current() source = appstruct['source'] targets = appstruct['targets'] if can_access(user, source) and all( can_access(user, target) for target in targets): diff_bodies = {} source_view = renderers.render(source.templates.get('diff', None), {'object': source}, request) for target in targets: target_view = renderers.render( target.templates.get('diff', None), {'object': target}, request) soupt, textdiff = html_diff_wrapper.render_html_diff( source_view, target_view) diff_bodies[target] = (textdiff, get_oid(target)) return {'context_view': source_view, 'contents': diff_bodies} return {}
def test_different_treatments_in_one_sentence(self): text1 = "fete de la science.Organiser des animations lors de la Fete de la science qui se deroule au mois d'octobre. Programme: - conferences - expositions - autres" text2 = "Fete de la science. Organiser des animations lors de la Fete de la science qui se deroule au mois du 24/09/2014 au 19/10/2014. Programme: - conferences - expositions - autres" soup, textdiff = html_diff_wrapper.render_html_diff(text1, text2, 'modif') spanids_data = [] spans = soup.find_all('span', {'id': "modif"}) descriminator = 1 for span in spans: span['data-item'] = str(descriminator) descriminator += 1 fselection = self._include_spanids(spans[0:2], "del", "ins") for span in fselection: spanids_data.append(span) lselection = self._include_spanids(spans[2:], "ins", "del") for span in lselection: spanids_data.append(span) html_diff_wrapper.unwrap_diff(spanids_data, soup) soup_to_text = html_diff_wrapper.soup_to_text(soup) self.assertEqual(soup_to_text, "Fete de la science. Organiser des animations lors de la Fete de la science qui se deroule au mois d'octobre. Programme: - conferences - expositions - autres")
def update(self): result = {} site = get_site_folder(True, self.request) user = get_current(self.request) is_manager = has_any_roles( user=user, roles=('Admin', ('SiteAdmin', site))) or\ is_site_moderator(self.request) duplicates = find_duplicates_artist(self.context, self.duplicates_state) diff_bodies = {} context_view = self.content(args={'object': self.context}, template=self.context.templates.get( 'diff', None))['body'] for duplicate in duplicates: duplicate_view = self.content(args={'object': duplicate}, template=duplicate.templates.get( 'diff', None))['body'] soupt, textdiff = html_diff_wrapper.render_html_diff( context_view, duplicate_view) diff_bodies[duplicate] = (textdiff, get_oid(duplicate)) values = { 'context': self.context, 'oid': get_oid(self.context), 'context_view': context_view, 'contents': diff_bodies, 'row_len': math.ceil(len(diff_bodies) / 2), 'is_manager': is_manager, 'view': self } body = self.content(args=values, template=self.template)['body'] item = self.adapt_item(body, self.viewid) result['coordinates'] = {self.coordinates: [item]} return result
def get_text_amendment_diff(proposal, amendment): soup, textdiff = html_diff_wrapper.render_html_diff( getattr(proposal, 'text', ''), getattr(amendment, 'text', '')) return textdiff
def get_text_amendment_diff(proposal, amendment): soup, textdiff = html_diff_wrapper.render_html_diff( getattr(proposal, 'text', ''), getattr(amendment, 'text', '')) return textdiff
def _entry_to_result(self, text1, text2, decision): soup_wrapped, textdiff = html_diff_wrapper.render_html_diff(text1, text2, 'modif') self._unwrap_spans('modif', decision, soup_wrapped) soup_to_text = html_diff_wrapper.soup_to_text(soup_wrapped) return soup_to_text
def _entry_to_result(self, text1, text2, decision): soup_wrapped, textdiff = html_diff_wrapper.render_html_diff( text1, text2, 'modif') self._unwrap_spans('modif', decision, soup_wrapped) soup_to_text = html_diff_wrapper.soup_to_text(soup_wrapped) return soup_to_text