Skip to content

Commit

Permalink
GlobalMessage model updated field for dismiss reference
Browse files Browse the repository at this point in the history
  • Loading branch information
metenn committed Oct 21, 2024
1 parent 515be71 commit 244817b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
7 changes: 6 additions & 1 deletion oioioi/globalmessage/admin.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from django.forms import ModelForm
from django.http import HttpRequest
from django.urls import re_path, reverse
from django.utils.translation import gettext_lazy as _

from oioioi.base import admin
from oioioi.base.permissions import is_superuser
from oioioi.globalmessage.models import GlobalMessage


class GlobalMessageAdmin(admin.ModelAdmin):
fieldsets = [
(None, {'fields': ['enabled', 'message']}),
Expand Down Expand Up @@ -33,6 +34,10 @@ def get_urls(self):

return custom_urls + urls

def save_model(self, request: HttpRequest, obj: GlobalMessage, form: ModelForm, change: bool) -> None:
obj.updated = request.timestamp
return super().save_model(request, obj, form, change)


admin.site.register(GlobalMessage, GlobalMessageAdmin)

Expand Down
20 changes: 20 additions & 0 deletions oioioi/globalmessage/migrations/0002_globalmessage_updated.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 4.2.11 on 2024-10-21 20:48

import django
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('globalmessage', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='globalmessage',
name='updated',
field=models.DateTimeField(default=django.utils.timezone.now, verbose_name='updated'),
preserve_default=False,
),
]
1 change: 1 addition & 0 deletions oioioi/globalmessage/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class GlobalMessage(models.Model):
enabled = models.BooleanField(default=False, verbose_name=_("enabled"))
start = models.DateTimeField(null=True, blank=True, verbose_name=_("start"))
end = models.DateTimeField(null=True, blank=True, verbose_name=_("end"))
updated = models.DateTimeField(null=False, blank=False, verbose_name=_("updated"))

def visible(self, timestamp):
return (
Expand Down
4 changes: 2 additions & 2 deletions oioioi/globalmessage/processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ def global_message_processor(request):
return {
'extra_body_global_message': render_to_string(
'global-message-user.html',
{'global_message': message, 'start': message.start.strftime('%s')},
{'global_message': message, 'start': message.updated.strftime('%s')},
),
'extra_admin_global_message': render_to_string(
'global-message-admin.html',
{'global_message': message, 'start': message.start.strftime('%s')},
{'global_message': message, 'start': message.updated.strftime('%s')},
),
}

Expand Down

0 comments on commit 244817b

Please sign in to comment.