forked from sch/Slixfeed
Fix submission of filters
This commit is contained in:
parent
aa747985d9
commit
288e5157fa
2 changed files with 40 additions and 11 deletions
|
@ -1968,6 +1968,41 @@ async def update_filters_value(db_file, key_value):
|
||||||
cur.execute(sql, par)
|
cur.execute(sql, par)
|
||||||
|
|
||||||
|
|
||||||
|
async def is_filter_key(db_file, key):
|
||||||
|
"""
|
||||||
|
Get filters key.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
db_file : str
|
||||||
|
Path to database file.
|
||||||
|
key : str
|
||||||
|
Key: allow, deny.
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
key : str
|
||||||
|
Key.
|
||||||
|
"""
|
||||||
|
with create_connection(db_file) as conn:
|
||||||
|
cur = conn.cursor()
|
||||||
|
try:
|
||||||
|
sql = (
|
||||||
|
"""
|
||||||
|
SELECT key
|
||||||
|
FROM filters
|
||||||
|
WHERE key = ?
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
par = (key,)
|
||||||
|
key = cur.execute(sql, par)
|
||||||
|
key = True
|
||||||
|
except:
|
||||||
|
key = False
|
||||||
|
logging.debug("No key {}.".format(key))
|
||||||
|
return key
|
||||||
|
|
||||||
|
|
||||||
async def get_filters_value(db_file, key):
|
async def get_filters_value(db_file, key):
|
||||||
"""
|
"""
|
||||||
Get filters value.
|
Get filters value.
|
||||||
|
@ -1981,7 +2016,7 @@ async def get_filters_value(db_file, key):
|
||||||
|
|
||||||
Returns
|
Returns
|
||||||
-------
|
-------
|
||||||
val : str
|
value : str
|
||||||
List of strings.
|
List of strings.
|
||||||
"""
|
"""
|
||||||
with create_connection(db_file) as conn:
|
with create_connection(db_file) as conn:
|
||||||
|
@ -1999,9 +2034,7 @@ async def get_filters_value(db_file, key):
|
||||||
value = str(value)
|
value = str(value)
|
||||||
except:
|
except:
|
||||||
value = None
|
value = None
|
||||||
logging.debug(
|
logging.debug("No specific value set for key {}.".format(key))
|
||||||
"No specific value set for key {}.".format(key)
|
|
||||||
)
|
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -548,7 +548,7 @@ class Slixfeed(slixmpp.ClientXMPP):
|
||||||
jid_file = jid
|
jid_file = jid
|
||||||
db_file = config.get_pathname_to_database(jid_file)
|
db_file = config.get_pathname_to_database(jid_file)
|
||||||
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 = await sqlite.get_filters_value(db_file, 'allow')
|
value = await sqlite.get_filters_value(db_file, 'allow')
|
||||||
form.add_field(var='allow',
|
form.add_field(var='allow',
|
||||||
ftype='text-single',
|
ftype='text-single',
|
||||||
|
@ -599,14 +599,10 @@ class Slixfeed(slixmpp.ClientXMPP):
|
||||||
# keywords = await sqlite.get_filters_value(db_file, key)
|
# keywords = await sqlite.get_filters_value(db_file, key)
|
||||||
keywords = ''
|
keywords = ''
|
||||||
val = await config.add_to_list(val, keywords)
|
val = await config.add_to_list(val, keywords)
|
||||||
if await sqlite.get_filters_value(db_file, key):
|
if await sqlite.is_filter_key(db_file, key):
|
||||||
await sqlite.update_filters_value(db_file, [key, val])
|
await sqlite.update_filters_value(db_file, [key, val])
|
||||||
else:
|
elif val:
|
||||||
await sqlite.set_filters_value(db_file, [key, val])
|
await sqlite.set_filters_value(db_file, [key, val])
|
||||||
# result = '{}: {}'.format(key, val)
|
|
||||||
form.add_field(var=key + '_title',
|
|
||||||
ftype='fixed',
|
|
||||||
value=key.capitalize() + ' filter')
|
|
||||||
form.add_field(var=key.capitalize() + ' list',
|
form.add_field(var=key.capitalize() + ' list',
|
||||||
ftype='text-single',
|
ftype='text-single',
|
||||||
value=val)
|
value=val)
|
||||||
|
|
Loading…
Reference in a new issue