Skip to content

Commit

Permalink
[wip]
Browse files Browse the repository at this point in the history
  • Loading branch information
jonavellecuerdo committed Dec 1, 2023
1 parent 99f410f commit 2960a46
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 17 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ django_settings_module = "solenoid.settings.base"
disallow_untyped_calls = true
disallow_untyped_defs = true
plugins = ["mypy_django_plugin.main"]
exclude = ["tests"]
exclude = ["tests", "migrations"]

[[tool.mypy.overrides]]
module = ["solenoid.userauth.*", "solenoid.settings.*", "celery_progress.backend"]
Expand Down
2 changes: 1 addition & 1 deletion solenoid/people/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Meta:
model = Liaison
fields = ("first_name", "last_name", "email_address")

def __init__(self, *args, **kwargs):
def __init__(self, *args, **kwargs): # type: ignore[no-untyped-def]
super(LiaisonCreateForm, self).__init__(*args, **kwargs)
self.fields["dlc"] = forms.ModelMultipleChoiceField(
queryset=DLC.objects.all(), required=False
Expand Down
9 changes: 6 additions & 3 deletions solenoid/people/signals.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
from django.db.models.signals import post_save
from django.db import models
from django.dispatch import receiver

from solenoid.emails.models import EmailMessage

from .models import DLC
from .models import DLC, Liaison


def update_emails_with_dlcs(dlcs, liaison=None):
def update_emails_with_dlcs(
dlcs: models.QuerySet | list, liaison: Liaison | None = None
) -> None:
"""
For a given liaison and set of DLCs, update all unsent EmailMessages
associated with those DLCs to have that Liaison.
Expand All @@ -25,6 +28,6 @@ def update_emails_with_dlcs(dlcs, liaison=None):


@receiver(post_save, sender=DLC)
def update_emails_with_dlcs_on_save(sender, **kwargs):
def update_emails_with_dlcs_on_save(sender: models.Model, **kwargs) -> None: # type: ignore[no-untyped-def]
dlc = kwargs["instance"]
update_emails_with_dlcs([dlc], dlc.liaison)
26 changes: 14 additions & 12 deletions solenoid/people/views.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import logging

from typing import Any

from django.contrib import messages
from django.urls import reverse_lazy
from django.http import HttpResponseRedirect
from django.http import HttpResponse, HttpResponseRedirect
from django.views.generic.edit import CreateView, UpdateView, DeleteView
from django.views.generic.list import ListView

Expand All @@ -21,7 +23,7 @@ class LiaisonCreate(ConditionalLoginRequiredMixin, CreateView):
form_class = LiaisonCreateForm
success_url = reverse_lazy("people:liaison_list")

def get_context_data(self, **kwargs):
def get_context_data(self, **kwargs): # type: ignore[no-untyped-def]
context = super(LiaisonCreate, self).get_context_data(**kwargs)
context["title"] = "Add liaison"
context["breadcrumbs"] = [
Expand All @@ -32,7 +34,7 @@ def get_context_data(self, **kwargs):
context["form_id"] = "liaison-create"
return context

def form_valid(self, form):
def form_valid(self, form: LiaisonCreateForm) -> HttpResponseRedirect:
liaison = form.save()
dlcs = form.cleaned_data["dlc"]
liaison.dlc_set.add(*dlcs)
Expand All @@ -44,7 +46,7 @@ class LiaisonList(ConditionalLoginRequiredMixin, ListView):
model = Liaison
queryset = Liaison.objects.all()

def get_context_data(self, **kwargs):
def get_context_data(self, **kwargs): # type: ignore[no-untyped-def]
context = super(LiaisonList, self).get_context_data(**kwargs)
context["dlc_set"] = DLC.objects.all()
context["title"] = "Manage liaisons"
Expand All @@ -62,7 +64,7 @@ class LiaisonUpdate(ConditionalLoginRequiredMixin, UpdateView):
form_class = LiaisonCreateForm
success_url = reverse_lazy("people:liaison_list")

def get_context_data(self, **kwargs):
def get_context_data(self, **kwargs): # type: ignore[no-untyped-def]
context = super(LiaisonUpdate, self).get_context_data(**kwargs)
context["title"] = "Edit liaison"
context["breadcrumbs"] = [
Expand All @@ -73,12 +75,12 @@ def get_context_data(self, **kwargs):
context["form_id"] = "liaison-update"
return context

def get_initial(self):
def get_initial(self) -> dict[str, Any]:
initial = super(LiaisonUpdate, self).get_initial()
initial["dlc"] = DLC.objects.filter(liaison=self.get_object())
return initial

def post(self, request, *args, **kwargs):
def post(self, request, *args, **kwargs) -> HttpResponse: # type: ignore[no-untyped-def]
# This would normally be set in post(), but we're not calling super, so
# we need to do it ourselves.
self.object = self.get_object()
Expand All @@ -88,8 +90,8 @@ def post(self, request, *args, **kwargs):
if form.is_valid():
try:
dlcs = DLC.objects.filter(pk__in=request.POST.getlist("dlc"))
except KeyError:
logger.exception()
except KeyError as e:
logger.exception(e)
raise

liaison = self.get_object()
Expand All @@ -112,11 +114,11 @@ def post(self, request, *args, **kwargs):
return self.form_invalid(form)


class LiaisonDelete(ConditionalLoginRequiredMixin, DeleteView):
class LiaisonDelete(ConditionalLoginRequiredMixin, DeleteView): # type: ignore
model = Liaison
queryset = Liaison.objects.all()

def get_context_data(self, **kwargs):
def get_context_data(self, **kwargs) -> dict[str, Any]: # type: ignore[no-untyped-def]
context = super(LiaisonDelete, self).get_context_data(**kwargs)
context["title"] = "Delete liaison ({name})".format(name=self.get_object())
context["breadcrumbs"] = [
Expand All @@ -126,6 +128,6 @@ def get_context_data(self, **kwargs):
]
return context

def get_success_url(self):
def get_success_url(self) -> Any:
messages.success(self.request, "Liaison deleted.")
return reverse_lazy("people:liaison_list")

0 comments on commit 2960a46

Please sign in to comment.