-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modify dropdown validate against to include rz-lgr, RefLgr and members.
Add a component to the utils to fetch the latest RefLgr list.
- Loading branch information
Showing
15 changed files
with
107 additions
and
49 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
19 changes: 14 additions & 5 deletions
19
src/lgr_basic/tests/test_validate_labels_against_dropdown.py
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 |
---|---|---|
@@ -1,25 +1,34 @@ | ||
from lgr_basic.forms import ValidateLabelSimpleForm | ||
from lgr_models.models.lgr import RzLgr | ||
from lgr_models.tests.lgr_webclient_test_base import LgrWebClientTestBase | ||
|
||
|
||
class TestValidateLabelsAgainstDropDown(LgrWebClientTestBase): | ||
test_label = 'مكتب' # arab character valid since the beginning (rz lgr version 1) | ||
dropdown_label = 'RZ-LGR 4' | ||
dropdown_lgr_keys = LgrWebClientTestBase.default_root_zones + ['Ref. LGR'] | ||
|
||
def test_validate_labels_against_full(self): | ||
self.login_admin() | ||
|
||
# given | ||
response = self.client.get('/b/') | ||
dropdown = response.context['widget'] | ||
self.assertEquals('rz_lgr', dropdown['name']) | ||
dropdown_dict = {v[1][0]['label']: v[1][0]['value'] for v in dropdown['optgroups']} | ||
self.assertListEqual(list(dropdown_dict.keys()), self.default_root_zones) | ||
form = response.context['form'] | ||
values = form.fields['rz_lgr'].choices | ||
dropdown_dict = {v[0][0]:v[1][0][0] for v in values} | ||
|
||
# when | ||
response = self.client.post('/b/', | ||
{'rz_lgr': dropdown_dict[self.dropdown_label], 'collisions': False, | ||
'labels': self.test_label}) | ||
|
||
# then | ||
self.assertEquals('rz_lgr', dropdown['name']) | ||
self.assertListEqual(list(dropdown_dict.keys()), self.dropdown_lgr_keys) | ||
self.assertNotContains(response, 'INVALID', status_code=200) | ||
|
||
def test_validate_labels_against(self): | ||
dropdown = ValidateLabelSimpleForm() | ||
values = [v[1] for v in dropdown.fields['rz_lgr'].choices] | ||
self.assertListEqual(values, self.default_root_zones) | ||
values = [v[0][0] for v in dropdown.fields['rz_lgr'].choices] | ||
self.assertListEqual(values, self.dropdown_lgr_keys) |
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
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,20 @@ | ||
from django.core.exceptions import ValidationError | ||
|
||
from lgr_utils.views import RefLgrAutocomplete | ||
from django import forms | ||
|
||
|
||
class RefLgrAutocompleteField(forms.ChoiceField): | ||
def validate(self, value): | ||
found = False | ||
for lgr_types in RefLgrAutocomplete.get_list(): | ||
for lgr in lgr_types[1]: | ||
if value == lgr[0]: | ||
found = True | ||
break; | ||
if not found: | ||
raise ValidationError( | ||
self.error_messages['invalid_choice'], | ||
code='invalid_choice', | ||
params={'value': value}, | ||
) |
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,11 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from django.urls import path | ||
|
||
from lgr_utils.views import RefLgrAutocomplete | ||
|
||
urlpatterns = [ | ||
# autocompletion | ||
path('ref-lgr-autocomplete/', RefLgrAutocomplete.as_view(), name='ref-lgr-autocomplete'), | ||
] |
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,18 @@ | ||
from dal_select2.views import Select2GroupListView | ||
from django.contrib.auth.mixins import LoginRequiredMixin | ||
|
||
from lgr_models.models.lgr import RzLgr, RzLgrMember, RefLgr | ||
|
||
|
||
class RefLgrAutocomplete(LoginRequiredMixin, Select2GroupListView): | ||
|
||
@staticmethod | ||
def get_list(): | ||
lgr_choices = [] | ||
for rz in RzLgr.objects.filter(active=True): | ||
rz_member_choices = ((str(rz.to_tuple()), rz.name),) + tuple( | ||
(str(rz_member.to_tuple()), rz_member.name) for rz_member in RzLgrMember.objects.filter(rz_lgr=rz)) | ||
lgr_choices += [((rz.name, rz.name), rz_member_choices)] | ||
lgr_choices += [(('Ref. LGR', 'Ref. LGR'), tuple( | ||
((str(ref_lgr.to_tuple()), ref_lgr.name) for ref_lgr in RefLgr.objects.all())))] | ||
return lgr_choices |
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