Skip to content
This repository has been archived by the owner on Sep 26, 2018. It is now read-only.

Notification with I18N integration (Client dependent) #71

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cloud/endagaweb/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,4 @@ class BTSLogfileAdmin(admin.ModelAdmin):
admin.site.register(models.UserProfile, UserProfileAdmin)
admin.site.register(models.BTSLogfile, BTSLogfileAdmin)
admin.site.register(models.FileUpload)
admin.site.register(models.Notification)
51 changes: 51 additions & 0 deletions cloud/endagaweb/forms/dashboard_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,3 +368,54 @@ def __init__(self, *args, **kwargs):
self.helper.form_action = '/dashboard/staff/tower-monitoring'
self.helper.add_input(Submit('submit', 'Select'))
self.helper.layout = Layout('tower')


class NotificationForm(forms.Form):
types = (
('automatic', 'Automatic'),
('mapped', 'Mapped')
)
help_text = (
'<b>Automatic:</b> Sent to user automatically, <br>'
'<b>Mapped:</b> Notification will be sent to mapped '
'users.')
type = forms.ChoiceField(
required=True,
label='',
help_text=help_text, choices=types,
widget=forms.RadioSelect(attrs={'title': 'Notification type'}),)
event = forms.CharField(widget=forms.TextInput(
attrs={'title': 'Event Type', 'style': 'width:300px'}),
required=True, label='Events')
message = forms.CharField(
label='Message', widget=forms.Textarea(
attrs={'title': 'Notification message',
'placeholder': 'Enter Message...',
'rows': '4'}), required=True,
min_length=20,
max_length=160)
number = forms.IntegerField(widget=forms.NumberInput(
attrs={'class': 'form-control', 'pattern': '[0-9]{3}',
'title': 'Notification number', 'style': 'width:200px',
'oninvalid': "setCustomValidity('Enter number (max: 3 digits)')",
'onchange': "try{"
"setCustomValidity('')}catch(e){}"
}),
required=True, disabled=True, min_value=1, max_value=999)
pk = forms.CharField(widget=forms.HiddenInput())

def __init__(self, *args, **kwargs):
super(NotificationForm, self).__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.form_id = 'network-notification-form'
self.helper.form_method = 'POST'
self.helper.form_action = '/dashboard/network/notification'

self.helper.layout = Layout(
'type',
'number',
'event',
'message',
'pk',
Submit('submit', 'Submit', css_class='invisible'),
)
18 changes: 18 additions & 0 deletions cloud/endagaweb/locale/en/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-07-19 08:17+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
19 changes: 19 additions & 0 deletions cloud/endagaweb/locale/es/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-07-19 08:16+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
19 changes: 19 additions & 0 deletions cloud/endagaweb/locale/fil/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-07-19 08:17+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

20 changes: 20 additions & 0 deletions cloud/endagaweb/locale/id/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-07-19 08:16+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=1; plural=0;\n"

14 changes: 14 additions & 0 deletions cloud/endagaweb/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1793,3 +1793,17 @@ class FileUpload(models.Model):
created_time = models.DateTimeField(auto_now_add=True)
modified_time = models.DateTimeField(auto_now_add=True)
accessed_time = models.DateTimeField(auto_now=True)


class Notification(models.Model):
notification_type = (
('automatic', 'Automatic'),
('mapped', 'Mapped')
)
network = models.ForeignKey('Network', on_delete=models.CASCADE)
event = models.CharField(max_length=100, null=True, unique=True)
number = models.CharField(max_length=3, null=True, default=None,
unique=True)
message = models.TextField(max_length=160)
type = models.CharField(max_length=10, choices=notification_type,
default='automatic')
21 changes: 21 additions & 0 deletions cloud/endagaweb/settings/prod.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import dj_database_url

from django.utils.translation import ugettext, ugettext_lazy as translate

# inherit base Django settings (more general than the endagaweb app)
from settings import * # noqa: F403

Expand Down Expand Up @@ -92,6 +94,7 @@
'django.middleware.security.SecurityMiddleware',
'endagaweb.middleware.TimezoneMiddleware',
'endagaweb.middleware.MultiNetworkMiddleware',
'django.middleware.locale.LocaleMiddleware',
)

AUTHENTICATION_BACKENDS = (
Expand Down Expand Up @@ -129,6 +132,7 @@
'guardian',
'rest_framework',
'rest_framework.authtoken',
'rosetta'
]

SITE_ID = 1
Expand Down Expand Up @@ -320,3 +324,20 @@

# Security middleware settings
SECURE_CONTENT_TYPE_NOSNIFF = True


# I18 integration for internationalization and localization
USE_I18N = True
LANGUAGES = (
('en', translate('English')),
('fil', translate('Filipino')),
('es', translate('Spanish')),
('id', translate('Indonesian'))
)
# Set the default language for your site.
LANGUAGE_CODE = 'en'

LOCALE_PATHS = (
os.path.join(os.environ["ENDAGA_BASE_PATH"], 'locale'),
)
TEMPLATES_PATH = os.path.join(os.environ["ENDAGA_BASE_PATH"], 'templates')
23 changes: 23 additions & 0 deletions cloud/endagaweb/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import os
import paramiko
import zipfile
import subprocess
try:
# we only import zlib here to check that it is available
# (why would it not be?), so we have to disable the 'unused' warning
Expand All @@ -43,6 +44,7 @@
from endagaweb.models import SystemEvent
from endagaweb.models import TimeseriesStat
from endagaweb.ic_providers.nexmo import NexmoProvider
from endagaweb.settings.prod import TEMPLATES_PATH


@app.task(bind=True)
Expand Down Expand Up @@ -439,3 +441,24 @@ def req_bts_log(self, obj, retry_delay=60*10, max_retries=432):
raise
finally:
obj.save()

@app.task(bind=True)
def translate(self, message, retry_delay=60*10, max_retries=432):
"""Tries to write notification message for translation.

The default retry is every 10 min for 3 days.
"""
print "writing network notification message for translation '%s'"
try:
translation_file = "/dashboard/network_detail/translate.html"
handle = open(TEMPLATES_PATH + translation_file, 'a+')
handle.write('{% trans "' + message + '" %}\r\n')
handle.close()
subprocess.Popen(
['python', 'manage.py', 'makemessages', '-l', 'en', '-l', 'fil'])
subprocess.Popen(['python', 'manage.py', 'compilemessages'])
except (requests.exceptions.ConnectionError, requests.exceptions.Timeout):
raise self.retry(countdown=retry_delay, max_retries=max_retries)
except Exception as exception:
raise self.retry(countdown=retry_delay, max_retries=max_retries)
print "Translation ERROR. Exception:- %s" % (exception)
1 change: 1 addition & 0 deletions cloud/endagaweb/templates/dashboard/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
<li class="divider"></li>
{% if user_profile.user.is_staff %}
<li><a href="/django-admin"><i class="fa fa-key"></i>&nbsp; Django Admin</a></li>
<li><a href="/rosetta" target="_blank"><i class="fa fa-globe"></i>&nbsp; Language Translations</a></li>
<li><a href="/dashboard/staff/all-numbers"><i class="fa fa-space-shuttle"></i>&nbsp; All Numbers</a></li>
<li><a href="/dashboard/staff/all-towers"><i class="fa fa-building-o"></i>&nbsp; All Towers</a></li>
<li><a href="/dashboard/staff/margin-analysis"><i class="fa fa-euro"></i>&nbsp; Margin Analysis</a></li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ <h3 class="page-title">
{% if network.name %}
<span id='name'>"{{ network.name }}"</span>
{% endif %}
{% if active_tab == 'network-notifications' %}
<a class="btn btn-primary pull-right" href="javascript:void(0);" onclick="resetForm()" data-target="#save-event-modal" data-toggle='modal'>Add Notification</a>
{% endif %}
</h3>
</div>
</div>
13 changes: 12 additions & 1 deletion cloud/endagaweb/templates/dashboard/network_detail/nav.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@
{% endif %} ">Denominations</a>
</li>

<li role="presentation" class="{% if active_tab == 'network-notifications' %} active {% endif %}">
<a href="
{% if active_tab == 'network-notifications' %} #
{% else %} {% url 'network-notifications' %}
{% endif %} ">Notifications</a>
</li>

<li role="presentation" class="{% if active_tab == 'inactive-subscribers' %} active {% endif %}">
<a href="
{% if active_tab == 'inactive-subscribers' %} #
Expand All @@ -43,5 +50,9 @@
{% else %}{% url 'network-edit' %}
{% endif %}">Edit</a>
</li>

<li role="presentation">
<a href="javascript:void(0);" data-toggle='modal' data-target='#broadcast-modal'>SMS Broadcast</a>
</li>
</ul>
</div>
</div>
Loading