X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=apps%2Fpatchwork%2Fmodels.py;h=02fb8b4a4e55fc77489145c3280c0b13169abec3;hb=65404776f7f0e975737a5c8c69dc0b2ae5fe93da;hp=e516be29d6730664f0a027248d9ec56dcfb9222e;hpb=a72679a9622db66e828e86377f29c9c0c6574d69;p=patchwork diff --git a/apps/patchwork/models.py b/apps/patchwork/models.py index e516be2..02fb8b4 100644 --- a/apps/patchwork/models.py +++ b/apps/patchwork/models.py @@ -31,11 +31,13 @@ import string import random try: - from email.mime.text import MIMEText + from email.mime.nonmultipart import MIMENonMultipart + from email.encoders import encode_7or8bit import email.utils except ImportError: # Python 2.4 compatibility - from email.MIMEText import MIMEText + from email.MIMENonMultipart import MIMENonMultipart + from email.Encoders import encode_7or8bit import email.Utils email.utils = email.Utils @@ -167,6 +169,14 @@ class HashField(models.CharField): def db_type(self): return 'char(%d)' % self.n_bytes +class PatchMbox(MIMENonMultipart): + patch_charset = 'utf-8' + def __init__(self, _text): + MIMENonMultipart.__init__(self, 'text', 'plain', + **{'charset': self.patch_charset}) + self.set_payload(_text.encode(self.patch_charset)) + encode_7or8bit(self) + class Patch(models.Model): project = models.ForeignKey(Project) msgid = models.CharField(max_length=255, unique = True) @@ -220,16 +230,25 @@ class Patch(models.Model): def mbox(self): comment = None try: - comment = Comment.objects.get(msgid = self.msgid) + comment = Comment.objects.get(patch = self, msgid = self.msgid) except Exception: pass body = '' if comment: - body = comment.content.strip() + "\n\n" + body = comment.content.strip() + "\n" + + responses = False + for comment in Comment.objects.filter(patch = self) \ + .exclude(msgid = self.msgid): + body += comment.patch_responses() + + if body: + body += '\n' + body += self.content - mail = MIMEText(body) + mail = PatchMbox(body) mail['Subject'] = self.name mail['Date'] = email.utils.formatdate( time.mktime(self.date.utctimetuple())) @@ -256,6 +275,12 @@ class Comment(models.Model): headers = models.TextField(blank = True) content = models.TextField() + response_re = re.compile('^(Acked|Signed-off|Nacked)-by: .*$', re.M) + + def patch_responses(self): + return ''.join([ match.group(0) + '\n' for match in \ + self.response_re.finditer(self.content)]) + class Meta: ordering = ['date'] @@ -308,6 +333,7 @@ class UserPersonConfirmation(models.Model): person.link_to_user(self.user) person.save() self.active = False + self.save() def save(self): max = 1 << 32