Skip to content

Commit

Permalink
Merge pull request #534 from Cadasta/bugfix/#530
Browse files Browse the repository at this point in the history
Fix #530: add project wizard data preservation
  • Loading branch information
oliverroick authored Aug 9, 2016
2 parents 575fb74 + d9fa9a4 commit 7be6296
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 2 deletions.
12 changes: 12 additions & 0 deletions cadasta/organization/tests/test_views_default_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,18 @@ def test_full_flow_valid(self):
assert Questionnaire.objects.filter(project=proj).exists() is True
# assert proj.public

def test_wizard_previous(self):
self.client.force_login(self.users[0])
extents_response = self.client.post(
reverse('project:add'), self.EXTENTS_POST_DATA
)
assert extents_response.status_code == 200
self.DETAILS_POST_DATA['wizard_goto_step'] = 'extents'
details_response = self.client.post(
reverse('project:add'), self.DETAILS_POST_DATA
)
assert details_response.status_code == 200

def test_full_flow_invalid_xlsform(self):
self.client.force_login(self.users[0])
extents_response = self.client.post(
Expand Down
9 changes: 9 additions & 0 deletions cadasta/organization/views/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,15 @@ def process_step(self, form):

return result

def render_goto_step(self, goto_step, **kwargs):
form = self.get_form(data=self.request.POST, files=self.request.FILES)
if form.is_valid():
self.storage.set_step_data(self.steps.current,
self.process_step(form))
self.storage.set_step_files(self.steps.current,
self.process_step_files(form))
return super().render_goto_step(goto_step, **kwargs)

def get_form_kwargs(self, step=None):
if step == 'details':
return {
Expand Down
2 changes: 1 addition & 1 deletion cadasta/templates/organization/project_add_details.html
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ <h3>3. Contacts</h3>
{% endblock %}

{% block step_content_buttons %}
<button class="btn btn-default" type="submit" name="wizard_goto_step" value="{{ wizard.steps.prev }}">
<button class="btn btn-default btn-details-previous" type="submit" name="wizard_goto_step" value="{{ wizard.steps.prev }}">
<span class="glyphicon glyphicon-triangle-left"></span>
{% trans "Previous" %}
</button>
Expand Down
5 changes: 5 additions & 0 deletions functional_tests/pages/ProjectAdd.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,11 @@ def click_submit_details(self):
submit_button = self.BY_CLASS('btn-primary')
submit_button.click()

def click_previous_details(self):
previous_button = self.BY_CLASS('btn-details-previous')
self.test.click_through(previous_button,
(By.CLASS_NAME, 'project-extent-map'))

def try_submit_details(self):
"""This method should be called when the details form has at
least one error. The method will attempt to submit the already
Expand Down
8 changes: 7 additions & 1 deletion functional_tests/projects/test_project_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,15 @@ def generic_test_orgadmin(self, access):
proj_add_page.click_submit_details()
proj_add_page.check_details(project)

# Correct the URL and finally submit details
# Correct the URL, press "Previous" then "Next" and ensure
# that details settings are preserved.
project['url'] = self.test_data['project_url']
proj_add_page.set_proj_url(project['url'])
proj_add_page.click_previous_details()
proj_add_page.submit_geometry()
proj_add_page.check_details(project)

# Finally submit details
proj_add_page.submit_details()

# Set permissions
Expand Down

0 comments on commit 7be6296

Please sign in to comment.