X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=apps%2Fpatchwork%2Fmodels.py;h=4bed9b8b2b526ecca4c5ea613b59048a3b7ea456;hb=f0ad2c6a249c0ee3a4b356e10033ea0041ecbea4;hp=a9e70ced4c141cdc5b3dfc97115d665707ef4617;hpb=2f0eb64a6d543b26aa0a38ff1d5a09389a5b2f5c;p=patchwork diff --git a/apps/patchwork/models.py b/apps/patchwork/models.py index a9e70ce..4bed9b8 100644 --- a/apps/patchwork/models.py +++ b/apps/patchwork/models.py @@ -28,25 +28,11 @@ import re import datetime, time import random -try: - from email.mime.nonmultipart import MIMENonMultipart - from email.encoders import encode_7or8bit - from email.parser import HeaderParser - from email.header import Header - import email.utils -except ImportError: - # Python 2.4 compatibility - from email.MIMENonMultipart import MIMENonMultipart - from email.Encoders import encode_7or8bit - from email.Parser import HeaderParser - from email.Header import Header - import email.Utils - email.utils = email.Utils - class Person(models.Model): email = models.CharField(max_length=255, unique = True) name = models.CharField(max_length=255, null = True, blank = True) - user = models.ForeignKey(User, null = True, blank = True) + user = models.ForeignKey(User, null = True, blank = True, + on_delete = models.SET_NULL) def __unicode__(self): if self.name: @@ -69,7 +55,7 @@ class Project(models.Model): web_url = models.CharField(max_length=2000, blank=True) scm_url = models.CharField(max_length=2000, blank=True) webscm_url = models.CharField(max_length=2000, blank=True) - send_notifications = models.BooleanField() + send_notifications = models.BooleanField(default=False) def __unicode__(self): return self.name @@ -79,6 +65,10 @@ class Project(models.Model): return False return self in user.get_profile().maintainer_projects.all() + class Meta: + ordering = ['linkname'] + + class UserProfile(models.Model): user = models.ForeignKey(User, unique = True) primary_project = models.ForeignKey(Project, null = True, blank = True) @@ -126,18 +116,6 @@ class UserProfile(models.Model): .values('pk').query) return qs - def save(self): - super(UserProfile, self).save() - people = Person.objects.filter(email = self.user.email) - if not people: - person = Person(email = self.user.email, - name = self.name(), user = self.user) - person.save() - else: - for person in people: - person.link_to_user(self.user) - person.save() - def __unicode__(self): return self.name() @@ -188,14 +166,6 @@ class HashField(models.CharField): def db_type(self, connection=None): 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) - def get_default_initial_patch_state(): return State.objects.get(ordering=0) @@ -245,60 +215,6 @@ class Patch(models.Model): str = fname_re.sub('-', self.name) return str.strip('-') + '.patch' - def mbox(self): - postscript_re = re.compile('\n-{2,3} ?\n') - - comment = None - try: - comment = Comment.objects.get(patch = self, msgid = self.msgid) - except Exception: - pass - - body = '' - if comment: - body = comment.content.strip() + "\n" - - parts = postscript_re.split(body, 1) - if len(parts) == 2: - (body, postscript) = parts - body = body.strip() + "\n" - postscript = postscript.strip() + "\n" - else: - postscript = '' - - for comment in Comment.objects.filter(patch = self) \ - .exclude(msgid = self.msgid): - body += comment.patch_responses() - - if body: - body += '\n' - - if postscript: - body += '---\n' + postscript.strip() + '\n' - - if self.content: - body += '\n' + self.content - - mail = PatchMbox(body) - mail['Subject'] = self.name - mail['Date'] = email.utils.formatdate( - time.mktime(self.date.utctimetuple())) - mail['From'] = email.utils.formataddr(( - str(Header(self.submitter.name, mail.patch_charset)), - self.submitter.email)) - mail['X-Patchwork-Id'] = str(self.id) - mail['Message-Id'] = self.msgid - mail.set_unixfrom('From patchwork ' + self.date.ctime()) - - - copied_headers = ['To', 'Cc'] - orig_headers = HeaderParser().parsestr(str(self.headers)) - for header in copied_headers: - if header in orig_headers: - mail[header] = orig_headers[header] - - return mail - @models.permalink def get_absolute_url(self): return ('patchwork.views.patch.patch', (), {'patch_id': self.id}) @@ -380,10 +296,6 @@ class Bundle(models.Model): 'bundlename': self.name, }) - def mbox(self): - return '\n'.join([p.mbox().as_string(True) - for p in self.ordered_patches()]) - class BundlePatch(models.Model): patch = models.ForeignKey(Patch) bundle = models.ForeignKey(Bundle)