Skip to content
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

1580 temat pracy dyplomowej nie traci głosów #1646

Open
wants to merge 3 commits into
base: master-dev
Choose a base branch
from

Conversation

jakub-galecki
Copy link
Collaborator

W przypadku zmiany istotnych pól w formularzu tematu pracy dyplomowej, temat nie tracił głosów. PR uwzględnia usunięcie głosów jeśli status tematu pracy dyplomowej został zmieniony na BEING_EVALUATED. Dodatkowa zmiana to taka, że jeśli zmieniły się istotne pola w temacie pracy dyplomowej, ale status pozostał BEING_EVALUATED to wysyłane zostaje powiadomienie tylko do osób, które oddały głos na temat pracy.

PR również uwzględnia zmianę treści powiadomień z
W pracy dyplomowej "{title}" pojawiła się możliwość głosowania.
na
W nowym temacie pracy dyplomowej "{title}" pojawiła się możliwość głosowania oraz
W zmodyfikowanym temacie pracy dyplomowej "{title}" pojawiła się możliwość głosowania

Podsumowując mamy następnę powiadomienia:

  • Jeśli temat pracy jest nowy: W nowym temacie pracy dyplomowej "{title}" pojawiła się możliwość głosowania (przesyłane do wszystkich)
  • Jeśli zmienił się status na BEING_EVALUATED: W zmodyfikowanym temacie pracy dyplomowej "{title}" pojawiła się możliwość głosowania (wysyłane do wszystkich)
  • Jeśli zmieniły się istotne pola, ale status się nie zmienił: W zmodyfikowanym temacie pracy dyplomowej "{title}" pojawiła się możliwość głosowania (wysyłane tylko do osób, które oddały głos)

image

@@ -28,3 +28,6 @@ class ThesisVote(models.IntegerChoices):
NONE = 1, "brak głosu"
REJECTED = 2, "odrzucona"
ACCEPTED = 3, "zaakceptowana"


SIGNIFICANT_FIELDS = ['title', 'supporting_advisor', 'kind', 'max_number_of_students', 'description']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dobry pomysł żeby bardziej wyeksponować tę listę, ale ona nie pasuje do tego pliku. Zostawiłbym ją jednak w forms.py, w formie takiej właśnie deklaracji zaraz za importami - jeśli kiedyś zaczniemy tego używać w jakichś kolejnych funkcjonalnościach, to wtedy się to przeniesie.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gotowe

Comment on lines 172 to 174
operation = 'create'
if 'operation' in kwargs:
operation = kwargs['operation']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
operation = 'create'
if 'operation' in kwargs:
operation = kwargs['operation']
operation = kwargs.get('operation', 'create')

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A tak w ogóle, to jakie są możliwe wartości tego kwargu?

Copy link
Contributor

@lgpawel lgpawel Feb 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A, on wcale nie jest biblioteczny? To na pewno nie chciałbym wprowadzać rozróżniania pomiędzy dwoma możliwościami przez sprawdzanie, czy jakiś napis jest taki a nie inny. Póki to są faktycznie dwie możliwości, to można to opędzić wartością boolowską (o nazwie np. is_new, jeśli nie wpadniemy na nic zgrabniejszego); gdyby było więcej scenariuszy, to należałoby zadeklarować jakiegoś enum-a.

Ponadto skoro mamy nad nim pełną kontrolę, to zamiast zaszywać tutaj jakieś wartości domyślne, to podawajmy go jawnie wysyłając sygnał – przy trzech wywołaniach nawet nie oszczędzamy napisanych znaków.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Zmienione na flage is_new

if 'notify_only_voted' in kwargs and kwargs['notify_only_voted']:
already_voted = [v.owner for v in thesis.thesis_votes.all() if v.vote != ThesisVote.NONE]
users = [voter.user for voter in already_voted]
notify_selected_users(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chciałbym, żeby w kodzie po zmianach dalej było dokładnie jedno wywołanie tej funkcji.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotowe

@@ -107,9 +107,22 @@ def save(self, *args, **kwargs):
"""
old = self.pk and type(self).objects.get(pk=self.pk)
super(Thesis, self).save(*args, **kwargs)
if not old or (old.status != ThesisStatus.BEING_EVALUATED and self.status == ThesisStatus.BEING_EVALUATED):
if not old:
self.thesis_votes.filter(vote__in=[ThesisVote.ACCEPTED, ThesisVote.REJECTED]).update(vote=ThesisVote.NONE)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Czy ta instrukcja ma znaczenie? Dla nowego tematu nie będzie (nietrywialnych) głosów.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instrukcja do usuwania głosów usunięta, faktycznie dla nowych tematów nie miała ona sensu

thesis_voting_activated.send(sender=self.__class__, instance=self)

if old and old.status != ThesisStatus.BEING_EVALUATED and self.status == ThesisStatus.BEING_EVALUATED:
# in case of new thesis titile send notification to all board members
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# in case of new thesis titile send notification to all board members
# in case of new thesis title send notification to all board members

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotowe

if old and (old.status == ThesisStatus.BEING_EVALUATED and
self.status == ThesisStatus.BEING_EVALUATED and
self.significant_field_changed):
# send notification only to the board memebers who already accepted the thesis
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# send notification only to the board memebers who already accepted the thesis
# send notification only to the board members who already voted on the thesis

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotowe

operation = kwargs['operation']

if operation == 'modify':
if 'notify_only_voted' in kwargs and kwargs['notify_only_voted']:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tu podobnie, zapewnijmy, żeby ten argument zawsze był w kwargs. No i łatwiej jest nazwać jego negację - notify_all (chyba że bardzo nam przeszkadza mniejsza precyzja opisu wywołania z notify_all=False).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usunąłem zmienna operation i dodałem flage notify_all

thesis_voting_activated.send(sender=self.__class__, instance=self)

if old and old.status != ThesisStatus.BEING_EVALUATED and self.status == ThesisStatus.BEING_EVALUATED:
# in case of new thesis titile send notification to all board members
self.thesis_votes.filter(vote__in=[ThesisVote.ACCEPTED, ThesisVote.REJECTED]).update(vote=ThesisVote.NONE)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Zdaje się, że w tej gałęzi nie ma znaczenia kolejność "resetowania" głosów oraz wysłania powiadomienia - a gdyby ją odwrócić, to "resetowanie" można postawić w ogóle za instrukcją warunkową.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wydaje mi się, że nie możemy wyciągnąć tego poza instrukcję warunkową, bo nie zawsze chcemy resetować głosy przy zapisie modelu. Proszę mnie poprawić jeśli się mylę.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Temat pracy dyplomowej cofnięty po zmianach do komisji nie "traci" głosów
2 participants