adding field overrides watch

restock-tag
dgtlmoon 5 months ago
parent b9679c6d24
commit 0b5de0ed2f

@ -1,4 +1,6 @@
from flask import Blueprint, request, make_response, render_template, flash, url_for, redirect from flask import Blueprint, request, render_template, flash, url_for, redirect
from changedetectionio.store import ChangeDetectionStore from changedetectionio.store import ChangeDetectionStore
from changedetectionio.flask_app import login_optionally_required from changedetectionio.flask_app import login_optionally_required
@ -96,15 +98,13 @@ def construct_blueprint(datastore: ChangeDetectionStore):
@tags_blueprint.route("/edit/<string:uuid>", methods=['GET']) @tags_blueprint.route("/edit/<string:uuid>", methods=['GET'])
@login_optionally_required @login_optionally_required
def form_tag_edit(uuid): def form_tag_edit(uuid):
from changedetectionio.blueprint.tags.form import group_restock_settings_form
from changedetectionio.processors.restock_diff.forms import processor_settings_form
if uuid == 'first': if uuid == 'first':
uuid = list(datastore.data['settings']['application']['tags'].keys()).pop() uuid = list(datastore.data['settings']['application']['tags'].keys()).pop()
default = datastore.data['settings']['application']['tags'].get(uuid) default = datastore.data['settings']['application']['tags'].get(uuid)
form = processor_settings_form(formdata=request.form if request.method == 'POST' else None, form = group_restock_settings_form(formdata=request.form if request.method == 'POST' else None,
data=default, data=default,
) )
@ -122,11 +122,24 @@ def construct_blueprint(datastore: ChangeDetectionStore):
import importlib.resources import importlib.resources
templates_dir = str(importlib.resources.files("changedetectionio").joinpath('templates')) templates_dir = str(importlib.resources.files("changedetectionio").joinpath('templates'))
env = Environment(loader=FileSystemLoader(templates_dir)) env = Environment(loader=FileSystemLoader(templates_dir))
template = env.from_string(form.extra_form_content()) template_str = """{% from '_helpers.html' import render_field, render_checkbox_field, render_button %}
<script>
$(document).ready(function () {
toggleOpacity('#overrides_watch', '#restock-fieldset-price-group', true);
});
</script>
<fieldset>
<div class="pure-control-group">
<fieldset class="pure-group">
{{ render_checkbox_field(form.overrides_watch) }}
</fieldset>
</fieldset>
"""
template_str += form.extra_form_content()
template = env.from_string(template_str)
included_content = template.render(**template_args) included_content = template.render(**template_args)
output = render_template("edit-tag.html", output = render_template("edit-tag.html",
settings_application=datastore.data['settings']['application'], settings_application=datastore.data['settings']['application'],
extra_tab_content=form.extra_tab_content() if form.extra_tab_content() else None, extra_tab_content=form.extra_tab_content() if form.extra_tab_content() else None,
extra_form_content=included_content, extra_form_content=included_content,
@ -139,13 +152,13 @@ def construct_blueprint(datastore: ChangeDetectionStore):
@tags_blueprint.route("/edit/<string:uuid>", methods=['POST']) @tags_blueprint.route("/edit/<string:uuid>", methods=['POST'])
@login_optionally_required @login_optionally_required
def form_tag_edit_submit(uuid): def form_tag_edit_submit(uuid):
from changedetectionio.processors.restock_diff.forms import processor_settings_form from changedetectionio.blueprint.tags.form import group_restock_settings_form
if uuid == 'first': if uuid == 'first':
uuid = list(datastore.data['settings']['application']['tags'].keys()).pop() uuid = list(datastore.data['settings']['application']['tags'].keys()).pop()
default = datastore.data['settings']['application']['tags'].get(uuid) default = datastore.data['settings']['application']['tags'].get(uuid)
form = processor_settings_form(formdata=request.form if request.method == 'POST' else None, form = group_restock_settings_form(formdata=request.form if request.method == 'POST' else None,
data=default, data=default,
) )
# @todo subclass form so validation works # @todo subclass form so validation works

@ -1,16 +1,15 @@
from wtforms import ( from wtforms import (
BooleanField,
Form, Form,
IntegerField,
RadioField,
SelectField,
StringField, StringField,
SubmitField, SubmitField,
TextAreaField,
validators, validators,
) )
from wtforms.fields.simple import BooleanField
from changedetectionio.processors.restock_diff.forms import processor_settings_form as restock_settings_form
class group_restock_settings_form(restock_settings_form):
overrides_watch = BooleanField('Activate for individual watches in this tag/group?', default=False)
class SingleTag(Form): class SingleTag(Form):

@ -1,14 +1,14 @@
from changedetectionio.model import watch_base from changedetectionio.model import watch_base
class model(watch_base): class model(watch_base):
def __init__(self, *arg, **kw): def __init__(self, *arg, **kw):
super(model, self).__init__(*arg, **kw) super(model, self).__init__(*arg, **kw)
self['overrides_watch'] = kw.get('default', {}).get('overrides_watch')
if kw.get('default'): if kw.get('default'):
self.update(kw['default']) self.update(kw['default'])
del kw['default'] del kw['default']

@ -34,7 +34,7 @@ class processor_settings_form(processor_text_json_diff_form):
</script> </script>
<fieldset> <fieldset id="restock-fieldset-price-group">
<div class="pure-control-group"> <div class="pure-control-group">
<fieldset class="pure-group"> <fieldset class="pure-group">
{{ render_checkbox_field(form.in_stock_only) }} {{ render_checkbox_field(form.in_stock_only) }}

@ -27,6 +27,5 @@ $(document).ready(function () {
toggleOpacity('#time_between_check_use_default', '#time_between_check', false); toggleOpacity('#time_between_check_use_default', '#time_between_check', false);
}); });

Loading…
Cancel
Save