-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add free-form subject field to contact form (#8896)
* 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
1 parent
e7c452d
commit 067edbc
Showing
2 changed files
with
16 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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() | ||
|
@@ -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 "" | ||
|
@@ -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'): | ||
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters