Add command to create feedbacks from emails.
See #975 - Legacy-Id: 5596
This commit is contained in:
parent
69c704de2d
commit
be95a83dca
ietf/nomcom
0
ietf/nomcom/management/__init__.py
Normal file
0
ietf/nomcom/management/__init__.py
Normal file
0
ietf/nomcom/management/commands/__init__.py
Normal file
0
ietf/nomcom/management/commands/__init__.py
Normal file
52
ietf/nomcom/management/commands/feedback_email.py
Normal file
52
ietf/nomcom/management/commands/feedback_email.py
Normal file
|
@ -0,0 +1,52 @@
|
|||
from optparse import make_option
|
||||
from email.utils import parseaddr
|
||||
import syslog
|
||||
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
|
||||
from ietf.nomcom.utils import parse_email
|
||||
from ietf.nomcom.models import Nominee, NomCom, Feedback
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = (u"Send a remind to each SDO Liaison Manager to update the list of persons authorized to send liaison statements on behalf of his SDO")
|
||||
option_list = BaseCommand.option_list + (
|
||||
make_option('--nomcom-year', dest='year', help='NomCom year'),
|
||||
make_option('--email-file', dest='email', help='Feedback email'),
|
||||
)
|
||||
|
||||
def handle(self, *args, **options):
|
||||
email = options.get('email', None)
|
||||
year = options.get('year', None)
|
||||
msg = None
|
||||
nominee = None
|
||||
nomcom = None
|
||||
help_message = 'Usage: feeback_email --nomcom-year <nomcom-year> --email-file <email-file>'
|
||||
|
||||
if not year:
|
||||
raise CommandError(help_message)
|
||||
|
||||
if not email:
|
||||
raise CommandError(help_message)
|
||||
else:
|
||||
msg = open(email, "r").read()
|
||||
|
||||
try:
|
||||
nomcom = NomCom.objects.get(group__acronym__icontains=year,
|
||||
group__state__slug='active')
|
||||
except NomCom.DoesNotExist:
|
||||
raise CommandError('NomCom %s does not exist' % year)
|
||||
|
||||
by, subject, body = parse_email(msg)
|
||||
name, addr = parseaddr(by)
|
||||
try:
|
||||
nominee = Nominee.objects.get_by_nomcom(nomcom).not_duplicated().get(email__address__icontains=addr)
|
||||
except Nominee.DoesNotExist:
|
||||
pass
|
||||
|
||||
feedback = Feedback(nomcom=nomcom,
|
||||
comments=body)
|
||||
if nominee:
|
||||
feedback.nominee = nominee
|
||||
feedback.save()
|
||||
syslog.syslog(u"Read feedback email by %s" % by)
|
|
@ -1,5 +1,6 @@
|
|||
import hashlib
|
||||
import re
|
||||
import email
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.exceptions import PermissionDenied
|
||||
|
@ -45,8 +46,8 @@ def get_year_by_nomcom(nomcom):
|
|||
|
||||
def get_user_email(user):
|
||||
emails = Email.objects.filter(person__user=user)
|
||||
email = emails and emails[0] or None
|
||||
return email
|
||||
mail = emails and emails[0] or None
|
||||
return mail
|
||||
|
||||
|
||||
def is_nomcom_member(user, nomcom):
|
||||
|
@ -139,3 +140,19 @@ def store_nomcom_private_key(request, year, private_key):
|
|||
if error:
|
||||
out = ''
|
||||
request.session['NOMCOM_PRIVATE_KEY_%s' % year] = out
|
||||
|
||||
|
||||
def extract_body(payload):
|
||||
if isinstance(payload, str):
|
||||
return payload
|
||||
else:
|
||||
return '\n'.join([extract_body(part.get_payload()) for part in payload])
|
||||
|
||||
|
||||
def parse_email(text):
|
||||
msg = email.message_from_string(text.encode("utf-8"))
|
||||
|
||||
# comment
|
||||
body = extract_body(msg.get_payload())
|
||||
|
||||
return msg['From'], msg['Subject'], body
|
||||
|
|
Loading…
Reference in a new issue