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

1701 promotor pomocniczy nie powinien głosować na swój temat pracy dyplomowej #1706

Open
wants to merge 16 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
10 changes: 7 additions & 3 deletions zapisy/apps/notifications/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,14 @@ 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']
new_supporting_advisor = kwargs['additional_notifiee']
Copy link
Contributor

Choose a reason for hiding this comment

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

Ani kwarg nie powinien mieć w nazwie additional, bo to nie jest dodatkowy odbiorca powiadomienia, tylko zamiast standardowych, tj. (prawie) całego składu komisji, ani lokalny identyfikator nie powinien odnosić się do promotora pomocniczego, bo z punktu widzenia tej funkcji (którą być może kiedyś spożytkuje się na nowo w inny sposób) to w ogóle jest przezroczysta kwestia, dlaczego ten specjalny odbiorca się tu pojawił.

Copy link
Contributor

Choose a reason for hiding this comment

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

A lepszym pomysłem niż to moje nieszczęsne notifiee jest recipient.


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]
if new_supporting_advisor is None:
all_voters = get_theses_board(thesis)
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]
else:
users = [new_supporting_advisor]
target = reverse('theses:selected_thesis', args=[thesis.id])

notify_selected_users(
Expand Down
10 changes: 2 additions & 8 deletions zapisy/apps/theses/admin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.contrib import admin

from apps.theses.forms import RemarkFormAdmin, ThesisFormAdmin, VoteFormAdmin
from apps.theses.models import Remark, ThesesSystemSettings, Thesis, Vote
from apps.theses.forms import RemarkFormAdmin, ThesisFormAdmin
from apps.theses.models import Remark, ThesesSystemSettings, Thesis


class ThesisAdmin(admin.ModelAdmin):
Expand All @@ -20,11 +20,6 @@ class RemarkAdmin(admin.ModelAdmin):
form = RemarkFormAdmin


class VoteAdmin(admin.ModelAdmin):
autocomplete_fields = []
form = VoteFormAdmin


class ThesesSystemSettingsAdmin(admin.ModelAdmin):
"""Theses system settings admin.

Expand All @@ -41,5 +36,4 @@ def has_delete_permission(self, request, obj=None):

admin.site.register(Thesis, ThesisAdmin)
admin.site.register(Remark, RemarkAdmin)
admin.site.register(Vote, VoteAdmin)
admin.site.register(ThesesSystemSettings, ThesesSystemSettingsAdmin)
6 changes: 0 additions & 6 deletions zapisy/apps/theses/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ class Meta:
fields = '__all__'


class VoteFormAdmin(forms.ModelForm):
class Meta:
model = Vote
fields = '__all__'


class ThesisFormBase(forms.ModelForm):
class Meta:
model = Thesis
Expand Down
6 changes: 5 additions & 1 deletion zapisy/apps/theses/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,11 @@ 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)
thesis_voting_activated.send(sender=self.__class__, instance=self, additional_notifiee=None)
if (old and old.status == ThesisStatus.BEING_EVALUATED and self.status == ThesisStatus.BEING_EVALUATED and
old.supporting_advisor is not None and is_theses_board_member(old.supporting_advisor.user)):
thesis_voting_activated.send(sender=self.__class__, instance=self,
additional_notifiee=old.supporting_advisor.user)

def get_accepted_votes(self):
return len(self.thesis_votes.filter(vote=ThesisVote.ACCEPTED))
Expand Down
5 changes: 5 additions & 0 deletions zapisy/apps/theses/templates/theses/thesis.html
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ <h2 class="mt-4">Głosowanie</h2>
</div>
</br>
{% endif %}
{% if board_member and is_advisor %}
<div class="d-inline-block mt-2 mb-2 w-100">
Promotor nie może głosować w sprawie swojego tematu pracy.
</div>
{% endif %}
{% for vote in votes %}
{% if vote.owner == request.user.employee %}
<div
Expand Down
14 changes: 10 additions & 4 deletions zapisy/apps/theses/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@
THESIS_BOARD_GROUP_NAME = "Komisja prac dyplomowych"


def get_theses_board():
"""Returns all members of the theses board."""
return Employee.objects.select_related(
def get_theses_board(exclude_advisors_for_thesis=None):
"""Returns all members of the board for specific thesis."""
board = Employee.objects.select_related(
'user'
).filter(user__groups__name=THESIS_BOARD_GROUP_NAME)
).filter(user__groups__name=THESIS_BOARD_GROUP_NAME)
if exclude_advisors_for_thesis is None:
return board
if exclude_advisors_for_thesis.supporting_advisor is None:
return board.exclude(id__in=[exclude_advisors_for_thesis.advisor.id])
return board.exclude(id__in=[exclude_advisors_for_thesis.advisor.id,
exclude_advisors_for_thesis.supporting_advisor.id])


def get_num_board_members() -> int:
Expand Down
6 changes: 4 additions & 2 deletions zapisy/apps/theses/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,15 @@ def view_thesis(request, id):
user_privileged_for_thesis = thesis.is_user_privileged(request.user)
can_edit_thesis = thesis.is_mine(request.user)
save_and_verify = thesis.is_mine(request.user) and thesis.is_returned
can_vote = thesis.is_voting_active and board_member
is_advisor = thesis.is_among_advisors(request.user)
can_vote = thesis.is_voting_active and board_member and not is_advisor
show_master_rejecter = is_master_rejecter(request.user) and (
thesis.is_voting_active or thesis.is_returned)
can_download_declarations = thesis.can_user_download_declarations(request.user)

students = thesis.students.all()

all_voters = get_theses_board()
all_voters = get_theses_board(thesis)
votes = []
voters = []
for vote in thesis.thesis_votes.all():
Expand Down Expand Up @@ -125,6 +126,7 @@ def view_thesis(request, id):
'show_master_rejecter': show_master_rejecter,
'can_see_remarks': user_privileged_for_thesis,
'save_and_verify': save_and_verify,
'is_advisor': is_advisor,
'can_vote': can_vote,
'can_edit_thesis': can_edit_thesis,
'can_download_declarations': can_download_declarations,
Expand Down
Loading