From d182c2c36fffc5d05ca429f2759cdd7c881cff8a Mon Sep 17 00:00:00 2001 From: FinnStutzenstein Date: Mon, 5 Aug 2019 13:11:32 +0200 Subject: [PATCH] Cascade categories on delete --- .../category-detail.component.ts | 2 +- .../category-list/category-list.component.ts | 2 +- .../0032_category_cascade_delete.py | 24 +++++++++++++++++++ openslides/motions/models.py | 6 ++--- 4 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 openslides/motions/migrations/0032_category_cascade_delete.py diff --git a/client/src/app/site/motions/modules/category/components/category-detail/category-detail.component.ts b/client/src/app/site/motions/modules/category/components/category-detail/category-detail.component.ts index 01c444cd9..288aee6bf 100644 --- a/client/src/app/site/motions/modules/category/components/category-detail/category-detail.component.ts +++ b/client/src/app/site/motions/modules/category/components/category-detail/category-detail.component.ts @@ -158,7 +158,7 @@ export class CategoryDetailComponent extends BaseViewComponent implements OnInit * Click handler to delete a category */ public async onDeleteButton(): Promise { - const title = this.translate.instant('Are you sure you want to delete this category?'); + const title = this.translate.instant('Are you sure you want to delete this category and all subcategories?'); const content = this.selectedCategory.prefixedName; if (await this.promptService.open(title, content)) { await this.repo.delete(this.selectedCategory); diff --git a/client/src/app/site/motions/modules/category/components/category-list/category-list.component.ts b/client/src/app/site/motions/modules/category/components/category-list/category-list.component.ts index defe562a1..18f8afa46 100644 --- a/client/src/app/site/motions/modules/category/components/category-list/category-list.component.ts +++ b/client/src/app/site/motions/modules/category/components/category-list/category-list.component.ts @@ -80,7 +80,7 @@ export class CategoryListComponent extends BaseViewComponent implements OnInit { this.dataSource = new MatTableDataSource(); this.repo.getViewModelListObservable().subscribe(viewCategories => { - if (viewCategories && viewCategories.length && this.dataSource) { + if (viewCategories && this.dataSource) { this.dataSource.data = viewCategories; } }); diff --git a/openslides/motions/migrations/0032_category_cascade_delete.py b/openslides/motions/migrations/0032_category_cascade_delete.py new file mode 100644 index 000000000..845cb75bc --- /dev/null +++ b/openslides/motions/migrations/0032_category_cascade_delete.py @@ -0,0 +1,24 @@ +# Generated by Django 2.2.3 on 2019-08-05 10:50 + +from django.db import migrations, models + +import openslides.utils.models + + +class Migration(migrations.Migration): + + dependencies = [("motions", "0031_state_css_classes_2")] + + operations = [ + migrations.AlterField( + model_name="category", + name="parent", + field=models.ForeignKey( + blank=True, + null=True, + on_delete=openslides.utils.models.CASCADE_AND_AUTOUPDATE, + related_name="children", + to="motions.Category", + ), + ) + ] diff --git a/openslides/motions/models.py b/openslides/motions/models.py index 9c181afe5..d5e6ba9a8 100644 --- a/openslides/motions/models.py +++ b/openslides/motions/models.py @@ -804,14 +804,14 @@ class Category(RESTModelMixin, models.Model): """Name of the category.""" prefix = models.CharField(blank=True, max_length=32) - """Prefix of the category. - + """ + Prefix of the category. Used to build the identifier of a motion. """ parent = models.ForeignKey( "self", - on_delete=SET_NULL_AND_AUTOUPDATE, + on_delete=CASCADE_AND_AUTOUPDATE, null=True, blank=True, related_name="children",