refactor: move BackendModel.update to Backend.update

This commit is contained in:
Éloi Rivard 2024-04-16 21:57:06 +02:00
parent 473a262ea2
commit b2d5f8d3a1
No known key found for this signature in database
GPG key ID: 7EDA204EA57DD184
4 changed files with 23 additions and 19 deletions

View file

@ -108,6 +108,24 @@ class BaseBackend:
"""
raise NotImplementedError()
def update(self, instance, **kwargs):
"""Assign a whole dict to the current instance. This is useful to
update models based on forms.
>>> user = User.get(user_name="george")
>>> user.first_name
George
>>> backend.update({
... client,
... first_name="Jane",
... last_name="Calamity",
... })
>>> user.first_name
Jane
"""
for attribute, value in kwargs.items():
setattr(instance, attribute, value)
def check_user_password(self, user, password: str) -> bool:
"""Check if the password matches the user password in the database."""
raise NotImplementedError()

View file

@ -88,23 +88,6 @@ class BackendModel:
implemented for every model and for every backend.
"""
def update(self, **kwargs):
"""Assign a whole dict to the current instance. This is useful to
update models based on forms.
>>> user = User.get(user_name="george")
>>> user.first_name
George
>>> user.update({
... first_name="Jane",
... last_name="Calamity",
... })
>>> user.first_name
Jane
"""
for attribute, value in kwargs.items():
setattr(self, attribute, value)
@classmethod
def get_model_annotations(cls, attribute):
annotations = cls.attributes[attribute]

View file

@ -118,7 +118,8 @@ def client_edit(client):
"client_edit.html", form=form, client=client, menuitem="admin"
)
client.update(
BaseBackend.instance.update(
client,
client_name=form["client_name"].data,
contacts=form["contacts"].data,
client_uri=form["client_uri"].data,

View file

@ -484,7 +484,9 @@ class ClientConfigurationEndpoint(ClientManagementMixin, _ClientConfigurationEnd
BaseBackend.instance.delete(client)
def update_client(self, client, client_metadata, request):
client.update(**self.client_convert_data(**client_metadata))
BaseBackend.instance.update(
client, **self.client_convert_data(**client_metadata)
)
BaseBackend.instance.save(client)
return client