mirror of
https://github.com/aljazceru/python-teos.git
synced 2025-12-17 14:14:22 +01:00
The Watcher used to create the summary, but that was not modular enough and introduced issues when testing
47 lines
1.6 KiB
Python
47 lines
1.6 KiB
Python
from common.appointment import Appointment
|
|
|
|
|
|
class ExtendedAppointment(Appointment):
|
|
def __init__(self, locator, to_self_delay, encrypted_blob, user_id):
|
|
super().__init__(locator, to_self_delay, encrypted_blob)
|
|
self.user_id = user_id
|
|
|
|
def get_summary(self):
|
|
"""
|
|
Returns the summary of an appointment, consisting on the locator, the user_id and the appointment size.
|
|
|
|
Returns:
|
|
:obj:`dict`: the appointment summary.
|
|
"""
|
|
return {"locator": self.locator, "user_id": self.user_id, "size": len(self.encrypted_blob)}
|
|
|
|
@classmethod
|
|
def from_dict(cls, appointment_data):
|
|
"""
|
|
Builds an appointment from a dictionary.
|
|
|
|
This method is useful to load data from a database.
|
|
|
|
Args:
|
|
appointment_data (:obj:`dict`): a dictionary containing the following keys:
|
|
``{locator, to_self_delay, encrypted_blob, user_id}``
|
|
|
|
Returns:
|
|
:obj:`ExtendedAppointment <teos.extended_appointment.ExtendedAppointment>`: An appointment initialized
|
|
using the provided data.
|
|
|
|
Raises:
|
|
ValueError: If one of the mandatory keys is missing in ``appointment_data``.
|
|
"""
|
|
|
|
appointment = Appointment.from_dict(appointment_data)
|
|
user_id = appointment_data.get("user_id")
|
|
|
|
if not user_id:
|
|
raise ValueError("Wrong appointment data, user_id is missing")
|
|
|
|
else:
|
|
appointment = cls(appointment.locator, appointment.to_self_delay, appointment.encrypted_blob, user_id)
|
|
|
|
return appointment
|