10000 DW: Added download form as an xls functionality by denniswambua · Pull Request #543 · onaio/onadata · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

DW: Added download form as an xls functionality #543

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 12, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions 8000 & 0 deletions onadata/apps/api/tests/viewsets/test_xform_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ def test_form_format(self):
response = view(request, pk=formid, format='xml')
self.assertEqual(response.status_code, 200)
response_doc = minidom.parseString(response.data)
response = view(request, pk=formid, format='xls')
self.assertEqual(response.status_code, 200)

xml_path = os.path.join(
settings.PROJECT_ROOT, "apps", "main", "tests", "fixtures",
Expand Down
19 changes: 16 additions & 3 deletions onadata/apps/api/viewsets/xform_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,12 @@ def _get_owner(request):


def response_for_format(data, format=None):
formatted_data = data.xml if format == 'xml' else json.loads(data.json)
if format == 'xml':
formatted_data = data.xml
elif format == 'xls':
formatted_data = data.xls
else:
formatted_data = json.loads(data.json)
return Response(formatted_data)


Expand Down Expand Up @@ -339,7 +344,7 @@ class XFormViewSet(AnonymousUserPublicFormsMixin, LabelsMixin, ModelViewSet):
> ...
> }, ...]

## Get `JSON` | `XML` Form Representation
## Get `JSON` | `XML` | `XLS` Form Representation
<pre class="prettyprint">
<b>GET</b> /api/v1/forms/<code>{pk}</code>/form.\
<code>{format}</code></pre>
Expand Down Expand Up @@ -381,6 +386,14 @@ class XFormViewSet(AnonymousUserPublicFormsMixin, LabelsMixin, ModelViewSet):
> </h:body>
> </h:html>

> XLS Example
>
> curl -X GET https://ona.io/api/v1/forms/28058/form.xls

> Response
>
> Xls file downloaded

## Get list of forms with specific tag(s)

Use the `tags` query parameter to filter the list of forms, `tags` should be a
Expand Down Expand Up @@ -591,7 +604,7 @@ def create(self, request, *args, **kwargs):
@action(methods=['GET'])
def form(self, request, format='json', **kwargs):
form = self.get_object()
if format not in ['json', 'xml']:
if format not in ['json', 'xml', 'xls']:
return HttpResponseBadRequest('400 BAD REQUEST',
mimetype='application/json',
status=400)
Expand Down
0