-
-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #523 from kobotoolbox/new-hook-signal-endpoint
Changed 'kpi' endpoint for hook signal
- Loading branch information
Showing
4 changed files
with
35 additions
and
2 deletions.
There are no files selected for viewing
Empty file.
Empty file.
33 changes: 33 additions & 0 deletions
33
onadata/apps/restservice/management/commands/update_kpi_hooks_endpoint.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/usr/bin/env python | ||
# vim: ai ts=4 sts=4 et sw=4 coding=utf-8 | ||
from django.core.management.base import BaseCommand | ||
from django.utils.translation import ugettext as _, ugettext_lazy | ||
|
||
from onadata.apps.restservice.models import RestService | ||
|
||
|
||
class Command(BaseCommand): | ||
""" | ||
A faster method is available with PostgreSQL: | ||
UPDATE restservice_restservice | ||
SET service_url = REGEXP_REPLACE( | ||
service_url, | ||
'/assets/([^/]*)/submissions/', | ||
'/assets/\1/hook-signal/' | ||
) | ||
WHERE service_url LIKE '/assets/%'; | ||
""" | ||
|
||
help = ugettext_lazy("Updates KPI rest service endpoint") | ||
|
||
def handle(self, *args, **kwargs): | ||
|
||
rest_services = RestService.objects.filter(name="kpi_hook").all() | ||
for rest_service in rest_services: | ||
service_url = rest_service.service_url | ||
if service_url.endswith("/submissions/"): | ||
service_url = service_url.replace("/submissions/", "/hook-signal/") | ||
rest_service.service_url = service_url | ||
rest_service.save(update_fields=["service_url"]) | ||
|
||
print("Done!") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters