Fix error upon attempt to edit filter via form while another form is not set

This commit is contained in:
Schimon Jehudah 2024-02-16 12:33:07 +00:00
parent 10762a69e4
commit bb44cd925c
4 changed files with 10 additions and 5 deletions

View file

@ -2078,8 +2078,7 @@ def get_filter_value(db_file, key):
""" """
) )
par = (key,) par = (key,)
value = cur.execute(sql, par).fetchone()[0] value = cur.execute(sql, par).fetchone()
value = str(value)
return value return value

View file

@ -1,2 +1,2 @@
__version__ = '0.1.8' __version__ = '0.1.9'
__version_info__ = (0, 1, 8) __version_info__ = (0, 1, 9)

View file

@ -551,12 +551,14 @@ class Slixfeed(slixmpp.ClientXMPP):
form = self['xep_0004'].make_form('form', 'Filters') form = self['xep_0004'].make_form('form', 'Filters')
form['instructions'] = '🛡️ Manage filters' # 🪄️ form['instructions'] = '🛡️ Manage filters' # 🪄️
value = sqlite.get_filter_value(db_file, 'allow') value = sqlite.get_filter_value(db_file, 'allow')
if value: value = str(value[0])
form.add_field(var='allow', form.add_field(var='allow',
ftype='text-single', ftype='text-single',
label='Allow list', label='Allow list',
value=value, value=value,
desc=('Keywords to allow (comma-separated keywords).')) desc=('Keywords to allow (comma-separated keywords).'))
value = sqlite.get_filter_value(db_file, 'deny') value = sqlite.get_filter_value(db_file, 'deny')
if value: value = str(value[0])
form.add_field(var='deny', form.add_field(var='deny',
ftype='text-single', ftype='text-single',
label='Deny list', label='Deny list',
@ -599,7 +601,7 @@ class Slixfeed(slixmpp.ClientXMPP):
# an empty form instead of editing a form. # an empty form instead of editing a form.
# keywords = sqlite.get_filter_value(db_file, key) # keywords = sqlite.get_filter_value(db_file, key)
keywords = '' keywords = ''
val = await config.add_to_list(val, keywords) val = await config.add_to_list(val, keywords) if val else ''
if sqlite.is_filter_key(db_file, key): if sqlite.is_filter_key(db_file, key):
await sqlite.update_filter_value(db_file, [key, val]) await sqlite.update_filter_value(db_file, [key, val])
elif val: elif val:

View file

@ -328,6 +328,7 @@ async def message(self, message):
if val: if val:
db_file = config.get_pathname_to_database(jid_file) db_file = config.get_pathname_to_database(jid_file)
keywords = sqlite.get_filter_value(db_file, key) keywords = sqlite.get_filter_value(db_file, key)
if keywords: keywords = str(keywords[0])
val = await config.add_to_list(val, keywords) val = await config.add_to_list(val, keywords)
if sqlite.is_filter_key(db_file, key): if sqlite.is_filter_key(db_file, key):
await sqlite.update_filter_value(db_file, await sqlite.update_filter_value(db_file,
@ -346,6 +347,7 @@ async def message(self, message):
if val: if val:
db_file = config.get_pathname_to_database(jid_file) db_file = config.get_pathname_to_database(jid_file)
keywords = sqlite.get_filter_value(db_file, key) keywords = sqlite.get_filter_value(db_file, key)
if keywords: keywords = str(keywords[0])
val = await config.remove_from_list(val, keywords) val = await config.remove_from_list(val, keywords)
if sqlite.is_filter_key(db_file, key): if sqlite.is_filter_key(db_file, key):
await sqlite.update_filter_value(db_file, await sqlite.update_filter_value(db_file,
@ -434,6 +436,7 @@ async def message(self, message):
if val: if val:
db_file = config.get_pathname_to_database(jid_file) db_file = config.get_pathname_to_database(jid_file)
keywords = sqlite.get_filter_value(db_file, key) keywords = sqlite.get_filter_value(db_file, key)
if keywords: keywords = str(keywords[0])
val = await config.add_to_list(val, keywords) val = await config.add_to_list(val, keywords)
if sqlite.is_filter_key(db_file, key): if sqlite.is_filter_key(db_file, key):
await sqlite.update_filter_value(db_file, await sqlite.update_filter_value(db_file,
@ -452,6 +455,7 @@ async def message(self, message):
if val: if val:
db_file = config.get_pathname_to_database(jid_file) db_file = config.get_pathname_to_database(jid_file)
keywords = sqlite.get_filter_value(db_file, key) keywords = sqlite.get_filter_value(db_file, key)
if keywords: keywords = str(keywords[0])
val = await config.remove_from_list(val, keywords) val = await config.remove_from_list(val, keywords)
if sqlite.is_filter_key(db_file, key): if sqlite.is_filter_key(db_file, key):
await sqlite.update_filter_value(db_file, await sqlite.update_filter_value(db_file,