Coverage for src/paperap/resources/ui_settings.py: 47%

1"""

2----------------------------------------------------------------------------

3

4 METADATA:

5

6 File: ui_settings.py

7 Project: paperap

8 Created: 2025-03-04

9 Version: 0.0.5

10 Author: Jess Mann

11 Email: jess@jmann.me

12 Copyright (c) 2025 Jess Mann

13

14----------------------------------------------------------------------------

15

16 LAST MODIFIED:

17

18 2025-03-04 By Jess Mann

19

20"""

21

22 from __future__ import annotations

23

24 from typing import Any

25

26 from paperap.models.ui_settings import UISettings, UISettingsQuerySet

27 from paperap.resources.base import BaseResource, StandardResource

28

29

30 class UISettingsResource(StandardResource[UISettings, UISettingsQuerySet]):

31 """Resource for managing UI settings."""

32

33 model_class = UISettings

34 name = "ui_settings"

35

36 def get_current(self) -> UISettings | None:

37 """

38 Get the current user's UI settings.

39

40 Returns:

41 The current user's UI settings.

42

43 """

44 if not (response := self.client.request("GET", "ui_settings/")):

45 return None

46

47 if isinstance(response, list) and len(response) > 0:

48 return UISettings.from_dict(response)

49 return None

50

51 def update_current(self, settings: dict[str, Any]) -> UISettings:

52 """

53 Update the current user's UI settings.

54

55 Args:

56 settings: The settings to update.

57

58 Returns:

59 The updated UI settings.

60

61 """

62 ui_settings = self.get_current()

63 if ui_settings:

64 ui_settings.settings.update(settings)

65 return self.update(ui_settings)

66

67 # Create new settings

68 return self.create({"settings": settings})