kopia lustrzana https://github.com/dgtlmoon/changedetection.io
				
				
				
			Filters - Adding "Strip ignored lines" in output option to filters (#3449)
							rodzic
							
								
									c8caa0662d
								
							
						
					
					
						commit
						4b9ae5a97c
					
				| 
						 | 
					@ -191,6 +191,12 @@ nav
 | 
				
			||||||
                        </ul>
 | 
					                        </ul>
 | 
				
			||||||
                     </span>
 | 
					                     </span>
 | 
				
			||||||
                    </fieldset>
 | 
					                    </fieldset>
 | 
				
			||||||
 | 
					                    <fieldset class="pure-group">
 | 
				
			||||||
 | 
					                        {{ render_checkbox_field(form.application.form.strip_ignored_lines) }}
 | 
				
			||||||
 | 
					                        <span class="pure-form-message-inline">Remove any text that appears in the "Ignore text" from the output (otherwise its just ignored for change-detection)<br>
 | 
				
			||||||
 | 
					                        <i>Note:</i> Changing this will change the status of your existing watches, possibly trigger alerts etc.
 | 
				
			||||||
 | 
					                        </span>
 | 
				
			||||||
 | 
					                    </fieldset>
 | 
				
			||||||
           </div>
 | 
					           </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            <div class="tab-pane-inner" id="api">
 | 
					            <div class="tab-pane-inner" id="api">
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -759,6 +759,7 @@ class processor_text_json_diff_form(commonSettingsForm):
 | 
				
			||||||
    check_unique_lines = BooleanField('Only trigger when unique lines appear in all history', default=False)
 | 
					    check_unique_lines = BooleanField('Only trigger when unique lines appear in all history', default=False)
 | 
				
			||||||
    remove_duplicate_lines = BooleanField('Remove duplicate lines of text', default=False)
 | 
					    remove_duplicate_lines = BooleanField('Remove duplicate lines of text', default=False)
 | 
				
			||||||
    sort_text_alphabetically =  BooleanField('Sort text alphabetically', default=False)
 | 
					    sort_text_alphabetically =  BooleanField('Sort text alphabetically', default=False)
 | 
				
			||||||
 | 
					    strip_ignored_lines = TernaryNoneBooleanField('Strip ignored lines', default=None)
 | 
				
			||||||
    trim_text_whitespace = BooleanField('Trim whitespace before and after text', default=False)
 | 
					    trim_text_whitespace = BooleanField('Trim whitespace before and after text', default=False)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    filter_text_added = BooleanField('Added lines', default=True)
 | 
					    filter_text_added = BooleanField('Added lines', default=True)
 | 
				
			||||||
| 
						 | 
					@ -936,6 +937,7 @@ class globalSettingsApplicationForm(commonSettingsForm):
 | 
				
			||||||
    removepassword_button = SubmitField('Remove password', render_kw={"class": "pure-button pure-button-primary"})
 | 
					    removepassword_button = SubmitField('Remove password', render_kw={"class": "pure-button pure-button-primary"})
 | 
				
			||||||
    render_anchor_tag_content = BooleanField('Render anchor tag content', default=False)
 | 
					    render_anchor_tag_content = BooleanField('Render anchor tag content', default=False)
 | 
				
			||||||
    shared_diff_access = BooleanField('Allow anonymous access to watch history page when password is enabled', default=False, validators=[validators.Optional()])
 | 
					    shared_diff_access = BooleanField('Allow anonymous access to watch history page when password is enabled', default=False, validators=[validators.Optional()])
 | 
				
			||||||
 | 
					    strip_ignored_lines = BooleanField('Strip ignored lines')
 | 
				
			||||||
    rss_hide_muted_watches = BooleanField('Hide muted watches from RSS feed', default=True,
 | 
					    rss_hide_muted_watches = BooleanField('Hide muted watches from RSS feed', default=True,
 | 
				
			||||||
                                      validators=[validators.Optional()])
 | 
					                                      validators=[validators.Optional()])
 | 
				
			||||||
    filter_failure_notification_threshold_attempts = IntegerField('Number of times the filter can be missing before sending a notification',
 | 
					    filter_failure_notification_threshold_attempts = IntegerField('Number of times the filter can be missing before sending a notification',
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -57,6 +57,7 @@ class model(dict):
 | 
				
			||||||
                    'rss_hide_muted_watches': True,
 | 
					                    'rss_hide_muted_watches': True,
 | 
				
			||||||
                    'schema_version' : 0,
 | 
					                    'schema_version' : 0,
 | 
				
			||||||
                    'shared_diff_access': False,
 | 
					                    'shared_diff_access': False,
 | 
				
			||||||
 | 
					                    'strip_ignored_lines': False,
 | 
				
			||||||
                    'tags': {}, #@todo use Tag.model initialisers
 | 
					                    'tags': {}, #@todo use Tag.model initialisers
 | 
				
			||||||
                    'timezone': None, # Default IANA timezone name
 | 
					                    'timezone': None, # Default IANA timezone name
 | 
				
			||||||
                    'webdriver_delay': None , # Extra delay in seconds before extracting text
 | 
					                    'webdriver_delay': None , # Extra delay in seconds before extracting text
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -58,6 +58,7 @@ class watch_base(dict):
 | 
				
			||||||
            'proxy': None,  # Preferred proxy connection
 | 
					            'proxy': None,  # Preferred proxy connection
 | 
				
			||||||
            'remote_server_reply': None,  # From 'server' reply header
 | 
					            'remote_server_reply': None,  # From 'server' reply header
 | 
				
			||||||
            'sort_text_alphabetically': False,
 | 
					            'sort_text_alphabetically': False,
 | 
				
			||||||
 | 
					            'strip_ignored_lines': None,
 | 
				
			||||||
            'subtractive_selectors': [],
 | 
					            'subtractive_selectors': [],
 | 
				
			||||||
            'tag': '',  # Old system of text name for a tag, to be removed
 | 
					            'tag': '',  # Old system of text name for a tag, to be removed
 | 
				
			||||||
            'tags': [],  # list of UUIDs to App.Tags
 | 
					            'tags': [],  # list of UUIDs to App.Tags
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -315,6 +315,11 @@ class perform_site_check(difference_detection_processor):
 | 
				
			||||||
        text_for_checksuming = stripped_text_from_html
 | 
					        text_for_checksuming = stripped_text_from_html
 | 
				
			||||||
        if text_to_ignore:
 | 
					        if text_to_ignore:
 | 
				
			||||||
            text_for_checksuming = html_tools.strip_ignore_text(stripped_text_from_html, text_to_ignore)
 | 
					            text_for_checksuming = html_tools.strip_ignore_text(stripped_text_from_html, text_to_ignore)
 | 
				
			||||||
 | 
					            # Some people prefer to also completely remove it
 | 
				
			||||||
 | 
					            strip_ignored_lines = watch.get('strip_ignored_lines') if watch.get('strip_ignored_lines') is not None else self.datastore.data['settings']['application'].get('strip_ignored_lines')
 | 
				
			||||||
 | 
					            if strip_ignored_lines:
 | 
				
			||||||
 | 
					                # @todo add test in the 'preview' mode, check the widget works? compare to datastruct
 | 
				
			||||||
 | 
					                stripped_text_from_html = text_for_checksuming
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # Re #133 - if we should strip whitespaces from triggering the change detected comparison
 | 
					        # Re #133 - if we should strip whitespaces from triggering the change detected comparison
 | 
				
			||||||
        if text_for_checksuming and self.datastore.data['settings']['application'].get('ignore_whitespace', False):
 | 
					        if text_for_checksuming and self.datastore.data['settings']['application'].get('ignore_whitespace', False):
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -34,7 +34,6 @@
 | 
				
			||||||
      transition: all 0.2s ease;
 | 
					      transition: all 0.2s ease;
 | 
				
			||||||
      cursor: pointer;
 | 
					      cursor: pointer;
 | 
				
			||||||
      display: block;
 | 
					      display: block;
 | 
				
			||||||
      min-width: 60px;
 | 
					 | 
				
			||||||
      text-align: center;
 | 
					      text-align: center;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							| 
						 | 
					@ -26,7 +26,10 @@
 | 
				
			||||||
                            <li>Changing this will affect the comparison checksum which may trigger an alert</li>
 | 
					                            <li>Changing this will affect the comparison checksum which may trigger an alert</li>
 | 
				
			||||||
                        </ul>
 | 
					                        </ul>
 | 
				
			||||||
                </span>
 | 
					                </span>
 | 
				
			||||||
 | 
					                <br><br>
 | 
				
			||||||
 | 
					                    <div class="pure-control-group">
 | 
				
			||||||
 | 
					                      {{ render_ternary_field(form.strip_ignored_lines) }}
 | 
				
			||||||
 | 
					                    </div>
 | 
				
			||||||
                </fieldset>
 | 
					                </fieldset>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                <fieldset>
 | 
					                <fieldset>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -58,3 +58,39 @@ def test_ignore(client, live_server, measure_memory_usage):
 | 
				
			||||||
    # Should be in base.html
 | 
					    # Should be in base.html
 | 
				
			||||||
    assert b'csrftoken' in res.data
 | 
					    assert b'csrftoken' in res.data
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def test_strip_ignore_lines(client, live_server, measure_memory_usage):
 | 
				
			||||||
 | 
					   #  live_server_setup(live_server) # Setup on conftest per function
 | 
				
			||||||
 | 
					    set_original_ignore_response()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    # Goto the settings page, add our ignore text
 | 
				
			||||||
 | 
					    res = client.post(
 | 
				
			||||||
 | 
					        url_for("settings.settings_page"),
 | 
				
			||||||
 | 
					        data={
 | 
				
			||||||
 | 
					            "requests-time_between_check-minutes": 180,
 | 
				
			||||||
 | 
					            "application-ignore_whitespace": "y",
 | 
				
			||||||
 | 
					            "application-strip_ignored_lines": "y",
 | 
				
			||||||
 | 
					            "application-global_ignore_text": "Which is across multiple",
 | 
				
			||||||
 | 
					            'application-fetch_backend': "html_requests"
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        follow_redirects=True
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					    assert b"Settings updated." in res.data
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test_url = url_for('test_endpoint', _external=True)
 | 
				
			||||||
 | 
					    res = client.post(
 | 
				
			||||||
 | 
					        url_for("imports.import_page"),
 | 
				
			||||||
 | 
					        data={"urls": test_url},
 | 
				
			||||||
 | 
					        follow_redirects=True
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					    assert b"1 Imported" in res.data
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    # Give the thread time to pick it up
 | 
				
			||||||
 | 
					    wait_for_all_checks(client)
 | 
				
			||||||
 | 
					    uuid = next(iter(live_server.app.config['DATASTORE'].data['watching']))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    # It should not be in the preview anymore
 | 
				
			||||||
 | 
					    res = client.get(url_for("ui.ui_views.preview_page", uuid=uuid))
 | 
				
			||||||
 | 
					    assert b'<div class="ignored">' not in res.data
 | 
				
			||||||
 | 
					    assert b'Which is across multiple' not in res.data
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Ładowanie…
	
		Reference in New Issue