diff options
author | Jelle van der Waa <jelle@archlinux.org> | 2020-11-08 17:07:25 +0100 |
---|---|---|
committer | jelle van der Waa <jelle@vdwaa.nl> | 2020-11-08 17:43:43 +0100 |
commit | 473877b348d75d05a4b97ac11c07dc410c42d741 (patch) | |
tree | 1f109b7993e8af2b1587baa52a90e2e24e570343 | |
parent | 44de9358ba3b8631dc1863ac7a5f25c42c7bdbaf (diff) | |
download | archweb-473877b348d75d05a4b97ac11c07dc410c42d741.tar.gz archweb-473877b348d75d05a4b97ac11c07dc410c42d741.zip |
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.
-rw-r--r-- | packages/utils.py | 7 | ||||
-rw-r--r-- | todolists/models.py | 4 | ||||
-rw-r--r-- | todolists/views.py | 2 |
3 files changed, 12 insertions, 1 deletions
diff --git a/packages/utils.py b/packages/utils.py index f8b33d23..1104f7d7 100644 --- a/packages/utils.py +++ b/packages/utils.py @@ -15,6 +15,7 @@ from main.utils import (database_vendor, 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 @@ class PackageJSONEncoder(DjangoJSONEncoder): 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: diff --git a/todolists/models.py b/todolists/models.py index 72476b48..f3b46507 100644 --- a/todolists/models.py +++ b/todolists/models.py @@ -80,6 +80,10 @@ class TodolistPackage(models.Model): 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: diff --git a/todolists/views.py b/todolists/views.py index b4d76b31..fdc5cfc6 100644 --- a/todolists/views.py +++ b/todolists/views.py @@ -241,7 +241,7 @@ class TodoListJSONEncoder(PackageJSONEncoder): '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) |