Skip to content

Commit

Permalink
✨ for :arrow_dow: download in .html close #48
Browse files Browse the repository at this point in the history
  • Loading branch information
puria committed May 19, 2018
1 parent ef2b279 commit a8971e5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 3 additions & 3 deletions ksweb/ksweb/controllers/questionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,16 @@ def compile(self, _id, workspace, **kwargs):
return dict(questionary=questionary, quest_compiled=questionary.evaluate_questionary,
html=self.get_questionary_html(_id), workspace=workspace)

@expose('odt:ksweb.templates.questionary.questionary', content_type='application/vnd.oasis.opendocument.text')
@expose(content_type='text/html')
@validate({
'_id': QuestionaryExistValidator(required=True),
}, error_handler=validation_errors_response)
@require(CanManageEntityOwner(msg=l_(u'You are not allowed to edit this questionary.'), field='_id',
entity_model=model.Questionary))
def download(self, _id):
questionary = model.Questionary.query.get(_id=ObjectId(_id))
response.headerlist.append(('Content-Disposition', 'attachment;filename=%s.odt' % questionary._id))
return dict(content=self.get_questionary_html(_id).striptags())
response.headerlist.append(('Content-Disposition', 'attachment;filename=%s.html' % questionary._id))
return self.get_questionary_html(_id)

@staticmethod
def get_questionary_html(quest_id):
Expand Down
8 changes: 8 additions & 0 deletions ksweb/ksweb/tests/functional/test_questionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,14 @@ def test_compile_advanced_questionary_not_showing_two_time_same_answer(self):

assert resp['quest_compiled']['completed'] is True, resp

def test_download(self):
self.test_compile_advanced_questionary()
form = self._get_questionary_by_title('Advanced_Questionary')
response = self.app.get('/questionary/download', params=dict(_id=str(form._id)))

assert response
assert str(form._id) in response.content_disposition


def test_completed(self):
self.test_questionary_create()
Expand Down

0 comments on commit a8971e5

Please sign in to comment.