Skip to content
Snippets Groups Projects
Commit 1647b9d4 authored by Nadja Geisler's avatar Nadja Geisler :sunny:
Browse files

Merge branch 'feature-colors' into 'main'

Introduce timestamp for plan publishing and use for color coding

Closes #159

See merge request !135
parents 45ae538b dd6e2374
No related branches found
No related tags found
1 merge request!135Introduce timestamp for plan publishing and use for color coding
Pipeline #107522 passed
from django import forms from django import forms
from django.apps import apps from django.apps import apps
from django.contrib import admin from django.contrib import admin, messages
from django.contrib.admin import SimpleListFilter, RelatedFieldListFilter from django.contrib.admin import SimpleListFilter, RelatedFieldListFilter, action
from django.db.models import Count, F from django.db.models import Count, F
from django.db.models.functions import Now
from django.shortcuts import render, redirect from django.shortcuts import render, redirect
from django.urls import reverse_lazy from django.urls import reverse_lazy
from django.utils import timezone from django.utils import timezone
...@@ -31,11 +32,12 @@ class EventRelatedFieldListFilter(RelatedFieldListFilter): ...@@ -31,11 +32,12 @@ class EventRelatedFieldListFilter(RelatedFieldListFilter):
@admin.register(Event) @admin.register(Event)
class EventAdmin(admin.ModelAdmin): class EventAdmin(admin.ModelAdmin):
model = Event 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_filter = ['active']
list_editable = ['active'] list_editable = ['active']
ordering = ['-start'] 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): 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 # 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): ...@@ -62,6 +64,16 @@ class EventAdmin(admin.ModelAdmin):
timezone.activate(obj.timezone) timezone.activate(obj.timezone)
return super().get_form(request, obj, change, **kwargs) 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) @admin.register(AKOwner)
class AKOwnerAdmin(admin.ModelAdmin): class AKOwnerAdmin(admin.ModelAdmin):
......
...@@ -29,6 +29,7 @@ class NewEventWizardSettingsForm(forms.ModelForm): ...@@ -29,6 +29,7 @@ class NewEventWizardSettingsForm(forms.ModelForm):
'start': DateTimePickerInput(options={"format": "YYYY-MM-DD HH:mm"}), 'start': DateTimePickerInput(options={"format": "YYYY-MM-DD HH:mm"}),
'end': 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"}), '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'),
),
]
...@@ -40,6 +40,8 @@ class Event(models.Model): ...@@ -40,6 +40,8 @@ class Event(models.Model):
active = models.BooleanField(verbose_name=_('Active State'), help_text=_('Marks currently active events')) 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'), plan_hidden = models.BooleanField(verbose_name=_('Plan Hidden'), help_text=_('Hides plan for non-staff users'),
default=True) 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) 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) wiki_export_template_name = models.CharField(verbose_name=_("Wiki Export Template Name"), blank=True, max_length=50)
......
...@@ -11,6 +11,11 @@ register = template.Library() ...@@ -11,6 +11,11 @@ register = template.Library()
@register.filter @register.filter
def highlight_change_colors(akslot): 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 seconds_since_update = akslot.seconds_since_last_update
# Last change long ago? Use default color # 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