forked from City-of-Helsinki/respa
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #302 from City-of-Turku/develop
Release tku-v1.9
- Loading branch information
Showing
33 changed files
with
759 additions
and
188 deletions.
There are no files selected for viewing
This file contains 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,79 @@ | ||
# Qualitytool Django management commands | ||
|
||
|
||
## Qualitytool command: post_daily_utilization | ||
|
||
### Overview | ||
This command posts the daily utilization of respa resources to Suomi.fi qualitytool API | ||
|
||
### Usage | ||
To use the command, run: | ||
|
||
``` | ||
python manage.py post_daily_utilization [Optional: --date YYYY-mm-dd] | ||
``` | ||
|
||
### Options | ||
- `--date YYYY-mm-dd (Optional)`: The date for which the utilization data should be uploaded. Defaults to the current date (`datetime.now().date()`). | ||
|
||
### Example | ||
To upload utilization data for January 1, 2023: | ||
|
||
``` | ||
python manage.py post_daily_utilization --date 2023-01-01 | ||
``` | ||
|
||
|
||
## Qualitytool command: save_daily_utilization_csv | ||
|
||
### Overview | ||
This command saves the daily utilization of respa resources to a given file path. | ||
|
||
### Usage | ||
To use the command, run: | ||
|
||
``` | ||
python manage.py save_daily_utilization_csv /file/path.csv [Optional: --date YYYY-mm-dd] | ||
``` | ||
|
||
### Options | ||
- `path`: The destination filepath | ||
- `--date YYYY-mm-dd (Optional)`: The date for which the utilization data should be uploaded. Defaults to the current date (`datetime.now().date()`). | ||
|
||
### Example | ||
To upload utilization data for January 1, 2023: | ||
|
||
``` | ||
python manage.py save_daily_utilization_csv /file/path.csv --date 2023-01-01 | ||
``` | ||
|
||
## Qualitytool command: sftp_daily_utilization | ||
|
||
### Overview | ||
This command uploads the daily utilization of respa resources to a sftp server. | ||
|
||
### Usage | ||
To use the command, run: | ||
|
||
``` | ||
python manage.py sftp_daily_utilization /file/path.csv [Optional: --date YYYY-mm-dd] | ||
``` | ||
|
||
### Environment Variables | ||
Ensure the following environment variables are set before running the command: | ||
|
||
- `QUALITYTOOL_SFTP_HOST`: The hostname of the SFTP server. | ||
- `QUALITYTOOL_SFTP_PORT`: The port number for SFTP (e.g., 22). | ||
- `QUALITYTOOL_SFTP_USERNAME`: The username for authenticating with the SFTP server. | ||
- `QUALITYTOOL_SFTP_PASSWORD`: The password for authenticating with the SFTP server. | ||
|
||
### Options | ||
- `path`: The destination filepath on the SFTP server where the utilization CSV file will be uploaded. | ||
- `--date YYYY-mm-dd (Optional)`: The date for which the utilization data should be uploaded. Defaults to the current date (`datetime.now().date()`). | ||
|
||
### Example | ||
To upload utilization data for January 1, 2023: | ||
|
||
``` | ||
python manage.py sftp_daily_utilization /file/path.csv --date 2023-01-01 | ||
``` |
This file contains 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 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 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
18 changes: 18 additions & 0 deletions
18
notifications/migrations/0019_add_type_reservation_reminder.py
This file contains 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 3.2.20 on 2023-10-04 06:55 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('notifications', '0018_auto_20220125_0815'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='notificationtemplate', | ||
name='type', | ||
field=models.CharField(choices=[('reservation_requested', 'Reservation requested'), ('reservation_requested_official', 'Reservation requested official'), ('reservation_requested_official_by_official', 'Reservation requested by official'), ('reservation_cancelled', 'Reservation cancelled'), ('reservation_cancelled_official', 'Reservation cancelled official'), ('reservation_cancelled_by_official', 'Reservation cancelled by official'), ('reservation_created', 'Reservation created'), ('reservation_created_official', 'Reservation created official'), ('reservation_created_by_official', 'Reservation created by official'), ('reservation_modified', 'Reservation modified'), ('reservation_modified_official', 'Reservation modified official'), ('reservation_modified_by_official', 'Reservation modified by official'), ('reservation_created_with_access_code', 'Reservation created with access code'), ('reservation_created_with_access_code_official', 'Reservation created with access code official'), ('reservation_created_with_access_code_by_official', 'Reservation created with access code by official'), ('reservation_confirmed', 'Reservation confirmed'), ('reservation_denied', 'Reservation denied'), ('reservation_access_code_created', 'Access code was created for a reservation'), ('reservation_waiting_for_payment', 'Reservation waiting for payment'), ('catering_order_created', 'Catering order created'), ('catering_order_modified', 'Catering order modified'), ('catering_order_deleted', 'Catering order deleted'), ('reservation_comment_created', 'Reservation comment created'), ('catering_order_comment_created', 'Catering order comment created'), ('reservation_bulk_created', 'Reservation bulk created'), ('reservation_reminder', 'Reservation reminder')], db_index=True, max_length=100, verbose_name='Type'), | ||
), | ||
] |
This file contains 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 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
46 changes: 46 additions & 0 deletions
46
qualitytool/management/commands/save_daily_utilization_csv.py
This file contains 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,46 @@ | ||
from django.core.management.base import BaseCommand | ||
from django.utils import timezone | ||
from django.conf import settings | ||
from datetime import datetime | ||
from qualitytool.models import ResourceQualityTool | ||
from qualitytool.manager import qt_manager | ||
import os.path as _ | ||
import logging | ||
|
||
|
||
logger = logging.getLogger() | ||
|
||
|
||
|
||
class Command(BaseCommand): | ||
help = "Saves daily utilization to a CSV file." | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument('--date', action='store') | ||
|
||
def handle(self, *args, **options): | ||
path = options.get('path') | ||
date = options.get('date', None) | ||
|
||
|
||
if date: | ||
date = timezone.make_aware(datetime.strptime(date, '%Y-%m-%d')) | ||
else: | ||
date = timezone.now() | ||
|
||
|
||
daily_utilizations = [ | ||
qt_manager.get_daily_utilization(qualitytool, date) | ||
for qualitytool in ResourceQualityTool.objects.all() | ||
] | ||
|
||
if not daily_utilizations: | ||
return | ||
|
||
|
||
with open(path, 'w') as csv_file: | ||
for daily_utilization in daily_utilizations: | ||
csv_file.write('%(row)s\n' % ({ | ||
'row': ','.join(str(val) for val in daily_utilization.values()) | ||
})) | ||
logging.info(f'Generated new daily utilization csv file with {len(daily_utilizations)} entries.') |
This file contains 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,60 @@ | ||
from django.core.management.base import BaseCommand | ||
from django.core.exceptions import ImproperlyConfigured | ||
from django.utils import timezone | ||
from django.conf import settings | ||
from datetime import datetime | ||
from qualitytool.models import ResourceQualityTool | ||
from qualitytool.manager import qt_manager | ||
import os.path as _ | ||
import logging | ||
import paramiko | ||
|
||
|
||
logger = logging.getLogger() | ||
|
||
class Command(BaseCommand): | ||
help = "Uploads daily utilization to a sftp server." | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument('path') | ||
parser.add_argument('--date', action='store') | ||
|
||
def handle(self, *args, **options): | ||
path = options.get('path') | ||
date = options.get('date', None) | ||
|
||
if not settings.QUALITYTOOL_SFTP_HOST: | ||
raise ImproperlyConfigured('Missing env setting: QUALITYTOOL_SFTP_HOST') | ||
|
||
if date: | ||
date = timezone.make_aware(datetime.strptime(date, '%Y-%m-%d')) | ||
else: | ||
date = timezone.now() | ||
|
||
|
||
daily_utilizations = [ | ||
qt_manager.get_daily_utilization(qualitytool, date) | ||
for qualitytool in ResourceQualityTool.objects.all() | ||
] | ||
|
||
if not daily_utilizations: | ||
return | ||
|
||
|
||
transport = paramiko.Transport((settings.QUALITYTOOL_SFTP_HOST, settings.QUALITYTOOL_SFTP_PORT)) | ||
|
||
transport.connect( | ||
username=settings.QUALITYTOOL_SFTP_USERNAME, | ||
password=settings.QUALITYTOOL_SFTP_PASSWORD) | ||
|
||
sftp = paramiko.SFTPClient.from_transport(transport) | ||
|
||
|
||
|
||
|
||
with sftp.open(path, 'w') as csv_file: | ||
for daily_utilization in daily_utilizations: | ||
csv_file.write('%(row)s\n' % ({ | ||
'row': ','.join(str(val) for val in daily_utilization.values()) | ||
})) | ||
logging.info(f'Generated new daily utilization csv file with {len(daily_utilizations)} entries.') |
This file contains 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
Oops, something went wrong.