mirror of
https://github.com/Hopiu/django-tos.git
synced 2026-03-16 20:10:24 +00:00
This commit fixes bug:
1) in urls a view "tos" has context object evaluated only in a runtime. This means that even if tos was changed, the "tos" view shows always the same old tos object.
2) check_tos view uses now messages framework instead of {{note}}
3) Support for translation in "you cannot login..." message added
The following code was tested with django 1.4 and it is reported to work well.
This commit is contained in:
parent
094f24f4cd
commit
2b3efcfcb0
2 changed files with 21 additions and 29 deletions
24
tos/urls.py
24
tos/urls.py
|
|
@ -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'),
|
||||
)
|
||||
26
tos/views.py
26
tos/views.py
|
|
@ -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))
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue