Skip to content
Browse files

Removed deprecated function-based view.

  • Loading branch information...
1 parent ccf0cdd commit e05165c8db7b80d95e3db0e836dd17a81efd04bb @zsiciarz committed Oct 24, 2011
Showing with 5 additions and 135 deletions.
  1. +1 −2 envelope/tests/__init__.py
  2. +0 −14 envelope/tests/urls.py
  3. +3 −52 envelope/tests/views.py
  4. +1 −67 envelope/views.py
View
3 envelope/tests/__init__.py
@@ -1,3 +1,2 @@
from .forms import BaseContactFormTestCase, ContactFormTestCase
-from .views import ClassContactViewTestCase, FunctionContactViewTestCase
-
+from .views import ContactViewTestCase
View
14 envelope/tests/urls.py
@@ -6,7 +6,6 @@
urlpatterns = patterns('',
(r'', include('envelope.urls')),
url(r'^class_contact/', ContactView.as_view(), name='class_contact'),
- url(r'^func_contact/', 'envelope.views.contact', name='func_contact'),
url(r'^customized_class_contact/',
ContactView.as_view(
@@ -15,17 +14,4 @@
),
name='customized_class_contact'
),
-
- url(r'^customized_func_contact/',
- 'envelope.views.contact',
- kwargs={
- 'redirect_to': 'customized_func_contact',
- 'extra_context': {
- 'foo': 'bar',
- 'spam': lambda: 'eggs',
- }
- },
- name='customized_func_contact'
- ),
)
-
View
55 envelope/tests/views.py
@@ -2,24 +2,19 @@
Unit tests for ``django-envelope`` views.
"""
-import warnings
-
from django.conf import settings
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
from django.test import TestCase
from django.utils.translation import ugettext_lazy as _
-class BaseContactViewTestCase(TestCase):
+class ContactViewTestCase(TestCase):
u"""
- Base unit tests for contact form view.
-
- These test cases are common to both class-based and function-based views.
- Only the specific subclasses are imported in tests/__init__.py in order
- not to duplicate tests.
+ Unit tests for contact form view.
"""
url = reverse('envelope-contact')
+ customized_url = reverse('customized_class_contact')
def setUp(self):
self.honeypot = getattr(settings, 'HONEYPOT_FIELD_NAME', 'email2')
@@ -90,14 +85,6 @@ def test_form_successful(self):
flash_success_message = _("Thank you for your message.")
self.assertContains(response, flash_success_message)
-
-class ClassContactViewTestCase(BaseContactViewTestCase):
- u"""
- Unit tests for class-based contact form view (the default one).
- """
- url = reverse('class_contact')
- customized_url = reverse('customized_class_contact')
-
def test_custom_template(self):
u"""
You can change the default template used to render the form.
@@ -111,39 +98,3 @@ def test_custom_success_url(self):
"""
response = self.client.post(self.customized_url, self.form_data)
self.assertRedirects(response, self.customized_url)
-
-
-class FunctionContactViewTestCase(BaseContactViewTestCase):
- u"""
- Unit tests for old-style contact form view (function-based, deprecated).
- """
- url = reverse('func_contact')
- customized_url = reverse('customized_func_contact')
-
- def test_deprecation(self):
- u"""
- Function-based view is deprecated since 0.3.0.
- """
- with warnings.catch_warnings(record=True) as warns:
- warnings.filterwarnings("always",
- category=PendingDeprecationWarning)
- self.client.get(self.url)
- self.assertEqual(len(warns), 1)
-
- def test_prefilled_form_no_full_name(self):
- u"""
- No new features in function-based view - this isn't implemented.
- """
- pass
-
- def test_extra_context(self):
- u"""
- Custom context variables can be supplied to the view.
- """
- response = self.client.get(self.customized_url)
- self.assertIn('foo', response.context)
- self.assertEqual(response.context['foo'], 'bar')
- # evaluate callables
- self.assertIn('spam', response.context)
- self.assertEqual(response.context['spam'], 'eggs')
-
View
68 envelope/views.py
@@ -7,8 +7,7 @@
import logging
from django.contrib import messages
-from django.shortcuts import redirect, render_to_response
-from django.template import RequestContext
+from django.shortcuts import redirect
from django.utils.decorators import method_decorator
from django.utils.translation import ugettext_lazy as _
from django.views.generic import FormView
@@ -105,68 +104,3 @@ def dispatch(self, *args, **kwargs):
Overridden here to make decorators work.
"""
return super(ContactView, self).dispatch(*args, **kwargs)
-
-
-@check_honeypot
-def contact(request,
- form_class=ContactForm,
- template_name='envelope/contact.html',
- redirect_to=None,
- extra_context=None):
- u"""
- Contact form view (function-based).
-
- If the user is authenticated, ``sender`` and ``email`` fields are
- automatically filled with proper values.
-
- **Optional arguments:**
- * ``form_class``: Which form class to use for contact message handling.
- The default (:class:`envelope.forms.ContactForm`) is often enough,
- but you can subclass it if you want, or even replace with a totally
- custom class. The only requirement is that your custom class has a
- ``save()`` method which should send the message somewhere. Stick to
- the default, or its subclasses.
- * ``template_name``: Full name of the template which will display
- the form. By default it is "envelope/contact.html".
- * ``redirect_to``: URL of the page with some kind of a "thank you
- for your feedback", displayed after the form is successfully
- submitted. If left unset, the view redirects to itself.
- * ``extra_context``: A dictionary of values to add to template context.
-
- .. deprecated:: 0.3.0
- """
- import warnings
- warnings.warn("envelope.views.contact is deprecated, use the ContactView class instead", PendingDeprecationWarning)
- if extra_context is None:
- extra_context = {}
- if request.method == 'POST':
- form = form_class(request.POST)
- if form.is_valid():
- form.save()
- messages.info(request,
- _("Thank you for your message."),
- fail_silently=True)
- if redirect_to is None:
- redirect_to = request.get_full_path()
- return redirect(redirect_to)
- else:
- messages.error(request,
- _("There was en error in the contact form."),
- fail_silently=True)
- else:
- if request.user.is_authenticated():
- initial = {
- 'sender': '%s (%s)' % (request.user.username,
- request.user.get_full_name()),
- 'email': request.user.email,
- }
- form = form_class(initial=initial)
- else:
- form = form_class()
- dictionary = {'form': form}
- for key, value in extra_context.items():
- dictionary[key] = callable(value) and value() or value
- return render_to_response(template_name,
- dictionary,
- context_instance=RequestContext(request))
-

0 comments on commit e05165c

Please sign in to comment.
Something went wrong with that request. Please try again.