Skip to content

Commit

Permalink
Merge pull request #204 from Cadasta/bugfix/#195
Browse files Browse the repository at this point in the history
Fix #195 -- Correct display of project forms
  • Loading branch information
ian-ross committed May 19, 2016
2 parents 196f872 + 90824f2 commit 692a2a0
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 2 deletions.
50 changes: 50 additions & 0 deletions cadasta/organization/tests/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,31 @@ def test_render_with_manager(self):


class PublicPrivateToggleTest(TestCase):
def test_render_none(self):
widget = PublicPrivateToggle()
html = widget.render('field-name', None)

expected = (
'<div class="public-private-widget">'
' <label for"field-name">Project visibility</label>'
' <div>'
' Public<br>'
' <span class="glyphicon glyphicon-eye-open"></span>'
' </div>'
' <div>'
' <input name="field-name" type="checkbox"'
' data-toggle="toggle" data-onstyle="danger"'
' data-offstyle="success" data-on=" " data-off=" ">'
' </div>'
' <div>'
' Private<br>'
' <span class="glyphicon glyphicon-eye-close"></span>'
' </div>'
'</div>'
)

assert expected == html

def test_render_public(self):
widget = PublicPrivateToggle()
html = widget.render('field-name', 'public')
Expand Down Expand Up @@ -108,6 +133,31 @@ def test_render_private(self):

assert expected == html

def test_render_on(self):
widget = PublicPrivateToggle()
html = widget.render('field-name', 'on')

expected = (
'<div class="public-private-widget">'
' <label for"field-name">Project visibility</label>'
' <div>'
' Public<br>'
' <span class="glyphicon glyphicon-eye-open"></span>'
' </div>'
' <div>'
' <input name="field-name" checked type="checkbox"'
' data-toggle="toggle" data-onstyle="danger"'
' data-offstyle="success" data-on=" " data-off=" ">'
' </div>'
' <div>'
' Private<br>'
' <span class="glyphicon glyphicon-eye-close"></span>'
' </div>'
'</div>'
)

assert expected == html


class ContactsWidgetTest(TestCase):
def test_value_from_datadict(self):
Expand Down
1 change: 1 addition & 0 deletions cadasta/organization/views/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ def get_context_data(self, *args, **kwargs):
logo = orgs.first().logo if orgs.first() is not None else ''
context['init_org_logo'] = logo
context['init_org_hidden'] = 'org-logo-hidden' if logo is None else ''
context['display_org'] = self.kwargs.get('organization')
form = context['wizard']['form']
if isinstance(form, forms.ProjectAddExtents):
context['wizard_step_classes'] = {
Expand Down
2 changes: 1 addition & 1 deletion cadasta/organization/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def render(self, name, value, attrs=None):
name=name,
public=_("Public"),
private=_("Private"),
checked=('checked' if value != 'public' else '')
checked=('checked' if value in ['private', 'on'] else '')
)


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 @@ -41,7 +41,7 @@
</div>
</div>

<div class="row{% if wizard.form.organization.value %} hidden{% endif %}">
<div class="row{% if display_org %} hidden{% endif %}">
<div class="col-md-7">
<div class="form-group">
{{ wizard.form.organization.errors }}
Expand Down

0 comments on commit 692a2a0

Please sign in to comment.