Show previous blacklist/whitelist in the text input

This commit is contained in:
2022-12-27 22:09:45 +01:00
parent 20861c07ad
commit d5d6a93645
3 changed files with 75 additions and 26 deletions

View File

@ -49,6 +49,7 @@ from reader import (
from starlette.responses import RedirectResponse
from starlette.templating import _TemplateResponse # noqa
from discord_rss_bot import blacklist, whitelist
from discord_rss_bot.blacklist import has_black_tags, should_be_skipped
from discord_rss_bot.feeds import send_to_discord
from discord_rss_bot.search import create_html_for_search_results
@ -284,8 +285,6 @@ async def set_whitelist(
Returns:
Redirect back to the feed page.
"""
# Add the whitelist to the feed.
if whitelist_title:
reader.set_tag(feed_url, "whitelist_title", whitelist_title) # type: ignore
if whitelist_summary:
@ -314,12 +313,19 @@ async def get_whitelist(feed_url: str, request: Request) -> _TemplateResponse:
url: str = urllib.parse.unquote(feed_url)
feed: Feed = reader.get_feed(url)
try:
whitelist: str = reader.get_tag(url, "whitelist") # type: ignore
except TagNotFoundError:
whitelist: str = ""
context = {"request": request, "feed": feed, "whitelist": whitelist}
# Get previous data, this is used when creating the form.
whitelist_title = whitelist.get_whitelist_title(reader, feed)
whitelist_summary = whitelist.get_whitelist_summary(reader, feed)
whitelist_content = whitelist.get_whitelist_content(reader, feed)
context = {
"request": request,
"feed": feed,
"whitelist_title": whitelist_title,
"whitelist_summary": whitelist_summary,
"whitelist_content": whitelist_content,
}
return templates.TemplateResponse("whitelist.html", context)
@ -362,12 +368,19 @@ async def get_blacklist(feed_url: str, request: Request) -> _TemplateResponse:
url: str = urllib.parse.unquote(feed_url)
feed: Feed = reader.get_feed(url)
try:
blacklist: str = reader.get_tag(url, "blacklist") # type: ignore
except TagNotFoundError:
blacklist: str = ""
context = {"request": request, "feed": feed, "blacklist": blacklist}
# Get previous data, this is used when creating the form.
blacklist_title = blacklist.get_blacklist_title(reader, feed)
blacklist_summary = blacklist.get_blacklist_summary(reader, feed)
blacklist_content = blacklist.get_blacklist_content(reader, feed)
context = {
"request": request,
"feed": feed,
"blacklist_title": blacklist_title,
"blacklist_summary": blacklist_summary,
"blacklist_content": blacklist_content,
}
return templates.TemplateResponse("blacklist.html", context)

View File

@ -7,22 +7,40 @@
<div class="row pb-2">
<div class="col-sm-12">
<div class="form-text">Comma separated list of words to blacklist. If a word is found in the
corresponding blacklists, the feed will not be sent. Whitelist always takes precedence over
blacklist. Leave empty to disable. Words are case-insensitive. No spaces should be used before
or after the comma.
<div class="form-text">
<ul class="list-inline">
<li>Comma separated list of words to blacklist. If a word is found in the
corresponding blacklists, the feed will not be sent.
</li>
<li>Whitelist always takes precedence over blacklist. Leave empty to disable.</li>
<li>Words are case-insensitive. No spaces should be used before or after the comma.</li>
<li>
Correct:
<code>
primogem,events,gameplay preview,special program
</code>
</li>
<li>
Wrong:
<code>
primogem, events, gameplay preview, special program
</code>
</li>
</ul>
</div>
<label for="blacklist_title" class="col-sm-6 col-form-label">Blacklist - Title</label>
<input name="blacklist_title" type="text" class="form-control bg-dark border-dark text-muted"
id="blacklist_title" placeholder="primogem,events,gameplay preview,special program">
id="blacklist_title" value="{% if whitelist_title %}{{ whitelist_title }}{% endif %}">
<label for="blacklist_summary" class="col-sm-6 col-form-label">Blacklist - Summary</label>
<input name="blacklist_summary" type="text" class="form-control bg-dark border-dark text-muted"
id="blacklist_summary" placeholder="primogem,events,gameplay preview,special program">
id="blacklist_summary" value="{% if blacklist_summary %}{{ blacklist_summary }}{% endif %}">
<label for="blacklist_content" class="col-sm-6 col-form-label">Blacklist - Content</label>
<input name="blacklist_content" type="text" class="form-control bg-dark border-dark text-muted"
id="blacklist_content" placeholder="primogem,events,gameplay preview,special program">
id="blacklist_content" value="{% if blacklist_content %}{{ blacklist_content }}{% endif %}">
</div>
</div>

View File

@ -7,22 +7,40 @@
<div class="row pb-2">
<div class="col-sm-12">
<div class="form-text">Comma separated list of words to whitelist. Only send message to
<div class="form-text">
<ul class="list-inline">
<li>Comma separated list of words to whitelist. Only send message to
Discord if one of these words are present in the corresponding fields.
Whitelist always takes precedence over blacklist. Leave empty to disable.
Words are case-insensitive. No spaces should be used before or after the comma.
</li>
<li>Whitelist always takes precedence over blacklist. Leave empty to disable.</li>
<li>Words are case-insensitive. No spaces should be used before or after the comma.</li>
<li>
Correct:
<code>
primogem,events,gameplay preview,special program
</code>
</li>
<li>
Wrong:
<code>
primogem, events, gameplay preview, special program
</code>
</li>
</ul>
</div>
<label for="whitelist_title" class="col-sm-6 col-form-label">Whitelist - Title</label>
<input name="whitelist_title" type="text" class="form-control bg-dark border-dark text-muted"
id="whitelist_title" placeholder="primogem,events,gameplay preview,special program">
id="whitelist_title" value="{% if whitelist_title %}{{ whitelist_title }}{% endif %}">
<label for="whitelist_summary" class="col-sm-6 col-form-label">Whitelist - Summary</label>
<input name="whitelist_summary" type="text" class="form-control bg-dark border-dark text-muted"
id="whitelist_summary" placeholder="primogem,events,gameplay preview,special program">
id="whitelist_summary" value="{% if whitelist_summary %}{{ whitelist_summary }}{% endif %}">
<label for="whitelist_content" class="col-sm-6 col-form-label">Whitelist - Content</label>
<input name="whitelist_content" type="text" class="form-control bg-dark border-dark text-muted"
id="whitelist_content" placeholder="primogem,events,gameplay preview,special program">
id="whitelist_content" value="{% if whitelist_content %}{{ whitelist_content }}{% endif %}">
</div>
</div>