diff --git a/AHC_app/AHC_app/celery_notifications/config.py b/AHC_app/AHC_app/celery_notifications/config.py index 7a3c94e..bcfa1c6 100644 --- a/AHC_app/AHC_app/celery_notifications/config.py +++ b/AHC_app/AHC_app/celery_notifications/config.py @@ -4,10 +4,8 @@ from celery.utils.log import get_task_logger from django.conf import settings -from AHC_app.celery_notifications.utils.discord_utils import send_via_discord -from AHC_app.celery_notifications.utils.sending_utils import ( - send_via_email, # , send_via_sms, send_via_discord -) +# from AHC_app.celery_notifications.utils.discord_utils import send_via_discord +from AHC_app.celery_notifications.utils.sending_utils import send_via_email logger = get_task_logger(__name__) @@ -44,6 +42,7 @@ def send_sms_notifications(**kwargs): @shared_task(bind=True) def send_discord_notifications(self, *args, **kwargs): - user_id = kwargs.get("user_id") - user_message = kwargs.get("user_message") - send_via_discord(user_id, user_message) + # user_id = kwargs.get("user_id") + # user_message = kwargs.get("user_message") + # send_via_discord(user_id, user_message) + pass diff --git a/AHC_app/AHC_app/celery_notifications/utils/discord_utils.py b/AHC_app/AHC_app/celery_notifications/utils/discord_utils.py index 7a0746d..87da4e7 100644 --- a/AHC_app/AHC_app/celery_notifications/utils/discord_utils.py +++ b/AHC_app/AHC_app/celery_notifications/utils/discord_utils.py @@ -4,7 +4,8 @@ from discord.ext import commands from django.conf import settings -TOKEN = settings.DISCORD_TOKEN +# TOKEN = settings.DISCORD_TOKEN +TOKEN = "none" def send_via_discord(user_id: int, user_message: str) -> None: diff --git a/AHC_app/Dockerfile-queue b/AHC_app/Dockerfile-queue new file mode 100644 index 0000000..0cc351b --- /dev/null +++ b/AHC_app/Dockerfile-queue @@ -0,0 +1,10 @@ +FROM python:3.12 +LABEL authors="AM" +WORKDIR /app +COPY Pipfile Pipfile.lock ./ + +RUN python -m pip install --upgrade pip && \ + pip install --no-cache-dir pipenv && \ + pipenv install --dev --system --deploy + +COPY . . diff --git a/AHC_app/Dockerfile b/AHC_app/Dockerfile-web similarity index 100% rename from AHC_app/Dockerfile rename to AHC_app/Dockerfile-web diff --git a/AHC_app/animals/apps.py b/AHC_app/animals/apps.py index fef2b06..47778cd 100644 --- a/AHC_app/animals/apps.py +++ b/AHC_app/animals/apps.py @@ -6,4 +6,4 @@ class AnimalsConfig(AppConfig): name = "animals" def ready(self): - import animals.signals + pass diff --git a/AHC_app/animals/signals.py b/AHC_app/animals/signals.py index 62fc846..05ebd4f 100644 --- a/AHC_app/animals/signals.py +++ b/AHC_app/animals/signals.py @@ -1,22 +1,17 @@ import os +from animals.models import Animal from django.db.models.signals import post_delete, post_save, pre_delete from django.dispatch import receiver from users.models import Profile -from animals.models import Animal - @receiver(post_save, sender=Animal) def remove_old_pictures_after_change(sender, instance, **kwargs): - animals_with_profile_images = Animal.objects.exclude(profile_image="").values_list( - "profile_image", flat=True - ) + animals_with_profile_images = Animal.objects.exclude(profile_image="").values_list("profile_image", flat=True) unused_images = os.listdir("static/media/profile_pics/animals/") - animals_with_profile_images = [ - str(picture).split("/")[-1] for picture in animals_with_profile_images - ] + animals_with_profile_images = [str(picture).split("/")[-1] for picture in animals_with_profile_images] for image_name in unused_images: if image_name not in animals_with_profile_images: @@ -36,14 +31,10 @@ def remove_old_pictures_after_animal_delete(sender, instance, **kwargs): @receiver(post_delete, sender=Profile) def remove_old_pictures_after_user_delete(sender, instance, **kwargs): - animals_with_profile_images = Animal.objects.exclude(profile_image="").values_list( - "profile_image", flat=True - ) + animals_with_profile_images = Animal.objects.exclude(profile_image="").values_list("profile_image", flat=True) unused_images = os.listdir("static/media/profile_pics/animals/") - animals_with_profile_images = [ - str(picture).split("/")[-1] for picture in animals_with_profile_images - ] + animals_with_profile_images = [str(picture).split("/")[-1] for picture in animals_with_profile_images] for image_name in unused_images: if image_name not in animals_with_profile_images: diff --git a/AHC_app/animals/utils_owner/forms.py b/AHC_app/animals/utils_owner/forms.py index 0385cd3..868e015 100644 --- a/AHC_app/animals/utils_owner/forms.py +++ b/AHC_app/animals/utils_owner/forms.py @@ -1,11 +1,10 @@ from datetime import date +from animals.models import Animal from django import forms from PIL import Image from users.models import Profile -from animals.models import Animal - class ImageUploadForm(forms.ModelForm): ALLOWED_EXTENSIONS = ["jpg", "jpeg", "png"] @@ -38,9 +37,7 @@ def clean_profile_image(self): class ChangeOwnerForm(forms.Form): - new_owner = forms.CharField( - max_length=255, required=True, label="New owner's profile name" - ) + new_owner = forms.CharField(max_length=255, required=True, label="New owner's profile name") set_keeper = forms.BooleanField(required=False, label="Set as keeper") def __init__(self, *args, **kwargs): @@ -63,9 +60,7 @@ def clean_new_owner(self): class ManageKeepersForm(forms.Form): - input_user = forms.CharField( - max_length=255, required=True, label="Full keeper profile name" - ) + input_user = forms.CharField(max_length=255, required=True, label="Full keeper profile name") def __init__(self, *args, **kwargs): self.instance = kwargs.pop("instance", None) @@ -75,9 +70,7 @@ def clean_input_user(self): input_user = self.cleaned_data.get("input_user") if input_user == self.instance.owner.user.username: - raise forms.ValidationError( - "As the owner you can not set yourself as a keeper." - ) + raise forms.ValidationError("As the owner you can not set yourself as a keeper.") if input_user in self.instance.allowed_users.all(): raise forms.ValidationError("User is already on the list of keepers.") @@ -101,9 +94,7 @@ def clean_birthdate(self): current_date = date.today() if birthdate > current_date: - raise forms.ValidationError( - "Date could not be set further than current day." - ) + raise forms.ValidationError("Date could not be set further than current day.") return birthdate diff --git a/AHC_app/docker-compose.yml b/AHC_app/docker-compose.yml index 54ac5d3..fdd7181 100644 --- a/AHC_app/docker-compose.yml +++ b/AHC_app/docker-compose.yml @@ -1,7 +1,9 @@ version: "3.9" services: web: - build: . + build: + context: . + dockerfile: Dockerfile-web image: ahc_app-web:latest ports: - "8000:8000" @@ -16,7 +18,7 @@ services: condition: service_healthy environment: - PYTHONUNBUFFERED=1 - - PYTHONPATH=/AHC_app + - PYTHONPATH=/app entrypoint: ["/bin/bash", "-c"] command: - | @@ -71,7 +73,9 @@ services: restart: always queue: - build: . + build: + context: . + dockerfile: Dockerfile-queue command: celery -A AHC_app.celery_notifications.config:celery_obj worker -l info depends_on: redis: @@ -84,6 +88,8 @@ services: - "5000:5000" environment: - DJANGO_SETTINGS_MODULE=AHC_app.settings + - PYTHONUNBUFFERED=1 + - PYTHONPATH=/app redis: image: redis:7-alpine diff --git a/AHC_app/homepage/admin.py b/AHC_app/homepage/admin.py index bc300d6..23fc0d8 100644 --- a/AHC_app/homepage/admin.py +++ b/AHC_app/homepage/admin.py @@ -1,5 +1,4 @@ from django.contrib import admin - from homepage.models import AnimalTitle, CronJob admin.site.register(AnimalTitle) diff --git a/AHC_app/homepage/management/commands/sync_cronjobs.py b/AHC_app/homepage/management/commands/sync_cronjobs.py index 5d13508..80ccaa6 100644 --- a/AHC_app/homepage/management/commands/sync_cronjobs.py +++ b/AHC_app/homepage/management/commands/sync_cronjobs.py @@ -8,9 +8,7 @@ class Command(BaseCommand): help = "Sync cronjobs with the actual cron configuration" def handle(self, *args, **options): - cronjob_info = subprocess.run( - ["crontab", "-l"], stdout=subprocess.PIPE, text=True - ).stdout.splitlines() + cronjob_info = subprocess.run(["crontab", "-l"], stdout=subprocess.PIPE, text=True).stdout.splitlines() CronJob.objects.all().delete() diff --git a/AHC_app/homepage/tests/test_homepage.py b/AHC_app/homepage/tests/test_homepage.py index dc91c82..fe3ad54 100644 --- a/AHC_app/homepage/tests/test_homepage.py +++ b/AHC_app/homepage/tests/test_homepage.py @@ -39,7 +39,7 @@ def test_should_return_status_code_200_when_view_is_get_called(self): actual_status_code = resp.status_code # assert actual_status_code == expected_status_code - self.assertEquals(expected_status_code, actual_status_code) + self.assertEqual(expected_status_code, actual_status_code) def test_should_return_valid_render_template_name_when_view_is_get_called(self): expected_template_name = "homepage/homepage.html" diff --git a/AHC_app/homepage/urls.py b/AHC_app/homepage/urls.py index 30af557..6f65fb3 100644 --- a/AHC_app/homepage/urls.py +++ b/AHC_app/homepage/urls.py @@ -1,5 +1,4 @@ from django.urls import path - from homepage.views import HomepageView urlpatterns = [ diff --git a/AHC_app/medical_notes/forms.py b/AHC_app/medical_notes/forms.py index 67e9a56..e69de29 100644 --- a/AHC_app/medical_notes/forms.py +++ b/AHC_app/medical_notes/forms.py @@ -1,2 +0,0 @@ -from medical_notes.forms.type_basic_note import * -from medical_notes.forms.type_measurement_notes import * diff --git a/AHC_app/medical_notes/signals/type_feeding_notes.py b/AHC_app/medical_notes/signals/type_feeding_notes.py index b6001c5..ce07d43 100644 --- a/AHC_app/medical_notes/signals/type_feeding_notes.py +++ b/AHC_app/medical_notes/signals/type_feeding_notes.py @@ -9,7 +9,5 @@ def clean_orphaned_diet_records(sender, instance, **kwargs): user_profile = UserProfile.objects.get(id=instance.related_note.author.id) with transaction.atomic(): - orphaned_notes = FeedingNote.objects.filter( - author=user_profile, related_note=None - ) + orphaned_notes = FeedingNote.objects.filter(author=user_profile, related_note=None) orphaned_notes.delete() diff --git a/AHC_app/medical_notes/signals/type_measurement_notes.py b/AHC_app/medical_notes/signals/type_measurement_notes.py index f4fee9a..6e7cb9e 100644 --- a/AHC_app/medical_notes/signals/type_measurement_notes.py +++ b/AHC_app/medical_notes/signals/type_measurement_notes.py @@ -23,17 +23,13 @@ def validate_one_to_one_fields(sender, instance, **kwargs): ) > 1 ): - raise ValidationError( - "BiometricRecord can only have one of OneToOneFields assigned." - ) + raise ValidationError("BiometricRecord can only have one of OneToOneFields assigned.") @receiver(post_save, sender=BiometricRecord) def clean_orphaned_metric_records(sender, instance, **kwargs): user_profile = UserProfile.objects.get(id=instance.related_note.author.id) - medical_records = MedicalRecord.objects.filter( - author=user_profile, type_of_event="biometric_record" - ) + medical_records = MedicalRecord.objects.filter(author=user_profile, type_of_event="biometric_record") for record in medical_records: if not record.biometricrecord_set.filter( diff --git a/AHC_app/medical_notes/views/type_measurement_notes.py b/AHC_app/medical_notes/views/type_measurement_notes.py index b1b93f4..e4c0a3b 100644 --- a/AHC_app/medical_notes/views/type_measurement_notes.py +++ b/AHC_app/medical_notes/views/type_measurement_notes.py @@ -33,9 +33,7 @@ def form_valid(self, form): if record_type == "weight": weight = form.cleaned_data["weight"] unit = form.cleaned_data["weight_unit_to_present"] - weight_record = BiometricWeightRecords.objects.create( - weight=weight, weight_unit_to_present=unit - ) + weight_record = BiometricWeightRecords.objects.create(weight=weight, weight_unit_to_present=unit) biometric_record = BiometricRecord.objects.create( animal=animal, related_note=related_note, @@ -44,9 +42,7 @@ def form_valid(self, form): elif record_type == "height": height = form.cleaned_data["height"] unit = form.cleaned_data["height_unit_to_present"] - height_record = BiometricHeightRecords.objects.create( - height=height, height_unit_to_present=unit - ) + height_record = BiometricHeightRecords.objects.create(height=height, height_unit_to_present=unit) biometric_record = BiometricRecord.objects.create( animal=animal, related_note=related_note, diff --git a/AHC_app/users/admin.py b/AHC_app/users/admin.py index 308a0b3..ed54a24 100644 --- a/AHC_app/users/admin.py +++ b/AHC_app/users/admin.py @@ -1,5 +1,4 @@ from django.contrib import admin - -from .models import Profile +from users.models import Profile admin.site.register(Profile) diff --git a/AHC_app/users/forms.py b/AHC_app/users/forms.py index fbb4264..37c2b8d 100644 --- a/AHC_app/users/forms.py +++ b/AHC_app/users/forms.py @@ -1,7 +1,6 @@ from django import forms from django.contrib.auth.forms import User, UserCreationForm - -from .models import Profile +from users.models import Profile class UserRegisterForm(UserCreationForm): diff --git a/AHC_app/users/signals.py b/AHC_app/users/signals.py index 75fd7e6..6821573 100644 --- a/AHC_app/users/signals.py +++ b/AHC_app/users/signals.py @@ -2,8 +2,7 @@ from django.db.models.signals import post_save, pre_save from django.dispatch import receiver from homepage.models import Privilege, ProfileBackground - -from .models import Profile +from users.models import Profile @receiver(pre_save, sender=Profile) @@ -16,18 +15,14 @@ def create_basic_privilege(sender, instance, **kwargs): @receiver(pre_save, sender=Profile) def create_background(sender, instance, **kwargs): if not instance.profile_background: - background, _ = ProfileBackground.objects.get_or_create( - title="Default Background" - ) + background, _ = ProfileBackground.objects.get_or_create(title="Default Background") instance.profile_background = background @receiver(post_save, sender=User) def create_profile(sender, instance, created, **kwargs): if created: - background, _ = ProfileBackground.objects.get_or_create( - title="Default Background" - ) + background, _ = ProfileBackground.objects.get_or_create(title="Default Background") Profile.objects.create(user=instance) diff --git a/AHC_app/users/urls.py b/AHC_app/users/urls.py index cd9109d..b0a23c4 100644 --- a/AHC_app/users/urls.py +++ b/AHC_app/users/urls.py @@ -6,18 +6,37 @@ PasswordResetView, ) from django.urls import path - -from . import views as user_views +from users import views as user_views urlpatterns = [ path("", auth_views.LoginView.as_view(template_name="users/login.html"), name="login"), path("login/", auth_views.LoginView.as_view(template_name="users/login.html"), name="login"), path("register/", user_views.UserRegisterView.as_view(), name="register"), - path("login_success/", auth_views.LoginView.as_view(template_name="users/login_success.html"), name="login_success"), + path( + "login_success/", auth_views.LoginView.as_view(template_name="users/login_success.html"), name="login_success" + ), path("logout/", auth_views.LogoutView.as_view(template_name="users/logout.html"), name="logout"), path("profile/", user_views.UserProfileView.as_view(), name="profile"), - path("password-reset/", PasswordResetView.as_view(template_name="users/password_reset.html", html_email_template_name="users/password_reset_email.html"), name="password-reset"), - path("password-reset/done/", PasswordResetDoneView.as_view(template_name="users/password_reset_done.html"), name="password_reset_done"), - path("password-reset-confirm///", PasswordResetConfirmView.as_view(template_name="users/password_reset_confirm.html"), name="password_reset_confirm"), - path("password-reset-complete/", PasswordResetCompleteView.as_view(template_name="users/password_reset_complete.html"), name="password_reset_complete"), + path( + "password-reset/", + PasswordResetView.as_view( + template_name="users/password_reset.html", html_email_template_name="users/password_reset_email.html" + ), + name="password-reset", + ), + path( + "password-reset/done/", + PasswordResetDoneView.as_view(template_name="users/password_reset_done.html"), + name="password_reset_done", + ), + path( + "password-reset-confirm///", + PasswordResetConfirmView.as_view(template_name="users/password_reset_confirm.html"), + name="password_reset_confirm", + ), + path( + "password-reset-complete/", + PasswordResetCompleteView.as_view(template_name="users/password_reset_complete.html"), + name="password_reset_complete", + ), ] diff --git a/AHC_app/users/views.py b/AHC_app/users/views.py index 9df47c7..dc39aeb 100644 --- a/AHC_app/users/views.py +++ b/AHC_app/users/views.py @@ -1,10 +1,9 @@ from django.contrib import messages from django.contrib.auth.mixins import LoginRequiredMixin from django.urls import reverse_lazy -from django.views.generic import CreateView, FormView, UpdateView - -from .forms import ProfileUpdateForm, UserRegisterForm, UserUpdateForm -from .models import Profile +from django.views.generic import CreateView, UpdateView +from users.forms import ProfileUpdateForm, UserRegisterForm, UserUpdateForm +from users.models import Profile class UserRegisterView(CreateView): diff --git a/kubernetes/queue/celery/deployment.yaml b/kubernetes/queue/celery/deployment.yaml index 7d26d36..ccfc7d9 100644 --- a/kubernetes/queue/celery/deployment.yaml +++ b/kubernetes/queue/celery/deployment.yaml @@ -27,7 +27,6 @@ spec: image: ahc_app-queue:latest imagePullPolicy: Never command: [ "celery", "-A", "AHC_app.celery_notifications.config:celery_obj", "worker", "-l", "info"] -# command: [ "sleep", "infinity" ] # debug env: - name: PYTHONUNBUFFERED value: "1"