Repository: fcurella/django-social-share Branch: master Commit: 57834ed60f9f Files: 33 Total size: 38.1 KB Directory structure: gitextract_08i4p9oj/ ├── .bumpversion.cfg ├── .github/ │ ├── FUNDING.yml │ └── workflows/ │ ├── gh-release.yml │ └── pythonpackage.yml ├── .gitignore ├── CODE_OF_CONDUCT.md ├── LICENSE ├── MANIFEST.in ├── Makefile ├── README.rst ├── VERSION ├── django_social_share/ │ ├── __init__.py │ ├── models.py │ ├── templates/ │ │ └── django_social_share/ │ │ └── templatetags/ │ │ ├── copy_script.html │ │ ├── copy_to_clipboard.html │ │ ├── pinterest_script.html │ │ ├── post_to_facebook.html │ │ ├── post_to_gplus.html │ │ ├── post_to_linkedin.html │ │ ├── post_to_reddit.html │ │ ├── post_to_telegram.html │ │ ├── post_to_twitter.html │ │ ├── post_to_whatsapp.html │ │ ├── save_to_pinterest.html │ │ └── send_email.html │ ├── templatetags/ │ │ ├── __init__.py │ │ └── social_share.py │ ├── tests/ │ │ ├── __init__.py │ │ ├── runtests.py │ │ └── tests.py │ └── views.py ├── setup.cfg └── setup.py ================================================ FILE CONTENTS ================================================ ================================================ FILE: .bumpversion.cfg ================================================ [bumpversion] files = VERSION django_social_share/__init__.py commit = True tag = True current_version = 2.3.0 ================================================ FILE: .github/FUNDING.yml ================================================ # These are supported funding model platforms github: @fcurella patreon: # Replace with a single Patreon username open_collective: # Replace with a single Open Collective username ko_fi: # Replace with a single Ko-fi username tidelift: pypi/django-social-hare community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry liberapay: # Replace with a single Liberapay username issuehunt: # Replace with a single IssueHunt username otechie: # Replace with a single Otechie username custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] ================================================ FILE: .github/workflows/gh-release.yml ================================================ on: push: # Sequence of patterns matched against refs/tags tags: - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10 name: Create Release jobs: build: name: Create Release runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v2 - name: Create Release id: create_release uses: actions/create-release@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token with: tag_name: ${{ github.ref }} release_name: Release ${{ github.ref }} draft: false prerelease: false ================================================ FILE: .github/workflows/pythonpackage.yml ================================================ name: Python build on: [push] jobs: tests: runs-on: ubuntu-latest strategy: max-parallel: 4 matrix: python-version: [3.6, 3.7, 3.8] django-version: - "Django>=2.0,<2.1" - "Django>=2.1,<2.2" - "Django>=2.2,<3.0" - "Django>=3.0,<3.1" steps: - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v1 with: python-version: ${{ matrix.python-version }} - name: Install dependencies run: | python -m pip install --upgrade pip pip install -q "${{ matrix.django-version }}" pip install -e . pip install coveralls - name: Test with pytest env: COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }} run: | coverage run --source django_social_share setup.py test && coveralls ================================================ FILE: .gitignore ================================================ *.egg-info *.pot *.py[co] *.out .eggs .cache .coverage parsetab.py __pycache__ MANIFEST dist/ docs/_build/ docs/locale/ node_modules/ tests/coverage_html/ tests/.coverage build/ tests/report/ .idea ================================================ FILE: CODE_OF_CONDUCT.md ================================================ # Contributor Covenant Code of Conduct ## Our Pledge In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. ## Our Standards Examples of behavior that contributes to creating a positive environment include: * Using welcoming and inclusive language * Being respectful of differing viewpoints and experiences * Gracefully accepting constructive criticism * Focusing on what is best for the community * Showing empathy towards other community members Examples of unacceptable behavior by participants include: * The use of sexualized language or imagery and unwelcome sexual attention or advances * Trolling, insulting/derogatory comments, and personal or political attacks * Public or private harassment * Publishing others' private information, such as a physical or electronic address, without explicit permission * Other conduct which could reasonably be considered inappropriate in a professional setting ## Our Responsibilities Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. ## Scope This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. ## Enforcement Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at community@curella.org. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. ## Attribution This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] [homepage]: http://contributor-covenant.org [version]: http://contributor-covenant.org/version/1/4/ ================================================ FILE: LICENSE ================================================ Copyright (C) 2011 by Flavio Curella Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: MANIFEST.in ================================================ include README.rst include LICENSE include VERSION recursive-include tests *.py recursive-include django_social_share/templates * ================================================ FILE: Makefile ================================================ release: rm -rf dist python setup.py sdist bdist_wheel twine upload dist/* ================================================ FILE: README.rst ================================================ Django Social Share ====================================== .. image:: https://github.com/fcurella/django-social-share/workflows/Python%20build/badge.svg .. image:: https://coveralls.io/repos/github/fcurella/django-social-share/badge.svg?branch=master :target: https://coveralls.io/github/fcurella/django-social-share?branch=master Provides templatetags for: * 'Tweet This' * 'Share this on Facebook' * 'Share on Google+' * 'Share on LinkedIn' * 'Share on Telegram' * 'Share on WhatsApp' * 'mailto://'. * 'Save to Pinterest' * 'Copy to Clipboard' Plain HTML templates_ are provided for your convenience, but you can override them to provide your own look and feel. Installation ------------- :: $ python -m pip install django-social-share Add the app to ``INSTALLED_APPS``:: INSTALLED_APPS += ['django_social_share'] You will also have to add ``django.template.context_processors.request`` to your ``context_processors`` list. This way the templatetags will use the correct scheme and hostname:: TEMPLATES=[ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [ os.path.join(BASE_DIR, 'templates'), ], 'OPTIONS': { 'context_processors': [ 'django.template.context_processors.request', ], } }, ] Note in most cases sharing will not work if you are using ``localhost`` or your domain is otherwise not accessible from the public internet. For testing local development, you can use a service like ngrok_, and set your `Site instance `_'s ``domain`` to the hostname provided by ``ngrok``. .. _ngrok: https://ngrok.com/ Usage ----- First, add ``{% load social_share %}`` to your HTML template. This tag should be placed at the top of most of your HTML document and should come before any other template tag unless otherwise. `django-social-share` provides two types of template tags: "snippet" tags and "context" tags. Snippet Tags ~~~~~~~~~~~~ Snippet tags returns HTML that you can just drop in your templates. This snippets are customizable, see templates_ . Available Snippets Tags: :: {% post_to_facebook %} {% post_to_gplus %} {% post_to_twitter %} {% post_to_linkedin %} {% post_to_reddit %} {% post_to_telegram %} {% post_to_whatsapp %} {% save_to_pinterest %} {% add_pinterest_script %} ```` may contain any valid Django Template code. Note that Facebook does not support this anymore. ```` is optional (except Telegram). If you pass a django model instance, it will use its ``get_absolute_url`` method. Additionally, if you have ``django_bitly`` installed, it will use its shortUrl on Twitter. ```` is also optional. It defines the text used for the ``a`` element. Defaults to 'Post to Facebook' and 'Post to Twitter'. Example:: {% load social_share %} {% post_to_facebook object_or_url "Post to Facebook!" %} {% post_to_twitter "New Song: {{object.title}}. Check it out!" object_or_url "Post to Twitter" %} {% post_to_gplus object_or_url "Post to Google+!" %} {% post_to_linkedin object_or_url %} {% send_email object.title "New Song: {{object.title}}. Check it out!" object_or_url "Share via email" %} {% post_to_reddit "New Song: {{object.title}}" %} {% post_to_telegram "New Song: {{object.title}}" %} {% post_to_whatsapp object_or_url "Share via WhatsApp" %} {% save_to_pinterest object_or_url %} {% add_pinterest_script %} // Required for save_to_pinterest. Add to the end of body tag. .. _templates: Templates --------- Templates for snippet tags are in: * ``django_social_share/templatetags/post_to_twitter.html`` * ``django_social_share/templatetags/post_to_facebook.html`` * ``django_social_share/templatetags/post_to_gplus.html`` * ``django_social_share/templatetags/send_email.html`` * ``django_social_share/templatetags/post_to_linkedin.html`` * ``django_social_share/templatetags/post_to_reddit.html``. * ``django_social_share/templatetags/post_to_telegram.html``. * ``django_social_share/templatetags/post_to_whatsapp.html``. * ``django_social_share/templatetags/save_to_pinterest.html``. * ``django_social_share/templatetags/pinterest_script.html``. * ``django_social_share/templatetags/copy_to_clipboard.html``. * ``django_social_share/templatetags/copy_script.html``. You can override them to suit your mileage. Context Tags ~~~~~~~~~~~~ Context Tags work by adding a variable to your template's context. This variable will containg just the URL to service's share feature, which you can use into your template as you wish. Available Context Tags: ============================================================================= ================= Tag example Variable name ============================================================================= ================= ``{% post_to_twitter_url %}`` ``tweet_url`` ``{% post_to_facebook_url %}`` ``facebook_url`` ``{% post_to_gplus_url %}`` ``gplus_url`` ``{% send_email_url %}`` ``mailto_url`` ``{% post_to_reddit_url %}`` ``reddit_url`` ``{% post_to_telegram %}`` ``telegram_url`` ``{% post_to_whatsapp_url %}`` ``whatsapp_url`` ``{% save_to_pinterest_url %}`` ``pinterest_url`` ``{% copy_to_clipboard %}`` ``copy_url`` ```` may contain any valid Django Template code. Note that Facebook does not support this anymore. ```` is optional (except Telegram). If you pass a django model instance, it will use its ``get_absolute_url`` method. Additionally, if you have ``django_bitly`` installed, it will use its shortUrl on Twitter. ```` is also optional. It defines the text used for the ``a`` element. Defaults to 'Post to Facebook' and 'Post to Twitter'. Example:: {% load social_share %} {% post_to_facebook object_or_url "Post to Facebook!" %} {% post_to_twitter "New Song: {{object.title}}. Check it out!" object_or_url "Post to Twitter" %} {% post_to_gplus object_or_url "Post to Google+!" %} {% post_to_linkedin object_or_url %} {% send_email object.title "New Song: {{object.title}}. Check it out!" object_or_url "Share via email" %} {% post_to_reddit "New Song: {{object.title}}" %} {% post_to_telegram "New Song: {{object.title}}" %} {% post_to_whatsapp object_or_url "Share via WhatsApp" %} {% save_to_pinterest object_or_url %} {% add_pinterest_script %} // Required for save_to_pinterest. Add to the end of body tag. {% copy_to_clipboard object_or_url "Copy to clipboard!" %} {% add_copy_script %} // Required for copy_to_clipboard. Add to the end of body tag. Issues ------ If you have any issues, please use `GitHub's issues `_. Please refrain from emailing the author. ================================================ FILE: VERSION ================================================ 2.3.0 ================================================ FILE: django_social_share/__init__.py ================================================ VERSION = tuple(map(int, "2.3.0".split('.'))) ================================================ FILE: django_social_share/models.py ================================================ from django.db import models ================================================ FILE: django_social_share/templates/django_social_share/templatetags/copy_script.html ================================================ ================================================ FILE: django_social_share/templates/django_social_share/templatetags/copy_to_clipboard.html ================================================
================================================ FILE: django_social_share/templates/django_social_share/templatetags/pinterest_script.html ================================================ ================================================ FILE: django_social_share/templates/django_social_share/templatetags/post_to_facebook.html ================================================ ================================================ FILE: django_social_share/templates/django_social_share/templatetags/post_to_gplus.html ================================================ ================================================ FILE: django_social_share/templates/django_social_share/templatetags/post_to_linkedin.html ================================================ {% load i18n social_share %}{% get_current_language as LANGUAGE_CODE %} ================================================ FILE: django_social_share/templates/django_social_share/templatetags/post_to_reddit.html ================================================ ================================================ FILE: django_social_share/templates/django_social_share/templatetags/post_to_telegram.html ================================================ ================================================ FILE: django_social_share/templates/django_social_share/templatetags/post_to_twitter.html ================================================ ================================================ FILE: django_social_share/templates/django_social_share/templatetags/post_to_whatsapp.html ================================================ ================================================ FILE: django_social_share/templates/django_social_share/templatetags/save_to_pinterest.html ================================================ ================================================ FILE: django_social_share/templates/django_social_share/templatetags/send_email.html ================================================ ================================================ FILE: django_social_share/templatetags/__init__.py ================================================ ================================================ FILE: django_social_share/templatetags/social_share.py ================================================ # -*- coding: utf-8 -*- from __future__ import unicode_literals import re from django import template from django.db.models import Model from django.template.defaultfilters import urlencode from django.utils.safestring import mark_safe try: from django_bitly.templatetags.bitly import bitlify DJANGO_BITLY = True except ImportError: DJANGO_BITLY = False register = template.Library() TWITTER_ENDPOINT = 'https://twitter.com/intent/tweet?text=%s' FACEBOOK_ENDPOINT = 'https://www.facebook.com/sharer/sharer.php?u=%s' GPLUS_ENDPOINT = 'https://plus.google.com/share?url=%s' MAIL_ENDPOINT = 'mailto:?subject=%s&body=%s' LINKEDIN_ENDPOINT = 'https://www.linkedin.com/shareArticle?mini=true&title=%s&url=%s' REDDIT_ENDPOINT = 'https://www.reddit.com/submit?title=%s&url=%s' TELEGRAM_ENDPOINT = 'https://t.me/share/url?text=%s&url=%s' WHATSAPP_ENDPOINT = 'https://api.whatsapp.com/send?text=%s' PINTEREST_ENDPOINT = 'https://www.pinterest.com/pin/create/button/?url=%s' BITLY_REGEX = re.compile(r'^https?://bit\.ly/') def compile_text(context, text): ctx = template.context.Context(context) return template.Template(text).render(ctx) def _build_url(request, obj_or_url): if obj_or_url is not None: if isinstance(obj_or_url, Model): if DJANGO_BITLY: url = bitlify(obj_or_url) # type: str if not BITLY_REGEX.match(url): return request.build_absolute_uri( obj_or_url.get_absolute_url() ) else: return url else: return request.build_absolute_uri(obj_or_url.get_absolute_url()) else: return request.build_absolute_uri(obj_or_url) return '' def _compose_tweet(text, url=None): TWITTER_MAX_NUMBER_OF_CHARACTERS = 140 TWITTER_LINK_LENGTH = 23 # "A URL of any length will be altered to 23 characters, even if the link itself is less than 23 characters long. # Compute length of the tweet url_length = len(' ') + TWITTER_LINK_LENGTH if url else 0 total_length = len(text) + url_length # Check that the text respects the max number of characters for a tweet if total_length > TWITTER_MAX_NUMBER_OF_CHARACTERS: text = text[:(TWITTER_MAX_NUMBER_OF_CHARACTERS - url_length - 1)] + "…" # len("…") == 1 return "%s %s" % (text, url) if url else text @register.simple_tag(takes_context=True) def post_to_twitter_url(context, text, obj_or_url=None): text = compile_text(context, text) request = context['request'] url = _build_url(request, obj_or_url) tweet = _compose_tweet(text, url) context['tweet_url'] = TWITTER_ENDPOINT % urlencode(tweet) return context @register.inclusion_tag('django_social_share/templatetags/post_to_twitter.html', takes_context=True) def post_to_twitter(context, text, obj_or_url=None, link_text='',link_class=""): context = post_to_twitter_url(context, text, obj_or_url) request = context['request'] url = _build_url(request, obj_or_url) tweet = _compose_tweet(text, url) context['link_class'] = link_class context['link_text'] = link_text or 'Post to Twitter' context['full_text'] = tweet return context @register.simple_tag(takes_context=True) def post_to_facebook_url(context, obj_or_url=None): request = context['request'] url = _build_url(request, obj_or_url) context['facebook_url'] = FACEBOOK_ENDPOINT % urlencode(url) return context @register.inclusion_tag('django_social_share/templatetags/post_to_facebook.html', takes_context=True) def post_to_facebook(context, obj_or_url=None, link_text='',link_class=''): context = post_to_facebook_url(context, obj_or_url) context['link_class'] = link_class or '' context['link_text'] = link_text or 'Post to Facebook' return context @register.simple_tag(takes_context=True) def post_to_gplus_url(context, obj_or_url=None): request = context['request'] url = _build_url(request, obj_or_url) context['gplus_url'] = GPLUS_ENDPOINT % urlencode(url) return context @register.inclusion_tag('django_social_share/templatetags/post_to_gplus.html', takes_context=True) def post_to_gplus(context, obj_or_url=None, link_text='',link_class=''): context = post_to_gplus_url(context, obj_or_url) context['link_class'] = link_class context['link_text'] = link_text or 'Post to Google+' return context @register.simple_tag(takes_context=True) def send_email_url(context, subject, text, obj_or_url=None): text = compile_text(context, text) subject = compile_text(context, subject) request = context['request'] url = _build_url(request, obj_or_url) full_text = "%s %s" % (text, url) context['mailto_url'] = MAIL_ENDPOINT % (urlencode(subject), urlencode(full_text)) return context @register.inclusion_tag('django_social_share/templatetags/send_email.html', takes_context=True) def send_email(context, subject, text, obj_or_url=None, link_text='',link_class=''): context = send_email_url(context, subject, text, obj_or_url) context['link_class'] = link_class context['link_text'] = link_text or 'Share via email' return context @register.filter(name='linkedin_locale') def linkedin_locale(value): if "-" not in value: return value lang, country = value.split('-') return '_'.join([lang, country.upper()]) @register.simple_tag(takes_context=True) def post_to_linkedin_url(context, obj_or_url=None): request = context['request'] url = _build_url(request, obj_or_url) context['linkedin_url'] = url return context @register.inclusion_tag('django_social_share/templatetags/post_to_linkedin.html', takes_context=True) def post_to_linkedin(context, obj_or_url=None,link_class=''): context = post_to_linkedin_url(context, obj_or_url) context['link_class'] = link_class return context @register.simple_tag(takes_context=True) def post_to_reddit_url(context, title, obj_or_url=None): request = context['request'] title = compile_text(context, title) url = _build_url(request, obj_or_url) context['reddit_url'] = mark_safe(REDDIT_ENDPOINT % (urlencode(title), urlencode(url))) return context @register.inclusion_tag('django_social_share/templatetags/post_to_reddit.html', takes_context=True) def post_to_reddit(context, title, obj_or_url=None, link_text='',link_class=''): context = post_to_reddit_url(context, title, obj_or_url) context['link_class'] = link_class context['link_text'] = link_text or 'Post to Reddit' return context @register.simple_tag(takes_context=True) def post_to_telegram_url(context, title, obj_or_url): request = context['request'] title = compile_text(context, title) url = _build_url(request, obj_or_url) context['telegram_url'] = mark_safe(TELEGRAM_ENDPOINT % (urlencode(title), urlencode(url))) return context @register.inclusion_tag('django_social_share/templatetags/post_to_telegram.html', takes_context=True) def post_to_telegram(context, title, obj_or_url=None, link_text='',link_class=''): context = post_to_telegram_url(context, title, obj_or_url) context['link_class'] = link_class context['link_text'] = link_text or 'Post to Telegram' return context @register.simple_tag(takes_context=True) def post_to_whatsapp_url(context, obj_or_url=None): request = context['request'] url = _build_url(request, obj_or_url) context['whatsapp_url'] = WHATSAPP_ENDPOINT % urlencode(url) return context @register.inclusion_tag('django_social_share/templatetags/post_to_whatsapp.html', takes_context=True) def post_to_whatsapp(context, obj_or_url=None, link_text='',link_class=''): context = post_to_whatsapp_url(context, obj_or_url) context['link_class'] = link_class context['link_text'] = link_text or 'Post to WhatsApp' return context @register.simple_tag(takes_context=True) def save_to_pinterest_url(context, obj_or_url=None): request = context['request'] url = _build_url(request, obj_or_url) context['pinterest_url'] = PINTEREST_ENDPOINT % urlencode(url) return context @register.inclusion_tag('django_social_share/templatetags/save_to_pinterest.html', takes_context=True) def save_to_pinterest(context, obj_or_url=None, pin_count=False, link_class=''): context = save_to_pinterest_url(context, obj_or_url) context['link_class'] = link_class context['pin_count'] = pin_count return context @register.inclusion_tag('django_social_share/templatetags/pinterest_script.html', takes_context=False) def add_pinterest_script(): pass @register.simple_tag(takes_context=True) def copy_to_clipboard_url(context, obj_or_url=None): request = context['request'] url = _build_url(request, obj_or_url) context['copy_url'] = url return context @register.inclusion_tag('django_social_share/templatetags/copy_to_clipboard.html', takes_context=True) def copy_to_clipboard(context, obj_or_url, link_text='', link_class=''): context = copy_to_clipboard_url(context, obj_or_url) context['link_class'] = link_class context['link_text'] = link_text or 'Copy to clipboard' return context @register.inclusion_tag('django_social_share/templatetags/copy_script.html', takes_context=False) def add_copy_script(): pass ================================================ FILE: django_social_share/tests/__init__.py ================================================ from .tests import * ================================================ FILE: django_social_share/tests/runtests.py ================================================ #!/usr/bin/env python import sys import os from django.conf import settings # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) settings.configure( SITE_ID=1, DATABASES={ 'default': {'ENGINE': 'django.db.backends.sqlite3', 'NAME': ':memory;'} }, INSTALLED_APPS=[ 'django.contrib.auth', 'django.contrib.sessions', 'django.contrib.contenttypes', 'django_social_share', 'django_social_share.tests', ], TEMPLATES=[ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [ os.path.join(BASE_DIR, 'templates'), ], 'OPTIONS': { 'context_processors': [ 'django.template.context_processors.request', ], } }, ] ) def runtests(*test_args): import django try: django.setup() # Django 1.7+ except AttributeError: pass import django.test.utils runner_class = django.test.utils.get_runner(settings) test_runner = runner_class(verbosity=1, interactive=True) failures = test_runner.run_tests(['django_social_share']) sys.exit(failures) if __name__ == '__main__': runtests() ================================================ FILE: django_social_share/tests/tests.py ================================================ from django.template import Context, Template from django.test import TestCase, RequestFactory class TemplateTagsTest(TestCase): def setUp(self): self.factory = RequestFactory() self.context = Context({ 'url': 'http://example.com', 'text': 'example', 'subject': 'Example Domain', 'link_text':'', 'link_class': 'example_class', 'request': self.factory.get('/') }) def test_twitter(self): template = Template("{% load social_share %} {% post_to_twitter text url %}") result = template.render(self.context) expected = ' \n' self.assertEqual(result, expected) def test_facebook(self): template = Template("{% load social_share %} {% post_to_facebook url text %}") result = template.render(self.context) expected = ' \n' self.assertEqual(result, expected) def test_gplus(self): template = Template("{% load social_share %} {% post_to_gplus url text %}") result = template.render(self.context) expected = '
\n example\n
\n' self.assertEqual(result, expected) def test_mail_url(self): template = Template("{% load social_share %} {% send_email_url subject text url %}") template.render(self.context) expected = 'mailto:?subject=Example%20Domain&body=example%20http%3A//example.com' self.assertEqual(self.context['mailto_url'], expected) def test_mail(self): template = Template("{% load social_share %} {% send_email subject text url %}") result = template.render(self.context) expected = ' \n' self.assertEqual(result, expected) def test_linkedin(self): template = Template("{% load social_share %} {% post_to_linkedin url %}") result = template.render(self.context) expected = '
\n \n \n
\n' self.assertEqual(result, expected) def test_reddit(self): template = Template("{% load social_share %} {% post_to_reddit text url text %}") result = template.render(self.context) expected = '
\n example\n
\n' self.assertEqual(result, expected) def test_telegram(self): template = Template("{% load social_share %} {% post_to_telegram text url text %}") result = template.render(self.context) expected = '
\n example\n
\n' self.assertEqual(result, expected) def test_whatsapp(self): template = Template("{% load social_share %} {% post_to_whatsapp url text %}") result = template.render(self.context) expected = '
\n example\n
\n' self.assertEqual(result, expected) def test_pinterest(self): template = Template("{% load social_share %} {% save_to_pinterest url %}") result = template.render(self.context) expected = '
\n \n
\n' self.assertEqual(result, expected) def test_pinterest_script(self): template = Template("{% load social_share %} {% add_pinterest_script %}") result = template.render(self.context) expected = ' \n' self.assertEqual(result, expected) def test_clipboard(self): template = Template("{% load social_share %} {% copy_to_clipboard url %}") result = template.render(self.context) expected = '
\n \n
\n' self.assertEqual(result, expected) def test_twitter_with_class(self): template = Template("{% load social_share %} {% post_to_twitter text url link_text link_class %}") result = template.render(self.context) expected = ' \n' self.assertEqual(result, expected) def test_facebook_with_class(self): template = Template("{% load social_share %} {% post_to_facebook url text link_class %}") result = template.render(self.context) expected = ' \n' self.assertEqual(result, expected) def test_gplus_with_class(self): template = Template("{% load social_share %} {% post_to_gplus url text link_class %}") result = template.render(self.context) expected = '
\n example\n
\n' self.assertEqual(result, expected) def test_mail_with_class(self): template = Template("{% load social_share %} {% send_email subject text url link_text link_class %}") result = template.render(self.context) expected = ' \n' self.assertEqual(result, expected) def test_linkedin_with_class(self): template = Template("{% load social_share %} {% post_to_linkedin url link_class %}") result = template.render(self.context) expected = '
\n \n \n
\n' self.assertEqual(result, expected) def test_reddit_with_class(self): template = Template("{% load social_share %} {% post_to_reddit text url text link_class %}") result = template.render(self.context) expected = '
\n example\n
\n' self.assertEqual(result, expected) def test_telegram_with_class(self): template = Template("{% load social_share %} {% post_to_telegram text url text link_class %}") result = template.render(self.context) expected = '
\n example\n
\n' self.assertEqual(result, expected) def test_whatsapp_with_class(self): template = Template("{% load social_share %} {% post_to_whatsapp url text link_class %}") result = template.render(self.context) expected = '
\n example\n
\n' self.assertEqual(result, expected) def test_pinterest_with_class(self): template = Template("{% load social_share %} {% save_to_pinterest url False link_class %}") result = template.render(self.context) expected = '
\n \n
\n' self.assertEqual(result, expected) def test_clipboard_with_class(self): template = Template("{% load social_share %} {% copy_to_clipboard url text link_class %}") result = template.render(self.context) expected = '
\n \n
\n' self.assertEqual(result, expected) ================================================ FILE: django_social_share/views.py ================================================ # Views.py ================================================ FILE: setup.cfg ================================================ [nosetests] with-coverage = true cover-package = recommends cover-html = true cover-erase = true cover-inclusive = true [metadata] license_file = LICENSE [wheel] universal = 1 ================================================ FILE: setup.py ================================================ import io import os from setuptools import setup, find_packages here = os.path.abspath(os.path.dirname(__file__)) with io.open(os.path.join(here, 'README.rst'), encoding='utf-8') as fp: README = fp.read() with open(os.path.join(here, 'VERSION')) as version_file: version = version_file.read().strip() requirements = [] test_requirements = [ "Django>=2.0", ] setup( name="django-social-share", version=version, description="Templatetags for 'tweet this' and 'share on facebook'", long_description=README, url='https://github.com/fcurella/django-social-share', license='MIT', author='Flavio Curella', author_email='flavio.curella@curella.org', packages=find_packages(exclude=['tests']), include_package_data=True, classifiers=[ 'Development Status :: 3 - Alpha', 'Environment :: Console', 'Intended Audience :: Developers', 'Intended Audience :: Information Technology', 'License :: OSI Approved :: MIT License', 'Operating System :: OS Independent', 'Programming Language :: Python', 'Framework :: Django', ], install_requires=requirements, tests_require=test_requirements, test_suite='django_social_share.tests.runtests.runtests' )