Add complete status to the todolist json endpoint
Include the status of a todolist package as a string, so the json output can be used to determine the completeness or the packages left to rebuild.
This commit is contained in:
parent
44de9358ba
commit
473877b348
@ -15,6 +15,7 @@
|
||||
from .models import (PackageGroup, PackageRelation,
|
||||
License, Depend, Conflict, Provision, Replacement,
|
||||
SignoffSpecification, Signoff, fake_signoff_spec)
|
||||
from todolists.models import TodolistPackage
|
||||
|
||||
|
||||
VERSION_RE = re.compile(r'^((\d+):)?(.+)-([^-]+)$')
|
||||
@ -429,6 +430,7 @@ class PackageJSONEncoder(DjangoJSONEncoder):
|
||||
'maintainers', 'packager']
|
||||
pkg_list_attributes = ['groups', 'licenses', 'conflicts',
|
||||
'provides', 'replaces']
|
||||
todolistpackage_attributes = ['status_str']
|
||||
|
||||
def default(self, obj):
|
||||
if hasattr(obj, '__iter__'):
|
||||
@ -453,6 +455,11 @@ def default(self, obj):
|
||||
return str(obj)
|
||||
elif isinstance(obj, User):
|
||||
return obj.username
|
||||
elif isinstance(obj, TodolistPackage):
|
||||
data = self.default(obj.pkg)
|
||||
for attr in self.todolistpackage_attributes:
|
||||
data[attr] = getattr(obj, attr)
|
||||
return data
|
||||
return super(PackageJSONEncoder, self).default(obj)
|
||||
|
||||
# vim: set ts=4 sw=4 et:
|
||||
|
@ -80,6 +80,10 @@ def __str__(self):
|
||||
def status_css_class(self):
|
||||
return self.get_status_display().lower().replace('-', '')
|
||||
|
||||
@property
|
||||
def status_str(self):
|
||||
return self.STATUS_CHOICES[self.status][1]
|
||||
|
||||
|
||||
def check_todolist_complete(sender, instance, **kwargs):
|
||||
if instance.status == instance.INCOMPLETE:
|
||||
|
@ -241,7 +241,7 @@ def default(self, obj):
|
||||
'description': obj.description,
|
||||
'created': obj.created,
|
||||
'last_modified': obj.last_modified,
|
||||
'packages': [pkg.pkg for pkg in obj.packages()],
|
||||
'packages': obj.packages()
|
||||
}
|
||||
|
||||
return super(TodoListJSONEncoder, self).default(obj)
|
||||
|
Loading…
Reference in New Issue
Block a user