Message ID | 20170221054529.13509-1-dja@axtens.net |
---|---|
State | Accepted |
Headers | show |
On Tue, 2017-02-21 at 16:45 +1100, Daniel Axtens wrote: > Some mailing lists accept patches for multiple projects, and use > a subject prefix to differentiate the projects. > > Therefore, for snowpatch, it's useful to be able to fetch the > subject prefixes. > > Export subject prefixes in the REST API. > > Signed-off-by: Daniel Axtens <dja@axtens.net> > Tested-by: Russell Currey <ruscur@russell.cc>
On 21/02/17 16:45, Daniel Axtens wrote: > Some mailing lists accept patches for multiple projects, and use > a subject prefix to differentiate the projects. > > Therefore, for snowpatch, it's useful to be able to fetch the > subject prefixes. > > Export subject prefixes in the REST API. > > Signed-off-by: Daniel Axtens <dja@axtens.net> Reviewed-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com> > > --- > v2: call them prefixes rather than categories, only expose in > detail view > --- > patchwork/api/patch.py | 9 +++++++-- > 1 file changed, 7 insertions(+), 2 deletions(-) > > diff --git a/patchwork/api/patch.py b/patchwork/api/patch.py > index 1a7be584d0be..ded491014ea0 100644 > --- a/patchwork/api/patch.py > +++ b/patchwork/api/patch.py > @@ -31,6 +31,7 @@ from patchwork.api.base import PatchworkPermission > from patchwork.api.filters import PatchFilter > from patchwork.models import Patch > from patchwork.models import State > +from patchwork.parser import clean_subject > > > def format_state_name(state): > @@ -116,17 +117,21 @@ class PatchListSerializer(HyperlinkedModelSerializer): > > class PatchDetailSerializer(PatchListSerializer): > headers = SerializerMethodField() > + prefixes = SerializerMethodField() > > def get_headers(self, patch): > if patch.headers: > return email.parser.Parser().parsestr(patch.headers, True) > > + def get_prefixes(self, instance): > + return clean_subject(instance.name)[1] > + > class Meta: > model = Patch > fields = PatchListSerializer.Meta.fields + ( > - 'headers', 'content', 'diff') > + 'headers', 'content', 'diff', 'prefixes') > read_only_fields = PatchListSerializer.Meta.read_only_fields + ( > - 'headers', 'content', 'diff') > + 'headers', 'content', 'diff', 'prefixes') > extra_kwargs = PatchListSerializer.Meta.extra_kwargs > > >
diff --git a/patchwork/api/patch.py b/patchwork/api/patch.py index 1a7be584d0be..ded491014ea0 100644 --- a/patchwork/api/patch.py +++ b/patchwork/api/patch.py @@ -31,6 +31,7 @@ from patchwork.api.base import PatchworkPermission from patchwork.api.filters import PatchFilter from patchwork.models import Patch from patchwork.models import State +from patchwork.parser import clean_subject def format_state_name(state): @@ -116,17 +117,21 @@ class PatchListSerializer(HyperlinkedModelSerializer): class PatchDetailSerializer(PatchListSerializer): headers = SerializerMethodField() + prefixes = SerializerMethodField() def get_headers(self, patch): if patch.headers: return email.parser.Parser().parsestr(patch.headers, True) + def get_prefixes(self, instance): + return clean_subject(instance.name)[1] + class Meta: model = Patch fields = PatchListSerializer.Meta.fields + ( - 'headers', 'content', 'diff') + 'headers', 'content', 'diff', 'prefixes') read_only_fields = PatchListSerializer.Meta.read_only_fields + ( - 'headers', 'content', 'diff') + 'headers', 'content', 'diff', 'prefixes') extra_kwargs = PatchListSerializer.Meta.extra_kwargs
Some mailing lists accept patches for multiple projects, and use a subject prefix to differentiate the projects. Therefore, for snowpatch, it's useful to be able to fetch the subject prefixes. Export subject prefixes in the REST API. Signed-off-by: Daniel Axtens <dja@axtens.net> --- v2: call them prefixes rather than categories, only expose in detail view --- patchwork/api/patch.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)