Commit 656af970 authored by Damien Lespiau's avatar Damien Lespiau
Browse files

models: Factor out a human_name() for patches, series and revisions



Several part of the code will need these string representations suitable
for human consumption (so a bit more refined than __str__ or just name
fields.

Until now, only the test results emails needed them.
Signed-off-by: default avatarDamien Lespiau <damien.lespiau@intel.com>
parent 7fcf43fd
......@@ -385,6 +385,9 @@ class Patch(models.Model):
def filename(self):
return filename(self.name, '.patch')
def human_name(self):
return self.name
@models.permalink
def get_absolute_url(self):
return ('patchwork.views.patch.patch', (), {'patch_id': self.id})
......@@ -553,6 +556,13 @@ class Series(models.Model):
def filename(self):
return filename(self.name, '.mbox')
def human_name(self):
name = self.name
if name == SERIES_DEFAULT_NAME:
name = "series starting with " + \
self.las_revision.ordered_patches()[0].name
return name
def __str__(self):
return self.name
......@@ -630,6 +640,14 @@ class SeriesRevision(models.Model):
self.save()
self.series.save()
def human_name(self):
name = self.series.name
if name == SERIES_DEFAULT_NAME:
name = "series starting with " + self.ordered_patches()[0].name
if self.version > 1:
name += " (rev%d)" % self.version
return name
def __str__(self):
return "Revision " + str(self.version)
......
......@@ -29,8 +29,7 @@ from django.core import mail
from django.db.models import Q
from django.http import HttpResponse
from patchwork.models import (Project, Series, SeriesRevision, Patch, EventLog,
Test, TestResult, TestState, Person,
SERIES_DEFAULT_NAME)
Test, TestResult, TestState, Person)
from rest_framework import (views, viewsets, mixins, filters, permissions,
status)
from rest_framework.authentication import BasicAuthentication
......@@ -295,16 +294,6 @@ class ResultMixin(object):
else:
return "Patch"
def _object_name(self, obj):
if isinstance(obj, SeriesRevision):
name = obj.series.name
if name == SERIES_DEFAULT_NAME:
name = "series starting with " + obj.ordered_patches()[0].name
if obj.version > 1:
name += " (rev%d)" % obj.version
return name
return obj.name
def _prepare_mail(self, request, result, obj, check_obj):
if result.state == TestState.STATE_SUCCESS:
tick = u"✓"
......@@ -312,10 +301,10 @@ class ResultMixin(object):
tick = u"✗"
subject = tick + u" %s: %s for %s" % (result.test.name,
result.get_state_display(),
self._object_name(obj))
obj.human_name())
body = ''
body += '== %s Details ==\n\n' % self._object_type(obj)
body += 'Series: ' + self._object_name(obj) + '\n'
body += 'Series: ' + obj.human_name() + '\n'
body += 'URL : ' + \
request.build_absolute_uri(check_obj.get_absolute_url()) + '\n'
body += 'State : ' + result.get_state_display() + '\n'
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment