Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
HamzaIbnFarooq committed Jan 25, 2021
1 parent b48bd96 commit 4e9de87
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 41 deletions.
70 changes: 35 additions & 35 deletions cms/templates/certificate_page.html
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -21,39 +21,39 @@

{% block content %}
<div class="container-fluid certificate-page">
{% if certificate_user == user %}
<div class="row no-print">
<div class="col px-0">
<div class="cer-user-info">
<div class="user-info-holder">
<ul class="social-links">
<li>
<a href="https://twitter.com/intent/tweet?url={{ request.build_absolute_uri|urlencode }}&text={{ share_text|urlencode }}">
<img src="{% static 'images/certificates/icon-twitter.svg' %}" alt="Share to Twitter">
</a>
</li>
<li>
<a href="http://www.facebook.com/share.php?u={{ request.build_absolute_uri|urlencode }}" target="_blank">
<img src="{% static 'images/certificates/icon-facebook.svg' %}" alt="Share to Facebook">
</a>
</li>
<li>
<a href="https://www.linkedin.com/profile/add?startTask={{ page.product_name|urlencode }}" target="_blank">
<img src="{% static 'images/certificates/icon-linkedin.svg' %}" alt="Share to LinkedIn">
</a>
</li>
<li>
<a href="javascript:window.print();">
<img src="{% static 'images/certificates/icon-print.svg' %}" alt="Print">
</a>
</li>
</ul>
<h2>Congratulations, {{ learner_name }}!</h2>
<p>You have successfully completed {{ page.product_name }}. Share your accomplishment with your friends, family and colleagues. </p>
</div>
</div>
</div>
</div>
{% if certificate_user == user %}
<div class="row no-print">
<div class="col px-0">
<div class="cer-user-info">
<div class="user-info-holder">
<ul class="social-links">
<li>
<a href="https://twitter.com/intent/tweet?url={{ request.build_absolute_uri|urlencode }}&text={{ share_text|urlencode }}">
<img src="{% static 'images/certificates/icon-twitter.svg' %}" alt="Share to Twitter">
</a>
</li>
<li>
<a href="http://www.facebook.com/share.php?u={{ request.build_absolute_uri|urlencode }}" target="_blank">
<img src="{% static 'images/certificates/icon-facebook.svg' %}" alt="Share to Facebook">
</a>
</li>
<li>
<a href="https://www.linkedin.com/profile/add?startTask={{ page.product_name|urlencode }}" target="_blank">
<img src="{% static 'images/certificates/icon-linkedin.svg' %}" alt="Share to LinkedIn">
</a>
</li>
<li>
<a href="javascript:window.print();">
<img src="{% static 'images/certificates/icon-print.svg' %}" alt="Print">
</a>
</li>
</ul>
<h2>Congratulations, {{ learner_name }}!</h2>
<p>You have successfully completed {{ page.product_name }}. Share your accomplishment with your friends, family and colleagues. </p>
</div>
</div>
</div>
</div>
{% endif %}
<div class="row">
<div class="col certificate-wrapper">
Expand Down Expand Up @@ -125,8 +125,8 @@ <h2>Congratulations, {{ learner_name }}!</h2>

{% block scripts %}
{{ block.super }}
{% if certificate_user == user %}
<script type="text/javascript" async src="https://platform.twitter.com/widgets.js"></script>
{% if certificate_user == user %}
<script type="text/javascript" async src="https://platform.twitter.com/widgets.js"></script>
{% endif %}
{% endblock %}

Expand Down
13 changes: 7 additions & 6 deletions cms/templatetags/wagtail_image_lazy_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
register = template.Library()


class LazyImageNodeCustom(LazyImageNode):
class CustomLazyImageNode(LazyImageNode):
"""
An extention to Wagtail-lazyimages library's wagtail_lazyimages.templatetags.lazyimages_tags.LazyImageNode
class for customizations
Expand All @@ -22,7 +22,8 @@ def render(self, context):
This method overrides LazyImageNode's render method to add file-hashes to image urls for better caching
Returns:
str or None: An image tag with required src and data-src attribute values
str or None: An image tag with required src (having tiny blurry placeholder image) and
data-src (having full-scale image) attribute values
"""
img = self.image_expr.resolve(context)
if not img:
Expand All @@ -41,23 +42,23 @@ def render(self, context):
@register.tag(name="wagtail_image_lazy_load")
def wagtail_image_lazy_load(img, filter_spec):
"""
Generates a lazy loadable image tag using Wagtail-lazyimages library and appends a version to the path to enable effective caching
Generates an image tag using Wagtail-lazyimages library and appends a version to the path to enable effective caching
This method is inspired by wagtail_lazyimages.templatetags.lazyimages_tags.lazy_image of Wagtail-lazyimages library
Args:
img (wagtail.images.models.Image): The image the a URL will be generated for
img (wagtail.images.models.Image): The image for which an image template tag will be generated
filter_spec (str): A filter specification for the image (see Wagtail docs)
Returns:
LazyImageNodeCustom object or None/empty str: A complete lazy loading image tag
CustomLazyImageNode object or None/empty str: A complete lazy loading image tag
"""

if not img:
return ""

node = image(img, filter_spec)
return LazyImageNodeCustom(
return CustomLazyImageNode(
node.image_expr,
node.filter_spec,
attrs=node.attrs,
Expand Down

0 comments on commit 4e9de87

Please sign in to comment.