]> git.ozlabs.org Git - patchwork/blobdiff - apps/patchwork/models.py
Add URL and SCM data to projects
[patchwork] / apps / patchwork / models.py
index 17a68db8077ea6332e53aba419cca2e024c41a2c..86a5266cff2d2177f682c57e6fcea8897b616b66 100644 (file)
@@ -64,6 +64,9 @@ class Project(models.Model):
     name = models.CharField(max_length=255, unique=True)
     listid = models.CharField(max_length=255, unique=True)
     listemail = models.CharField(max_length=200)
+    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()
 
     def __unicode__(self):
@@ -136,13 +139,14 @@ class UserProfile(models.Model):
     def __unicode__(self):
         return self.name()
 
-def _user_created_callback(sender, created, instance, **kwargs):
-    if not created:
-        return
-    profile = UserProfile(user = instance)
+def _user_saved_callback(sender, created, instance, **kwargs):
+    try:
+        profile = instance.get_profile()
+    except UserProfile.DoesNotExist:
+        profile = UserProfile(user = instance)
     profile.save()
 
-models.signals.post_save.connect(_user_created_callback, sender = User)
+models.signals.post_save.connect(_user_saved_callback, sender = User)
 
 class State(models.Model):
     name = models.CharField(max_length = 100)
@@ -179,7 +183,7 @@ class HashField(models.CharField):
         kwargs['max_length'] = self.n_bytes
         super(HashField, self).__init__(*args, **kwargs)
 
-    def db_type(self):
+    def db_type(self, connection=None):
         return 'char(%d)' % self.n_bytes
 
 class PatchMbox(MIMENonMultipart):
@@ -190,6 +194,9 @@ class PatchMbox(MIMENonMultipart):
         self.set_payload(_text.encode(self.patch_charset))
         encode_7or8bit(self)
 
+def get_default_initial_patch_state():
+    return State.objects.get(ordering=0)
+
 class Patch(models.Model):
     project = models.ForeignKey(Project)
     msgid = models.CharField(max_length=255)
@@ -197,7 +204,7 @@ class Patch(models.Model):
     date = models.DateTimeField(default=datetime.datetime.now)
     submitter = models.ForeignKey(Person)
     delegate = models.ForeignKey(User, blank = True, null = True)
-    state = models.ForeignKey(State)
+    state = models.ForeignKey(State, default=get_default_initial_patch_state)
     archived = models.BooleanField(default = False)
     headers = models.TextField(blank = True)
     content = models.TextField(null = True, blank = True)
@@ -408,6 +415,11 @@ class EmailOptout(models.Model):
     def __unicode__(self):
         return self.email
 
+    @classmethod
+    def is_optout(cls, email):
+        email = email.lower().strip()
+        return cls.objects.filter(email = email).count() > 0
+
 class PatchChangeNotification(models.Model):
     patch = models.ForeignKey(Patch, primary_key = True)
     last_modified = models.DateTimeField(default = datetime.datetime.now)