Skip to content

Commit

Permalink
Merge pull request #188 from lsst-ts/tickets/LOVE-65
Browse files Browse the repository at this point in the history
LOVE screen sizes enhancement
  • Loading branch information
sebastian-aranda authored Jun 22, 2023
2 parents 6d8ac79 + 8826c52 commit 8531d01
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 9 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
Version History
===============

v5.13.0
--------

* LOVE screen sizes enhancement `<https://github.com/lsst-ts/LOVE-manager/pull/188>`_

v5.12.0
--------

Expand Down
20 changes: 16 additions & 4 deletions manager/ui_framework/migrations/0005_auto_20230508_1512.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,25 @@
class Migration(migrations.Migration):

dependencies = [
('ui_framework', '0004_auto_20211027_1557'),
("ui_framework", "0004_auto_20211027_1557"),
]

operations = [
migrations.AlterField(
model_name='view',
name='thumbnail',
field=models.ImageField(blank=True, max_length=200, null=True, upload_to='thumbnails/'),
model_name="view",
name="thumbnail",
field=models.ImageField(
blank=True, max_length=200, null=True, upload_to="thumbnails/"
),
),
migrations.AddField(
model_name="view",
name="screen",
field=models.CharField(
choices=[("4k", "4k"), ("desktop", "desktop"), ("mobile", "mobile")],
default="desktop",
max_length=20,
null=True,
),
),
]
13 changes: 13 additions & 0 deletions manager/ui_framework/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ def save(self, *args, **kwargs):
class View(BaseModel):
"""View Model."""

class ScreenSizes(models.TextChoices):
FULL_4K = "4k", "4k"
DESKTOP = "desktop", "desktop"
MOBILE = "mobile", "mobile"

name = models.CharField(max_length=20)
"""The name of the View. e.g 'My View'"""

Expand All @@ -85,6 +90,14 @@ class View(BaseModel):
)
"""A reference to the image thumbnail of the view"""

screen = models.CharField(
max_length=20,
null=True,
choices=ScreenSizes.choices,
default=ScreenSizes.DESKTOP,
)
"""The screen size for which the View is optimized"""

def __str__(self):
"""Redefine how objects of this class are transformed to string."""
return self.name
Expand Down
4 changes: 2 additions & 2 deletions manager/ui_framework/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class Meta:
"""Meta class to map serializer's fields with the model fields."""

model = View
fields = ("id", "name", "thumbnail", "data")
fields = ("id", "name", "thumbnail", "screen", "data")


class ViewSummarySerializer(serializers.ModelSerializer):
Expand All @@ -155,7 +155,7 @@ class Meta:
"""Meta class to map serializer's fields with the model fields."""

model = View
fields = ("id", "name", "thumbnail")
fields = ("id", "name", "thumbnail", "screen")


class WorkspaceSerializer(serializers.ModelSerializer):
Expand Down
1 change: 1 addition & 0 deletions manager/ui_framework/tests/tests_custom_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def test_get_workspaces_with_view_name(self):
"thumbnail": None
if v.thumbnail.name == "" or v.thumbnail.name is None
else settings.MEDIA_URL + str(v.thumbnail.name),
"screen": v.screen,
}
for v_pk in w["views"]
for v in [View.objects.get(pk=v_pk)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ def test_new_view_from_remote_storage(self):
mock_requests_post_client = mock_requests_post.start()
response_requests_post = requests.Response()
response_requests_post.status_code = 200
response_requests_post.json = lambda: {"ack": "ok", "url": "http://test/"}
response_requests_post.json = lambda: {
"ack": "ok",
"url": "http://foo.bar/file.png",
}
mock_requests_post_client.return_value = response_requests_post

# Act 1
Expand All @@ -90,14 +93,15 @@ def test_new_view_from_remote_storage(self):

# - thumbnail url
view = View.objects.get(name="view name")
self.assertEqual(view.thumbnail.url, "http://test/")
self.assertEqual(view.thumbnail.url, "http://foo.bar/file.png")

# - expected response data
expected_response = {
"id": view.id,
"name": "view name",
"thumbnail": view.thumbnail.url,
"data": {"key1": "value1"},
"screen": "desktop",
}
self.assertEqual(response.data, expected_response)

Expand Down Expand Up @@ -143,6 +147,7 @@ def test_new_view(self):
"name": "view name",
"thumbnail": view.thumbnail.url,
"data": {"key1": "value1"},
"screen": "desktop",
}
self.assertEqual(response.data, expected_response)

Expand Down
8 changes: 7 additions & 1 deletion manager/ui_framework/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,22 @@ def setUp(self):
{
"name": "My View 0",
"data": json.dumps({"data_name": "My View 0"}),
"screen": "desktop",
}, # noqa: E231
{
"name": "My View 1",
"data": json.dumps({"data_name": "My View 1"}),
"screen": "desktop",
}, # noqa: E231
{
"name": "My View 2",
"data": json.dumps({"data_name": "My View 2"}),
"screen": "desktop",
}, # noqa: E231
{
"name": "My View 3",
"data": json.dumps({"data_name": "My View 3"}),
"screen": "desktop",
}, # noqa: E231
]
self.workspaces_data = [
Expand Down Expand Up @@ -151,7 +155,9 @@ def setUp(self):
"class": Workspace,
"key": "workspace",
"old_count": Workspace.objects.count(),
"new_data": {"name": "My new Workspace",}, # noqa: E231
"new_data": {
"name": "My new Workspace",
}, # noqa: E231
"current_data": self.workspaces_data,
"list_data": self.workspaces_data,
"selected_id": self.workspaces_data[0]["id"],
Expand Down

0 comments on commit 8531d01

Please sign in to comment.