kopia lustrzana https://github.com/dgtlmoon/changedetection.io
UI - Watch edit - "Clone" Should be "Clone & Edit" without watch history, redirect to the new edit page (#3063 #2782)
rodzic
54b7c070f7
commit
c7ffebce2a
|
@ -96,12 +96,13 @@ def construct_blueprint(datastore: ChangeDetectionStore, update_q, running_updat
|
||||||
uuid = list(datastore.data['watching'].keys()).pop()
|
uuid = list(datastore.data['watching'].keys()).pop()
|
||||||
|
|
||||||
new_uuid = datastore.clone(uuid)
|
new_uuid = datastore.clone(uuid)
|
||||||
if new_uuid:
|
|
||||||
if not datastore.data['watching'].get(uuid).get('paused'):
|
|
||||||
update_q.put(queuedWatchMetaData.PrioritizedItem(priority=5, item={'uuid': new_uuid}))
|
|
||||||
flash('Cloned.')
|
|
||||||
|
|
||||||
return redirect(url_for('watchlist.index'))
|
if not datastore.data['watching'].get(uuid).get('paused'):
|
||||||
|
update_q.put(queuedWatchMetaData.PrioritizedItem(priority=5, item={'uuid': new_uuid}))
|
||||||
|
|
||||||
|
flash('Cloned, you are editing the new watch.')
|
||||||
|
|
||||||
|
return redirect(url_for("ui.ui_edit.edit_page", uuid=new_uuid))
|
||||||
|
|
||||||
@ui_blueprint.route("/checknow", methods=['GET'])
|
@ui_blueprint.route("/checknow", methods=['GET'])
|
||||||
@login_optionally_required
|
@login_optionally_required
|
||||||
|
|
|
@ -251,8 +251,14 @@ class ChangeDetectionStore:
|
||||||
# Clone a watch by UUID
|
# Clone a watch by UUID
|
||||||
def clone(self, uuid):
|
def clone(self, uuid):
|
||||||
url = self.data['watching'][uuid].get('url')
|
url = self.data['watching'][uuid].get('url')
|
||||||
extras = self.data['watching'][uuid]
|
extras = deepcopy(self.data['watching'][uuid])
|
||||||
new_uuid = self.add_watch(url=url, extras=extras)
|
new_uuid = self.add_watch(url=url, extras=extras)
|
||||||
|
watch = self.data['watching'][new_uuid]
|
||||||
|
|
||||||
|
if self.data['settings']['application'].get('extract_title_as_title') or watch['extract_title_as_title']:
|
||||||
|
# Because it will be recalculated on the next fetch
|
||||||
|
self.data['watching'][new_uuid]['title'] = None
|
||||||
|
|
||||||
return new_uuid
|
return new_uuid
|
||||||
|
|
||||||
def url_exists(self, url):
|
def url_exists(self, url):
|
||||||
|
@ -363,7 +369,6 @@ class ChangeDetectionStore:
|
||||||
new_watch.ensure_data_dir_exists()
|
new_watch.ensure_data_dir_exists()
|
||||||
self.__data['watching'][new_uuid] = new_watch
|
self.__data['watching'][new_uuid] = new_watch
|
||||||
|
|
||||||
|
|
||||||
if write_to_disk_now:
|
if write_to_disk_now:
|
||||||
self.sync_to_json()
|
self.sync_to_json()
|
||||||
|
|
||||||
|
|
|
@ -588,10 +588,10 @@ keyword") }}
|
||||||
{{ render_button(form.save_button) }}
|
{{ render_button(form.save_button) }}
|
||||||
<a href="{{url_for('ui.form_delete', uuid=uuid)}}"
|
<a href="{{url_for('ui.form_delete', uuid=uuid)}}"
|
||||||
class="pure-button button-small button-error ">Delete</a>
|
class="pure-button button-small button-error ">Delete</a>
|
||||||
<a href="{{url_for('ui.clear_watch_history', uuid=uuid)}}"
|
{% if watch.history_n %}<a href="{{url_for('ui.clear_watch_history', uuid=uuid)}}"
|
||||||
class="pure-button button-small button-error ">Clear History</a>
|
class="pure-button button-small button-error ">Clear History</a>{% endif %}
|
||||||
<a href="{{url_for('ui.form_clone', uuid=uuid)}}"
|
<a href="{{url_for('ui.form_clone', uuid=uuid)}}"
|
||||||
class="pure-button button-small ">Create Copy</a>
|
class="pure-button button-small ">Clone & Edit</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -2,29 +2,39 @@
|
||||||
|
|
||||||
import time
|
import time
|
||||||
from flask import url_for
|
from flask import url_for
|
||||||
from . util import live_server_setup
|
from .util import live_server_setup, wait_for_all_checks
|
||||||
|
|
||||||
|
|
||||||
|
def test_clone_functionality(client, live_server, measure_memory_usage):
|
||||||
def test_trigger_functionality(client, live_server, measure_memory_usage):
|
|
||||||
|
|
||||||
live_server_setup(live_server)
|
live_server_setup(live_server)
|
||||||
|
with open("test-datastore/endpoint-content.txt", "w") as f:
|
||||||
|
f.write("<html><body>Some content</body></html>")
|
||||||
|
|
||||||
# Give the endpoint time to spin up
|
test_url = url_for('test_endpoint', _external=True)
|
||||||
time.sleep(1)
|
|
||||||
|
|
||||||
# Add our URL to the import page
|
# Add our URL to the import page
|
||||||
res = client.post(
|
res = client.post(
|
||||||
url_for("imports.import_page"),
|
url_for("imports.import_page"),
|
||||||
data={"urls": "https://changedetection.io"},
|
data={"urls": test_url},
|
||||||
follow_redirects=True
|
follow_redirects=True
|
||||||
)
|
)
|
||||||
assert b"1 Imported" in res.data
|
assert b"1 Imported" in res.data
|
||||||
|
wait_for_all_checks(client)
|
||||||
|
|
||||||
|
# So that we can be sure the same history doesnt carry over
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
res = client.get(
|
res = client.get(
|
||||||
url_for("ui.form_clone", uuid="first"),
|
url_for("ui.form_clone", uuid="first"),
|
||||||
follow_redirects=True
|
follow_redirects=True
|
||||||
)
|
)
|
||||||
|
existing_uuids = set()
|
||||||
|
|
||||||
assert b"Cloned." in res.data
|
for uuid, watch in live_server.app.config['DATASTORE'].data['watching'].items():
|
||||||
|
new_uuids = set(watch.history.keys())
|
||||||
|
duplicates = existing_uuids.intersection(new_uuids)
|
||||||
|
assert len(duplicates) == 0
|
||||||
|
existing_uuids.update(new_uuids)
|
||||||
|
|
||||||
|
assert b"Cloned" in res.data
|
||||||
|
|
|
@ -273,6 +273,7 @@ def test_limit_tag_ui(client, live_server, measure_memory_usage):
|
||||||
assert b'Deleted' in res.data
|
assert b'Deleted' in res.data
|
||||||
res = client.get(url_for("tags.delete_all"), follow_redirects=True)
|
res = client.get(url_for("tags.delete_all"), follow_redirects=True)
|
||||||
assert b'All tags deleted' in res.data
|
assert b'All tags deleted' in res.data
|
||||||
|
|
||||||
def test_clone_tag_on_import(client, live_server, measure_memory_usage):
|
def test_clone_tag_on_import(client, live_server, measure_memory_usage):
|
||||||
#live_server_setup(live_server)
|
#live_server_setup(live_server)
|
||||||
test_url = url_for('test_endpoint', _external=True)
|
test_url = url_for('test_endpoint', _external=True)
|
||||||
|
@ -292,6 +293,7 @@ def test_clone_tag_on_import(client, live_server, measure_memory_usage):
|
||||||
res = client.get(url_for("ui.form_clone", uuid=watch_uuid), follow_redirects=True)
|
res = client.get(url_for("ui.form_clone", uuid=watch_uuid), follow_redirects=True)
|
||||||
|
|
||||||
assert b'Cloned' in res.data
|
assert b'Cloned' in res.data
|
||||||
|
res = client.get(url_for("watchlist.index"))
|
||||||
# 2 times plus the top link to tag
|
# 2 times plus the top link to tag
|
||||||
assert res.data.count(b'test-tag') == 3
|
assert res.data.count(b'test-tag') == 3
|
||||||
assert res.data.count(b'another-tag') == 3
|
assert res.data.count(b'another-tag') == 3
|
||||||
|
@ -317,8 +319,9 @@ def test_clone_tag_on_quickwatchform_add(client, live_server, measure_memory_usa
|
||||||
|
|
||||||
watch_uuid = next(iter(live_server.app.config['DATASTORE'].data['watching']))
|
watch_uuid = next(iter(live_server.app.config['DATASTORE'].data['watching']))
|
||||||
res = client.get(url_for("ui.form_clone", uuid=watch_uuid), follow_redirects=True)
|
res = client.get(url_for("ui.form_clone", uuid=watch_uuid), follow_redirects=True)
|
||||||
|
|
||||||
assert b'Cloned' in res.data
|
assert b'Cloned' in res.data
|
||||||
|
|
||||||
|
res = client.get(url_for("watchlist.index"))
|
||||||
# 2 times plus the top link to tag
|
# 2 times plus the top link to tag
|
||||||
assert res.data.count(b'test-tag') == 3
|
assert res.data.count(b'test-tag') == 3
|
||||||
assert res.data.count(b'another-tag') == 3
|
assert res.data.count(b'another-tag') == 3
|
||||||
|
|
Ładowanie…
Reference in New Issue