Skip to content

Commit

Permalink
Production Release 1.0.0 (#120)
Browse files Browse the repository at this point in the history
* Changes for unit of measurements (#118)

* new org uom creation changes

* patch version update

* fix uom request call

* add abbrevation field to organization model

* handle abbrevation while registration

* exclude custodian names from org list

* email alert changes

* feedback changes - 1

* fix shipment service call

* fix shipment alert template

* fix shipment alert template - 2

* fix lint test issues
  • Loading branch information
patelradhika authored Aug 31, 2023
1 parent 9262ac7 commit 84fbc23
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 78 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ RUN ./scripts/collectstatic.sh
RUN apk del .build-deps

# Specify tag name to be created on github
LABEL version="1.1.1"
LABEL version="1.0.0"

EXPOSE 8080
ENTRYPOINT ["bash", "/code/scripts/docker-entrypoint.sh"]
18 changes: 18 additions & 0 deletions core/migrations/0002_organization_abbrevation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.2.10 on 2023-06-19 09:21

from django.db import migrations, models


class Migration(migrations.Migration):

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

operations = [
migrations.AddField(
model_name='organization',
name='abbrevation',
field=models.CharField(blank=True, default='DEFAULT', max_length=7, verbose_name='Organization Abbrevation'),
),
]
1 change: 1 addition & 0 deletions core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ class Organization(models.Model):
organization_type = models.ForeignKey(
OrganizationType, on_delete=models.CASCADE, null=True
)
abbrevation = models.CharField("Organization Abbrevation", max_length=7, blank=True, default="DEFAULT")

class Meta:
ordering = ('name',)
Expand Down
3 changes: 2 additions & 1 deletion core/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,12 @@ class CoreUserWritableSerializer(CoreUserSerializer):
distance = serializers.CharField(required=False)
temperature = serializers.CharField(required=False)
weight = serializers.CharField(required=False)
organization_abbrevation = serializers.CharField(source='organization.abbrevation', required=False)

class Meta:
model = CoreUser
fields = CoreUserSerializer.Meta.fields + ('password', 'organization_name', 'country', 'currency', 'date_format',
'time_format', 'distance', 'temperature', 'weight')
'time_format', 'distance', 'temperature', 'weight', 'organization_abbrevation')
read_only_fields = CoreUserSerializer.Meta.read_only_fields

def create(self, validated_data):
Expand Down
1 change: 1 addition & 0 deletions core/tests/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def test_org_serializer(request_factory, org):
'allow_import_export',
'radius',
'organization_type',
'abbrevation',
]
assert set(data.keys()) == set(keys)

Expand Down
47 changes: 25 additions & 22 deletions core/views/coreuser.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import requests
from urllib.parse import urljoin

from django.conf import settings
Expand Down Expand Up @@ -34,8 +35,8 @@
from core.email_utils import send_email
import logging

# from datetime import datetime
# from dateutil import tz
from datetime import datetime
from pytz import timezone
# from twilio.rest import Client
logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -321,23 +322,26 @@ def alert(self, request, *args, **kwargs):
messages = request.data['messages']
try:
for message in messages:
# try:
# time_tuple = datetime.strptime(message['date_time'], "%Y-%m-%dT%H:%M:%S%z")
# except ValueError:
# time_tuple = datetime.strptime(message['date_time'], "%Y-%m-%dT%H:%M:%S.%f%z")
# message['date_time'] = time_tuple.replace(tzinfo=tz.gettz('UTC'))
subject = '{} Alert'.format(message['parameter'].capitalize())
if message.get('shipment_id'):
message['shipment_url'] = urljoin(
settings.FRONTEND_URL,
'/app/shipment/edit/:' + str(message['shipment_id']),
)
else:
message['shipment_url'] = None
subject = message['header']
message['color'] = color_codes.get(message['severity'])
context = {'message': message}
alert_time = datetime.strptime(message['alert_time'], "%Y-%m-%dT%H:%M:%S.%f%z")
template_name = 'email/coreuser/shipment_alert.txt'
html_template_name = 'email/coreuser/shipment_alert.html'

# Set shipment url
message['shipment_url'] = urljoin(settings.FRONTEND_URL, '/app/shipment/')

# Get Currency default for the organization
uom_currency_url = (
settings.TP_SHIPMENT_URL
+ 'unit_of_measure/?organization_uuid='
+ org_uuid
+ '&unit_of_measure_for=Currency'
)
uom_currency = requests.get(uom_currency_url).json()[0]
message['currency'] = ' ' + uom_currency.get('unit_of_measure')

# TODO send email via preferences
core_users = CoreUser.objects.filter(
organization__organization_uuid=org_uuid
Expand All @@ -349,12 +353,11 @@ def alert(self, request, *args, **kwargs):
preferences.get('environmental', None)
or preferences.get('geofence', None)
):
# user_timezone = user.user_timezone
# if user_timezone:
# local_zone = tz.gettz(user_timezone)
# message['date_time'] = message['date_time'].astimezone(local_zone)
# else:
# message['date_time'] = time_tuple.strftime("%B %d, %Y, %I:%M %p")+" (UTC)"
user_timezone = user.user_timezone
if user_timezone:
message['local_time'] = alert_time.astimezone(timezone(user_timezone)).strftime('%-d %b, %Y %-I:%M:%S %p %Z')
else:
message['local_time'] = alert_time.strftime('%-d %b, %Y %-I:%M:%S %p %Z')
send_email(
email_address,
subject,
Expand Down Expand Up @@ -394,4 +397,4 @@ def update_profile(self, request, pk=None, *args, **kwargs):
return Response(serializer.data)


color_codes = {'error': '#cc3300', 'info': '#2196F3', 'success': '#339900'}
color_codes = {'error': '#FF0033', 'info': '#0099CC', 'success': '#009900'}
2 changes: 1 addition & 1 deletion core/views/organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def fetch_existing_orgs(self, request, pk=None, *args, **kwargs):
Any logged in user can access this
"""
# returns names of existing orgs in Buildly Core as a list
queryset = Organization.objects.all()
queryset = Organization.objects.all().exclude(organization_type=1)
names = list()
for record in queryset:
names.append(record.name)
Expand Down
3 changes: 2 additions & 1 deletion requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ bravado-core==5.13.1
drf-yasg==1.10.2
requests==2.25.0
aiohttp==3.5.4
django-auth-ldap==2.1.0
django-auth-ldap==2.1.0
pytz
139 changes: 87 additions & 52 deletions templates/email/coreuser/shipment_alert.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,46 +31,91 @@
<tbody>
<tr style="height: 104px">
<td style="width: 691px; height: 150px">
<h1 style="text-align: center">
<span style="color:{{message.color}}"
><strong
><span
style="
font-size: 40px;
font-family: roboto, helvetica neue, helvetica, arial, sans-serif;
"
>{{message.alert_message}}
</strong
></span
>
</h1>
<div>
{% if message.shipment_id != None %}
<h3 style="color: #000000">Shipment: {{ message.shipment_name }}</h3>
<p>{{message.body_text}}</p>
<p>
<strong>Shipment: </strong>
<a href="{{message.shipment_url}}">
<span style="color:{{ message.color }}">
{{ message.shipment_name }}
</span>
</a>
</p>

{% if message.severity == 'error' %}
<p>
<strong>ISSUE: </strong>
<span style="color:{{ message.color }}">
{{ message.alert_message }}{{ message.local_time }}
</span>
</p>
{% elif message.severity == 'info' %}
<p>
<strong>ISSUE: </strong>
<span style="color:{{ message.color }}">
{{ message.alert_message }}{{ message.local_time }}
</span>
</p>
{% elif message.severity == 'success' %}
<p>
<strong>RESOLUTION: </strong>
<span style="color:{{ message.color }}">
{{ message.alert_message }}{{ message.local_time }}
</span>
</p>
{% endif %}

{% if message.severity == 'error' %}
<p>
<strong>ISSUE LOCATION: </strong>
<span style="color:{{ message.color }}">{{ message.location }}</span>
</p>
{% elif message.severity == 'info' %}
<p>
<strong>ISSUE LOCATION: </strong>
<span style="color:{{ message.color }}">{{ message.location }}</span>
</p>
{% elif message.severity == 'success' %}
<p>
<strong>RESOLUTION LOCATION: </strong>
<span style="color:{{ message.color }}">{{ message.location }}</span>
</p>
{% endif %}

{% if message.severity == 'error' %}
<p>
<strong>ITEMS IN JEOPARDY: </strong>
<span style="color:{{ message.color }}">
{{ message.items }}
</span>
</p>
{% elif message.severity == 'info' %}
<p>
<strong>ITEMS IN JEOPARDY: </strong>
<span style="color:{{ message.color }}">
{{ message.items }}
</span>
</p>
{% elif message.severity == 'success' %}
<p>
<strong>ITEMS RECOVERED: </strong>
<span style="color:{{ message.color }}">
{{ message.items }}
</span>
</p>
{% endif %}
<p style="color:{{ message.color }}">{{message.alert_message}}</p>
<p style="color:#000000">Alert for {{message.parameter}} : <span style="color:{{ message.color }}">{{message.recorded_value}}</span></p>

<p>
<!--<span style="color: #424242">Captured at: {{ message.date_time }}</span>-->
{% if message.shipment_id != None %}
<a
href="{{ message.shipment_url }}"
target="_blank"
style="
float: right;
font-weight: bold;
letter-spacing: normal;
padding: 0.5rem;
line-height: 100%;
text-align: center;
text-decoration: none;
color: #ebc645;
background-color: #424242;
"
>
Go to Shipment</a
>
{% endif %}
<strong>SHIPMENT VALUE: </strong>
<span style="color:{{ message.color }}">
{{ message.shipment_value }}{{ message.currency }}
</span>
</p>
<p>
<strong>ACTION: </strong>
<span style="color:{{ message.color }}">
Please verify any product damage or loss as soon as possible.
</span>
</p>
</div>
</td>
Expand All @@ -86,38 +131,28 @@ <h3 style="color: #000000">Shipment: {{ message.shipment_name }}</h3>
font-family: Roboto, 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 14px;
"
>Transparent Path spc</span
>A product of Transparent Path spc</span
><br />
<span
style="
color: #737581;
font-family: Roboto, 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 14px;
"
>1700 Westlake Avenue North Suite 200 Seattle, WA 98109</span
>
</p>
<p>
<span
style="
color: #737581;
font-family: Roboto, 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 14px;
"
>Have any questions or thoughts on Transparent Path spc?</span
>1700 Westlake Avenue North • Suite 200 • Seattle, WA 98109 • USA</span
><br />
<span
style="
color: #737581;
font-family: Roboto, 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 14px;
"
>Reach out to us at anytime at
>To report an issue, email our Support Team at
<a
href="mailto:support@tpath.io"
href="mailto:support@transparentpath.com"
target="_blank"
style="text-decoration: underline; color: #0abffc"
><span style="color: #0abffc">support@tpath.io</span></a
><span style="color: #0abffc">support@transparentpath.com</span></a
></span
>
</p>
Expand Down

0 comments on commit 84fbc23

Please sign in to comment.