From a93dd49db67f22f4ac780898fe94703a59dc7b0e Mon Sep 17 00:00:00 2001 From: Peter Odeny Date: Sat, 15 Oct 2022 00:18:06 +0200 Subject: [PATCH] clean code to run locally (#354) * clean code to run locally * debugging of docker and other issues Co-authored-by: anamariaroman --- core/admin.py | 2 +- core/migrations/0003_partner.py | 2 +- core/migrations/0007_auto_20220823_1406.py | 17 ++++++++++++++++ core/models.py | 7 ++++++- core/views/coreuser.py | 23 ++++++++++++---------- core/views/organization.py | 2 +- docker-compose.yml | 3 ++- requirements/base.txt | 2 +- 8 files changed, 42 insertions(+), 16 deletions(-) create mode 100644 core/migrations/0007_auto_20220823_1406.py diff --git a/core/admin.py b/core/admin.py index 30d4055f..475cef87 100644 --- a/core/admin.py +++ b/core/admin.py @@ -3,7 +3,7 @@ from django.utils.translation import ugettext_lazy as _ from core.models import CoreUser, CoreGroup, CoreSites, EmailTemplate, \ - Industry, LogicModule, Organization, OrganizationType, Consortium + Industry, LogicModule, Organization, OrganizationType, Consortium, Partner class LogicModuleAdmin(admin.ModelAdmin): diff --git a/core/migrations/0003_partner.py b/core/migrations/0003_partner.py index 15486e9a..245fc3a6 100644 --- a/core/migrations/0003_partner.py +++ b/core/migrations/0003_partner.py @@ -7,7 +7,7 @@ class Migration(migrations.Migration): dependencies = [ - ('core', '0002_auto_20200303_1657'), + ('core', '0001_initial'), ] operations = [ diff --git a/core/migrations/0007_auto_20220823_1406.py b/core/migrations/0007_auto_20220823_1406.py new file mode 100644 index 00000000..bcce66ab --- /dev/null +++ b/core/migrations/0007_auto_20220823_1406.py @@ -0,0 +1,17 @@ +# Generated by Django 2.2.28 on 2022-08-23 14:06 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0006_auto_20220620_0528'), + ] + + operations = [ + migrations.AlterModelOptions( + name='partner', + options={'verbose_name_plural': 'Partners'}, + ), + ] diff --git a/core/models.py b/core/models.py index 93627a0d..ed7555c3 100644 --- a/core/models.py +++ b/core/models.py @@ -318,7 +318,7 @@ class Consortium(models.Model): class Meta: ordering = ('name',) - verbose_name_plural = "Consortiums" + verbose_name_plural = 'Consortiums' def save(self, *args, **kwargs): if self.create_date is None: @@ -336,3 +336,8 @@ class Partner(models.Model): create_date = models.DateTimeField(null=True, blank=True) edit_date = models.DateTimeField(null=True, blank=True) + class Meta: + verbose_name_plural = 'Partners' + + def __str__(self): + return f'{self.name}' or f'{self.uuid}' diff --git a/core/views/coreuser.py b/core/views/coreuser.py index 8b529ee7..f62801dc 100644 --- a/core/views/coreuser.py +++ b/core/views/coreuser.py @@ -14,7 +14,8 @@ from core.serializers import (CoreUserSerializer, CoreUserWritableSerializer, CoreUserInvitationSerializer, CoreUserResetPasswordSerializer, CoreUserResetPasswordCheckSerializer, CoreUserResetPasswordConfirmSerializer, CoreUserEmailAlertSerializer, - CoreUserProfileSerializer) + CoreUserProfileSerializer, CoreUserUpdateOrganizationSerializer, + CoreUserEmailNotificationSerializer) from django.http import Http404 from rest_framework.views import APIView @@ -280,6 +281,12 @@ def get_permissions(self): queryset = CoreUser.objects.all() permission_classes = (AllowAuthenticatedRead,) + color_codes = { + 'error': '#cc3300', + 'info': '#2196F3', + 'success': '#339900' + } + @swagger_auto_schema(methods=['post'], request_body=CoreUserEmailAlertSerializer, responses=SUCCESS_RESPONSE) @@ -308,7 +315,7 @@ def alert(self, request, *args, **kwargs): '/app/shipment/edit/:'+str(message['shipment_id'])) else: message['shipment_url'] = None - message['color'] = color_codes.get(message['severity']) + message['color'] = self.color_codes.get(message['severity']) context = { 'message': message, } @@ -358,13 +365,6 @@ def update_profile(self, request, pk=None, *args, **kwargs): serializer.save() return Response(serializer.data) - -color_codes = { - 'error': '#cc3300', - 'info': '#2196F3', - 'success': '#339900' -} - @action(detail=False, methods=['patch'], name='Update Organization', url_path='update_org/(?P\d+)') def update_info(self, request, pk=None, *args, **kwargs): """ @@ -403,7 +403,10 @@ def notification(self, request, *args, **kwargs): send_email(email_address, subject, context, template_name, html_template_name) except Exception as ex: print('Exception: ', ex) + return Response( { 'detail': 'The notification were sent successfully on email.', - }, status=status.HTTP_200_OK) + }, status=status.HTTP_200_OK + ) + diff --git a/core/views/organization.py b/core/views/organization.py index 6421a3fb..32ce103d 100644 --- a/core/views/organization.py +++ b/core/views/organization.py @@ -58,7 +58,7 @@ def fetch_existing_orgs(self, request, pk=None, *args, **kwargs): """ Fetch Already existing Organizations in Buildly Core, Any logged in user can access this - """s + """ # returns names of existing orgs in Buildly Core as a list queryset = Organization.objects.all() names = list() diff --git a/docker-compose.yml b/docker-compose.yml index 92b9f8b5..0893a477 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -66,7 +66,8 @@ services: USE_PASSWORD_MINIMUM_LENGTH_VALIDATOR: "True" PASSWORD_MINIMUM_LENGTH: "6" USE_PASSWORD_COMMON_VALIDATOR: "True" - USE_PASSWORD_NUMERIC_VALIDATOR: "True" FRONTEND_URL: "http://localhost:3000/login/" + USE_PASSWORD_NUMERIC_VALIDATOR: "True" + FRONTEND_URL: "http://localhost:3000/login/" EMAIL_HOST: "smtp.sendgrid.net" EMAIL_HOST_USER: "apikey" EMAIL_HOST_PASSWORD: "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" diff --git a/requirements/base.txt b/requirements/base.txt index 9f15bb86..abb19ec3 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -11,7 +11,7 @@ futures==3.1.1 django-cors-headers==2.5.3 pyswagger==0.8.39 bravado-core==5.13.1 -drf-yasg==1.10.2 +drf-yasg==1.17.1 requests==2.25.0 aiohttp==3.7.4 django-auth-ldap==2.1.0