Skip to content

Commit

Permalink
Removed deprecated stuff and updated docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias Lorenz committed Apr 11, 2016
1 parent 3b55f27 commit 55c9b97
Show file tree
Hide file tree
Showing 28 changed files with 203 additions and 414 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
=== 1.67 ===
=== 1.67.X ===

- prepared app for Django 1.9 and Python 3.5
- dropped support for Django<1.6
- Removed deprecated stuff and updated docs

=== 1.66.X ===

Expand Down
3 changes: 1 addition & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
A collection of things that we re-use in every Django project, such as
custom middlewares, testrunner, templates, templatetags, test mixins,
test factories etc...
custom middlewares, templates, templatetags, test mixins etc...
17 changes: 0 additions & 17 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ and applications.

**Current features**:

* A custom testrunner that uses django-nose for discovering tests and
django-coverage for automatically generating a coverage report on each test
run
* A factory for creating User objects
* TestCase mixins to ease the process of testing views via ``self.client.get``
* A JSONResponseMixin
* New generic class based view DetailViewWithPostAction which is able to
Expand Down Expand Up @@ -41,19 +37,6 @@ and applications.
* An AJAX View to display paginated comments for every possible object.
* Tools to improve django-hvad

**Coming soon**:

* View mixins to make class based views private for authenticated users
* Extensive fabfile for checking pep8 compliancy, running tests, importing
and exporting the database and locale files, dumping and loading fixtures
etc.
* Useful shell scripts to be installed on the server for various maintenance
and deployment tasks
* Smart urlpatterns to serve static and media files when you set DEBUG=False
locally, no need to setup Apache on your development machine
* A set of templates for django-registration and some partials for rendering
forms compatible with Twitter Bootstrap.

Installation
------------

Expand Down
4 changes: 0 additions & 4 deletions django_libs/constants.py

This file was deleted.

2 changes: 2 additions & 0 deletions django_libs/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ def analytics(request):
return {
'ANALYTICS_TRACKING_ID': getattr(
settings, 'ANALYTICS_TRACKING_ID', 'UA-XXXXXXX-XX'),
'ANALYTICS_DOMAIN': getattr(
settings, 'ANALYTICS_DOMAIN', 'auto')
}
68 changes: 59 additions & 9 deletions django_libs/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
import re

from django.conf import settings
from django.core.mail import mail_managers
from django.http import HttpResponseRedirect

try:
from django.middleware.common import _is_ignorable_404
except ImportError:
_is_ignorable_404 = None
from django.utils.encoding import force_text


class AjaxRedirectMiddleware(object):
Expand Down Expand Up @@ -91,7 +88,60 @@ def _redirect(self, request, secure):
return HttpResponseRedirect(newurl)


if _is_ignorable_404:
from .middleware_1_5 import * # NOQA
else:
from .middleware_1_6 import * # NOQA
class CustomBrokenLinkEmailsMiddleware(object):
"""Custom version that adds the user to the error email."""
def process_response(self, request, response):
"""
Send broken link emails for relevant 404 NOT FOUND responses.
"""
if response.status_code == 404 and not settings.DEBUG:
domain = request.get_host()
path = request.get_full_path()
referer = force_text(
request.META.get('HTTP_REFERER', ''), errors='replace')

if not self.is_ignorable_request(request, path, domain, referer):
ua = request.META.get('HTTP_USER_AGENT', '<none>')
ip = request.META.get('REMOTE_ADDR', '<none>')

user = None
if request.user and hasattr(request.user, 'email'):
user = request.user.email
content = (
"Referrer: %s\n"
"Requested URL: %s\n"
"User agent: %s\n"
"IP address: %s\n"
"User: %s\n"
) % (referer, path, ua, ip, user)
if self.is_internal_request(domain, referer):
internal = 'INTERNAL '
else:
internal = ''
mail_managers(
"Broken %slink on %s" % (
internal,
domain
),
content,
fail_silently=True)
return response

def is_internal_request(self, domain, referer):
"""
Returns True if referring URL is the same domain as current request.
"""
# Different subdomains are treated as different domains.
return bool(re.match("^https?://%s/" % re.escape(domain), referer))

def is_ignorable_request(self, request, uri, domain, referer):
"""
Returns True if the given request *shouldn't* notify the site managers.
"""
# '?' in referer is identified as search engine source
if (not referer or (not self.is_internal_request(
domain, referer) and '?' in referer)):
return True
return any(
pattern.search(uri) for pattern in settings.IGNORABLE_404_URLS)
67 changes: 0 additions & 67 deletions django_libs/middleware_1_5.py

This file was deleted.

65 changes: 0 additions & 65 deletions django_libs/middleware_1_6.py

This file was deleted.

2 changes: 1 addition & 1 deletion django_libs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(self, *args, **kwargs):
super(ColorField, self).__init__(*args, **kwargs)
self.validators.append(RegexValidator(
regex='^([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$',
message='Only RGB color model inputs allowed, like 00000',
message='Only RGB color model inputs allowed, like FF00CC',
code='nomatch'))

def formfield(self, **kwargs):
Expand Down
Empty file removed django_libs/raven/__init__.py
Empty file.
13 changes: 8 additions & 5 deletions django_libs/templates/django_libs/analytics.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<script>
var _gaq=[['_setAccount','{{ ANALYTICS_TRACKING_ID }}'],['_trackPageview']{% if anonymize_ip %},['_gat._anonymizeIp']{% endif %}];
(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];
g.src=('https:'==location.protocol?'//ssl':'//www')+'.google-analytics.com/ga.js';
s.parentNode.insertBefore(g,s)}(document,'script'));
</script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

ga('create', '{{ ANALYTICS_TRACKING_ID }}', '{{ ANALYTICS_DOMAIN }}');
ga('send', 'pageview');
</script>
9 changes: 0 additions & 9 deletions django_libs/templates/django_libs/analytics2.html

This file was deleted.

58 changes: 3 additions & 55 deletions django_libs/templatetags/libs_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from django.contrib.sites.models import Site
from django.core.urlresolvers import resolve, Resolver404
from django.db.models.fields import FieldDoesNotExist
from django.template.defaultfilters import truncatewords_html, stringfilter
from django.template.defaultfilters import stringfilter
from django.utils.encoding import force_text

from ..loaders import load_member
Expand Down Expand Up @@ -80,43 +80,6 @@ def render(self, context):
return self.original_tag(output, *self.args)


@register.tag('block_truncatewords_html')
def block_truncatewords_html(parser, token):
"""
DEPRECATED: Use block_anyfilter instead!
Allows to truncate any block of content.
This is useful when rendering other tags that generate content,
such as django-cms' ``render_placeholder`` tag, which is not available
as an assignment tag::
{% load libs_tags %}
{% block_truncatewords_html 15 %}
{% render_placeholder object.placeholder %}
{% endblocktruncatewordshtml %}
"""
bits = token.contents.split()
try:
word_count = bits[1]
except IndexError:
word_count = 15
nodelist = parser.parse(('endblocktruncatewordshtml',))
parser.delete_first_token()
return BlockTruncateWordsHtmlNode(nodelist, word_count)


class BlockTruncateWordsHtmlNode(template.Node):
def __init__(self, nodelist, word_count):
self.nodelist = nodelist
self.word_count = word_count

def render(self, context):
output = self.nodelist.render(context)
return truncatewords_html(output, self.word_count)


@register.assignment_tag
def calculate_dimensions(image, long_side, short_side):
"""Returns the thumbnail dimensions depending on the images format."""
Expand Down Expand Up @@ -233,7 +196,7 @@ def get_verbose(obj, field_name=""):
"""
if hasattr(obj, "_meta") and hasattr(obj._meta, "get_field_by_name"):
try:
return obj._meta.get_field_by_name(field_name)[0].verbose_name
return obj._meta.get_field(field_name).verbose_name
except FieldDoesNotExist:
pass
return ""
Expand Down Expand Up @@ -462,22 +425,7 @@ def is_context_variable(context, variable_name):


@register.inclusion_tag('django_libs/analytics.html')
def render_analytics_code(anonymize_ip='anonymize'):
"""
Renders the google analytics snippet.
:anonymize_ip: Use to add/refuse the anonymizeIp setting.
"""
return {
'ANALYTICS_TRACKING_ID': getattr(
settings, 'ANALYTICS_TRACKING_ID', 'UA-XXXXXXX-XX'),
'anonymize_ip': anonymize_ip,
}


@register.inclusion_tag('django_libs/analytics2.html')
def render_analytics2_code():
def render_analytics_code():
"""
Renders the new google analytics snippet.
Expand Down

0 comments on commit 55c9b97

Please sign in to comment.