Replace deprecated PlaceholderField

This commit is contained in:
Stefan Wehrmeyer 2025-05-24 07:52:54 +02:00
parent 398eef9120
commit 374f6f762e
3 changed files with 27 additions and 8 deletions

View file

@ -1,5 +1,4 @@
from adminsortable2.admin import SortableAdminMixin from adminsortable2.admin import SortableAdminMixin
from cms.admin.placeholderadmin import PlaceholderAdminMixin
from django.contrib import admin, auth from django.contrib import admin, auth
from django.contrib.auth.models import Group from django.contrib.auth.models import Group
from django.shortcuts import get_object_or_404, redirect, render from django.shortcuts import get_object_or_404, redirect, render
@ -330,9 +329,7 @@ class GovernmentPlanUpdateAdmin(admin.ModelAdmin):
return super().has_change_permission(request, obj=obj) return super().has_change_permission(request, obj=obj)
class GovernmentPlanSectionAdmin( class GovernmentPlanSectionAdmin(SortableAdminMixin, admin.ModelAdmin):
SortableAdminMixin, PlaceholderAdminMixin, admin.ModelAdmin
):
save_on_top = True save_on_top = True
prepopulated_fields = {"slug": ("title",)} prepopulated_fields = {"slug": ("title",)}
search_fields = ("title",) search_fields = ("title",)

View file

@ -0,0 +1,16 @@
# Generated by Django 5.2.1 on 2025-05-24 05:52
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
("froide_govplan", "0013_government_active"),
]
operations = [
migrations.RemoveField(
model_name="governmentplansection",
name="content_placeholder",
),
]

View file

@ -9,6 +9,7 @@ from django.contrib.postgres.search import SearchQuery, SearchRank, SearchVector
from django.db import models from django.db import models
from django.urls import reverse from django.urls import reverse
from django.utils import timezone from django.utils import timezone
from django.utils.functional import cached_property
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from filer.fields.image import FilerImageField from filer.fields.image import FilerImageField
from froide.follow.models import Follower from froide.follow.models import Follower
@ -22,11 +23,12 @@ from . import conf
from .utils import make_request_url from .utils import make_request_url
try: try:
from cms.models.fields import PlaceholderField from cms.models.fields import PlaceholderRelationField
from cms.utils.placeholder import get_placeholder_from_slot
from cms.models.pluginmodel import CMSPlugin from cms.models.pluginmodel import CMSPlugin
except ImportError: except ImportError:
CMSPlugin = None CMSPlugin = None
PlaceholderField = None PlaceholderRelationField = None
if conf.GOVPLAN_ENABLE_FOIREQUEST: if conf.GOVPLAN_ENABLE_FOIREQUEST:
@ -453,8 +455,8 @@ class GovernmentPlanSection(models.Model):
order = models.PositiveIntegerField(default=0) order = models.PositiveIntegerField(default=0)
featured = models.DateTimeField(null=True, blank=True) featured = models.DateTimeField(null=True, blank=True)
if PlaceholderField: if PlaceholderRelationField:
content_placeholder = PlaceholderField("content") placeholders = PlaceholderRelationField()
class Meta: class Meta:
verbose_name = _("Government plan section") verbose_name = _("Government plan section")
@ -476,6 +478,10 @@ class GovernmentPlanSection(models.Model):
def get_absolute_domain_url(self): def get_absolute_domain_url(self):
return settings.SITE_URL + self.get_absolute_url() return settings.SITE_URL + self.get_absolute_url()
@cached_property
def content_placeholder(self):
return get_placeholder_from_slot(self.placeholders, "content")
def get_plans(self, queryset=None): def get_plans(self, queryset=None):
if queryset is None: if queryset is None:
queryset = GovernmentPlan.objects.filter(public=True) queryset = GovernmentPlan.objects.filter(public=True)