Skip to content
Snippets Groups Projects
Commit f444f3a6 authored by Benjamin Hättasch's avatar Benjamin Hättasch
Browse files

Introduce intermediate page for plan publishing

Use action with intermediate page instead of direct action for publishing and unpublishing of plans
This allows to create a link on the events detail page and on the status page to change the plans visibility
Add link to detail view
Visualize plan visibility on status page and allow to toggle it from there
This implements the final function of #159
parent 0bc73445
No related branches found
No related tags found
1 merge request!133Add new functionality to backend
Pipeline #107571 passed
......@@ -3,7 +3,6 @@ from django.apps import apps
from django.contrib import admin, messages
from django.contrib.admin import SimpleListFilter, RelatedFieldListFilter, action, display
from django.db.models import Count, F
from django.db.models.functions import Now
from django.http import HttpResponseRedirect
from django.shortcuts import render, redirect
from django.urls import reverse_lazy, path
......@@ -20,7 +19,7 @@ from AKModel.models import Event, AKOwner, AKCategory, AKTrack, AKTag, AKRequire
ConstraintViolation
from AKModel.urls import get_admin_urls_event_wizard, get_admin_urls_event
from AKModel.views import CVMarkResolvedView, CVSetLevelViolationView, CVSetLevelWarningView, AKResetInterestView, \
AKResetInterestCounterView
AKResetInterestCounterView, PlanPublishView, PlanUnpublishView
class EventRelatedFieldListFilter(RelatedFieldListFilter):
......@@ -39,7 +38,7 @@ class EventAdmin(admin.ModelAdmin):
list_filter = ['active']
list_editable = ['active']
ordering = ['-start']
readonly_fields = ['status_url', 'plan_hidden', 'plan_published_at']
readonly_fields = ['status_url', 'plan_hidden', 'plan_published_at', 'toggle_plan_visibility']
actions = ['publish', 'unpublish']
def add_view(self, request, form_url='', extra_context=None):
......@@ -53,6 +52,10 @@ class EventAdmin(admin.ModelAdmin):
if apps.is_installed("AKScheduling"):
from AKScheduling.urls import get_admin_urls_scheduling
urls.extend(get_admin_urls_scheduling(self.admin_site))
urls.extend([
path('plan/publish/', PlanPublishView.as_view(), name="plan-publish"),
path('plan/unpublish/', PlanUnpublishView.as_view(), name="plan-unpublish"),
])
urls.extend(super().get_urls())
return urls
......@@ -61,6 +64,16 @@ class EventAdmin(admin.ModelAdmin):
return format_html("<a href='{url}'>{text}</a>",
url=reverse_lazy('admin:event_status', kwargs={'slug': obj.slug}), text=_("Status"))
@display(description=_("Toggle plan visibility"))
def toggle_plan_visibility(self, obj):
if obj.plan_hidden:
url = f"{reverse_lazy('admin:plan-publish')}?pks={obj.pk}"
text = _('Publish plan')
else:
url = f"{reverse_lazy('admin:plan-unpublish')}?pks={obj.pk}"
text = _('Unpublish plan')
return format_html("<a href='{url}'>{text}</a>", url=url, text=text)
def get_form(self, request, obj=None, change=False, **kwargs):
# Use timezone of event
timezone.activate(obj.timezone)
......@@ -68,13 +81,13 @@ class EventAdmin(admin.ModelAdmin):
@action(description=_('Publish plan'))
def publish(self, request, queryset):
queryset.update(plan_published_at=Now(), plan_hidden=False)
self.message_user(request, _('Plan published'), messages.SUCCESS)
selected = queryset.values_list('pk', flat=True)
return HttpResponseRedirect(f"{reverse_lazy('admin:plan-publish')}?pks={','.join(str(pk) for pk in selected)}")
@action(description=_('Unpublish plan'))
def unpublish(self, request, queryset):
queryset.update(plan_published_at=None, plan_hidden=True)
self.message_user(request, _('Plan unpublished'), messages.SUCCESS)
selected = queryset.values_list('pk', flat=True)
return HttpResponseRedirect(f"{reverse_lazy('admin:plan-unpublish')}?pks={','.join(str(pk) for pk in selected)}")
@admin.register(AKOwner)
......
This diff is collapsed.
......@@ -11,6 +11,13 @@
<h2><a href="{% url 'admin:AKModel_event_change' event.pk %}">{{event}}</a></h2>
<h5>{{ event.start }} - {{ event.end }}</h5>
<div class="custom-control custom-switch mt-2 mb-2">
<input type="checkbox" class="custom-control-input" id="planPublishedSwitch"
{% if not event.plan_hidden %}checked{% endif %}
onclick="location.href='{% if event.plan_hidden %}{% url 'admin:plan-publish' %}{% else %}{% url 'admin:plan-unpublish' %}{% endif %}?pks={{event.pk}}';">
<label class="custom-control-label" for="planPublishedSwitch">{% trans "Plan published?" %}</label>
</div>
<div class="row">
<div class="col-md-8">
<h3 class="block-header">{% trans "Categories" %}</h3>
......
......@@ -4,6 +4,7 @@ from abc import ABC, abstractmethod
from itertools import zip_longest
from django.contrib import admin, messages
from django.db.models.functions import Now
from django.shortcuts import get_object_or_404, redirect
from django.urls import reverse_lazy, reverse
from django.utils.translation import gettext_lazy as _
......@@ -474,3 +475,23 @@ class AKResetInterestCounterView(IntermediateAdminActionView):
def action(self, form):
self.entities.update(interest_counter=0)
class PlanPublishView(IntermediateAdminActionView):
title = _('Publish plan')
model = Event
confirmation_message = _('Publish the plan(s) of:')
success_message = _('Plan published')
def action(self, form):
self.entities.update(plan_published_at=Now(), plan_hidden=False)
class PlanUnpublishView(IntermediateAdminActionView):
title = _('Unpublish plan')
model = Event
confirmation_message = _('Unpublish the plan(s) of:')
success_message = _('Plan unpublished')
def action(self, form):
self.entities.update(plan_published_at=None, plan_hidden=True)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment