diff --git a/mayan/apps/appearance/templates/appearance/login.html b/mayan/apps/appearance/templates/appearance/login.html index 92b327432d..787a4a538c 100644 --- a/mayan/apps/appearance/templates/appearance/login.html +++ b/mayan/apps/appearance/templates/appearance/login.html @@ -3,34 +3,38 @@ {% load i18n %} {% load static %} -{% load common_tags %} {% load autoadmin_tags %} +{% load common_tags %} +{% load motd_tags %} {% block base_title %}{% trans 'Login' %}{% endblock %} {% block project_name %}{% endblock %} {% block content_plain %} -
-
- {% autoadmin_properties %} - {% if autoadmin_properties.account %} -
-
-

{% trans "First time login" %}

-
-
-

{% trans 'You have just finished installing Mayan EDMS, congratulations!' %}

-

{% trans 'Login using the following credentials:' %}

-

{% blocktrans with autoadmin_properties.account as account %}Username: {{ account }}{% endblocktrans %}

-

{% blocktrans with autoadmin_properties.account.email as email %}Email: {{ email }}{% endblocktrans %}

-

{% blocktrans with autoadmin_properties.password as password %}Password: {{ password }}{% endblocktrans %}

-

{% trans 'Be sure to change the password to increase security and to disable this message.' %}

+ {% autoadmin_properties %} + {% if autoadmin_properties.account %} +
+
+
+
+

{% trans "First time login" %}

+
+
+

{% trans 'You have just finished installing Mayan EDMS, congratulations!' %}

+

{% trans 'Login using the following credentials:' %}

+

{% blocktrans with autoadmin_properties.account as account %}Username: {{ account }}{% endblocktrans %}

+

{% blocktrans with autoadmin_properties.account.email as email %}Email: {{ email }}{% endblocktrans %}

+

{% blocktrans with autoadmin_properties.password as password %}Password: {{ password }}{% endblocktrans %}

+

{% trans 'Be sure to change the password to increase security and to disable this message.' %}

+
- {% endif %}
-
+ {% endif %} + + {% motd %} +
diff --git a/mayan/apps/motd/__init__.py b/mayan/apps/motd/__init__.py new file mode 100644 index 0000000000..71e348ee1d --- /dev/null +++ b/mayan/apps/motd/__init__.py @@ -0,0 +1,3 @@ +from __future__ import unicode_literals + +default_app_config = 'motd.apps.MOTDApp' diff --git a/mayan/apps/motd/admin.py b/mayan/apps/motd/admin.py new file mode 100644 index 0000000000..f77cff8606 --- /dev/null +++ b/mayan/apps/motd/admin.py @@ -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') diff --git a/mayan/apps/motd/apps.py b/mayan/apps/motd/apps.py new file mode 100644 index 0000000000..09a8336a50 --- /dev/null +++ b/mayan/apps/motd/apps.py @@ -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() diff --git a/mayan/apps/motd/managers.py b/mayan/apps/motd/managers.py new file mode 100644 index 0000000000..c47516c7e9 --- /dev/null +++ b/mayan/apps/motd/managers.py @@ -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)) diff --git a/mayan/apps/motd/migrations/0001_initial.py b/mayan/apps/motd/migrations/0001_initial.py new file mode 100644 index 0000000000..545f550f5d --- /dev/null +++ b/mayan/apps/motd/migrations/0001_initial.py @@ -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', + }, + ), + ] diff --git a/mayan/apps/motd/migrations/0002_auto_20160313_0340.py b/mayan/apps/motd/migrations/0002_auto_20160313_0340.py new file mode 100644 index 0000000000..e1d52bc36e --- /dev/null +++ b/mayan/apps/motd/migrations/0002_auto_20160313_0340.py @@ -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), + ), + ] diff --git a/mayan/apps/motd/migrations/0003_auto_20160313_0349.py b/mayan/apps/motd/migrations/0003_auto_20160313_0349.py new file mode 100644 index 0000000000..24e610c760 --- /dev/null +++ b/mayan/apps/motd/migrations/0003_auto_20160313_0349.py @@ -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'), + ), + ] diff --git a/mayan/apps/motd/migrations/__init__.py b/mayan/apps/motd/migrations/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/mayan/apps/motd/models.py b/mayan/apps/motd/models.py new file mode 100644 index 0000000000..6c8dfd7885 --- /dev/null +++ b/mayan/apps/motd/models.py @@ -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 diff --git a/mayan/apps/motd/templates/motd/messages.html b/mayan/apps/motd/templates/motd/messages.html new file mode 100644 index 0000000000..ff54741974 --- /dev/null +++ b/mayan/apps/motd/templates/motd/messages.html @@ -0,0 +1,23 @@ +{% load i18n %} + +{% if messages %} +
+
+
+
+

{% trans 'Messages of the day' %}

+
+
+ {% for message in messages %} +
    +
  • +

    {{ message.label }}

    +

    {{ message.message | linebreaks }}

    +
  • +
+ {% endfor %} +
+
+
+
+{% endif %} diff --git a/mayan/apps/motd/templatetags/__init__.py b/mayan/apps/motd/templatetags/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/mayan/apps/motd/templatetags/motd_tags.py b/mayan/apps/motd/templatetags/motd_tags.py new file mode 100644 index 0000000000..e490386f85 --- /dev/null +++ b/mayan/apps/motd/templatetags/motd_tags.py @@ -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()} diff --git a/mayan/apps/motd/tests/__init__.py b/mayan/apps/motd/tests/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/mayan/apps/motd/tests/test_models.py b/mayan/apps/motd/tests/test_models.py new file mode 100644 index 0000000000..858bbf1b55 --- /dev/null +++ b/mayan/apps/motd/tests/test_models.py @@ -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) diff --git a/mayan/settings/base.py b/mayan/settings/base.py index aef56a55c2..84ee1d6115 100644 --- a/mayan/settings/base.py +++ b/mayan/settings/base.py @@ -91,6 +91,7 @@ INSTALLED_APPS = ( 'mailer', 'metadata', 'mirroring', + 'motd', 'ocr', 'rest_api', 'sources',