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

Improve overall api usage #37

Draft
wants to merge 16 commits into
base: master
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased](https://github.com/at-gmbh/personio-py/compare/v0.2.3...HEAD)

* add support for additional attributes for attendances ([#37](https://github.com/at-gmbh/personio-py/pull/37))
...

## [0.2.3](https://github.com/at-gmbh/personio-py/tree/v0.2.3) - 2023-05-05
Expand Down
296 changes: 189 additions & 107 deletions src/personio_py/client.py

Large diffs are not rendered by default.

23 changes: 20 additions & 3 deletions src/personio_py/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
import logging
import re
from datetime import date, datetime, timedelta
from datetime import date, datetime, timedelta, time
from decimal import Decimal
from typing import Any, Dict, List, NamedTuple, Optional, TYPE_CHECKING, Type, TypeVar, Union

Expand Down Expand Up @@ -104,6 +104,18 @@ def deserialize(self, value: str, **kwargs) -> date:
return date.fromisoformat(value[:10])


class TimeFieldMapping(FieldMapping):
def __init__(self, api_field: str, class_field: str):
super().__init__(api_field, class_field, field_type=time)

def serialize(self, value: time) -> str:
return value.isoformat()

def deserialize(self, value: str, **kwargs) -> time:
if value == "24:00":
value = "23:59"
return time.fromisoformat(value)

class DurationFieldMapping(FieldMapping):

pattern = re.compile(r"\d\d?:\d\d")
Expand Down Expand Up @@ -167,8 +179,13 @@ def deserialize(self, value: Dict, client: 'Personio' = None) \
-> Optional['PersonioResourceType']:
if value and isinstance(value, dict):
if not self.field_type._flat_dict:
value = value['attributes']
return self.field_type.from_dict(value, client=client)

attributes = value['attributes']
if hasattr(value, 'id') and value['id']:
attributes['id'] = value['id']
else:
attributes = value
return self.field_type.from_dict(attributes, client=client)
else:
return None

Expand Down
Loading