Commit f96a3f7f45a3e7ba2863f119a50c710539e9ab34
1 parent
71a6fc6f
brak wymagania atrybutów dla kandydatów
Showing
3 changed files
with
28 additions
and
13 deletions
dictionary/ajax_lexeme_view.py
... | ... | @@ -254,6 +254,7 @@ def update_lexeme(request, form_data): |
254 | 254 | l.save() |
255 | 255 | else: |
256 | 256 | raise AjaxError(error_messages(form)) |
257 | + cand = l.status == Lexeme.STATUS_CANDIDATE | |
257 | 258 | |
258 | 259 | for vocab in editable_vocabularies(request.user): |
259 | 260 | if vocab != owner: |
... | ... | @@ -270,13 +271,16 @@ def update_lexeme(request, form_data): |
270 | 271 | parts_of_speech=l.part_of_speech) |
271 | 272 | for c in classifications: |
272 | 273 | classification_form = ClassificationForm( |
273 | - data=form_dict, classification=c, prefix='cl' + str(c.pk)) | |
274 | + data=form_dict, classification=c, prefix='cl' + str(c.pk), | |
275 | + required=not cand) | |
274 | 276 | if classification_form.is_valid(): |
275 | - cvs = ClassificationValue.objects.filter( | |
276 | - pk__in=classification_form.cleaned_data['values']) | |
277 | + values = classification_form.cleaned_data['values'] | |
278 | + if values is None: | |
279 | + values = () | |
280 | + cvs = ClassificationValue.objects.filter(pk__in=values) | |
277 | 281 | l_cvs = l.classification_values(c) |
278 | 282 | for cv in l_cvs: |
279 | - if cv.pk not in classification_form.cleaned_data['values']: | |
283 | + if cv.pk not in values: | |
280 | 284 | cv.remove_lexeme(l) |
281 | 285 | for cv in cvs: |
282 | 286 | if cv not in l_cvs: |
... | ... | @@ -344,7 +348,8 @@ def update_lexeme(request, form_data): |
344 | 348 | attribute=attr, data=form_dict, prefix=prefix) |
345 | 349 | else: |
346 | 350 | attr_form = LexemeClosedAttributeForm( |
347 | - attribute=attr, data=form_dict, prefix=prefix) | |
351 | + attribute=attr, data=form_dict, prefix=prefix, | |
352 | + required=not cand) | |
348 | 353 | if attr_form.is_valid(): |
349 | 354 | if not attr.closed: |
350 | 355 | value = attr_form.cleaned_data['value'] |
... | ... | @@ -362,9 +367,12 @@ def update_lexeme(request, form_data): |
362 | 367 | else: |
363 | 368 | prefix = 'attrmulti' + str(attr.pk) |
364 | 369 | attr_form = LexemeMultipleAttributeForm( |
365 | - attribute=attr, data=form_dict, prefix=prefix) | |
370 | + attribute=attr, data=form_dict, prefix=prefix, | |
371 | + required=not cand) | |
366 | 372 | if attr_form.is_valid(): |
367 | 373 | new_values = attr_form.cleaned_data['value'] |
374 | + if new_values is None: | |
375 | + new_values = () | |
368 | 376 | for av in set(attr_values) - set(new_values): |
369 | 377 | av.remove_lexeme(l) |
370 | 378 | for av in set(new_values) - set(attr_values): |
... | ... |
dictionary/forms.py
... | ... | @@ -150,10 +150,10 @@ class LexemeEditForm(ModelForm): |
150 | 150 | |
151 | 151 | # abstract |
152 | 152 | class LexemeAttributeForm(Form): |
153 | - def __init__(self, attribute, **kwargs): | |
153 | + def __init__(self, attribute, required=True, **kwargs): | |
154 | 154 | super(LexemeAttributeForm, self).__init__(**kwargs) |
155 | 155 | self.fields['value'].label = attribute.name |
156 | - self.fields['value'].required = attribute.required | |
156 | + self.fields['value'].required = attribute.required and required | |
157 | 157 | |
158 | 158 | |
159 | 159 | class LexemeOpenAttributeForm(LexemeAttributeForm): |
... | ... | @@ -249,10 +249,11 @@ class ClassificationForm(Form): |
249 | 249 | widget=SelectMultiple(attrs={'class': 'classification-values'})) |
250 | 250 | |
251 | 251 | def __init__(self, classification, editable=True, values=None, |
252 | - **kwargs): | |
252 | + required=True, **kwargs): | |
253 | 253 | super(ClassificationForm, self).__init__(**kwargs) |
254 | 254 | self.fields['values'].label = classification.name |
255 | 255 | self.fields['values'].choices = classification.make_choices() |
256 | + self.fields['values'].required = required | |
256 | 257 | if values: |
257 | 258 | self.fields['values'].initial = [value.pk for value in values] |
258 | 259 | if not editable: |
... | ... |
dictionary/models.py
... | ... | @@ -769,10 +769,17 @@ class LexemeInflectionPattern(Model): |
769 | 769 | tabletemplate=None).filter(id__in=l_attr_vals)) |
770 | 770 | for attr_val in relevant_attr_vals: |
771 | 771 | tts = tts.filter(attribute_values=attr_val) |
772 | - return tts.get() | |
772 | + try: | |
773 | + return tts.get() | |
774 | + except TableTemplate.MultipleObjectsReturned: | |
775 | + return None | |
776 | + except TableTemplate.DoesNotExist: | |
777 | + return None | |
773 | 778 | |
774 | 779 | def cells(self, variant='1'): |
775 | 780 | tt = self.table_template(variant) |
781 | + if not tt: | |
782 | + return [] | |
776 | 783 | return tt.filter_table_cells( |
777 | 784 | self.pattern.type, self.gender, |
778 | 785 | self.lexeme.lexemeattributevalue_set.all()) |
... | ... | @@ -782,9 +789,8 @@ class LexemeInflectionPattern(Model): |
782 | 789 | |
783 | 790 | def inflection_table(self, variant, separated=False, qualifiers=None, |
784 | 791 | edit_view=False, attr_vals=None, span=False): |
785 | - try: | |
786 | - tt = self.table_template(variant) | |
787 | - except TableTemplate.DoesNotExist: | |
792 | + tt = self.table_template(variant) | |
793 | + if tt is None: | |
788 | 794 | return [] |
789 | 795 | lip_qualifiers = self.qualifiers.all() if not edit_view else [] |
790 | 796 | if attr_vals is None: |
... | ... |