Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactoring the Entry.short_url property
- Loading branch information
1 parent
b515dd6
commit 46bcd16
Showing
7 changed files
with
61 additions
and
12 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
"""Url shortener for Zinnia""" | ||
import warnings | ||
|
||
from django.utils.importlib import import_module | ||
from django.core.exceptions import ImproperlyConfigured | ||
|
||
from zinnia.settings import URL_SHORTENER_BACKEND | ||
from zinnia.url_shortener.backends.default import backend as default_backend | ||
|
||
|
||
def get_url_shortener(): | ||
"""Return the selected url shortener backend""" | ||
try: | ||
backend_module = import_module(URL_SHORTENER_BACKEND) | ||
backend = getattr(backend_module, 'backend') | ||
except (ImportError, AttributeError): | ||
warnings.warn('%s backend cannot be imported' % URL_SHORTENER_BACKEND, | ||
RuntimeWarning) | ||
backend = default_backend | ||
except ImproperlyConfigured, e: | ||
warnings.warn(str(e), RuntimeWarning) | ||
backend = default_backend | ||
|
||
return backend |
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 @@ | ||
"""Shortlink backends for Zinnia""" |
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,20 @@ | ||
"""Bit.ly url shortener backend for Zinnia""" | ||
from django.conf import settings | ||
from django.core.exceptions import ImproperlyConfigured | ||
|
||
try: | ||
from django_bitly.models import Bittle | ||
except ImportError: | ||
raise ImproperlyConfigured('django_bitly is not available') | ||
|
||
if not getattr(settings, 'BITLY_LOGIN', ''): | ||
raise ImproperlyConfigured('You have to set a BITLY_LOGIN setting') | ||
|
||
if not getattr(settings, 'BITLY_API_KEY', ''): | ||
raise ImproperlyConfigured('You have to set a BITLY_API_KEY setting') | ||
|
||
|
||
def backend(entry): | ||
"""Bit.ly url shortener backend for Zinnia""" | ||
bittle = Bittle.objects.bitlify(entry) | ||
return bittle.shortUrl |
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,11 @@ | ||
"""Default url shortener backend for Zinnia""" | ||
from django.contrib.sites.models import Site | ||
from django.core.urlresolvers import reverse | ||
|
||
from zinnia.settings import PROTOCOL | ||
|
||
|
||
def backend(entry): | ||
"""Default url shortener backend for Zinnia""" | ||
return '%s://%s%s' % (PROTOCOL, Site.objects.get_current().domain, | ||
reverse('zinnia_entry_shortlink', args=[entry.pk])) |