Skip to content

Commit

Permalink
Merge branch 'main' into feature/python-39
Browse files Browse the repository at this point in the history
  • Loading branch information
felixrindt committed Oct 15, 2020
2 parents a62ca43 + 5424af1 commit 17edb31
Show file tree
Hide file tree
Showing 16 changed files with 456 additions and 28 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/pythonapp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ jobs:
source $HOME/.poetry/env
$HOME/.poetry/bin/poetry run black --check .
- name: Test apps
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
cp .env.example .env
$HOME/.poetry/bin/poetry run pytest
$HOME/.poetry/bin/poetry run coverage run --source=ephios -m pytest tests/
$HOME/.poetry/bin/poetry run coveralls
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
![ephios](https://github.com/ephios-dev/ephios/workflows/ephios/badge.svg)
[![Coverage Status](https://coveralls.io/repos/github/ephios-dev/ephios/badge.svg?branch=main)](https://coveralls.io/github/ephios-dev/ephios?branch=main)
# ephios
ephios is a tool to manage shifts for medical services.

Expand Down
2 changes: 1 addition & 1 deletion ephios/event_management/mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from django.utils.translation import gettext as _
from guardian.shortcuts import get_users_with_perms

from ephios.event_management.models import AbstractParticipation, LocalParticipation
from ephios.event_management.models import AbstractParticipation
from ephios.extra.permissions import get_groups_with_perms
from ephios.settings import SITE_URL
from ephios.user_management.models import UserProfile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import json

from django.db import migrations, models
import ephios.extra.json

import ephios.extra.json
from ephios.extra.json import CustomJSONDecoder


Expand Down
9 changes: 4 additions & 5 deletions ephios/event_management/signup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import functools
import json
from argparse import Namespace
from dataclasses import dataclass, field
from datetime import date
Expand Down Expand Up @@ -47,9 +46,8 @@ class AbstractParticipant:
date_of_birth: date
email: Optional[str] # if set to None, no notifications are sent

@property
def age(self):
today, born = date.today(), self.date_of_birth
def get_age(self, today: date = None):
today, born = today or date.today(), self.date_of_birth
return today.year - born.year - ((today.month, today.day) < (born.month, born.day))

def __str__(self):
Expand Down Expand Up @@ -156,7 +154,8 @@ def check_inside_signup_timeframe(method, participant):

def check_participant_age(method, participant):
minimum_age = method.configuration.minimum_age
if minimum_age is not None and participant.age < minimum_age:
day = method.shift.start_time.date()
if minimum_age is not None and participant.get_age(day) < minimum_age:
return ParticipationError(
_("You are too young. The minimum age is {age}.").format(age=minimum_age)
)
Expand Down
4 changes: 2 additions & 2 deletions ephios/event_management/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
View,
)
from django.views.generic.detail import SingleObjectMixin
from guardian.shortcuts import get_objects_for_user, get_users_with_perms
from guardian.shortcuts import get_objects_for_user

from ephios.event_management.forms import EventForm, ShiftForm
from ephios.event_management.models import Event, Shift
from ephios.extra.permissions import CustomPermissionRequiredMixin, get_groups_with_perms
from ephios.extra.permissions import CustomPermissionRequiredMixin


class HomeView(LoginRequiredMixin, TemplateView):
Expand Down
2 changes: 0 additions & 2 deletions ephios/extra/management/commands/setupdata.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import json
import uuid
from datetime import datetime

from django.contrib.auth.hashers import make_password
from django.core.management.base import BaseCommand
from django.core.serializers.json import DjangoJSONEncoder
from django.db import transaction
from django.utils.timezone import make_aware
from django.utils.translation import gettext as _
Expand Down
1 change: 0 additions & 1 deletion ephios/user_management/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
BooleanField,
ModelForm,
ModelMultipleChoiceField,
TextInput,
inlineformset_factory,
)
from django.utils.translation import gettext as _
Expand Down
32 changes: 32 additions & 0 deletions ephios/user_management/migrations/0004_auto_20201014_1648.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Generated by Django 3.1.2 on 2020-10-14 14:48

import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("user_management", "0003_userprofile_calendar_token_squashed_0008_auto_20200925_1640"),
]

operations = [
migrations.AlterField(
model_name="qualification",
name="included_qualifications",
field=models.ManyToManyField(
blank=True, related_name="included_by", to="user_management.Qualification"
),
),
migrations.AlterField(
model_name="qualificationgrant",
name="user",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="qualification_grants",
to=settings.AUTH_USER_MODEL,
verbose_name="user profile",
),
),
]
26 changes: 14 additions & 12 deletions ephios/user_management/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import secrets
import uuid
from datetime import date, datetime
from datetime import date

import guardian.mixins
from django.contrib.auth import get_user_model
Expand All @@ -12,12 +12,10 @@
CharField,
DateField,
EmailField,
Exists,
F,
ForeignKey,
Max,
Model,
OuterRef,
Q,
)
from django.utils import timezone
Expand Down Expand Up @@ -116,14 +114,13 @@ def as_participant(self):

@property
def qualifications(self):
return Qualification.objects.annotate(
has_active_grant=Exists(
QualificationGrant.objects.filter(user=self, qualification=OuterRef("pk")).filter(
Q(expires__gt=timezone.now()) | Q(expires__isnull=True)
)
),
expires=Max(F("grants__expires")),
).filter(has_active_grant=True)
return Qualification.objects.filter(
pk__in=self.qualification_grants.filter(
Q(expires__gt=timezone.now()) | Q(expires__isnull=True)
).values_list("qualification_id", flat=True)
).annotate(
expires=Max(F("grants__expires"), filter=Q(grants__user=self)),
)

def get_shifts(self, with_participation_state_in):
from ephios.event_management.models import Shift
Expand Down Expand Up @@ -181,7 +178,12 @@ class QualificationGrant(Model):
verbose_name=_("qualification"),
related_name="grants",
)
user = ForeignKey(get_user_model(), on_delete=models.CASCADE, verbose_name=_("user profile"))
user = ForeignKey(
get_user_model(),
related_name="qualification_grants",
on_delete=models.CASCADE,
verbose_name=_("user profile"),
)
expires = models.DateTimeField(_("expiration date"), blank=True, null=True)

def __str__(self):
Expand Down
1 change: 1 addition & 0 deletions ephios/user_management/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ class GroupListView(CustomPermissionRequiredMixin, ListView):
class GroupCreateView(CustomPermissionRequiredMixin, CreateView):
model = Group
permission_required = "auth.add_group"
accept_object_perms = False
template_name = "user_management/group_form.html"
form_class = GroupForm

Expand Down
Loading

0 comments on commit 17edb31

Please sign in to comment.