Skip to content

Commit

Permalink
Better secret field display, refs #46
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Apr 27, 2024
1 parent 7643fd2 commit f5c3fa9
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion datasette_enrichments/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import traceback
import urllib
from datasette.plugins import pm
from markupsafe import Markup, escape
from .views import enrichment_picker, enrichment_view
from wtforms import PasswordField
from wtforms.validators import DataRequired
Expand Down Expand Up @@ -151,10 +152,21 @@ def stash_api_key(form, field):
datasette._enrichments_gpt_stashed_keys[key] = field.data
field.data = key

formatted_description = self.secret.description
if self.secret.obtain_url and self.secret.obtain_label:
html_bits = []
if self.secret.description:
html_bits.append(escape(self.secret.description))
html_bits.append(" - ")
html_bits.append(
f'<a href="{self.secret.obtain_url}" target="_blank">{self.secret.obtain_label}</a>'
)
formatted_description = Markup("".join(html_bits))

class FormWithSecret(FormClass):
enrichment_secret = PasswordField(
self.secret.name,
description=self.secret.description,
description=formatted_description,
validators=[
DataRequired(message="Secret is required."),
stash_api_key,
Expand Down

0 comments on commit f5c3fa9

Please sign in to comment.