Commit 08abf4b5 by Bach Dániel

dashboard: use TimeFramedModel in Message

parent c1e8f14e
......@@ -16,8 +16,6 @@
# with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
from django.conf import settings
from django.db.models import Q
from django.utils import timezone
from .models import Message
......@@ -38,7 +36,4 @@ def extract_settings(request):
def broadcast_messages(request):
now = timezone.now()
messages = Message.objects.filter(enabled=True).exclude(
Q(starts_at__gt=now) | Q(ends_at__lt=now))
return {'broadcast_messages': messages}
return {'broadcast_messages': Message.timeframed.filter(enabled=True)}
......@@ -1629,7 +1629,7 @@ class DiskForm(ModelForm):
class MessageForm(ModelForm):
class Meta:
model = Message
fields = ("message", "enabled", "effect", "starts_at", "ends_at")
fields = ("message", "enabled", "effect", "start", "end")
@property
def helper(self):
......
......@@ -19,14 +19,16 @@ class Migration(migrations.Migration):
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, verbose_name='created', editable=False)),
('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, verbose_name='modified', editable=False)),
('start', models.DateTimeField(null=True, verbose_name='start', blank=True)),
('end', models.DateTimeField(null=True, verbose_name='end', blank=True)),
('message', models.CharField(max_length=500, verbose_name='message')),
('starts_at', models.DateTimeField(null=True, verbose_name='starts at', blank=True)),
('ends_at', models.DateTimeField(null=True, verbose_name='ends at', blank=True)),
('effect', models.CharField(default=b'info', max_length=10, verbose_name='effect', choices=[(b'success', 'success'), (b'info', 'info'), (b'warning', 'warning'), (b'danger', 'danger')])),
('enabled', models.BooleanField(default=False, verbose_name='enabled')),
],
options={
'ordering': ['-ends_at'],
'ordering': ['id'],
'verbose_name': 'message',
'verbose_name_plural': 'messages',
},
bases=(models.Model,),
),
......
......@@ -39,7 +39,7 @@ from django.core.exceptions import ObjectDoesNotExist
from sizefield.models import FileSizeField
from jsonfield import JSONField
from model_utils.models import TimeStampedModel
from model_utils.models import TimeFramedModel, TimeStampedModel
from model_utils.fields import StatusField
from model_utils import Choices
......@@ -59,12 +59,8 @@ def pwgen():
return User.objects.make_random_password()
class Message(TimeStampedModel):
class Message(TimeStampedModel, TimeFramedModel):
message = CharField(max_length=500, verbose_name=_('message'))
starts_at = DateTimeField(
null=True, blank=True, verbose_name=_('starts at'))
ends_at = DateTimeField(
null=True, blank=True, verbose_name=_('ends at'))
effect = CharField(
default='info', max_length=10, verbose_name=_('effect'),
choices=(('success', _('success')), ('info', _('info')),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment