|
8 | 8 | CountrySerializer, |
9 | 9 | MiniDistrictSerializer, |
10 | 10 | ) |
| 11 | +from api.models import District |
11 | 12 |
|
12 | 13 | from eap.models import ( |
13 | 14 | EAP, |
@@ -60,7 +61,7 @@ class Meta: |
60 | 61 | read_only_fields = ('early_action',) |
61 | 62 |
|
62 | 63 |
|
63 | | -class PrioritizedRiskSerializer(serializers.ModelSerializer): |
| 64 | +class PrioritizedRiskSerializer(serializers.ModelSerializer): |
64 | 65 | class Meta: |
65 | 66 | model = PrioritizedRisk |
66 | 67 | fields = ('__all__') |
@@ -118,74 +119,26 @@ class EAPSerializer( |
118 | 119 |
|
119 | 120 | class Meta: |
120 | 121 | model = EAP |
121 | | - fields = [ |
122 | | - "id", |
123 | | - "created_at", |
124 | | - "modified_at", |
125 | | - "eap_number", |
126 | | - "approval_date", |
127 | | - "status", |
128 | | - "operational_timeframe", |
129 | | - "lead_time", |
130 | | - "eap_timeframe", |
131 | | - "num_of_people", |
132 | | - "total_budget", |
133 | | - "readiness_budget", |
134 | | - "pre_positioning_budget", |
135 | | - "early_action_budget", |
136 | | - "trigger_statement", |
137 | | - "overview", |
138 | | - "originator_name", |
139 | | - "originator_title", |
140 | | - "originator_email", |
141 | | - "originator_phone", |
142 | | - "nsc_name", |
143 | | - "nsc_title", |
144 | | - "nsc_email", |
145 | | - "nsc_phone", |
146 | | - "ifrc_focal_name", |
147 | | - "ifrc_focal_title", |
148 | | - "ifrc_focal_email", |
149 | | - "ifrc_focal_phone", |
150 | | - "created_by", |
151 | | - "created_by_details", |
152 | | - "modified_by", |
153 | | - "modified_by_details", |
154 | | - "country", |
155 | | - "country_details", |
156 | | - # "districts", |
157 | | - "districts_details", |
158 | | - "disaster_type", |
159 | | - "hazard_type_details", |
160 | | - "status_display", |
161 | | - "references", |
162 | | - "partners", |
163 | | - "documents", |
164 | | - "documents_details", |
165 | | - "early_actions", |
166 | | - ] |
167 | | - |
168 | | - def validate(self, validated_data): |
169 | | - if self.partial: |
170 | | - return validated_data |
171 | | - districts = validated_data.get('districts', None) |
172 | | - if districts: |
| 122 | + fields = ('__all__') |
| 123 | + |
| 124 | + def validate(self, data): |
| 125 | + if 'districts' in data: |
| 126 | + districts = data.get('districts') or [] |
| 127 | + country = data.get('country') |
173 | 128 | for district in districts: |
174 | | - if district.country != validated_data['country']: |
| 129 | + if district.country != country: |
175 | 130 | raise serializers.ValidationError({ |
176 | | - 'district': ugettext('Different districts found for given country') |
| 131 | + 'districts': ugettext('Different districts found for given country') |
177 | 132 | }) |
178 | | - return validated_data |
| 133 | + return data |
179 | 134 |
|
180 | 135 | def create(self, validated_data): |
181 | 136 | validated_data['created_by'] = self.context['request'].user |
182 | | - eap = super().create(validated_data) |
183 | | - return eap |
| 137 | + return super().create(validated_data) |
184 | 138 |
|
185 | 139 | def update(self, instance, validated_data): |
186 | 140 | validated_data['modified_by'] = self.context['request'].user |
187 | | - eap = super().update(instance, validated_data) |
188 | | - return eap |
| 141 | + return super().update(instance, validated_data) |
189 | 142 |
|
190 | 143 |
|
191 | 144 | class EAPActivationSerializer(serializers.ModelSerializer): |
|
0 commit comments