jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/358506 )
Change subject: Expose all toolinfo data for indexing ...................................................................... Expose all toolinfo data for indexing Publish all ToolInfo models at an URL that can be registered with Hay's Directory. Hay's spec allows a single toolinfo.json file to aggregate multiple tools, so this will let us publish all toolinfo data managed via Striker for that tool and others to index themselves. Bug: T149458 Change-Id: I679062cf218266db8a6132ffc3f6fa7afe9043f6 --- M striker/tools/models.py M striker/tools/urls.py M striker/tools/views.py 3 files changed, 46 insertions(+), 0 deletions(-) Approvals: Krinkle: Looks good to me, but someone else must approve BryanDavis: Looks good to me, approved jenkins-bot: Verified diff --git a/striker/tools/models.py b/striker/tools/models.py index b1e67da..59c1204 100644 --- a/striker/tools/models.py +++ b/striker/tools/models.py @@ -18,6 +18,8 @@ # You should have received a copy of the GNU General Public License # along with Striker. If not, see <http://www.gnu.org/licenses/>. +import collections + from django.conf import settings from django.core import urlresolvers from django.db import models @@ -186,3 +188,23 @@ def __str__(self): return self.name + + def toolinfo(self): + if self.is_webservice: + url = 'https://tools.wmflabs.org/{}/{}'.format( + self.tool, + self.suburl + ) + else: + url = self.docs + + return collections.OrderedDict([ + ('name', self.name), + ('title', self.title), + ('description', self.description), + ('url', url), + ('keywords', ", ".join(tag.name for tag in self.tags.all())), + ('author', ", ".join( + a.get_full_name() for a in self.authors.all())), + ('repository', self.repository), + ]) diff --git a/striker/tools/urls.py b/striker/tools/urls.py index 72bed6b..ceadb76 100644 --- a/striker/tools/urls.py +++ b/striker/tools/urls.py @@ -112,4 +112,9 @@ striker.tools.views.ToolInfoTagAutocomplete.as_view(), name='tags_autocomplete' ), + urls.url( + r'toolinfo/v1/toolinfo.json$', + 'striker.tools.views.toolinfo', + name='toolinfo' + ), ] diff --git a/striker/tools/views.py b/striker/tools/views.py index 2f8b853..89f2295 100644 --- a/striker/tools/views.py +++ b/striker/tools/views.py @@ -29,9 +29,11 @@ from django.core import paginator from django.core import urlresolvers from django.core.exceptions import ObjectDoesNotExist +from django.core.serializers.json import DjangoJSONEncoder from django.db import transaction from django.db.utils import DatabaseError from django.http import HttpResponseRedirect +from django.http import JsonResponse from django.utils import timezone from django.utils.text import slugify from django.utils.translation import ugettext_lazy as _ @@ -687,3 +689,20 @@ def create_object(self, text): return ToolInfoTag.objects.create(name=text, slug=slugify(text)) + + +def toolinfo(req): + class PrettyPrintJSONEncoder(DjangoJSONEncoder): + def __init__(self, *args, **kwargs): + kwargs['indent'] = 2 + kwargs['separators'] = (',', ':') + super(PrettyPrintJSONEncoder, self).__init__(*args, **kwargs) + + return JsonResponse( + [ + info.toolinfo() + for info in ToolInfo.objects.all().order_by('name') + ], + encoder=PrettyPrintJSONEncoder, + safe=False, + ) -- To view, visit https://gerrit.wikimedia.org/r/358506 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I679062cf218266db8a6132ffc3f6fa7afe9043f6 Gerrit-PatchSet: 2 Gerrit-Project: labs/striker Gerrit-Branch: master Gerrit-Owner: BryanDavis <bda...@wikimedia.org> Gerrit-Reviewer: Andrew Bogott <abog...@wikimedia.org> Gerrit-Reviewer: BryanDavis <bda...@wikimedia.org> Gerrit-Reviewer: Krinkle <krinklem...@gmail.com> Gerrit-Reviewer: Madhuvishy <mviswanat...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits