-
Notifications
You must be signed in to change notification settings - Fork 14
Ft admin asset Type threshold notification #329
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kenneth051
wants to merge
8
commits into
develop
Choose a base branch
from
ft-admin-assettype-threshold-notofication-167967311
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
06c817c
admin should get notified on assettype threshold
kenneth051 b7164bc
fixing readme file and black
kenneth051 1f112e1
updating read me file
kenneth051 338b4aa
fixing circle ci
kenneth051 2f0ee6f
fixing circle CI
kenneth051 0081d62
updating readme
kenneth051 b50ff67
fix circleCI tests
kenneth051 4278cd4
fix flake8 and circleCI tests
kenneth051 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,14 @@ This repository contains the API endpoints and models for the ART project implem | |
| <sup>**RETRY_TIMEOUT**</sup> | <sup>**Optional** - Number of seconds to wait before retrying an external request (currently to AIS) if an error other than 401 is received.</sup> | <sup>**10**</sup> | | ||
| <sup>**LOGLEVEL**</sup> | <sup>**Optional** - Default log level - error, warning, info, debug.</sup> | <sup>**info**</sup> | | ||
| <sup>**ADMINS**</sup> | <sup>**Optional** - Email addresses to send error logs to.</sup> | <sup>**art:[email protected],art_group:[email protected]**</sup> | | ||
| <sup>**DEFAULT_THRESHOLD**</sup> | <sup>**REQUIRED** - Minimal asset threshold</sup> | <sup>**Integer value EG 20**</sup>| | ||
| <sup>**EMAIL_HOST**</sup> | <sup>**REQUIRED** - email host.</sup> | <sup>**smtp.gmail.com**</sup> | | ||
| <sup>**EMAIL_HOST_USER**</sup> | <sup>**REQUIRED** - email host user account</sup> | | | ||
| <sup>**EMAIL_HOST_PASSWORD**</sup> | <sup>**REQUIRED** - email host user account password</sup> | | | ||
| <sup>**EMAIL_PORT**</sup> | <sup>**REQUIRED** - email port.</sup> | <sup>**587**</sup> | | ||
| <sup>**EMAIL_USE_TLS**</sup> | <sup>**REQUIRED** - email TLS.</sup> | <sup>**True**</sup> | | ||
| <sup>**EMAIL_SENDER**</sup> | <sup>**REQUIRED** - email sender's address.</sup> | | | ||
|
||
|
||
### Project setup | ||
#### Installation script | ||
|
@@ -60,6 +68,7 @@ The easiest way to set up is to run `. ./install_art.sh` which does the followin | |
- Install the project dependencies stored in [Pipfile](/Pipfile). Run `pipenv install --dev`. | ||
- Run migrations - `python manage.py migrate` | ||
- Create cache table `python manage.py createcachetable` | ||
-Open a terminal tab then run the command `python manage.py qcluster` to start django q to enable in sending email notifications | ||
|
||
#### Development using Docker | ||
To use the Docker setup, ensure you have Docker installed then run the following commands: | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Third-Party Imports | ||
from decouple import config | ||
from django_q.tasks import async_task | ||
|
||
# App Imports | ||
from core.constants import MSG, SUBJECT | ||
from core.models.user import User | ||
|
||
|
||
def send_email(data): | ||
""""This method sends emails to users""" | ||
for user in User.objects.filter(is_staff=True): | ||
async_task( | ||
"django.core.mail.send_mail", | ||
SUBJECT, | ||
MSG.format(data.name), | ||
config("EMAIL_SENDER"), | ||
[user.email], | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 2.1.10 on 2019-08-26 12:56 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('core', '0052_notifications'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='assettype', | ||
name='threshold', | ||
field=models.IntegerField(default=0), | ||
), | ||
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,11 +5,13 @@ | |
from datetime import datetime | ||
|
||
# Third-Party Imports | ||
from decouple import config | ||
from django.conf import settings | ||
from django.core.exceptions import ValidationError | ||
from django.db import models | ||
|
||
# App Imports | ||
from api.send_email import send_email | ||
from core import constants | ||
from core.managers import CaseInsensitiveManager | ||
from core.slack_bot import SlackIntegration | ||
|
@@ -26,7 +28,7 @@ def user_abstract(user, filename): | |
:params: user -> user object | ||
:params: filename -> string | ||
""" | ||
return f'user_{user}_{filename}' | ||
return f"user_{user}_{filename}" | ||
|
||
|
||
class AssetCategory(models.Model): | ||
|
@@ -92,6 +94,7 @@ class AssetType(models.Model): | |
last_modified = models.DateTimeField(auto_now=True, editable=False) | ||
asset_sub_category = models.ForeignKey("AssetSubCategory", on_delete=models.PROTECT) | ||
has_specs = models.BooleanField(default=False) | ||
threshold = models.IntegerField(default=0) | ||
|
||
objects = CaseInsensitiveManager() | ||
|
||
|
@@ -542,6 +545,13 @@ def save(self, *args, **kwargs): | |
self.previous_assignee = None | ||
try: | ||
super().save(*args, **kwargs) | ||
if self.previous_assignee is None: | ||
threshold_data = self.asset.model_number.asset_make.asset_type | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This variable would be more descriptive if named |
||
threshold_data.threshold = threshold_data.threshold - 1 | ||
if threshold_data.threshold <= int(config("DEFAULT_THRESHOLD")): | ||
send_email(threshold_data) | ||
threshold_data.save() | ||
|
||
except Exception: | ||
raise | ||
else: | ||
|
@@ -619,10 +629,10 @@ class AssetIncidentReport(models.Model): | |
loss_of_property = models.TextField(null=True, blank=True) | ||
witnesses = models.TextField(null=True, blank=True) | ||
police_abstract_obtained = models.CharField(max_length=255) | ||
submitted_by = models.ForeignKey('User', null=True, on_delete=models.PROTECT) | ||
submitted_by = models.ForeignKey("User", null=True, on_delete=models.PROTECT) | ||
created_at = models.DateTimeField(default=datetime.now, editable=False) | ||
police_abstract = models.FileField( | ||
'Police Abstract', upload_to=user_abstract, blank=True | ||
"Police Abstract", upload_to=user_abstract, blank=True | ||
) | ||
|
||
def __str__(self): | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.