Skip to content

Commit

Permalink
Using image from project for meta
Browse files Browse the repository at this point in the history
  • Loading branch information
stefdworschak committed Sep 7, 2021
1 parent 84400c3 commit e50c72d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
5 changes: 2 additions & 3 deletions images/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,8 @@ def render_image(request, showcase_id, image_hash):
try:
image_hash_uuid = uuid.UUID(image_hash)
showcase = get_object_or_404(Showcase, hash=image_hash_uuid)
if showcase.showcase_image:
data_uri = showcase.showcase_image
image_data = data_uri.partition('base64,')[2]
if showcase.get_image():
image_data = showcase.get_image().partition('base64,')[2]
binary = base64.b64decode(image_data)
return HttpResponse(binary, content_type='image/png')
except ValueError:
Expand Down
7 changes: 7 additions & 0 deletions showcase/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ def get_project(self):
except:
return None

def get_image(self):
if self.showcase_image:
return self.showcase_image
if self.hack_project.project_image:
return self.hack_project.project_image
return

@property
def url(self):
return (f'{settings.ACCOUNT_DEFAULT_HTTP_PROTOCOL}://'
Expand Down
2 changes: 1 addition & 1 deletion teams/templates/team.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

{% if showcase %}
<meta property='og:title' content='{{showcase.hack_project.display_name}}'/>
{% if showcase.showcase_image %}
{% if showcase.get_image %}
<meta property='og:image' content='{{showcase.image_url}}'/>
{% endif %}
<meta property='og:description' content='{{showcase.hack_project.description}}'/>
Expand Down

0 comments on commit e50c72d

Please sign in to comment.