Skip to content

Commit

Permalink
Merge pull request #586 from DH-IT-Portal-Development/fix/refactor_ch…
Browse files Browse the repository at this point in the history
…oices

Fix/refactor choices
  • Loading branch information
EdoStorm96 authored Nov 28, 2023
2 parents 198d1f4 + c885f2d commit 466eb3a
Show file tree
Hide file tree
Showing 21 changed files with 240 additions and 289 deletions.
35 changes: 14 additions & 21 deletions main/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,32 @@
from django.db import models
from django.utils.translation import ugettext_lazy as _

YES = 'Y'
NO = 'N'
DOUBT = '?'
YES_NO_DOUBT = (
(YES, _('ja')),
(NO, _('nee')),
(DOUBT, _('twijfel')),
)

class YesNoDoubt(models.TextChoices):
YES = 'Y', _('ja')
NO = 'N', _('nee')
DOUBT = '?', _('twijfel')

class SystemMessage(models.Model):
URGENT = 1
ATTENTION = 2
INFO = 3
# Not translated, as it's backend only
LEVELS = (
(URGENT, "Urgent"),
(ATTENTION, "Attention"),
(INFO, "Info")
)

class Levels(models.IntegerChoices):
# Not translated, as it's backend only
URGENT = 1, "Urgent"
ATTENTION = 2, "Attention"
INFO = 3, "Info"

message = models.TextField()
level = models.IntegerField(choices=LEVELS)
level = models.IntegerField(choices=Levels.choices)
not_before = models.DateTimeField()
not_after = models.DateTimeField()

@property
def css_class(self):
if self.level == self.URGENT:
if self.level == self.Levels.URGENT:
return 'failed'
if self.level == self.ATTENTION:
if self.level == self.Levels.ATTENTION:
return 'warning'
if self.level == self.INFO:
if self.level == self.Levels.INFO:
return 'info'

return ''
Expand Down
12 changes: 6 additions & 6 deletions main/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ def get_user_reviews(self):
"""Returns all Committee Reviews of this user"""
reviews = {}
objects = Review.objects.filter(
stage__gte=Review.ASSIGNMENT,
proposal__status__gte=Proposal.SUBMITTED,
stage__gte=Review.Stages.ASSIGNMENT,
proposal__status__gte=Proposal.Statuses.SUBMITTED,
proposal__created_by=self.get_object()
)

Expand Down Expand Up @@ -375,10 +375,10 @@ def get_object(self, queryset=None):
commission |= get_user_model().objects.filter(
groups__name=settings.GROUP_GENERAL_CHAMBER)

if proposal.status >= Proposal.SUBMITTED:
if proposal.status >= Proposal.Statuses.SUBMITTED:
if self.request.user not in commission:
raise PermissionDenied
elif proposal.status >= Proposal.SUBMITTED_TO_SUPERVISOR:
elif proposal.status >= Proposal.Statuses.SUBMITTED_TO_SUPERVISOR:
if self.request.user not in supervisor:
raise PermissionDenied
else:
Expand Down Expand Up @@ -432,10 +432,10 @@ def check_allowed(self):
groups__name=settings.GROUP_GENERAL_CHAMBER
)

if proposal.status >= Proposal.SUBMITTED:
if proposal.status >= Proposal.Statuses.SUBMITTED:
if self.request.user not in commission:
raise PermissionDenied
elif proposal.status >= Proposal.SUBMITTED_TO_SUPERVISOR:
elif proposal.status >= Proposal.Statuses.SUBMITTED_TO_SUPERVISOR:
if self.request.user not in supervisor:
raise PermissionDenied
else:
Expand Down
14 changes: 7 additions & 7 deletions proposals/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ def get_context(self):

context['is_secretary'] = is_secretary(self.request.user)
context['proposal'] = {
'SUBMITTED_TO_SUPERVISOR': Proposal.SUBMITTED_TO_SUPERVISOR,
'DECISION_MADE': Proposal.DECISION_MADE,
'SUBMITTED_TO_SUPERVISOR': Proposal.Statuses.SUBMITTED_TO_SUPERVISOR,
'DECISION_MADE': Proposal.Statuses.DECISION_MADE,
}
context['review'] = {
'REVISION': Review.REVISION,
'REVISION': Review.Continuations.REVISION,
}
context['user_pk'] = self.request.user.pk

Expand All @@ -81,7 +81,7 @@ class MyConceptsApiView(BaseProposalsApiView):
def get_queryset(self):
"""Returns all non-submitted Proposals for the current User"""
return self.get_my_proposals().filter(
status__lt=Proposal.SUBMITTED_TO_SUPERVISOR
status__lt=Proposal.Statuses.SUBMITTED_TO_SUPERVISOR
)


Expand All @@ -101,8 +101,8 @@ class MySubmittedApiView(BaseProposalsApiView):
def get_queryset(self):
"""Returns all submitted Proposals for the current User"""
return self.get_my_proposals().filter(
status__gte=Proposal.SUBMITTED_TO_SUPERVISOR,
status__lt=Proposal.DECISION_MADE
status__gte=Proposal.Statuses.SUBMITTED_TO_SUPERVISOR,
status__lt=Proposal.Statuses.DECISION_MADE
)


Expand All @@ -111,7 +111,7 @@ class MyCompletedApiView(BaseProposalsApiView):
def get_queryset(self):
"""Returns all completed Proposals for the current User"""
return self.get_my_proposals().filter(
status__gte=Proposal.DECISION_MADE
status__gte=Proposal.Statuses.DECISION_MADE
)


Expand Down
2 changes: 1 addition & 1 deletion proposals/copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def copy_proposal(original_proposal, is_revision, created_by_user):
copy_proposal.reference_number = generate_ref_number()

copy_proposal.created_by = created_by_user
copy_proposal.status = Proposal.DRAFT
copy_proposal.status = Proposal.Statuses.DRAFT
copy_proposal.status_review = None
copy_proposal.pdf = None
copy_proposal.date_created = timezone.now()
Expand Down
20 changes: 10 additions & 10 deletions proposals/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
mark_safe_lazy = lazy(mark_safe, str)

from main.forms import ConditionalModelForm, SoftValidationMixin
from main.models import DOUBT, NO, YES, YES_NO_DOUBT
from main.models import YesNoDoubt
from main.utils import YES_NO, get_users_as_list
from .field import ParentChoiceModelField
from .models import Proposal, Relation, Wmo
Expand Down Expand Up @@ -264,7 +264,7 @@ def clean(self):
class ProposalStartPracticeForm(forms.Form):
practice_reason = forms.ChoiceField(
label=_('Ik maak een oefenaanvraag aan'),
choices=Proposal.PRACTICE_REASONS,
choices=Proposal.PracticeReasons.choices,
widget=forms.RadioSelect())


Expand Down Expand Up @@ -302,7 +302,7 @@ def _get_parent_queryset(self):
).filter(
Q(applicants=self.user, ) | Q(supervisor=self.user)
).filter(
Q(status=Proposal.DRAFT) | Q(status__gte=Proposal.DECISION_MADE)
Q(status=Proposal.Statuses.DRAFT) | Q(status__gte=Proposal.Statuses.DECISION_MADE)
).distinct()


Expand Down Expand Up @@ -346,7 +346,7 @@ def _get_parent_queryset(self):
# Those are eligible for revisions
return Proposal.objects.filter(
is_pre_assessment=False,
status=Proposal.DECISION_MADE,
status=Proposal.Statuses.DECISION_MADE,
status_review=False,
children__isnull=True,
).filter(
Expand Down Expand Up @@ -412,9 +412,9 @@ def __init__(self, *args, **kwargs):
"""
super(WmoForm, self).__init__(*args, **kwargs)
self.fields['metc'].empty_label = None
self.fields['metc'].choices = YES_NO_DOUBT
self.fields['metc'].choices = YesNoDoubt.choices
self.fields['is_medical'].empty_label = None
self.fields['is_medical'].choices = YES_NO_DOUBT
self.fields['is_medical'].choices = YesNoDoubt.choices

def clean(self):
"""
Expand All @@ -429,13 +429,13 @@ def clean(self):
'gaan.'))

self.check_dependency(cleaned_data, 'metc', 'metc_details',
f1_value=YES)
f1_value=YesNoDoubt.YES)
self.check_dependency(cleaned_data, 'metc', 'metc_institution',
f1_value=YES,
f1_value=YesNoDoubt.YES,
error_message=_(
'Je dient een instelling op te geven.'))
self.check_dependency_list(cleaned_data, 'metc', 'is_medical',
f1_value_list=[NO, DOUBT])
f1_value_list=[YesNoDoubt.NO, YesNoDoubt.DOUBT])


class WmoCheckForm(forms.ModelForm):
Expand All @@ -455,7 +455,7 @@ def __init__(self, *args, **kwargs):
"""
super(WmoCheckForm, self).__init__(*args, **kwargs)
self.fields['is_medical'].empty_label = None
self.fields['is_medical'].choices = YES_NO_DOUBT
self.fields['is_medical'].choices = YesNoDoubt.choices


class WmoApplicationForm(SoftValidationMixin, ConditionalModelForm):
Expand Down
73 changes: 29 additions & 44 deletions proposals/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from django.utils.safestring import mark_safe
mark_safe_lazy = lazy(mark_safe, str)

from main.models import YES, YES_NO_DOUBT
from main.models import YesNoDoubt
from main.validators import MaxWordsValidator, validate_pdf_or_doc
from .utils import available_urls, FilenameFactory, OverwriteStorage
from datetime import date, timedelta
Expand Down Expand Up @@ -133,28 +133,17 @@ class Proposal(models.Model):

objects = ProposalQuerySet.as_manager()

DRAFT = 1
SUBMITTED_TO_SUPERVISOR = 40
SUBMITTED = 50
DECISION_MADE = 55
WMO_DECISION_MADE = 60
STATUSES = (
(DRAFT, _('Concept')),
class Statuses(models.IntegerChoices):
DRAFT = 1, _('Concept')
SUBMITTED_TO_SUPERVISOR = 40, _('Opgestuurd ter beoordeling door eindverantwoordelijke')
SUBMITTED = 50, _('Opgestuurd ter beoordeling door FETC-GW')
DECISION_MADE = 55, _('Aanvraag is beoordeeld door FETC-GW')
WMO_DECISION_MADE = 60, _('Aanvraag is beoordeeld door FETC-GW')

(SUBMITTED_TO_SUPERVISOR,
_('Opgestuurd ter beoordeling door eindverantwoordelijke')),
(SUBMITTED, _('Opgestuurd ter beoordeling door FETC-GW')),
class PracticeReasons(models.IntegerChoices):
COURSE = 1, _('om de portal te exploreren')
EXPLORATION = 2, _('in het kader van een cursus')

(DECISION_MADE, _('Aanvraag is beoordeeld door FETC-GW')),
(WMO_DECISION_MADE, _('Aanvraag is beoordeeld door FETC-GW')),
)

COURSE = 1
EXPLORATION = 2
PRACTICE_REASONS = (
(COURSE, _('in het kader van een cursus')),
(EXPLORATION, _('om de portal te exploreren')),
)

# Fields of a proposal
reference_number = models.CharField(
Expand Down Expand Up @@ -397,8 +386,8 @@ class Proposal(models.Model):

# Status
status = models.PositiveIntegerField(
choices=STATUSES,
default=DRAFT,
choices=Statuses.choices,
default=Statuses.DRAFT,
)

status_review = models.BooleanField(
Expand Down Expand Up @@ -647,10 +636,10 @@ def supervisor_decision(self):
"""Returns the Decision of the supervisor for this Proposal (if any and in current stage)"""
from reviews.models import Review, Decision

if self.supervisor and self.status == Proposal.SUBMITTED_TO_SUPERVISOR:
if self.supervisor and self.status == Proposal.Statuses.SUBMITTED_TO_SUPERVISOR:
decisions = Decision.objects.filter(
review__proposal=self,
review__stage=Review.SUPERVISOR
review__stage=Review.Stages.SUPERVISOR
).order_by('-pk')

if decisions:
Expand All @@ -668,7 +657,7 @@ def latest_review(self):

def enforce_wmo(self):
"""Send proposal back to draft phase with WMO enforced."""
self.status = self.DRAFT
self.status = self.Statuses.DRAFT
self.save()
self.wmo.enforced_by_commission = True
self.wmo.save()
Expand All @@ -677,11 +666,11 @@ def mark_reviewed(self, continuation, time=None):
"""Finalize a proposal after a decision has been made."""
if time is None:
time = timezone.now()
self.status = self.DECISION_MADE
self.status = self.Statuses.DECISION_MADE
# Importing here to prevent circular import
from reviews.models import Review
self.status_review = continuation in [
Review.GO, Review.GO_POST_HOC
Review.Continuations.GO, Review.Continuations.GO_POST_HOC
]
self.date_reviewed = time
self.generate_pdf()
Expand Down Expand Up @@ -723,20 +712,16 @@ def __str__(self):


class Wmo(models.Model):
NO_WMO = 0
WAITING = 1
JUDGED = 2
WMO_STATUSES = (
(NO_WMO, _('Geen beoordeling door METC noodzakelijk')),
(WAITING, _('In afwachting beslissing METC')),
(JUDGED, _('Beslissing METC geüpload')),
)
class WMOStatuses(models.IntegerChoices):
NO_WMO = 0, _('Geen beoordeling door METC noodzakelijk')
WAITING = 1, _('In afwachting beslissing METC')
JUDGED = 2, _('Beslissing METC geüpload')

metc = models.CharField(
_('Vindt de dataverzameling plaats binnen het UMC Utrecht of \
andere instelling waar toetsing door een METC verplicht is gesteld?'),
max_length=1,
choices=YES_NO_DOUBT,
choices=YesNoDoubt.choices,
blank=True,
default=None,
)
Expand Down Expand Up @@ -765,7 +750,7 @@ class Wmo(models.Model):
onderzoekspopulatie. (CCMO-notitie, Definitie medisch-wetenschappelijk \
onderzoek, 2005, ccmo.nl)'),
max_length=1,
choices=YES_NO_DOUBT,
choices=YesNoDoubt.choices,
blank=True,
)

Expand Down Expand Up @@ -793,8 +778,8 @@ class Wmo(models.Model):

# Status
status = models.PositiveIntegerField(
choices=WMO_STATUSES,
default=NO_WMO,
choices=WMOStatuses.choices,
default=WMOStatuses.NO_WMO,
)

enforced_by_commission = models.BooleanField(default=False)
Expand All @@ -812,13 +797,13 @@ def save(self, *args, **kwargs):
super(Wmo, self).save(*args, **kwargs)

def update_status(self):
if self.metc == YES or self.is_medical == YES or self.enforced_by_commission:
if self.metc == YesNoDoubt.YES or self.is_medical == YesNoDoubt.YES or self.enforced_by_commission:
if self.metc_decision and self.metc_decision_pdf:
self.status = self.JUDGED
self.status = self.WMOStatuses.JUDGED
else:
self.status = self.WAITING
self.status = self.WMOStatuses.WAITING
else:
self.status = self.NO_WMO
self.status = self.WMOStatuses.NO_WMO

def __str__(self):
return _('WMO {title}, status {status}').format(
Expand Down
Loading

0 comments on commit 466eb3a

Please sign in to comment.