-
Notifications
You must be signed in to change notification settings - Fork 5
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 #29 from andela/ft-share-articles-164798217
#164798217 User should be able to share articles
- Loading branch information
Showing
8 changed files
with
75 additions
and
4 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -12,3 +12,6 @@ EMAIL_PORT='587' | |
|
||
WORD_LENGTH='5' | ||
WORD_PER_MINUTE='256' | ||
BASE_ARTICLE_SHARE_URL='http://www.front/articles' | ||
|
||
|
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
Empty file.
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,34 @@ | ||
import urllib.parse | ||
from django.urls import reverse | ||
from django.conf import settings | ||
|
||
|
||
def share_articles_links(obj, request): | ||
""" | ||
Generates sharing links for popular plaforms | ||
like facebook, googleplus, twitter and email | ||
Args: | ||
article_title(String): title of article to share | ||
article_link(String): http link to article | ||
returns | ||
share_links(dict): collection of sharing links | ||
""" | ||
share_links = {} | ||
article_title = obj.title | ||
article_link = f'{settings.BASE_ARTICLE_SHARE_URL}/{obj.slug}' if settings.BASE_ARTICLE_SHARE_URL else \ | ||
request \ | ||
.build_absolute_uri(reverse('articles:auth-articles', \ | ||
kwargs={'slug': obj.slug})) | ||
|
||
encoded_article_link = urllib.parse.quote(article_link) | ||
encoded_article_title = urllib.parse.quote(article_title) | ||
|
||
share_links['facebook'] = 'https://www.facebook.com/sharer/sharer.php?u=' + encoded_article_link | ||
share_links['twitter'] = 'https://twitter.com/home?status=' + encoded_article_link | ||
share_links['googleplus'] = 'https://plus.google.com/share?url=' + encoded_article_link | ||
share_links['email'] = 'mailto:?&subject=' + encoded_article_title + '&body=' \ | ||
+ encoded_article_title + '%0A%0A' + encoded_article_link | ||
return share_links |
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