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

Introduce timestamp for plan publishing and use for color coding

This mostly implements #159
Introduce a new field that denotes the timestamp when the plan was published
Introduce admin actions to publish and unpublish the plan and set that timestamp accordingly
Prevent other means to change visibility of the plan
Use that timestamp to only highlight recent changes when they occurred after the plan was already published
parent 31472554
No related branches found
No related tags found
No related merge requests found
from django import forms
from django.apps import apps
from django.contrib import admin
from django.contrib.admin import SimpleListFilter, RelatedFieldListFilter
from django.contrib import admin, messages
from django.contrib.admin import SimpleListFilter, RelatedFieldListFilter, action
from django.db.models import Count, F
from django.db.models.functions import Now
from django.shortcuts import render, redirect
from django.urls import reverse_lazy
from django.utils import timezone
......@@ -31,11 +32,12 @@ class EventRelatedFieldListFilter(RelatedFieldListFilter):
@admin.register(Event)
class EventAdmin(admin.ModelAdmin):
model = Event
list_display = ['name', 'status_url', 'place', 'start', 'end', 'active']
list_display = ['name', 'status_url', 'place', 'start', 'end', 'active', 'plan_hidden']
list_filter = ['active']
list_editable = ['active']
ordering = ['-start']
readonly_fields = ['status_url']
readonly_fields = ['status_url', 'plan_hidden', 'plan_published_at']
actions = ['publish', 'unpublish']
def add_view(self, request, form_url='', extra_context=None):
# Always use wizard to create new events (the built-in form wouldn't work anyways since the timezone cannot
......@@ -62,6 +64,16 @@ class EventAdmin(admin.ModelAdmin):
timezone.activate(obj.timezone)
return super().get_form(request, obj, change, **kwargs)
@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)
@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)
@admin.register(AKOwner)
class AKOwnerAdmin(admin.ModelAdmin):
......
......@@ -29,6 +29,7 @@ class NewEventWizardSettingsForm(forms.ModelForm):
'start': DateTimePickerInput(options={"format": "YYYY-MM-DD HH:mm"}),
'end': DateTimePickerInput(options={"format": "YYYY-MM-DD HH:mm"}),
'reso_deadline': DateTimePickerInput(options={"format": "YYYY-MM-DD HH:mm"}),
'plan_hidden': forms.HiddenInput(),
}
......
This diff is collapsed.
# Generated by Django 3.2.16 on 2022-10-15 10:18
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('AKModel', '0052_history_upgrade'),
]
operations = [
migrations.AddField(
model_name='event',
name='plan_published_at',
field=models.DateTimeField(blank=True, help_text='Timestamp at which the plan was published', null=True, verbose_name='Plan published at'),
),
]
......@@ -39,6 +39,8 @@ class Event(models.Model):
active = models.BooleanField(verbose_name=_('Active State'), help_text=_('Marks currently active events'))
plan_hidden = models.BooleanField(verbose_name=_('Plan Hidden'), help_text=_('Hides plan for non-staff users'),
default=True)
plan_published_at = models.DateTimeField(verbose_name=_('Plan published at'), blank=True, null=True,
help_text=_('Timestamp at which the plan was published'))
base_url = models.URLField(verbose_name=_("Base URL"), help_text=_("Prefix for wiki link construction"), blank=True)
wiki_export_template_name = models.CharField(verbose_name=_("Wiki Export Template Name"), blank=True, max_length=50)
......
......@@ -11,6 +11,11 @@ register = template.Library()
@register.filter
def highlight_change_colors(akslot):
# Do not highlight in preview mode or when changes occurred before the plan was published
if akslot.event.plan_hidden or (akslot.event.plan_published_at is not None
and akslot.event.plan_published_at > akslot.updated):
return akslot.ak.category.color
seconds_since_update = akslot.seconds_since_last_update
# Last change long ago? Use default color
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment