From e66c42890c5ef3db4f1683c404708b5486ee4e7d Mon Sep 17 00:00:00 2001 From: Timothy Hobbs Date: Wed, 19 Dec 2018 17:12:46 +0100 Subject: [PATCH 1/2] Don't crash when mail body is empty --- helpdesk/email.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/helpdesk/email.py b/helpdesk/email.py index 3a95d198..96f3ec13 100644 --- a/helpdesk/email.py +++ b/helpdesk/email.py @@ -362,11 +362,13 @@ def ticket_from_message(message, queue, logger): if not body: mail = BeautifulSoup(part.get_payload(), "lxml") - if ">" in mail.text: - body = mail.find('body') - body = body.text - body = body.encode('ascii', errors='ignore') - else: + beautiful_body = mail.find('body') + if beautiful_body: + try: + body = beautiful_body.text + except AttributeError: + pass + if not body: body = mail.text if ticket: From a11c595a7ccd0040fac76a99404d0c322fbd62e5 Mon Sep 17 00:00:00 2001 From: Garret Wassermann Date: Thu, 20 Dec 2018 21:30:23 -0500 Subject: [PATCH 2/2] PEP-8 fixes --- helpdesk/models.py | 2 +- helpdesk/views/kb.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/helpdesk/models.py b/helpdesk/models.py index a2311b96..89f1a08b 100644 --- a/helpdesk/models.py +++ b/helpdesk/models.py @@ -1060,7 +1060,7 @@ class KBItem(models.Model): An item within the knowledgebase. Very straightforward question/answer style system. """ - voted_by= models.ManyToManyField(settings.AUTH_USER_MODEL) + voted_by = models.ManyToManyField(settings.AUTH_USER_MODEL) category = models.ForeignKey( KBCategory, on_delete=models.CASCADE, diff --git a/helpdesk/views/kb.py b/helpdesk/views/kb.py index 5e66d6ab..b76a6873 100644 --- a/helpdesk/views/kb.py +++ b/helpdesk/views/kb.py @@ -46,7 +46,7 @@ def vote(request, item): item = get_object_or_404(KBItem, pk=item) vote = request.GET.get('vote', None) if vote in ('up', 'down'): - if request.user not in item.voted_by: + if request.user not in item.voted_by: item.votes += 1 if vote == 'up':