Initial commit to support messages of the day. GitLab issue #222.

This commit is contained in:
Roberto Rosario
2016-03-13 00:56:31 -04:00
parent 6eb868bdfb
commit daa3ca2430
16 changed files with 261 additions and 18 deletions

View File

@@ -3,34 +3,38 @@
{% load i18n %} {% load i18n %}
{% load static %} {% load static %}
{% load common_tags %}
{% load autoadmin_tags %} {% load autoadmin_tags %}
{% load common_tags %}
{% load motd_tags %}
{% block base_title %}{% trans 'Login' %}{% endblock %} {% block base_title %}{% trans 'Login' %}{% endblock %}
{% block project_name %}{% endblock %} {% block project_name %}{% endblock %}
{% block content_plain %} {% block content_plain %}
<div class="row"> {% autoadmin_properties %}
<div class="col-xs-10 col-xs-offset-1 col-sm-10 col-sm-offset-1 col-md-8 col-md-offset-2 col-lg-6 col-lg-offset-3"> {% if autoadmin_properties.account %}
{% autoadmin_properties %} <div class="row">
{% if autoadmin_properties.account %} <div class="col-xs-10 col-xs-offset-1 col-sm-10 col-sm-offset-1 col-md-8 col-md-offset-2 col-lg-6 col-lg-offset-3">
<div class="panel panel-primary"> <div class="panel panel-primary">
<div class="panel-heading"> <div class="panel-heading">
<h3 class="panel-title">{% trans "First time login" %}</h3> <h3 class="panel-title">{% trans "First time login" %}</h3>
</div> </div>
<div class="panel-body"> <div class="panel-body">
<p>{% trans 'You have just finished installing <strong>Mayan EDMS</strong>, congratulations!' %}</p> <p>{% trans 'You have just finished installing <strong>Mayan EDMS</strong>, congratulations!' %}</p>
<p>{% trans 'Login using the following credentials:' %}</p> <p>{% trans 'Login using the following credentials:' %}</p>
<p>{% blocktrans with autoadmin_properties.account as account %}Username: <strong>{{ account }}</strong>{% endblocktrans %}</p> <p>{% blocktrans with autoadmin_properties.account as account %}Username: <strong>{{ account }}</strong>{% endblocktrans %}</p>
<p>{% blocktrans with autoadmin_properties.account.email as email %}Email: <strong>{{ email }}</strong>{% endblocktrans %}</p> <p>{% blocktrans with autoadmin_properties.account.email as email %}Email: <strong>{{ email }}</strong>{% endblocktrans %}</p>
<p>{% blocktrans with autoadmin_properties.password as password %}Password: <strong>{{ password }}</strong>{% endblocktrans %}</p> <p>{% blocktrans with autoadmin_properties.password as password %}Password: <strong>{{ password }}</strong>{% endblocktrans %}</p>
<p>{% trans 'Be sure to change the password to increase security and to disable this message.' %}</p> <p>{% trans 'Be sure to change the password to increase security and to disable this message.' %}</p>
</div>
</div> </div>
</div> </div>
{% endif %}
</div> </div>
</div> {% endif %}
{% motd %}
<div class="row"> <div class="row">
<div class="col-xs-10 col-xs-offset-1 col-sm-8 col-sm-offset-2 col-md-6 col-md-offset-3 col-lg-4 col-lg-offset-4"> <div class="col-xs-10 col-xs-offset-1 col-sm-8 col-sm-offset-2 col-md-6 col-md-offset-3 col-lg-4 col-lg-offset-4">
<div class="panel panel-primary"> <div class="panel panel-primary">

View File

@@ -0,0 +1,3 @@
from __future__ import unicode_literals
default_app_config = 'motd.apps.MOTDApp'

10
mayan/apps/motd/admin.py Normal file
View File

@@ -0,0 +1,10 @@
from __future__ import unicode_literals
from django.contrib import admin
from .models import MessageOfTheDay
@admin.register(MessageOfTheDay)
class MessageOfTheDayAdmin(admin.ModelAdmin):
list_display = ('label', 'enabled', 'start_datetime', 'end_datetime')

30
mayan/apps/motd/apps.py Normal file
View File

@@ -0,0 +1,30 @@
from __future__ import unicode_literals
import logging
from django import apps
from django.conf import settings
from django.conf.urls import include, url
from django.contrib.auth.signals import user_logged_in
from django.db.models.signals import post_save
from django.utils.translation import ugettext_lazy as _
from common import MayanAppConfig
#from .links import (
# link_about, link_current_user_details, link_current_user_edit,
# link_current_user_locale_profile_details,
# link_current_user_locale_profile_edit, link_filters, link_license,
# link_packages_licenses, link_setup, link_tools
#)
logger = logging.getLogger(__name__)
class MOTDApp(MayanAppConfig):
name = 'motd'
test = True
verbose_name = _('Message of the day')
def ready(self):
super(MOTDApp, self).ready()

View File

@@ -0,0 +1,11 @@
from django.db import models
from django.db.models import Q
from django.utils import timezone
class MessageOfTheDayManager(models.Manager):
def get_for_now(self):
now = timezone.now()
return self.filter(enabled=True).filter(
Q(start_datetime__isnull=True) | Q(start_datetime__lte=now)
).filter(Q(end_datetime__isnull=True) | Q(end_datetime__gte=now))

View File

@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
]
operations = [
migrations.CreateModel(
name='MessageOfTheDay',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('label', models.CharField(max_length=32, verbose_name='Label')),
('message', models.TextField(verbose_name='Message', blank=True)),
('enabled', models.BooleanField(default=True, verbose_name='Enabled')),
('start_datetime', models.DateTimeField(verbose_name='Start date time', blank=True)),
('end_datetime', models.DateTimeField(verbose_name='End date time', blank=True)),
],
options={
'verbose_name': 'Message of the day',
'verbose_name_plural': 'Messages of the day',
},
),
]

View File

@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('motd', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='messageoftheday',
name='end_datetime',
field=models.DateTimeField(null=True, verbose_name='End date time', blank=True),
),
migrations.AlterField(
model_name='messageoftheday',
name='start_datetime',
field=models.DateTimeField(null=True, verbose_name='Start date time', blank=True),
),
]

View File

@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('motd', '0002_auto_20160313_0340'),
]
operations = [
migrations.AlterField(
model_name='messageoftheday',
name='message',
field=models.TextField(verbose_name='Message'),
),
]

View File

30
mayan/apps/motd/models.py Normal file
View File

@@ -0,0 +1,30 @@
from __future__ import unicode_literals
from django.conf import settings
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
from django.utils.translation import ugettext_lazy as _
from .managers import MessageOfTheDayManager
@python_2_unicode_compatible
class MessageOfTheDay(models.Model):
label = models.CharField(max_length=32, verbose_name=_('Label'))
message = models.TextField(verbose_name=_('Message'))
enabled = models.BooleanField(default=True, verbose_name=_('Enabled'))
start_datetime = models.DateTimeField(
blank=True, null=True, verbose_name=_('Start date time')
)
end_datetime = models.DateTimeField(
blank=True, null=True, verbose_name=_('End date time')
)
objects = MessageOfTheDayManager()
class Meta:
verbose_name = _('Message of the day')
verbose_name_plural = _('Messages of the day')
def __str__(self):
return self.label

View File

@@ -0,0 +1,23 @@
{% load i18n %}
{% if messages %}
<div class="row">
<div class="col-xs-12 col-sm-10 col-sm-offset-1 col-md-10 col-md-offset-1 col-lg-8 col-lg-offset-2">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">{% trans 'Messages of the day' %}</h3>
</div>
<div class="panel-body">
{% for message in messages %}
<ul class="list-group">
<li class="list-group-item">
<h4 class="list-group-item-heading">{{ message.label }}</h4>
<p class="list-group-item-text">{{ message.message | linebreaks }}</p>
</li>
</ul>
{% endfor %}
</div>
</div>
</div>
</div>
{% endif %}

View File

View File

@@ -0,0 +1,12 @@
from __future__ import unicode_literals
from django.template import Library
from ..models import MessageOfTheDay
register = Library()
@register.inclusion_tag('motd/messages.html')
def motd():
return {'messages': MessageOfTheDay.objects.get_for_now()}

View File

View File

@@ -0,0 +1,48 @@
from __future__ import unicode_literals
from datetime import timedelta
from django.test import TestCase
from django.utils import timezone
from ..models import MessageOfTheDay
TEST_LABEL = 'test label'
TEST_MESSAGE = 'test message'
class MOTDTestCase(TestCase):
def setUp(self):
self.motd = MessageOfTheDay.objects.create(
label=TEST_LABEL, message=TEST_MESSAGE
)
def test_basic(self):
queryset = MessageOfTheDay.objects.get_for_now()
self.assertEqual(queryset.exists(), True)
def test_start_datetime(self):
self.motd.start_datetime = timezone.now() - timedelta(days=1)
self.motd.save()
queryset = MessageOfTheDay.objects.get_for_now()
self.assertEqual(queryset.first(), self.motd)
def test_end_datetime(self):
self.motd.start_datetime = timezone.now() - timedelta(days=2)
self.motd.end_datetime = timezone.now() - timedelta(days=1)
self.motd.save()
queryset = MessageOfTheDay.objects.get_for_now()
self.assertEqual(queryset.exists(), False)
def test_enable(self):
self.motd.enabled=False
self.motd.save()
queryset = MessageOfTheDay.objects.get_for_now()
self.assertEqual(queryset.exists(), False)

View File

@@ -91,6 +91,7 @@ INSTALLED_APPS = (
'mailer', 'mailer',
'metadata', 'metadata',
'mirroring', 'mirroring',
'motd',
'ocr', 'ocr',
'rest_api', 'rest_api',
'sources', 'sources',