Merge pull request #1 from cypreess/master

Bugs fixes
This commit is contained in:
John Weaver 2012-10-19 17:08:27 -07:00
commit 5ada5a4305
5 changed files with 25 additions and 32 deletions

View file

@ -4,3 +4,4 @@ The following is a list of much appreciated contributors:
Daniel Greenfeld <pydanny@gmail.com>
Frank Wiles <frank@revsys.com>
Krzysztof Dorosz <cypreess@gmail.com>

View file

@ -22,6 +22,6 @@ Installation
# terms of service links
urlpatterns += patterns('',
(r'^login/$', 'tos.views.login', {}, 'login',),
(r'^terms-of-service/', include('tos.urls')),
url(r'^login/$', 'tos.views.login', {}, 'auth_login',),
url(r'^terms-of-service/', include('tos.urls')),
)

View file

@ -1 +1 @@
VERSION = (0, 1, 0)
VERSION = (0, 1, 1)

View file

@ -1,26 +1,10 @@
from django.conf.urls.defaults import *
from django.views.generic.simple import direct_to_template
from tos.models import TermsOfService
from tos.views import check_tos
from django.conf.urls import url, patterns
from tos.views import check_tos, TosView
urlpatterns = patterns('',
# Terms of Service conform
url(
regex = '^confirm/$',
view = check_tos,
name = 'tos_check_tos',
),
url(r'^confirm/$', check_tos, name='tos_check_tos'),
# Terms of service simple display
url(
regex = '^$',
view = direct_to_template,
kwargs = {'template': 'tos/tos.html',
'extra_context':{
'tos':TermsOfService.objects.get_current_tos()
},
},
name = 'tos',
),
url(r'^$', TosView.as_view(), name='tos'),
)

View file

@ -1,17 +1,29 @@
from django.views.generic import TemplateView
import re
from django.conf import settings
from django.contrib import messages
from django.contrib.auth import login as auth_login
from django.contrib.auth import REDIRECT_FIELD_NAME
from django.contrib.auth.forms import AuthenticationForm
from django.contrib.auth.models import User
from django.contrib.sites.models import Site, RequestSite
from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.views.decorators.cache import never_cache
from django.views.decorators.csrf import csrf_protect
from django.utils.translation import ugettext_lazy as _
from tos.models import has_user_agreed_latest_tos, TermsOfService, UserAgreement
class TosView(TemplateView):
template_name = "tos/tos.html"
def get_context_data(self, **kwargs):
context = super(TosView, self).get_context_data(**kwargs)
context['tos'] = TermsOfService.objects.get_current_tos()
return context
def _redirect_to(redirect_to):
""" Moved redirect_to logic here to avoid duplication in views"""
@ -31,13 +43,9 @@ def _redirect_to(redirect_to):
@never_cache
def check_tos(request, template_name='tos/tos_check.html',
redirect_field_name=REDIRECT_FIELD_NAME,):
redirect_to = _redirect_to(request.REQUEST.get(redirect_field_name, ''))
note=""
tos = TermsOfService.objects.get_current_tos()
if request.method=="POST":
if request.POST.get("accept", "") == "accept":
user = request.session['tos_user']
@ -53,12 +61,12 @@ def check_tos(request, template_name='tos/tos_check.html',
return HttpResponseRedirect(redirect_to)
else:
note="You cannot login without agreeing to the terms of this site."
messages.error(request, _(u"You cannot login without agreeing to the terms of this site."))
return render_to_response(template_name, {
'tos':tos,
'note':note,
redirect_field_name: redirect_to,
}, context_instance=RequestContext(request))