Skip to content

Commit

Permalink
Fix: #48 Default cover and logo image on creating a data source
Browse files Browse the repository at this point in the history
  • Loading branch information
albinpa authored and georgepadayatti committed Apr 5, 2024
1 parent b3480b7 commit 5c6dfde
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion config/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from connection.models import Connection
from dataspace_backend.settings import DATA_MARKETPLACE_DW_URL, DATA_MARKETPLACE_APIKEY
import requests
from dataspace_backend import settings

# Create your views here.

Expand All @@ -42,6 +43,25 @@ def construct_logo_image_url(
endpoint = f"/{url_prefix}/data-source/{data_source_id}/logoimage/"
return f"{protocol}{baseurl}{endpoint}"

def load_default_cover_image():
cover_image_path = os.path.join(settings.BASE_DIR, "resources","assets", "cover.jpeg")

with open(cover_image_path, 'rb') as cover_image_file:
image_data = cover_image_file.read()
image = ImageModel(image_data=image_data)
image.save()
return image.id

def load_default_logo_image():
logo_image_path = os.path.join(settings.BASE_DIR, "resources","assets", "logo.jpeg")

with open(logo_image_path, 'rb') as logo_image_file:
image_data = logo_image_file.read()
image = ImageModel(image_data=image_data)
image.save()
return image.id



class DataSourceView(APIView):
serializer_class = DataSourceSerializer
Expand Down Expand Up @@ -73,7 +93,12 @@ def post(self, request):
admin=admin, **serializer.validated_data
)

# TODO: Add default cover image and logo image URL
# Add default cover image and logo image URL
cover_image_id = load_default_cover_image()
logo_image_id = load_default_logo_image()
datasource.coverImageId = cover_image_id
datasource.logoId = logo_image_id

# Update data source with cover and logo image URL
datasource.coverImageUrl = construct_cover_image_url(
baseurl=request.get_host(),
Expand Down
Binary file added resources/assets/cover.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/assets/logo.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5c6dfde

Please sign in to comment.