Skip to content

Commit

Permalink
Add free-form subject field to contact form (#8896)
Browse files Browse the repository at this point in the history
* Add free-form subject field to contact form & remove dead markup

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
jimchamp and pre-commit-ci[bot] authored Mar 15, 2024
1 parent e7c452d commit 067edbc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
15 changes: 12 additions & 3 deletions openlibrary/plugins/openlibrary/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ def POST(self):
patron_name = form.get("name", "")
email = form.get("email", "")
topic = form.get("topic", "")
subject_line = form.get('subject', '')
description = form.get("question", "")
url = form.get("url", "")
user = accounts.get_current_user()
useragent = web.ctx.env.get("HTTP_USER_AGENT", "")
if not all([email, topic, description]):
if not all([email, description]):
return ""

hashed_ip = hashlib.md5(web.ctx.ip.encode('utf-8')).hexdigest()
Expand All @@ -59,7 +60,7 @@ def POST(self):
else:
assignee = default_assignees.get("default", "[email protected]")
stats.increment("ol.support.all")
subject = "Support case *%s*" % topic
subject = "Support case *%s*" % self.prepare_subject_line(subject_line)

url = web.ctx.home + url
displayname = user and user.get_name() or ""
Expand All @@ -73,6 +74,14 @@ def POST(self):
)
return render_template("email/case_created", assignee)

def prepare_subject_line(self, subject, max_length=60):
if not subject:
return '[no subject]'
if len(subject) <= max_length:
return subject

return subject[:max_length]


def sendmail(from_address, to_address, subject, message):
if config.get('dummy_sendmail'):
Expand All @@ -95,7 +104,7 @@ def sendmail(from_address, to_address, subject, message):
A new support case has been filed by %(displayname)s <%(email)s>.
Topic: %(topic)s
Subject: %(subject_line)s
URL: %(url)s
User-Agent: %(useragent)s
OL-username: %(username)s
Expand Down
20 changes: 4 additions & 16 deletions openlibrary/templates/support.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,10 @@ <h1>$_("How can we help?")</h1>
</div>

<div class="formElement">
<div class="label"><label for="topic">$_("Topic")</label></div>
<div class="input">
<select class="required" name="topic" id="topic">
<option value="">$_('Select...')</option>
<option value="Borrowing Books">$_('Borrowing Help')</option>
<option value="Developer/Code">$_('Developer/Code Question')</option>
<option value="Editing Problem">$_('Editing Issue')</option>
<option value="Login Trouble">$_('Login Trouble')</option>
<option value="Spam Report">$_('Spam Report')</option>
<option value="Waiting List Issue">$_('Waiting List')</option>
<option value="Other">$_('Other Question')</option>
</select>
</div>
<div class="label"><label for="subject">$_("Subject")</label></div>
<div class="input">
<input type="text" name="subject">
</div>
</div>

<div class="formElement">
Expand All @@ -50,10 +41,7 @@ <h1>$_("How can we help?")</h1>
<p>$_('If you encounter an error message, please include it. For questions about our books, please provide the title/author or Open Library ID.')</p>
</div>

<!-- <div class="formElement"> -->
<!-- <div class="label"><label for="url">$_("Which page were you looking at?")</label></div> -->
<div class="input"><input type="hidden" name="url" id="url" value="$url"/></div>
<!-- </div> -->

$if recaptcha:
$:render_template("recaptcha", recaptcha.public_key, error=None)
Expand Down

0 comments on commit 067edbc

Please sign in to comment.