Merge pull request #4722 from FinnStutzenstein/motionTextNotRequiredForParagraphAmendments

Do not require the motion text for paragraph based amendments
This commit is contained in:
Emanuel Schütze 2019-05-20 21:46:15 +02:00 committed by GitHub
commit 0a99c2b0f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 40 additions and 33 deletions

View File

@ -46,32 +46,18 @@
<mat-step>
<ng-template matStepLabel>{{ 'Change paragraph' | translate }}</ng-template>
<h3><span translate>Amendment text</span>&nbsp;<span>*</span></h3>
<h3><span translate>Amendment text</span></h3>
<!-- Text -->
<section *ngFor="let paragraph of contentForm.value.selectedParagraphs">
<h4 [class.red-warning-text]="contentForm.get('text_' + paragraph.paragraphNo).invalid && (
contentForm.get('text_' + paragraph.paragraphNo).dirty ||
contentForm.get('text_' + paragraph.paragraphNo).touched
)"
>
<h4>
<span *ngIf="paragraph.lineFrom >= paragraph.lineTo - 1" class="line-number">
{{ 'Line' | translate }} {{ paragraph.lineFrom }}</span>&nbsp;<span>*</span>
{{ 'Line' | translate }} {{ paragraph.lineFrom }}:</span>
<span *ngIf="paragraph.lineFrom < paragraph.lineTo - 1" class="line-number">
{{ 'Line' | translate }} {{ paragraph.lineFrom }}
- {{ paragraph.lineTo - 1 }}</span>&nbsp;<span>*</span>
- {{ paragraph.lineTo - 1 }}:</span>
</h4>
<editor [formControlName]="'text_' + paragraph.paragraphNo" [init]="tinyMceSettings" required></editor>
<div
*ngIf="contentForm.get('text_' + paragraph.paragraphNo).invalid && (
contentForm.get('text_' + paragraph.paragraphNo).dirty ||
contentForm.get('text_' + paragraph.paragraphNo).touched
)"
class="red-warning-text"
translate
>
This field is required.
</div>
<editor [formControlName]="'text_' + paragraph.paragraphNo" [init]="tinyMceSettings"></editor>
</section>
<!-- Reason -->

View File

@ -645,15 +645,14 @@
<!-- The HTML Editor for paragraph-based amendments -->
<ng-container *ngIf="motion && editMotion && motion.isParagraphBasedAmendment()">
<section *ngFor="let paragraph of contentForm.value.selected_paragraphs">
<h4>
<h3>
<span *ngIf="paragraph.lineFrom >= paragraph.lineTo - 1" class="line-number">
{{ 'Line' | translate }} {{ paragraph.lineFrom }}</span
>
{{ 'Line' | translate }} {{ paragraph.lineFrom }}
</span>
<span *ngIf="paragraph.lineFrom < paragraph.lineTo - 1" class="line-number">
{{ 'Line' | translate }} {{ paragraph.lineFrom }} - {{ paragraph.lineTo - 1 }}</span
>&nbsp;
<span>*</span>
</h4>
{{ 'Line' | translate }} {{ paragraph.lineFrom }} - {{ paragraph.lineTo - 1 }}
</span>
</h3>
<editor [formControlName]="'text_' + paragraph.paragraphNo" [init]="tinyMceSettings" required></editor>
<div
*ngIf="
@ -840,13 +839,13 @@
*ngIf="paragraph.diffLineTo === paragraph.diffLineFrom + 1 && !showAmendmentContext"
class="amendment-line-header"
>
<span translate>Line</span> {{ paragraph.diffLineFrom }}:
{{ 'Line' | translate }} {{ paragraph.diffLineFrom }}:
</h3>
<h3
*ngIf="paragraph.diffLineTo !== paragraph.diffLineFrom + 1 && !showAmendmentContext"
class="amendment-line-header"
>
<span translate>Line</span> {{ paragraph.diffLineFrom }} - {{ paragraph.diffLineTo - 1 }}:
{{ 'Line' | translate }} {{ paragraph.diffLineFrom }} - {{ paragraph.diffLineTo - 1 }}:
</h3>
<div class="paragraphcontext" [innerHtml]="sanitizedText(paragraph.textPre)"></div>

View File

@ -77,6 +77,10 @@ span {
}
}
.amendment-line-header {
font-style: italic;
}
.motion-content {
h4 {
margin: 10px 10px 15px 0;

View File

@ -656,7 +656,7 @@ export class MotionDetailComponent extends BaseViewComponent implements OnInit,
paragraphsToChoose.forEach(
(paragraph: ParagraphToChoose, paragraphNo: number): void => {
if (formMotion.amendment_paragraphs[paragraphNo]) {
if (formMotion.amendment_paragraphs[paragraphNo] !== null) {
this.contentForm.addControl(
'text_' + paragraphNo,
new FormControl('', Validators.required)

View File

@ -401,7 +401,8 @@ class MotionSerializer(ModelSerializer):
modified_final_version = CharField(allow_blank=True, required=False)
reason = CharField(allow_blank=True, required=False)
state_restriction = SerializerMethodField()
text = CharField(allow_blank=True)
text = CharField(allow_blank=True, required=False) # This will be checked
# during validation
title = CharField(max_length=255)
amendment_paragraphs = AmendmentParagraphsJSONSerializerField(required=False)
workflow_id = IntegerField(
@ -472,6 +473,7 @@ class MotionSerializer(ModelSerializer):
if "reason" in data:
data["reason"] = validate_html(data["reason"])
# The motion text is only needed, if it is not a paragraph based amendment.
if "amendment_paragraphs" in data:
data["amendment_paragraphs"] = list(
map(
@ -483,7 +485,9 @@ class MotionSerializer(ModelSerializer):
)
data["text"] = ""
else:
if "text" in data and not data["text"]:
if (self.partial and "text" in data and not data["text"]) or (
not self.partial and not data.get("text")
):
raise ValidationError({"detail": "The text field may not be blank."})
if config["motions_reason_required"]:
if (self.partial and "reason" in data and not data["reason"]) or (

View File

@ -266,9 +266,15 @@ class CreateMotion(TestCase):
def test_without_data(self):
response = self.client.post(reverse("motion-list"), {})
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertTrue("title" in response.data)
def test_without_text(self):
response = self.client.post(
reverse("motion-list"), {"title": "test_title_dlofp23m9O(ZD2d1lwHG"}
)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(
response.data,
{"title": ["This field is required."], "text": ["This field is required."]},
str(response.data["detail"][0]), "The text field may not be blank."
)
def test_with_category(self):
@ -569,6 +575,14 @@ class UpdateMotion(TestCase):
self.assertEqual(motion.title, "test_title_aeng7ahChie3waiR8xoh")
self.assertEqual(motion.identifier, "test_identifier_jieseghohj7OoSah1Ko9")
def test_patch_empty_text(self):
response = self.client.patch(
reverse("motion-detail", args=[self.motion.pk]), {"text": ""}, format="json"
)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
motion = Motion.objects.get()
self.assertEqual(motion.text, "test_text_xeigheeha7thopubeu4U")
def test_patch_workflow(self):
"""
Tests to only update the workflow of a motion.