api package

admin

Setting up the default Django admin page.

class api.admin.ClockedInShiftAdmin(model, admin_site)

Bases: api.admin.ShiftAdmin

duration(obj)

Creates a link to the corresponding Contract object to display in the columns. :param obj: :return: string

list_display = ('id', 'link_user', 'link_contract', 'created_at', 'duration')
property media
class api.admin.ContractAdmin(model, admin_site)

Bases: django.contrib.admin.options.ModelAdmin

Creates a link to the corresponding User object to display in the columns. :param obj: :return: string

list_display = ('id', 'link_user', 'name', 'minutes', 'start_date', 'end_date', 'modified_at')
list_per_page = 100
property media
ordering = ('-modified_at',)
class api.admin.ReportAdmin(model, admin_site)

Bases: django.contrib.admin.options.ModelAdmin

format_date(obj)

Creates a link to the corresponding Contract object to display in the columns. :param obj: :return: string

Creates a link to the corresponding User object to display in the columns. :param obj: :return: string

list_display = ('id', 'link_user', 'format_date', 'link_contract', 'created_at', 'modified_at')
property media
class api.admin.ShiftAdmin(model, admin_site)

Bases: django.contrib.admin.options.ModelAdmin

Creates a link to the corresponding User object to display in the columns. :param obj: :return: string

list_display = ('id', 'link_user', 'started', 'stopped', 'locked', 'modified_at')
list_per_page = 200
property media
ordering = ('-modified_at',)
class api.admin.UserAdmin(model, admin_site)

Bases: django.contrib.auth.admin.UserAdmin

fieldsets = ((None, {'fields': ('username', 'password')}), ('Persönliche Informationen', {'fields': ('first_name', 'last_name', 'email', 'language', 'personal_number', 'dsgvo_accepted', 'onboarding_passed')}), ('Berechtigungen', {'fields': ('is_active', 'is_staff', 'is_superuser', 'groups', 'user_permissions')}), ('Wichtige Daten', {'fields': ('last_login', 'date_joined')}))
list_display = ('id', 'email', 'username', 'first_name', 'last_name', 'date_joined', 'modified_at')
property media
ordering = ('-date_joined',)
readonly_fields = ('date_joined',)

apps

Django default to define the app name.

class api.apps.APIConfig(app_name, app_module)

Bases: django.apps.config.AppConfig

name = 'api'
ready()

Override this method in subclasses to run code when Django starts.

filters

Option to add more filters to the Django filters.

class api.filters.ShiftFilterSet(data=None, queryset=None, *, request=None, prefix=None)

Bases: django_filters.filterset.FilterSet

class Meta

Bases: object

fields = ['started', 'contract']
model

alias of api.models.Shift

base_filters = {'contract': <django_filters.filters.UUIDFilter object>, 'month': <django_filters.filters.NumberFilter object>, 'started': <django_filters.filters.DateTimeFilter object>, 'year': <django_filters.filters.NumberFilter object>}
declared_filters = {'contract': <django_filters.filters.UUIDFilter object>, 'month': <django_filters.filters.NumberFilter object>, 'year': <django_filters.filters.NumberFilter object>}

models

Django default to define the main modules for the app.

Note

The user modell of Djangos is using as primary key for default the username, but we want to use the mail address. Therefor you can find in models.py an override for the classes BaseUserManager and AbstractUser.

class api.models.ClockedInShift(id, user, started, contract, created_at, created_by, modified_at, modified_by)

Bases: django.db.models.base.Model

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

contract

Accessor to the related object on the forward side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Restaurant.place is a ForwardOneToOneDescriptor instance.

contract_id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

created_at

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

created_by

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

created_by_id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

get_next_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=True, **kwargs)
get_next_by_modified_at(*, field=<django.db.models.fields.DateTimeField: modified_at>, is_next=True, **kwargs)
get_next_by_started(*, field=<django.db.models.fields.DateTimeField: started>, is_next=True, **kwargs)
get_previous_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=False, **kwargs)
get_previous_by_modified_at(*, field=<django.db.models.fields.DateTimeField: modified_at>, is_next=False, **kwargs)
get_previous_by_started(*, field=<django.db.models.fields.DateTimeField: started>, is_next=False, **kwargs)
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

modified_at

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

modified_by

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

modified_by_id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>
started

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

user

Accessor to the related object on the forward side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Restaurant.place is a ForwardOneToOneDescriptor instance.

user_id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class api.models.Contract(id, user, name, minutes, start_date, end_date, initial_carryover_minutes, carryover_target_date, created_at, created_by, last_used, modified_at, modified_by)

Bases: django.db.models.base.Model

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

carryover_target_date

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

clocked_in_shift

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

created_at

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

created_by

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

created_by_id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

end_date

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

get_next_by_carryover_target_date(*, field=<django.db.models.fields.DateField: carryover_target_date>, is_next=True, **kwargs)
get_next_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=True, **kwargs)
get_next_by_end_date(*, field=<django.db.models.fields.DateField: end_date>, is_next=True, **kwargs)
get_next_by_last_used(*, field=<django.db.models.fields.DateTimeField: last_used>, is_next=True, **kwargs)
get_next_by_modified_at(*, field=<django.db.models.fields.DateTimeField: modified_at>, is_next=True, **kwargs)
get_next_by_start_date(*, field=<django.db.models.fields.DateField: start_date>, is_next=True, **kwargs)
get_previous_by_carryover_target_date(*, field=<django.db.models.fields.DateField: carryover_target_date>, is_next=False, **kwargs)
get_previous_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=False, **kwargs)
get_previous_by_end_date(*, field=<django.db.models.fields.DateField: end_date>, is_next=False, **kwargs)
get_previous_by_last_used(*, field=<django.db.models.fields.DateTimeField: last_used>, is_next=False, **kwargs)
get_previous_by_modified_at(*, field=<django.db.models.fields.DateTimeField: modified_at>, is_next=False, **kwargs)
get_previous_by_start_date(*, field=<django.db.models.fields.DateField: start_date>, is_next=False, **kwargs)
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

initial_carryover_minutes

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

last_used

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

minutes

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

modified_at

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

modified_by

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

modified_by_id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

name

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>
reports

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

shifts

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

start_date

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

user

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

user_id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class api.models.CustomUserManager(*args, **kwargs)

Bases: django.contrib.auth.base_user.BaseUserManager

create_superuser(email, password, **extra_fields)
create_user(email='', first_name='', last_name='', personal_number='', password='', username='', **extra_fields)
use_in_migrations = True

If set to True the manager will be serialized into migrations and will thus be available in e.g. RunPython operations.

class api.models.Report(id, month_year, worktime, contract, user, created_at, created_by, modified_at, modified_by)

Bases: django.db.models.base.Model

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

contract

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

contract_id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

created_at

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

created_by

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

created_by_id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

property debit_worktime

Calculate the actual debit worktime for a report.

The actual debitworktime can be lower than the provided value from the contract due to: incomplete months (contract starts not at first, or end not on the last of a month.)

get_next_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=True, **kwargs)
get_next_by_modified_at(*, field=<django.db.models.fields.DateTimeField: modified_at>, is_next=True, **kwargs)
get_next_by_month_year(*, field=<django.db.models.fields.DateField: month_year>, is_next=True, **kwargs)
get_previous_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=False, **kwargs)
get_previous_by_modified_at(*, field=<django.db.models.fields.DateTimeField: modified_at>, is_next=False, **kwargs)
get_previous_by_month_year(*, field=<django.db.models.fields.DateField: month_year>, is_next=False, **kwargs)
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

modified_at

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

modified_by

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

modified_by_id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

month_year

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>
user

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

user_id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

worktime

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class api.models.Shift(id, user, started, stopped, contract, type, note, was_reviewed, locked, created_at, created_by, modified_at, modified_by)

Bases: django.db.models.base.Model

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

TYPE_CHOICES = (('st', 'Shift'), ('sk', 'Sick'), ('vn', 'Vacation'), ('bh', 'Bank Holiday'))
contract

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

contract_id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

created_at

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

created_by

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

created_by_id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

get_next_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=True, **kwargs)
get_next_by_modified_at(*, field=<django.db.models.fields.DateTimeField: modified_at>, is_next=True, **kwargs)
get_next_by_started(*, field=<django.db.models.fields.DateTimeField: started>, is_next=True, **kwargs)
get_next_by_stopped(*, field=<django.db.models.fields.DateTimeField: stopped>, is_next=True, **kwargs)
get_previous_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=False, **kwargs)
get_previous_by_modified_at(*, field=<django.db.models.fields.DateTimeField: modified_at>, is_next=False, **kwargs)
get_previous_by_started(*, field=<django.db.models.fields.DateTimeField: started>, is_next=False, **kwargs)
get_previous_by_stopped(*, field=<django.db.models.fields.DateTimeField: stopped>, is_next=False, **kwargs)
get_type_display(*, field=<django.db.models.fields.CharField: type>)
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

locked

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

modified_at

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

modified_by

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

modified_by_id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

note

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>
started

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

stopped

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

tagged_items

Accessor to the related objects manager on the one-to-many relation created by GenericRelation.

In the example:

class Post(Model):
    comments = GenericRelation(Comment)

post.comments is a ReverseGenericManyToOneDescriptor instance.

tags = <taggit.managers._TaggableManager object>
type

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

user

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

user_id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

was_reviewed

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class api.models.UUIDTaggedItem(id, tag, content_type, object_id)

Bases: taggit.models.GenericUUIDTaggedItemBase, taggit.models.TaggedItemBase

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

content_object

Provide a generic many-to-one relation through the content_type and object_id fields.

This class also doubles as an accessor to the related object (similar to ForwardManyToOneDescriptor) by adding itself as a model attribute.

content_type

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>
tag

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

class api.models.User(password, last_login, is_superuser, is_staff, is_active, id, username, email, first_name, last_name, personal_number, language, date_joined, modified_at, dsgvo_accepted, onboarding_passed)

Bases: django.contrib.auth.models.AbstractUser

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

LANGUAGE_CHOICES = (('de', 'Deutsch'), ('en', 'English'))
exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

REQUIRED_FIELDS = ['first_name', 'last_name', 'personal_number']
USERNAME_FIELD = 'email'
clocked_in_shift

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

contracts

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

dsgvo_accepted

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

emailaddress_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

get_language_display(*, field=<django.db.models.fields.CharField: language>)
get_next_by_date_joined(*, field=<django.db.models.fields.DateTimeField: date_joined>, is_next=True, **kwargs)
get_next_by_modified_at(*, field=<django.db.models.fields.DateTimeField: modified_at>, is_next=True, **kwargs)
get_previous_by_date_joined(*, field=<django.db.models.fields.DateTimeField: date_joined>, is_next=False, **kwargs)
get_previous_by_modified_at(*, field=<django.db.models.fields.DateTimeField: modified_at>, is_next=False, **kwargs)
groups

Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.

In the example:

class Pizza(Model):
    toppings = ManyToManyField(Topping, related_name='pizzas')

Pizza.toppings and Topping.pizzas are ManyToManyDescriptor instances.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

language

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

logentry_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

modified_at

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <api.models.CustomUserManager object>
onboarding_passed

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

personal_number

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

reports

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

shifts

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

socialaccount_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

user_permissions

Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.

In the example:

class Pizza(Model):
    toppings = ManyToManyField(Topping, related_name='pizzas')

Pizza.toppings and Topping.pizzas are ManyToManyDescriptor instances.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

permissions

Additional permission class to manage that only privilege user are able to access there data.

class api.permissions.AccessOwnDataPermission

Bases: rest_framework.permissions.IsAuthenticated

Permission class which only permits access of Objects which are owned by the User issueing the request.

has_object_permission(request, view, obj)

Return True if permission is granted, False otherwise.

serializers

Django default formatter to bring Python objects into JSON-Structure and back, including validation.

class api.serializers.ClockedInShiftSerializer(*args, **kwargs)

Bases: api.serializers.RestrictModificationModelSerializer

class Meta

Bases: object

extra_kwargs = {'created_at': {'required': False}, 'created_by': {'write_only': True}, 'modified_at': {'required': False}, 'modified_by': {'write_only': True}, 'user': {'write_only': True}}
fields = '__all__'
model

alias of api.models.ClockedInShift

validate_contract(contract)
class api.serializers.ContractSerializer(*args, **kwargs)

Bases: api.serializers.RestrictModificationModelSerializer

class Meta

Bases: object

extra_kwargs = {'created_at': {'required': False}, 'created_by': {'write_only': True}, 'modified_at': {'required': False}, 'modified_by': {'write_only': True}, 'user': {'write_only': True}}
fields = '__all__'
model

alias of api.models.Contract

update(instance, validated_data)
validate(attrs)

Object-level validation. Validate that the start_date is smaller than the end_date. :param attrs: :return:

validate_end_date(end_date)

Check that the contract ends either on the 15th or last day of a month. :param end_date: :return:

validate_start_date(start_date)

Check that the day of the start_date is the 1st or 16th day of the month. :param start_date: :return:

class api.serializers.DjoserUserSerializer(*args, **kwargs)

Bases: rest_framework.serializers.Serializer

class Meta

Bases: object

fields = ['id', 'username', 'email', 'first_name', 'last_name', 'personal_number', 'language', 'dsgvo_accepted', 'date_joined', 'modified_at', 'last_login', 'is_superuser', 'onboarding_passed']
ref_name = 'djoser-custom-serializer'
class api.serializers.ReportSerializer(*args, **kwargs)

Bases: api.serializers.RestrictModificationModelSerializer

This Serializer class does not provide any custom validation since it is only used within a ReadOnlyViewSet and therefore will never perform a create or update.

class Meta

Bases: object

extra_kwargs = {'created_at': {'required': False}, 'created_by': {'write_only': True}, 'modified_at': {'required': False}, 'modified_by': {'write_only': True}, 'user': {'write_only': True}}
fields = '__all__'
model

alias of api.models.Report

calculate_carryover(report_object)
get_carry_over_last_month(obj)
get_carry_over_next_month(obj)
get_debit_worktime(obj)
get_net_worktime(obj)
class api.serializers.RestrictModificationModelSerializer(*args, **kwargs)

Bases: rest_framework.serializers.ModelSerializer

This class, derived from ModelSerializer, is used as a base class for all Serializer classes within the project. The purpose of this baseclass is to assure that whatever a (possible) malicious User provides within the fields ‘user’, ‘created_by’ or ‘modified_by’ is set to the user id given by the JWT Authentication. This solely refers to POST, PUT and PATCH methods and thereby prevent manipulation of other users content.

add_user_id(request, data)
to_internal_value(data)

Dict of native values <- Dict of primitive datatypes.

class api.serializers.ShiftSerializer(*args, **kwargs)

Bases: api.serializers.RestrictModificationModelSerializer

class Meta

Bases: object

extra_kwargs = {'created_at': {'required': False}, 'created_by': {'write_only': True}, 'locked': {'read_only': True}, 'modified_at': {'required': False}, 'modified_by': {'write_only': True}, 'user': {'write_only': True}, 'was_reviewed': {'required': False}}
fields = '__all__'
model

alias of api.models.Shift

create(validated_data)

Customization of the derived create method. It adds the utility to create Tags. :param validated_data: :return:

update(instance, validated_data)

On an update, we override the tags. Therefore all previous tags have to be provided to ‘add’ a new one. Example:

old tags –> [‘tag1’, ‘tag2’]

new tags –> [‘tag1’, ‘tag2’, ‘tag3’]

provided tags to achieve this : [‘tag1’, ‘tag2’, ‘tag3’]

Parameters
  • instance

  • validated_data

Returns

validate(attrs)
validate_contract(contract)
validate_tags(tags)

Validate that the deserialization of the tags field is a list and that all values within this list are strings. :param tags: :return:

class api.serializers.TagsSerializerField(*args, **kwargs)

Bases: rest_framework.fields.Field

Custom Field to represent Tags within the ShiftSerializer. Tags are represented by a list of strings.

to_internal_value(data)

Transform the incoming primitive data into a native value.

to_representation(obj)

Transform the outgoing native value into primitive data.

class api.serializers.TimedeltaSerializerMethodField(*args, **kwargs)

Bases: rest_framework.fields.SerializerMethodField

to_representation(value)

Transform the outgoing native value into primitive data.

class api.serializers.UserSerializer(*args, **kwargs)

Bases: api.serializers.RestrictModificationModelSerializer

Serializer only needed for GDPR-Export of User data.

class Meta

Bases: object

fields = ['id', 'username', 'email', 'first_name', 'last_name', 'personal_number', 'language', 'dsgvo_accepted', 'date_joined', 'modified_at', 'last_login', 'is_superuser', 'onboarding_passed']
model

alias of api.models.User

ref_name = 'user-gdpr-serializers'

urls

Django default to define the urls of the app.

utilities

Just a bunch of useful functions, including the action_performed receiver functions.

api.utilities.create_report_after_contract_creation(sender, instance, created, **kwargs)

Reciever function: Receiver Function to be called by the post_save signal of a Contract object. It creates a Report object for the month when the Contract starts. The User might create a Contract after it already started so we also create all Report objects for the months between the carryover_target_date month and ‘now”.

State: 14. April 2019

Parameters
  • sender

  • instance

  • created

  • kwargs

Returns

api.utilities.create_reports_for_contract(contract)

Function used to create all Reports from carryover_target_date to date.today(). :param contract: :return:

api.utilities.relativedelta_to_string(relative_time_delta)

Format a relativedelta object for string representation in the format +/- HH:MM.

Example:

relativedelta(days=-3, hours=-8) becomes -80:00.

relativedelta(days=-1, hours=-8, minutes=-30) becomes -32:30.

Parameters

relative_time_delta

Returns

api.utilities.timedelta_to_string(timedelta)

Format a timedelta object for string representation in the format HH:MM

Parameters

timedelta

Returns

api.utilities.update_last_used_on_contract(sender, instance, created=False, **kwargs)

Reciever functions: After saving or deleting a shift set the last_used field of the corresponding contract. :param sender: :param instance: :param created: :param kwargs: :return:

api.utilities.update_report_after_shift_save(sender, instance, created=False, **kwargs)

Reciever function: After saving a Shift we need to update the corresponding Report to reflect the now possibly updated overall work time.

While updating we skip the whole mechanism if a Shift is planned (was_reviewd=False). Furthermore we skip all planned Shifts inside the Update mechanism.

Parameters
  • sender

  • instance

  • created

  • kwargs

Returns

api.utilities.update_reports(contract, month_year)

Update the Reports for the given contract starting with the given month/year. :param contract: :param month_year: :return:

views

Django default to define the CRUD-interaction functions.

Note

The viewsets of Djangos rest framework are bringing in most of the CRUD functions by default. For further information checkout the Documentation of the viewsets.

class api.views.ClockedInShiftViewSet(**kwargs)

Bases: rest_framework.viewsets.ModelViewSet

basename = None
description = None
detail = None
list(request, *args, **kwargs)

Override the list method to utilize the url matching. Since there will only be one or no ClockedInShift object we want a method to retrieve it without a pk. :param request: :param args: :param kwargs: :return:

name = None
queryset
serializer_class

alias of api.serializers.ClockedInShiftSerializer

suffix = None
class api.views.ContractViewSet(**kwargs)

Bases: rest_framework.viewsets.ModelViewSet

basename = None
description = None
detail = None
get_queryset()

Customized method to only retrieve Objects owned by the User issueing the request. :return:

get_shifts_list(request, *args, **kwargs)

Custom endpoint which retrieves all shifts corresponding to the issued Contract object. :param request: :param args: :param kwargs: :return:

lock_shifts(request, month=None, year=None, *args, **kwargs)
name = None
queryset
serializer_class

alias of api.serializers.ContractSerializer

suffix = None
class api.views.GDPRExportView(**kwargs)

Bases: rest_framework.viewsets.ViewSet

basename = None
construct_json_object(user)
description = None
detail = None
name = None
render_json_object(json_object)
retrieve(request, *args, **kwargs)

Endpoint to download all saved Data associated with the requesting User.

The Response contains a JSON file as attachment! :param request: :param args: :param kwargs: :return:

suffix = None
class api.views.ReportViewSet(**kwargs)

Bases: rest_framework.viewsets.ReadOnlyModelViewSet

aggregate_export_content(report_object)

Method which aggregates a dictionary to fill in the Stundenzettel HTML-Template. :param report_object: :return:

aggregate_general_content(report_object, shifts)

Aggregate Data for Tablefooter and User info of the Stundenzettel. :param report_object: :param shifts: :return:

aggregate_shift_content(shifts)

Method to aggregate a content with all dates at which a shift was worked. By creating this dictionary we merge all Shifts on a date to One Object with the following rule:

Take the started value of the first Shift of the date as actual started value. Use the stopped value of the last Shift of the date as actual stopped value. Calculate the total work time as Sum of stopped - started values of each Shift at a date. Calculate the break time as the actual stopped - actual started - worktime.

E.g.:

Assume we have at a given date (1.1.1999) 3 Shifts. 1. 10:00-11:30 2. 13:00-15:30 3. 16:00-18:30

From this follow the values: actual started : 10:00 actual stopped : 18:30 work time : 6 hours 30 minutes break time : 2 hours

Parameters

report_object

Returns

basename = None
calculate_carryover_worktime(report_object, next_month=True)
check_for_not_locked_shifts(report_object)

Validate wether the creation of a Worktimesheet from a Report is allowed. The criteria for this check to pass is, that there is no shift in the previous month which doesn’t have locked=False. :param report_object: :return:

check_for_overlapping_shifts(shift_queryset)

Check the given Queryset for possible overlapping shifts and raise a Validation error with pairs of overlapping shifts. :param shift_queryset: :return:

compile_pdf(template_name, content_dict)

Compile a PDF given a Django HTML-Tmeplate name as string, a content dictionary and possible options. :param template_name: :param content_dict: :return:

description = None
detail = None
export(request, *args, **kwargs)

Endpoint to export a given Report as Stundenzettel. :param request: :param args: :param kwargs: :return:

get_current(request, contract_id, *args, **kwargs)

Custom endpoint which retrieves the Report of the current month. :param contract_id: :param request: :param args: :param kwargs: :return:

get_queryset()

Customized method to only retrieve Objects owned by the User issueing the request. :return:

get_shifts_to_export(report_object)

Methode to provide all Shift Objects for a given Report to be exported in a Stundenzettel ordered by started field. :param report_object: :return:

name = None
queryset
serializer_class

alias of api.serializers.ReportSerializer

suffix = None
class api.views.ShiftViewSet(**kwargs)

Bases: rest_framework.viewsets.ModelViewSet

basename = None
description = None
detail = None
filterset_class

alias of api.filters.ShiftFilterSet

get_queryset()

Customized method to only retrieve Objects owned by the User issueing the request. :return:

list_month_year(request, month=None, year=None, *args, **kwargs)

Custom endpoint which retrieves all shifts corresponding to the provided <month> and <year> url params. :param request: :param month: :param year: :param args: :param kwargs: :return:

name = None
queryset
serializer_class

alias of api.serializers.ShiftSerializer

suffix = None
api.views.index(request)

This function based view provides a proof of concept (for the local env) that the celery workers (in extern Docker Containers) work. :param request: :return: