Modified the REST API to provide group descriptions taken from the group charters if group.description is blank.
- Legacy-Id: 12993
This commit is contained in:
parent
2ba55b1b5b
commit
58dae78a43
|
@ -2,6 +2,7 @@
|
|||
|
||||
import datetime
|
||||
import email.utils
|
||||
import re
|
||||
from urlparse import urljoin
|
||||
|
||||
from django.db import models
|
||||
|
@ -168,6 +169,22 @@ class Group(GroupInfo):
|
|||
status_events = status_events.filter(time__gte=previous_meeting.end_date()+datetime.timedelta(days=1))
|
||||
return status_events.first()
|
||||
|
||||
def get_description(self):
|
||||
"""
|
||||
Return self.description if set, otherwise the first paragraph of the
|
||||
charter if any, else a short error message. Used to provide a
|
||||
fallback for self.description in group.resources.GroupResource.
|
||||
"""
|
||||
desc = 'No description available'
|
||||
if self.description:
|
||||
desc = self.description
|
||||
elif self.charter:
|
||||
text = self.charter.text()
|
||||
# split into paragraphs and grab the first non-empty one
|
||||
if text:
|
||||
desc = [ p for p in re.split('\r?\n\s*\r?\n\s*', text) if p.strip() ][0]
|
||||
return desc
|
||||
|
||||
class GroupHistory(GroupInfo):
|
||||
group = models.ForeignKey(Group, related_name='history_set')
|
||||
acronym = models.CharField(max_length=40)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# Autogenerated by the mkresources management command 2014-11-13 23:15
|
||||
from ietf.api import ModelResource
|
||||
from ietf.api import ToOneField
|
||||
from tastypie.fields import ToManyField
|
||||
from tastypie.fields import ToManyField, CharField
|
||||
from tastypie.constants import ALL, ALL_WITH_RELATIONS
|
||||
from tastypie.cache import SimpleCache
|
||||
|
||||
|
@ -22,6 +22,7 @@ class GroupResource(ModelResource):
|
|||
charter = ToOneField('ietf.doc.resources.DocumentResource', 'charter', null=True)
|
||||
unused_states = ToManyField('ietf.doc.resources.StateResource', 'unused_states', null=True)
|
||||
unused_tags = ToManyField(DocTagNameResource, 'unused_tags', null=True)
|
||||
description = CharField(attribute='get_description')
|
||||
class Meta:
|
||||
cache = SimpleCache()
|
||||
queryset = Group.objects.all()
|
||||
|
|
|
@ -133,6 +133,7 @@ def make_test_data():
|
|||
group = Group.objects.create(
|
||||
name="Martian Special Interest Group",
|
||||
acronym="mars",
|
||||
description="This group discusses mars issues.",
|
||||
state_id="active",
|
||||
type_id="wg",
|
||||
parent=area,
|
||||
|
@ -159,6 +160,7 @@ def make_test_data():
|
|||
group = Group.objects.create(
|
||||
name="Asteroid Mining Equipment Standardization Group",
|
||||
acronym="ames",
|
||||
description="This group works towards standardization of asteroid mining equipment.",
|
||||
state_id="proposed",
|
||||
type_id="wg",
|
||||
parent=area,
|
||||
|
@ -185,6 +187,7 @@ def make_test_data():
|
|||
frfarea = Group.objects.create(
|
||||
name="Far Future Area Group",
|
||||
acronym="frfarea",
|
||||
description="This group discusses future space colonization issues.",
|
||||
state_id="active",
|
||||
type_id="ag",
|
||||
parent=area,
|
||||
|
@ -195,6 +198,7 @@ def make_test_data():
|
|||
irg_rg = Group.objects.create(
|
||||
name="Internet Research Group",
|
||||
acronym="irg",
|
||||
description="This group handles internet research.",
|
||||
state_id="active",
|
||||
type_id="rg",
|
||||
parent=irtf,
|
||||
|
|
Loading…
Reference in a new issue