]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
models: Convert functions to properties
authorStephen Finucane <stephen@that.guru>
Sat, 29 Oct 2016 13:13:33 +0000 (14:13 +0100)
committerStephen Finucane <stephen@that.guru>
Mon, 31 Oct 2016 16:06:10 +0000 (16:06 +0000)
A number of models contain functions that are, semantically speaking,
actually properties. Mark them as such.

Signed-off-by: Stephen Finucane <stephen@that.guru>
Reviewed-by: Andy Doan <andy.doan@linaro.org>
Reviewed-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
patchwork/models.py
patchwork/views/__init__.py
patchwork/views/patch.py
patchwork/views/user.py
patchwork/views/xmlrpc.py

index b18213d66a4d82874a0b389e553ae57ed8ea53e5..8a9762a2754b71a22fe8b44fe9b3e8bc6aaaf502 100644 (file)
@@ -47,7 +47,7 @@ class Person(models.Model):
                              on_delete=models.SET_NULL)
 
     def link_to_user(self, user):
-        self.name = user.profile.name()
+        self.name = user.profile.name
         self.user = user
 
     def __str__(self):
@@ -132,17 +132,20 @@ class UserProfile(models.Model):
         default=100, null=False, blank=False,
         help_text='Number of items to display per page')
 
+    @property
     def name(self):
         if self.user.first_name or self.user.last_name:
             names = [self.user.first_name, self.user.last_name]
             return ' '.join([x for x in names if x])
         return self.user.username
 
+    @property
     def contributor_projects(self):
         submitters = Person.objects.filter(user=self.user)
         return Project.objects.filter(id__in=Submission.objects.filter(
             submitter__in=submitters).values('project_id').query)
 
+    @property
     def n_todo_patches(self):
         return self.todo_patches().count()
 
@@ -159,7 +162,7 @@ class UserProfile(models.Model):
         return qs
 
     def __str__(self):
-        return self.name()
+        return self.name
 
 
 def _user_saved_callback(sender, created, instance, **kwargs):
@@ -272,6 +275,7 @@ class EmailMixin(models.Model):
         r'^(Tested|Reviewed|Acked|Signed-off|Nacked|Reported)-by: .*$',
         re.M | re.I)
 
+    @property
     def patch_responses(self):
         if not self.content:
             return ''
@@ -432,6 +436,7 @@ class Patch(Submission):
 
         return self.project.is_editable(user)
 
+    @property
     def filename(self):
         fname_re = re.compile(r'[^-_A-Za-z0-9\.]+')
         str = fname_re.sub('-', self.name)
index df30f518f58c3fda6663306b2fe1000d51b3c186..8b5e881c4eaea1979df0408a0b28cfe9cf85fa30 100644 (file)
@@ -368,10 +368,10 @@ def patch_to_mbox(patch):
         postscript = ''
 
     # TODO(stephenfin): Make this use the tags infrastructure
-    body += patch.patch_responses()
+    body += patch.patch_responses
 
     for comment in Comment.objects.filter(submission=patch):
-        body += comment.patch_responses()
+        body += comment.patch_responses
 
     if postscript:
         body += '---\n' + postscript + '\n'
index 244abe2e6d7e2ffca0aab7eda24646ddfa1c39cb..caabdd77ffc355230d5f7ecfa61991b87ec220f1 100644 (file)
@@ -120,7 +120,7 @@ def content(request, patch_id):
     response = HttpResponse(content_type="text/x-patch")
     response.write(patch.diff)
     response['Content-Disposition'] = 'attachment; filename=' + \
-        patch.filename().replace(';', '').replace('\n', '')
+        patch.filename.replace(';', '').replace('\n', '')
     return response
 
 
@@ -133,5 +133,5 @@ def mbox(request, patch_id):
     else:
         response.write(patch_to_mbox(patch).as_string(True))
     response['Content-Disposition'] = 'attachment; filename=' + \
-        patch.filename().replace(';', '').replace('\n', '')
+        patch.filename.replace(';', '').replace('\n', '')
     return response
index f76a05f69e6851158b86e42f551721354969a7d3..c182aa3458478141119fb83e54ec6fddfdc12096 100644 (file)
@@ -92,7 +92,7 @@ def register_confirm(request, conf):
         person = Person.objects.get(email__iexact=conf.user.email)
     except Person.DoesNotExist:
         person = Person(email=conf.user.email,
-                        name=conf.user.profile.name())
+                        name=conf.user.profile.name)
     person.user = conf.user
     person.save()
 
index 30829e7fd94e61b4663702fe6a90911008e4f24d..0c3f581d8f4b13cc77a60c8d49be924f4b25162c 100644 (file)
@@ -273,7 +273,7 @@ def patch_to_dict(obj):
     return {
         'id': obj.id,
         'date': six.text_type(obj.date).encode('utf-8'),
-        'filename': obj.filename(),
+        'filename': obj.filename,
         'msgid': obj.msgid,
         'name': obj.name,
         'project': six.text_type(obj.project).encode('utf-8'),