Skip to content

Commit

Permalink
BE-1273 fixed comments on pr
Browse files Browse the repository at this point in the history
  • Loading branch information
tom committed May 17, 2021
1 parent abb6649 commit 334da47
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 46 deletions.
3 changes: 3 additions & 0 deletions livestyled/models/device_form_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ def __init__(
device_id,
form_id,
data,
expires_at=None,
created_at=None,
updated_at=None
):
self._id = id
self.data = data
self.created_at = created_at
self.updated_at = updated_at
self.expires_at = expires_at
self._device = Device.placeholder(id=device_id)
self._form = Form.placeholder(id=form_id)

Expand All @@ -31,6 +33,7 @@ def create_new(
device_id=None,
form_id=None,
data=data,
expires_at=None,
created_at=None,
updated_at=None,
)
Expand Down
78 changes: 39 additions & 39 deletions livestyled/models/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,41 @@
from livestyled.models.form_field import FormField


class FormTranslation:
def __init__(
self,
id,
language,
title,
description,
submit_button_title=None,
completion_title=None,
completion_button_title=None,
completion_description=None,
):
self._id = id
self.language = language
self.title = title
self.description = description
self.submit_button_title = submit_button_title
self.completion_button_title = completion_button_title
self.completion_title = completion_title
self.completion_description = completion_description

def __eq__(self, other):
return all(
[
self.language == other.language,
self.title == other.title,
self.description == other.description,
self.submit_button_title == other.submit_button_title,
self.completion_title == other.completion_title,
self.completion_button_title == other.completion_button_title,
self.completion_description == other.completion_description
]
)


class Form:
def __init__(
self,
Expand All @@ -28,9 +63,9 @@ def __init__(
self.allow_update = allow_update
self.refresh_on_success = refresh_on_success
if fields:
self.fields = [FormField(**ff) for ff in fields]
self.fields = [FormField(**field) for field in fields]
if translations:
self.fields = [FormTranslation(**ft) for ft in translations]
self.fields = [FormTranslation(**translation) for translation in translations]
self.requires_login = requires_login
self.validation_integration = validation_integration

Expand All @@ -44,8 +79,8 @@ def create_new(
show_completion_date: bool or None = None,
allow_update: bool or None = None,
refresh_on_success: bool or None = None,
fields: List or None = None,
translations: List or None = None,
fields: List[FormField] or None = None,
translations: List[FormTranslation] or None = None,
requires_login: bool or None = None,
validation_integration: str or None = None,
):
Expand Down Expand Up @@ -101,38 +136,3 @@ def placeholder(
requires_login=None,
validation_integration=None,
)


class FormTranslation:
def __init__(
self,
id,
language,
title,
description,
submit_button_title=None,
completion_title=None,
completion_button_title=None,
completion_description=None,
):
self._id = id
self.language = language
self.title = title
self.description = description
self.submit_button_title = submit_button_title
self.completion_button_title = completion_button_title
self.completion_title = completion_title
self.completion_description = completion_description

def __eq__(self, other):
return all(
[
self.language == other.language,
self.title == other.title,
self.description == other.description,
self.submit_button_title == other.submit_button_title,
self.completion_title == other.completion_title,
self.completion_button_title == other.completion_button_title,
self.completion_description == other.completion_description
]
)
2 changes: 1 addition & 1 deletion livestyled/models/form_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def __init__(
self.sort_id = sort_id
self.auto_fill = auto_fill
if translations:
self.fields = [FormFieldTranslation(**fft) for fft in translations]
self.fields = [FormFieldTranslation(**translation) for translation in translations]

@classmethod
def create_new(
Expand Down
14 changes: 8 additions & 6 deletions livestyled/resource_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1253,18 +1253,20 @@ def get_locations(

def get_form_data(
self,
device_id=None,
form_id=None,
expires_at_before=None,
expires_at_after=None
) -> Generator[DeviceFormData, None, None]:
filters = {}
if device_id:
filters['device'] = device_id
if form_id:
filters['form'] = form_id
if expires_at_before:
filters = {
'expiresAt[before]': expires_at_before
}
filters['expiresAt[before]'] = expires_at_before
if expires_at_after:
filters = {
'expiresAt[after]': expires_at_after
}
filters['expiresAt[after]'] = expires_at_after
if filters:
return self._get_resource_list(DeviceFormDataSchema, filters=filters)
return self._get_resource_list(DeviceFormDataSchema)
1 change: 1 addition & 0 deletions livestyled/schemas/device_form_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Meta:
default_ordering = 'id'

id = fields.Int()
expires_at = fields.AwareDateTime(data_key='expiresAt', load_only=True, allow_none=True)
created_at = fields.AwareDateTime(data_key='createdAt', load_only=True, allow_none=True)
updated_at = fields.AwareDateTime(data_key='updatedAt', load_only=True, allow_none=True)
data = fields.List(fields.Inferred, data_key='data')
Expand Down

0 comments on commit 334da47

Please sign in to comment.