-
Notifications
You must be signed in to change notification settings - Fork 8
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 #201 from rapidpro/develop
Updates for deploy for 1.5.1
- Loading branch information
Showing
31 changed files
with
858 additions
and
273 deletions.
There are no files selected for viewing
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
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
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
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
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,53 @@ | ||
from django.conf import settings | ||
from temba_client.clients import CursorQuery | ||
from temba_client.v2 import Boundary, TembaClient | ||
|
||
|
||
def get_client(org): | ||
host = getattr(settings, 'SITE_API_HOST', None) | ||
agent = getattr(settings, 'SITE_API_USER_AGENT', None) | ||
return make_client(host, org.api_token, user_agent=agent) | ||
|
||
|
||
def make_client(host, api_token, user_agent): | ||
# This method looks pointless, but it lets us mock it easily | ||
# and change every call that returns a client. | ||
return TracProClient(host, api_token, user_agent=user_agent) | ||
|
||
|
||
class TracProClient(TembaClient): | ||
""" | ||
Customized TembaClient where the API calls that return multiple things | ||
actually return them without having to tack on .all(). | ||
(Does this by returning a TracProCursorQuery instead of a CursorQuery. | ||
Apart from being iterable-over, it should work the same.) | ||
""" | ||
def _get_query(self, endpoint, params, clazz): | ||
""" | ||
GETs a result query for the given endpoint | ||
""" | ||
return TracProCursorQuery(self, '%s/%s.json' % (self.root_url, endpoint), params, clazz) | ||
|
||
def get_boundaries(self): | ||
return self._get_query('boundaries', {'geometry': 'true'}, Boundary) | ||
|
||
|
||
class TracProCursorQuery(CursorQuery): | ||
""" | ||
Customized CursorQuery that allows iterating over it without having | ||
to call `.all()` on it. More Pythonic. | ||
FYI: Always acts as if `retry_on_rate_exceed` is True. If more control | ||
is needed, use the underlying client directly. | ||
""" | ||
def _get_result(self): | ||
if not hasattr(self, '_result'): | ||
self._result = self.all(True) | ||
return self._result | ||
|
||
def __iter__(self): | ||
return self._get_result().__iter__() | ||
|
||
def __getitem__(self, index): | ||
return self._get_result()[index] |
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,19 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('contacts', '0013_auto_20161118_1516'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='datafield', | ||
name='value_type', | ||
field=models.CharField(max_length=1, verbose_name='value type', choices=[('T', 'Text'), ('N', 'Numeric'), ('D', 'Datetime'), ('S', 'State'), ('I', 'District'), ('N', 'Numeric'), ('W', 'Ward')]), | ||
), | ||
] |
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
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
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
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
Oops, something went wrong.