-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #87 from wmo-raf/dev
Updates and Bug Fixes
- Loading branch information
Showing
18 changed files
with
207 additions
and
85 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
base/migrations/0027_integrationsettings_google_site_verification_key.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 4.2.3 on 2024-03-27 11:29 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('base', '0026_remove_importantpages_cap_feed_and_more'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='integrationsettings', | ||
name='google_site_verification_key', | ||
field=models.CharField(blank=True, max_length=255, null=True, verbose_name='Google Site Verification Key'), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,58 @@ | ||
import urllib.parse | ||
|
||
from django import template | ||
from django.conf import settings | ||
|
||
register = template.Library() | ||
|
||
SOCIAL_MEDIA_SHARE_CONFIG = getattr(settings, 'SOCIAL_MEDIA_SHARE_CONFIG', {}) | ||
ONLINE_SHARE_CONFIG = getattr(settings, 'ONLINE_SHARE_CONFIG', {}) | ||
|
||
|
||
@register.inclusion_tag("social_media_share_buttons_include.html") | ||
def share_buttons(url, text=None): | ||
share_urls = [] | ||
for config in ONLINE_SHARE_CONFIG: | ||
enabled = config.get('enabled', False) | ||
name = config.get('name', None) | ||
base_url = config.get('base_url', None) | ||
link_param = config.get('link_param', None) | ||
text_in_url = config.get('text_in_url', False) | ||
text_param = config.get('text_param', None) | ||
encode = config.get('encode', False) | ||
fa_icon = config.get('fa_icon', False) | ||
|
||
link_query = None | ||
text_query = None | ||
|
||
@register.simple_tag | ||
def get_social_media_share(platform, url, text=None): | ||
share_url = None | ||
item_url = url | ||
item_text = text | ||
|
||
try: | ||
config = SOCIAL_MEDIA_SHARE_CONFIG[platform] | ||
if not enabled or not name or not base_url or not link_param: | ||
continue | ||
|
||
base_config = config.get('base_url', None) | ||
url_config = config.get('link_param', None) | ||
text_config = config.get('text_param', None) | ||
if encode: | ||
item_url = urllib.parse.quote(item_url) | ||
if item_text: | ||
item_text = urllib.parse.quote(item_text) | ||
|
||
if base_config and url_config: | ||
text_param = None | ||
url_param = None | ||
if item_text: | ||
if text_in_url: | ||
item_url = f"{item_text}%20{item_url}" | ||
elif text_param: | ||
text_query = f"{text_param}={item_text}" | ||
|
||
if url_config and url: | ||
url_param = '{}={}'.format(url_config, url) | ||
if link_param and item_url: | ||
link_query = f"{link_param}={item_url}" | ||
|
||
if text_config and text: | ||
text_param = '{}={}'.format(text_config, text) | ||
share_url = f"{base_url}?{link_query}" | ||
|
||
if url_param: | ||
share_url = '{}?{}'.format(base_config, url_param) | ||
if text_param: | ||
share_url = '{}&{}'.format(share_url, text_param) | ||
if text_query: | ||
share_url = f"{share_url}&{text_query}" | ||
|
||
return share_url | ||
except KeyError: | ||
return None | ||
share_urls.append({ | ||
'name': name, | ||
'url': share_url, | ||
'fa_icon': fa_icon | ||
}) | ||
|
||
return share_url | ||
return {"share_urls": share_urls} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 16 additions & 25 deletions
41
nmhs_cms/templates/social_media_share_buttons_include.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,17 @@ | ||
{% load get_share_url %} | ||
{% for share_url in share_urls %} | ||
|
||
<a class="button is-small is-rounded" | ||
href="{% get_social_media_share 'facebook' page.get_site.root_url|add:url text %}" | ||
target="_blank" rel="noopener" | ||
data-ga-event-category="Social Media Share" | ||
data-ga-event-label="Facebook" | ||
data-ga-value="{{ text }}" | ||
> | ||
<span class="icon"> | ||
<i class="fab fa-facebook-f" aria-hidden="true"></i> | ||
</span> | ||
<span class="share-button-title">Facebook</span> | ||
</a> | ||
<a class="button is-small is-rounded" | ||
href="{% get_social_media_share 'twitter' page.get_site.root_url|add:url text %}" | ||
target="_blank" rel="noopener" | ||
data-ga-event-category="Social Media Share" | ||
data-ga-event-label="Twitter" | ||
data-ga-value="{{ text }}" | ||
> | ||
<span class="icon"> | ||
<i class="fab fa-twitter" aria-hidden="true"></i> | ||
</span> | ||
<span class="share-button-title">Twitter</span> | ||
</a> | ||
<a class="button is-small is-rounded" | ||
href="{{ share_url.url }}" | ||
target="_blank" rel="noopener" | ||
data-ga-event-category="Social Media Share" | ||
data-ga-event-label="{{ share_url.name }}" | ||
data-ga-value="{{ share_url.url }}" | ||
> | ||
<span class="icon"> | ||
<i class="fab fa-{{ share_url.fa_icon }}" aria-hidden="true"></i> | ||
</span> | ||
<span class="share-button-title">{{ share_url.name }}</span> | ||
</a> | ||
|
||
|
||
{% endfor %} |
Oops, something went wrong.