forked from Github-Mirrors/canaille
refactor: move BackendModel.update to Backend.update
This commit is contained in:
parent
473a262ea2
commit
b2d5f8d3a1
4 changed files with 23 additions and 19 deletions
|
@ -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()
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue