# HG changeset patch # User Brian Neal # Date 1451164255 21600 # Node ID e932f2ecd4a79b745a2e9d1d357848a5976359bb # Parent e1c03da72818623887decc3519398422937a55b0 Django 1.8 warnings / tech debt cleanup. diff -r e1c03da72818 -r e932f2ecd4a7 accounts/urls.py --- a/accounts/urls.py Sun Dec 20 22:18:59 2015 -0600 +++ b/accounts/urls.py Sat Dec 26 15:10:55 2015 -0600 @@ -29,7 +29,8 @@ url(r'^password/$', auth_views.password_change, {'template_name': 'accounts/password_change.html', - 'post_change_redirect': settings.LOGIN_REDIRECT_URL}), + 'post_change_redirect': settings.LOGIN_REDIRECT_URL}, + name='accounts-password_change'), url(r'^password/reset/$', auth_views.password_reset, kwargs={'template_name': 'accounts/password_reset.html', diff -r e1c03da72818 -r e932f2ecd4a7 antispam/views.py --- a/antispam/views.py Sun Dec 20 22:18:59 2015 -0600 +++ b/antispam/views.py Sat Dec 26 15:10:55 2015 -0600 @@ -1,7 +1,6 @@ """Views for the antispam application.""" -from django.shortcuts import render_to_response -from django.template import RequestContext +from django.shortcuts import render def suspended(request): @@ -10,7 +9,6 @@ """ is_active = request.user.is_active - return render_to_response('antispam/suspended.html', { + return render(request, 'antispam/suspended.html', { 'is_active': is_active, - }, - context_instance = RequestContext(request)) + }) diff -r e1c03da72818 -r e932f2ecd4a7 comments/templatetags/comment_tags.py --- a/comments/templatetags/comment_tags.py Sun Dec 20 22:18:59 2015 -0600 +++ b/comments/templatetags/comment_tags.py Sat Dec 26 15:10:55 2015 -0600 @@ -117,38 +117,9 @@ return GetCommentFormNode(obj, var) -class RenderCommentFormNode(template.Node): - def __init__(self, obj): - self.object = template.Variable(obj) - - def render(self, context): - object = self.object.resolve(context) - context.push() - form_str = render_to_string('comments/comment_form.html', { - 'form': CommentForm(object), - }, - context) - context.pop() - return form_str - - -@register.tag -def render_comment_form(parser, token): - """ - Renders a comment form for the specified object using the template - comments/comment_form.html. - Syntax: - {% render_comment_form for [object] %} - """ - try: - (tag, for_word, obj) = token.split_contents() - except ValueError: - raise template.TemplateSyntaxError, "%r tag requires exactly 2 arguments" % token.contents.split()[0] - - if for_word != 'for': - raise template.TemplateSyntaxError("First argument in %r tag must be 'for'" % tag) - - return RenderCommentFormNode(obj) +@register.inclusion_tag('comments/comment_form.html') +def render_comment_form(user, obj): + return {'user': user, 'form': CommentForm(obj)} @register.inclusion_tag('comments/comment_list.html') diff -r e1c03da72818 -r e932f2ecd4a7 comments/views.py --- a/comments/views.py Sun Dec 20 22:18:59 2015 -0600 +++ b/comments/views.py Sat Dec 26 15:10:55 2015 -0600 @@ -8,8 +8,7 @@ from django.http import HttpResponseBadRequest from django.http import HttpResponseForbidden from django.db.models import get_model -from django.shortcuts import render_to_response -from django.template import RequestContext +from django.shortcuts import render from django.utils.html import escape from django.views.decorators.http import require_POST @@ -99,10 +98,9 @@ comment.save(html=form.comment_html) # return the rendered comment - return render_to_response('comments/comment.html', { + return render(request, 'comments/comment.html', { 'comment': comment, - }, - context_instance = RequestContext(request)) + }) @require_POST @@ -155,7 +153,6 @@ except ImageCheckError as ex: html = PREVIEW_UNAVAILABLE.format(ex) - return render_to_response('comments/markdown_preview.html', { + return render(request, 'comments/markdown_preview.html', { 'data': html, - }, - context_instance = RequestContext(request)) + }) diff -r e1c03da72818 -r e932f2ecd4a7 core/functions.py --- a/core/functions.py Sun Dec 20 22:18:59 2015 -0600 +++ b/core/functions.py Sat Dec 26 15:10:55 2015 -0600 @@ -10,7 +10,7 @@ from django.conf import settings import django.core.mail -import core.tasks +from .tasks import send_mail as send_mail_task class TemporaryFile(object): @@ -70,7 +70,7 @@ } if defer: - core.tasks.send_mail.delay(**msg_kwargs) + send_mail_task.delay(**msg_kwargs) else: msg = django.core.mail.EmailMessage(**msg_kwargs) msg.send() diff -r e1c03da72818 -r e932f2ecd4a7 core/views.py --- a/core/views.py Sun Dec 20 22:18:59 2015 -0600 +++ b/core/views.py Sat Dec 26 15:10:55 2015 -0600 @@ -7,7 +7,7 @@ from django.contrib.auth.models import User from django.http import HttpResponse -from django.shortcuts import render_to_response +from django.shortcuts import render from django.contrib.auth.decorators import login_required from django.views.decorators.http import require_GET from django.views.generic import TemplateView @@ -21,7 +21,7 @@ to be called via AJAX. """ - return render_to_response('core/markdown_help.html') + return render(request, 'core/markdown_help.html') def ajax_users(request): diff -r e1c03da72818 -r e932f2ecd4a7 custom_search/views.py --- a/custom_search/views.py Sun Dec 20 22:18:59 2015 -0600 +++ b/custom_search/views.py Sat Dec 26 15:10:55 2015 -0600 @@ -1,7 +1,7 @@ """Custom views for searching.""" import logging -from django.shortcuts import render_to_response +from django.shortcuts import render from haystack.views import SearchView from xapian import QueryParserError @@ -46,8 +46,7 @@ } context.update(self.extra_context()) - return render_to_response(self.template, context, - context_instance=self.context_class(self.request)) + return render(self.request, self.template, context) def extra_context(self): return { diff -r e1c03da72818 -r e932f2ecd4a7 forums/templatetags/forum_tags.py --- a/forums/templatetags/forum_tags.py Sun Dec 20 22:18:59 2015 -0600 +++ b/forums/templatetags/forum_tags.py Sat Dec 26 15:10:55 2015 -0600 @@ -88,11 +88,14 @@ @register.simple_tag -def forum_date(date, user, long_format=True): +def forum_date(date, user, long_format=True, none_date_retval=u'Never'): """ This tag displays an arbitrary datetime, adjusted by the user's time zone preferences. """ + if date is None: + return none_date_retval + fmt_index = 0 if long_format else 1 date = SERVER_TZ.localize(date) diff -r e1c03da72818 -r e932f2ecd4a7 forums/views/favorites.py --- a/forums/views/favorites.py Sun Dec 20 22:18:59 2015 -0600 +++ b/forums/views/favorites.py Sat Dec 26 15:10:55 2015 -0600 @@ -5,8 +5,7 @@ from django.core.urlresolvers import reverse from django.views.decorators.http import require_POST from django.shortcuts import get_object_or_404 -from django.shortcuts import render_to_response -from django.template import RequestContext +from django.shortcuts import render from django.http import HttpResponseRedirect from django.http import HttpResponseForbidden from django.http import Http404 @@ -63,23 +62,23 @@ except InvalidPage: raise Http404 - return render_to_response('forums/manage_topics.html', { + return render(request, 'forums/manage_topics.html', { 'page_title': 'Favorite Topics', 'description': 'Your favorite topics are listed below.', 'page': page, - }, - context_instance=RequestContext(request)) + }) + @login_required def favorites_status(request, topic_id): """Display the favorite status for the given topic.""" topic = get_object_or_404(Topic.objects.select_related(), id=topic_id) is_favorite = request.user in topic.bookmarkers.all() - return render_to_response('forums/favorite_status.html', { + return render(request, 'forums/favorite_status.html', { 'topic': topic, 'is_favorite': is_favorite, - }, - context_instance=RequestContext(request)) + }) + @login_required @require_POST diff -r e1c03da72818 -r e932f2ecd4a7 forums/views/spam.py --- a/forums/views/spam.py Sun Dec 20 22:18:59 2015 -0600 +++ b/forums/views/spam.py Sat Dec 26 15:10:55 2015 -0600 @@ -9,8 +9,7 @@ from django.core.urlresolvers import reverse from django.http import HttpResponseRedirect from django.shortcuts import get_object_or_404 -from django.shortcuts import render_to_response -from django.template import RequestContext +from django.shortcuts import render from django.contrib.auth.models import User from forums.models import Post @@ -66,12 +65,11 @@ return HttpResponseRedirect(reverse('forums-spammer_nailed', args=[ poster.id])) - return render_to_response('forums/spammer.html', { + return render(request, 'forums/spammer.html', { 'can_moderate': can_moderate, 'can_deactivate': can_deactivate, 'post': post, - }, - context_instance=RequestContext(request)) + }) @login_required @@ -84,11 +82,10 @@ success = not user.is_active and profile.status == bio.models.STA_SPAMMER - return render_to_response('forums/spammer_nailed.html', { + return render(request, 'forums/spammer_nailed.html', { 'spammer': user, 'success': success, - }, - context_instance=RequestContext(request)) + }) @login_required @@ -111,9 +108,8 @@ return HttpResponseRedirect(post.get_absolute_url()) - return render_to_response('forums/stranger.html', { + return render(request, 'forums/stranger.html', { 'can_moderate': can_moderate, 'can_promote': can_promote, 'post': post, - }, - context_instance=RequestContext(request)) + }) diff -r e1c03da72818 -r e932f2ecd4a7 forums/views/subscriptions.py --- a/forums/views/subscriptions.py Sun Dec 20 22:18:59 2015 -0600 +++ b/forums/views/subscriptions.py Sat Dec 26 15:10:55 2015 -0600 @@ -8,8 +8,7 @@ from django.http import Http404 from django.template.loader import render_to_string from django.shortcuts import get_object_or_404 -from django.shortcuts import render_to_response -from django.template import RequestContext +from django.shortcuts import render from django.views.decorators.http import require_POST from forums.models import Topic @@ -75,11 +74,10 @@ """Display the subscription status for the given topic.""" topic = get_object_or_404(Topic.objects.select_related(), id=topic_id) is_subscribed = request.user in topic.subscribers.all() - return render_to_response('forums/subscription_status.html', { + return render(request, 'forums/subscription_status.html', { 'topic': topic, 'is_subscribed': is_subscribed, - }, - context_instance=RequestContext(request)) + }) @login_required @@ -114,9 +112,8 @@ except InvalidPage: raise Http404 - return render_to_response('forums/manage_topics.html', { + return render(request, 'forums/manage_topics.html', { 'page_title': 'Topic Subscriptions', 'description': 'The forum topics you are currently subscribed to are listed below.', 'page': page, - }, - context_instance=RequestContext(request)) + }) diff -r e1c03da72818 -r e932f2ecd4a7 news/views.py --- a/news/views.py Sun Dec 20 22:18:59 2015 -0600 +++ b/news/views.py Sat Dec 26 15:10:55 2015 -0600 @@ -4,7 +4,6 @@ import datetime from django.conf import settings -from django.template import RequestContext from django.template.loader import render_to_string from django.http import HttpResponseRedirect from django.contrib.auth.decorators import login_required diff -r e1c03da72818 -r e932f2ecd4a7 podcast/models.py --- a/podcast/models.py Sun Dec 20 22:18:59 2015 -0600 +++ b/podcast/models.py Sat Dec 26 15:10:55 2015 -0600 @@ -4,14 +4,15 @@ """ import datetime +from django.core.urlresolvers import reverse from django.db import models -EXPLICIT_CHOICES = ( - ('yes', 'Yes'), - ('no', 'No'), - ('clean', 'Clean'), - ) +EXPLICIT_CHOICES = [ + ('yes', 'Yes'), + ('no', 'No'), + ('clean', 'Clean'), +] class Channel(models.Model): @@ -53,15 +54,14 @@ explicit = models.CharField(max_length=8, choices=EXPLICIT_CHOICES) update_date = models.DateTimeField(db_index=True, blank=True) - @models.permalink def get_absolute_url(self): - return ('podcast.views.detail', [str(self.id)]) + return reverse('podcast-detail', args=[str(self.id)]) def __unicode__(self): return self.title class Meta: - ordering = ('-pubdate', ) + ordering = ['-pubdate'] verbose_name = 'podcast' verbose_name_plural = 'podcasts' diff -r e1c03da72818 -r e932f2ecd4a7 podcast/views.py --- a/podcast/views.py Sun Dec 20 22:18:59 2015 -0600 +++ b/podcast/views.py Sat Dec 26 15:10:55 2015 -0600 @@ -6,8 +6,7 @@ import os.path from urlparse import urlparse -from django.shortcuts import render_to_response -from django.template import RequestContext +from django.shortcuts import render from django.shortcuts import get_object_or_404 from podcast.models import Channel @@ -61,10 +60,9 @@ except Channel.DoesNotExist: channel = None - return render_to_response('podcast/index.html', { + return render(request, 'podcast/index.html', { 'channel': channel, - }, - context_instance = RequestContext(request)) + }) def detail(request, id): @@ -78,15 +76,14 @@ jplayer_media, jplayer_supplied = jplayer_params(ext, podcast.enclosure_url, alt_ext, podcast.alt_enclosure_url) - return render_to_response('podcast/detail.html', { + return render(request, 'podcast/detail.html', { 'channel': podcast.channel, 'podcast': podcast, 'ext': ext, 'alt_ext': alt_ext, 'jplayer_media': jplayer_media, 'jplayer_supplied': jplayer_supplied, - }, - context_instance = RequestContext(request)) + }) def feed(request): @@ -98,7 +95,6 @@ if channel: channel.items = Item.objects.filter(channel=channel) - return render_to_response('podcast/feed.xml', { + return render(request, 'podcast/feed.xml', { 'channel': channel, - }, - context_instance = RequestContext(request)) + }) diff -r e1c03da72818 -r e932f2ecd4a7 potd/views.py --- a/potd/views.py Sun Dec 20 22:18:59 2015 -0600 +++ b/potd/views.py Sat Dec 26 15:10:55 2015 -0600 @@ -2,9 +2,8 @@ Views for the POTD application. """ -from django.shortcuts import render_to_response +from django.shortcuts import render from django.shortcuts import get_object_or_404 -from django.template import RequestContext from potd.models import Current from potd.models import Photo @@ -12,16 +11,15 @@ def view(request): potd = Current.objects.get_current_photo() - return render_to_response('potd/view.html', { + return render(request, 'potd/view.html', { 'potd': potd, 'is_current': True, - }, - context_instance = RequestContext(request)) + }) + def archive(request, id): photo = get_object_or_404(Photo, pk=id) - return render_to_response('potd/view.html', { + return render(request, 'potd/view.html', { 'potd': photo, 'is_current': False, - }, - context_instance = RequestContext(request)) + }) diff -r e1c03da72818 -r e932f2ecd4a7 sg101/templates/bio/view_profile.html --- a/sg101/templates/bio/view_profile.html Sun Dec 20 22:18:59 2015 -0600 +++ b/sg101/templates/bio/view_profile.html Sat Dec 26 15:10:55 2015 -0600 @@ -90,8 +90,8 @@ Upload Photo
  • Edit Links Edit Elsewhere Links
  • -
  • Change Password - Change Password
  • +
  • Change Password + Change Password
  • {% else %} {% if user.is_authenticated %} diff -r e1c03da72818 -r e932f2ecd4a7 sg101/templates/contests/contest_detail.html --- a/sg101/templates/contests/contest_detail.html Sun Dec 20 22:18:59 2015 -0600 +++ b/sg101/templates/contests/contest_detail.html Sat Dec 26 15:10:55 2015 -0600 @@ -87,7 +87,7 @@ {% render_comment_list contest %} {% if contest.is_active %}

    Leave a comment?

    -{% render_comment_form for contest %} +{% render_comment_form user contest %} {% else %}

    Comments are closed for this contest. If you'd like to share your thoughts on this contest with the site staff, you can contact us directly.

    diff -r e1c03da72818 -r e932f2ecd4a7 sg101/templates/downloads/download_detail.html --- a/sg101/templates/downloads/download_detail.html Sun Dec 20 22:18:59 2015 -0600 +++ b/sg101/templates/downloads/download_detail.html Sat Dec 26 15:10:55 2015 -0600 @@ -27,5 +27,5 @@

    This download has {{ comment_count }} comment{{ comment_count|pluralize }}.


    {% render_comment_list download %} -{% render_comment_form for download %} +{% render_comment_form user download %} {% endblock %} diff -r e1c03da72818 -r e932f2ecd4a7 sg101/templates/messages/inbox.html --- a/sg101/templates/messages/inbox.html Sun Dec 20 22:18:59 2015 -0600 +++ b/sg101/templates/messages/inbox.html Sat Dec 26 15:10:55 2015 -0600 @@ -21,7 +21,7 @@ {% for msg in page.object_list %} - + {{ msg.sender.username }} {% for msg in page.object_list %} - + {{ msg.receiver.username }} {% for msg in page.object_list %} - + {{ msg.sender.username }} - + {{ msg.receiver.username }} Leave a comment?

    -{% render_comment_form for story %} +{% render_comment_form user story %} {% else %}

    Comments are closed for this story. If you'd like to share your thoughts on this story with the site staff, you can contact us directly.

    diff -r e1c03da72818 -r e932f2ecd4a7 sg101/templates/podcast/detail.html --- a/sg101/templates/podcast/detail.html Sun Dec 20 22:18:59 2015 -0600 +++ b/sg101/templates/podcast/detail.html Sat Dec 26 15:10:55 2015 -0600 @@ -30,7 +30,7 @@ {% endblock %} {% block podcast-content %}

    {{ podcast.pubdate|date:"F d, Y" }} • {{ podcast.title }}

    {{ podcast.subtitle }}

    diff -r e1c03da72818 -r e932f2ecd4a7 sg101/templates/polls/poll_detail.html --- a/sg101/templates/polls/poll_detail.html Sun Dec 20 22:18:59 2015 -0600 +++ b/sg101/templates/polls/poll_detail.html Sat Dec 26 15:10:55 2015 -0600 @@ -55,7 +55,7 @@ {% render_comment_list poll %} {% if poll.is_open %}

    Leave a comment?

    -{% render_comment_form for poll %} +{% render_comment_form user poll %} {% else %}

    Comments are closed for this poll. If you'd like to share your thoughts on this poll with the site staff, you can contact us directly.

    diff -r e1c03da72818 -r e932f2ecd4a7 sg101/templates/potd/view.html --- a/sg101/templates/potd/view.html Sun Dec 20 22:18:59 2015 -0600 +++ b/sg101/templates/potd/view.html Sat Dec 26 15:10:55 2015 -0600 @@ -45,7 +45,7 @@ {% render_comment_list potd %} {% if potd.can_comment_on %}

    Leave a comment?

    -{% render_comment_form for potd %} +{% render_comment_form user potd %}
    {% else %}

    Comments are allowed only on today's photo of the day. If you'd like to share your thoughts on this photo diff -r e1c03da72818 -r e932f2ecd4a7 shoutbox/views.py --- a/shoutbox/views.py Sun Dec 20 22:18:59 2015 -0600 +++ b/shoutbox/views.py Sat Dec 26 15:10:55 2015 -0600 @@ -3,13 +3,11 @@ """ import re -from django.shortcuts import render_to_response -from django.template import RequestContext +from django.shortcuts import render from django.core.paginator import InvalidPage from django.http import HttpResponse from django.http import HttpResponseBadRequest from django.http import HttpResponseForbidden -from django.http import HttpResponseRedirect from django.http import Http404 from django.contrib.auth.decorators import login_required from django.views.decorators.http import require_POST @@ -17,7 +15,6 @@ from core.paginator import DiggPaginator from core.functions import email_admins from core.functions import get_page -from shoutbox.forms import ShoutBoxForm from shoutbox.models import Shout from shoutbox.models import ShoutFlag @@ -32,10 +29,9 @@ shout = Shout(user=request.user, shout=msg) shout.save() - return render_to_response('shoutbox/shout.html', { + return render(request, 'shoutbox/shout.html', { 'shout': shout, - }, - context_instance = RequestContext(request)) + }) def view_shout(request, id): @@ -43,13 +39,11 @@ try: shout = Shout.objects.get(pk=id) except Shout.DoesNotExist: - return render_to_response('shoutbox/missing_shout.html', {}, - context_instance = RequestContext(request)) + return render(request, 'shoutbox/missing_shout.html') - return render_to_response('shoutbox/view_shout.html', { + return render(request, 'shoutbox/view_shout.html', { 'shout': shout, - }, - context_instance = RequestContext(request)) + }) def view_history(request): @@ -63,10 +57,9 @@ except InvalidPage: raise Http404 - return render_to_response('shoutbox/view.html', { + return render(request, 'shoutbox/view.html', { 'page': the_page, - }, - context_instance = RequestContext(request)) + }) shout_id_re = re.compile(r'shout-(\d+)') @@ -153,5 +146,3 @@ """) return HttpResponse('The shout was flagged. A moderator will review the shout shortly. ' \ 'Thanks for helping to improve the quality of this site.') - -# vim: ts=4 sw=4 diff -r e1c03da72818 -r e932f2ecd4a7 smiley/views.py --- a/smiley/views.py Sun Dec 20 22:18:59 2015 -0600 +++ b/smiley/views.py Sat Dec 26 15:10:55 2015 -0600 @@ -1,8 +1,7 @@ """ Views for the Smiley application. """ -from django.shortcuts import render_to_response -from django.template import RequestContext +from django.shortcuts import render from django.contrib.auth.decorators import login_required from django.views.decorators.http import require_GET @@ -11,8 +10,6 @@ @login_required @require_GET def farm(request, extra=False): - return render_to_response('smiley/smiley_farm.html', { + return render(request, 'smiley/smiley_farm.html', { 'smilies': Smiley.objects.get_smilies(extra), - }, - context_instance = RequestContext(request)) - + }) diff -r e1c03da72818 -r e932f2ecd4a7 weblinks/views.py --- a/weblinks/views.py Sun Dec 20 22:18:59 2015 -0600 +++ b/weblinks/views.py Sat Dec 26 15:10:55 2015 -0600 @@ -3,8 +3,7 @@ """ import random -from django.shortcuts import render_to_response -from django.template import RequestContext +from django.shortcuts import render from django.core.paginator import InvalidPage from django.http import HttpResponse from django.http import HttpResponseBadRequest @@ -35,11 +34,10 @@ def link_index(request): categories = Category.objects.all() total_links = Link.public_objects.all().count() - return render_to_response('weblinks/index.html', { + return render(request, 'weblinks/index.html', { 'categories': categories, 'total_links': total_links, - }, - context_instance = RequestContext(request)) + }) ####################################################################### @@ -52,11 +50,10 @@ except InvalidPage: raise Http404 - return render_to_response('weblinks/link_summary.html', { + return render(request, 'weblinks/link_summary.html', { 'page': the_page, 'title': 'Newest Links', - }, - context_instance = RequestContext(request)) + }) ####################################################################### @@ -68,11 +65,10 @@ the_page = paginator.page(page) except InvalidPage: raise Http404 - return render_to_response('weblinks/link_summary.html', { + return render(request, 'weblinks/link_summary.html', { 'page': the_page, 'title': 'Popular Links', - }, - context_instance = RequestContext(request)) + }) ####################################################################### @@ -92,18 +88,15 @@ else: add_form = AddLinkForm() - return render_to_response('weblinks/add_link.html', { + return render(request, 'weblinks/add_link.html', { 'add_form': add_form, - }, - context_instance = RequestContext(request)) + }) ####################################################################### @login_required def add_thanks(request): - return render_to_response('weblinks/add_link.html', { - }, - context_instance = RequestContext(request)) + return render(request, 'weblinks/add_link.html') ####################################################################### @@ -135,12 +128,11 @@ except InvalidPage: raise Http404 - return render_to_response('weblinks/view_links.html', { + return render(request, 'weblinks/view_links.html', { 's' : sort, 'category' : cat, 'page' : the_page, - }, - context_instance = RequestContext(request)) + }) ####################################################################### @@ -193,7 +185,6 @@ link = get_object_or_404(Link, pk=id) if not link.is_public: raise Http404 - return render_to_response('weblinks/link_detail.html', { + return render(request, 'weblinks/link_detail.html', { 'link': link, - }, - context_instance = RequestContext(request)) + })