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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion zapisy/apps/notifications/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,17 +163,28 @@ def notify_that_news_was_added(sender: News, **kwargs) -> None:
@receiver(thesis_voting_activated, sender=Thesis)
def notify_board_members_about_voting(sender: Thesis, **kwargs) -> None:
thesis = kwargs['instance']
notify_all = kwargs['notify_all']
is_new = kwargs['is_new']

all_voters = get_theses_board()
accepting_voters = [v.owner for v in thesis.thesis_votes.all() if v.vote == ThesisVote.ACCEPTED]
users = [voter.user for voter in all_voters if voter not in accepting_voters]
target = reverse('theses:selected_thesis', args=[thesis.id])

status = 'nowym'
if not is_new:
status = 'zmodyfikowanym'

if not notify_all:
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(
users,
Notification(get_id(), get_time(),
NotificationType.THESIS_VOTING_HAS_BEEN_ACTIVATED, {
'title': thesis.title
'title': thesis.title,
'status': status,
}, target))


Expand Down
4 changes: 2 additions & 2 deletions zapisy/apps/notifications/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class NotificationType(str, Enum):
NotificationType.NEWS_HAS_BEEN_ADDED_HIGH_PRIORITY:
"Dodano nową wiadomość w aktualnościach:\n# {title}\n\n{contents}",
NotificationType.THESIS_VOTING_HAS_BEEN_ACTIVATED:
'W pracy dyplomowej "{title}" pojawiła się możliwość głosowania.',
'W {status} temacie pracy dyplomowej "{title}" pojawiła się możliwość głosowania.',
NotificationType.THESIS_HAS_BEEN_ACCEPTED:
'Praca dyplomowa "{title}" została zaakceptowana przez komisję.',
}
Expand All @@ -59,7 +59,7 @@ class NotificationType(str, Enum):
NotificationType.NEWS_HAS_BEEN_ADDED_HIGH_PRIORITY:
"{title}",
NotificationType.THESIS_VOTING_HAS_BEEN_ACTIVATED:
'W pracy dyplomowej "{title}" pojawiła się możliwość głosowania.',
'W {status} temacie pracy dyplomowej "{title}" pojawiła się możliwość głosowania.',
NotificationType.THESIS_HAS_BEEN_ACCEPTED:
'Praca dyplomowa "{title}" została zaakceptowana.',
}
9 changes: 6 additions & 3 deletions zapisy/apps/theses/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
from apps.theses.validators import MAX_MAX_ASSIGNED_STUDENTS


SIGNIFICANT_FIELDS = ['title', 'supporting_advisor', 'kind', 'max_number_of_students', 'description']


class ThesisFormAdmin(forms.ModelForm):
class Meta:
model = Thesis
Expand Down Expand Up @@ -127,11 +130,11 @@ def save(self, commit=True):
instance.modified = timezone.now()

status = self.status
instance.significant_field_changed = False

if len(set(self.changed_data).intersection([
'title', 'supporting_advisor', 'kind',
'max_number_of_students', 'description'])) > 0:
if len(set(self.changed_data).intersection(SIGNIFICANT_FIELDS)) > 0:
instance.status = ThesisStatus.BEING_EVALUATED.value
instance.significant_field_changed = True
elif status == ThesisStatus.ACCEPTED.value and 'students' in self.data:
instance.status = ThesisStatus.IN_PROGRESS.value
elif status == ThesisStatus.IN_PROGRESS.value and 'students' not in self.data:
Expand Down
18 changes: 16 additions & 2 deletions zapisy/apps/theses/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +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):
thesis_voting_activated.send(sender=self.__class__, instance=self)

if not old:
thesis_voting_activated.send(sender=self.__class__, instance=self, is_new=True, notify_all=True)

if old and old.status != ThesisStatus.BEING_EVALUATED and self.status == ThesisStatus.BEING_EVALUATED:
# in case of new thesis title 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ę.

thesis_voting_activated.send(sender=self.__class__, instance=self, is_new=False, notify_all=True)

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 members who already voted on the thesis
thesis_voting_activated.send(sender=self.__class__, instance=self, is_new=False,
notify_all=False)
self.thesis_votes.filter(vote__in=[ThesisVote.ACCEPTED, ThesisVote.REJECTED]).update(vote=ThesisVote.NONE)

def get_accepted_votes(self):
return len(self.thesis_votes.filter(vote=ThesisVote.ACCEPTED))
Expand Down
Loading