diff --git a/elections2021/management/commands/import_matrix.py b/elections2021/management/commands/import_matrix.py index f80f41df3df128967724b12726de3523a3c35ba5..b100835b24618624b2670439983b221e9621dfd0 100644 --- a/elections2021/management/commands/import_matrix.py +++ b/elections2021/management/commands/import_matrix.py @@ -47,6 +47,7 @@ from ...models import Elections2021ProgramPointPage OLD_TITLE = "old_title" TITLE = "title" +ORDER = "order" FIELDNAMES = ( "x1", @@ -91,6 +92,7 @@ FIELDNAMES = ( MINISTRY_HEALTH, MINISTRY_AGRICULTURE, MINISTRY_ENVIRONMENT, + ORDER, ) @@ -153,6 +155,7 @@ class Command(BaseCommand): page.weight_ministry_health = int(row[MINISTRY_HEALTH]) page.weight_ministry_agriculture = int(row[MINISTRY_AGRICULTURE]) page.weight_ministry_environment = int(row[MINISTRY_ENVIRONMENT]) + page.default_order = int(row[ORDER]) revision = page.save_revision() if was_live and not had_unpublished_changes: diff --git a/elections2021/migrations/0028_elections2021programpointpage_default_order.py b/elections2021/migrations/0028_elections2021programpointpage_default_order.py new file mode 100644 index 0000000000000000000000000000000000000000..9a9dec692ed56502116168e0a3152bf75cc10007 --- /dev/null +++ b/elections2021/migrations/0028_elections2021programpointpage_default_order.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.2 on 2021-05-18 09:36 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("elections2021", "0027_auto_20210518_0147"), + ] + + operations = [ + migrations.AddField( + model_name="elections2021programpointpage", + name="default_order", + field=models.IntegerField(default=0, verbose_name="výchozí řazení"), + ), + ] diff --git a/elections2021/models.py b/elections2021/models.py index e8b4e0fc7693ed88040c1d2c7a2bf861b058928a..5fe4a67a1aff796e7a11fe649129b2484257c712 100644 --- a/elections2021/models.py +++ b/elections2021/models.py @@ -1158,7 +1158,11 @@ class Elections2021ProgramPage( @route(r"^$") def plan_all(self, request): - points = Elections2021ProgramPointPage.objects.live().specific() + points = ( + Elections2021ProgramPointPage.objects.live() + .specific() + .order_by("-default_order") + ) points = Paginator(points, PROGRAM_POINTS_PER_PAGE).get_page( request.GET.get("page") ) @@ -1466,6 +1470,8 @@ class Elections2021ProgramPointPage(SubpageMixin, MetadataPageMixin, Page): blank=True, ) + default_order = models.IntegerField("výchozí řazení", default=0) + # target weights weight_childless = models.IntegerField("váha bezdětní", default=0) weight_parents = models.IntegerField("váha rodiče", default=0) @@ -1581,6 +1587,7 @@ class Elections2021ProgramPointPage(SubpageMixin, MetadataPageMixin, Page): ] weights_panels = [ + FieldPanel("default_order"), MultiFieldPanel( [ FieldPanel("weight_childless"),