Merged [2619] from kivinen@iki.fi:

Setting user cookies, and settable expires soon and new tags
	in id/rfc list.
 - Legacy-Id: 2634
Note: SVN reference [2619] has been migrated to Git commit ddd9b6fe4d702af5e9b132621a47f59fe2f36b4e
This commit is contained in:
Henrik Levkowetz 2010-11-06 09:33:32 +00:00
parent 2e07520667
commit 23cfcbebb1
7 changed files with 131 additions and 2 deletions

2
ietf/cookies/__init__.py Normal file
View file

@ -0,0 +1,2 @@
# Copyright The IETF Trust 2010, All Rights Reserved

12
ietf/cookies/urls.py Normal file
View file

@ -0,0 +1,12 @@
# Copyright The IETF Trust 2010, All Rights Reserved
from django.conf.urls.defaults import patterns
from ietf.cookies import views
urlpatterns = patterns('',
(r'^$', views.settings),
(r'^new_enough/(?P<days>.*)$', views.new_enough),
(r'^new_enough/', views.new_enough),
(r'^expires_soon/(?P<days>.*)$', views.expires_soon),
(r'^expires_soon/', views.expires_soon),
)

44
ietf/cookies/views.py Normal file
View file

@ -0,0 +1,44 @@
# Copyright The IETF Trust 2010, All Rights Reserved
from django.http import HttpResponse
from django.shortcuts import render_to_response as render, get_object_or_404
from django.template import RequestContext
def settings(request, new_enough = -1, expires_soon = -1):
if new_enough < 0:
if "new_enough" in request.COOKIES:
new_enough = int(request.COOKIES["new_enough"])
else:
new_enough = 14
if expires_soon < 0:
if "expires_soon" in request.COOKIES:
expires_soon = int(request.COOKIES["expires_soon"])
else:
expires_soon = 14
return render("cookies/settings.html",
{
"new_enough" : new_enough,
"expires_soon" : expires_soon
}, context_instance=RequestContext(request))
def new_enough(request, days="14"):
try:
days = int(days)
except:
days = 0
if days == 0:
days = 14
response = settings(request, days, -1)
response.set_cookie("new_enough", days)
return response
def expires_soon(request, days="14"):
try:
days = int(days)
except:
days = 0
if days == 0:
days = 14
response = settings(request, -1, days)
response.set_cookie("expires_soon", days)
return response

View file

@ -13,6 +13,7 @@ except ImportError:
import re import re
import datetime import datetime
import types import types
from django.template import RequestContext
register = template.Library() register = template.Library()
@ -339,6 +340,22 @@ def unescape(text):
text = text.replace("<br/>", "\n") text = text.replace("<br/>", "\n")
return text return text
@register.filter(name='new_enough')
def new_enough(x,request):
if "new_enough" in request.COOKIES:
days = int(request.COOKIES["new_enough"])
else:
days = 14
return x < days
@register.filter(name='expires_soon')
def expires_soon(x,request):
if "expires_soon" in request.COOKIES:
days = int(request.COOKIES["expires_soon"])
else:
days = 14
return x > -days
@register.filter(name='greater_than') @register.filter(name='greater_than')
def greater_than(x, y): def greater_than(x, y):
return x > int(y) return x > int(y)

View file

@ -0,0 +1,53 @@
{# Copyright The IETF Trust 2010, All Rights Reserved #}
{% extends "base.html" %}
{% load ietf_filters %}
{% block title %}User settings{% endblock %}
{% block content %}
<h2>Cookie settings for the ietf datatracker.</h2>
<p> Following settings are implemented using cookies, so if you have
cookies disabled then you are not able to change the settings
(everything still continues to work by using default settings).</p>
<table id="settings">
<tr class="setting-header">
<td colspan="6">
<h2 class="ietf-divider">How many days is considered new</h2>
</td>
<tr>
<tr class="setting-description">
<td colspan="6">
<p>This setting affects how many days is considered new enough to get the special marking in the drafts page. Default setting is 14 days.</p>
</td>
</tr>
<tr class="settings-values">
<td>{% if new_enough|equal:"7" %}<span class="ietf-highlight-y"><a href="/cookies/new_enough/7">7 days</a></span>{%else%}<a href="/cookies/new_enough/7">7 days</a>{% endif %}</td></td>
<td>{% if new_enough|equal:"14" %}<span class="ietf-highlight-y"><a href="/cookies/new_enough/14">14 days</a></span>{%else%}<a href="/cookies/new_enough/14">14 days</a>{% endif %}</td>
<td>{% if new_enough|equal:"21" %}<span class="ietf-highlight-y"><a href="/cookies/new_enough/21">21 days</a></span>{%else%}<a href="/cookies/new_enough/21">21 days</a>{% endif %}</td>
<td>{% if new_enough|equal:"30" %}<span class="ietf-highlight-y"><a href="/cookies/new_enough/30">30 days</a></span>{%else%}<a href="/cookies/new_enough/30">30 days</a>{% endif %}</td>
<td>{% if new_enough|equal:"60" %}<span class="ietf-highlight-y"><a href="/cookies/new_enough/60">60 days</a></span>{%else%}<a href="/cookies/new_enough/60">60 days</a>{% endif %}</td>
<td>{% if new_enough|equal:"90" %}<span class="ietf-highlight-y"><a href="/cookies/new_enough/90">90 days</a></span>{%else%}<a href="/cookies/new_enough/90">90 days</a>{% endif %}</td>
</tr>
<tr class="setting-header">
<td colspan="6">
<h2 class="ietf-divider">How many days is considered soon</h2>
</td>
<tr>
<tr class="setting-description">
<td colspan="6">
<p>This setting tells what is considered soon when showing document which is going to be expire soon. Default setting is 14 days.</p>
</td>
</tr>
<tr class="settings-values">
<td>{% if expires_soon|equal:"7" %}<span class="ietf-highlight-y"><a href="/cookies/expires_soon/7">7 days</a></span>{%else%}<a href="/cookies/expires_soon/7">7 days</a>{% endif %}</td></td>
<td>{% if expires_soon|equal:"14" %}<span class="ietf-highlight-y"><a href="/cookies/expires_soon/14">14 days</a></span>{%else%}<a href="/cookies/expires_soon/14">14 days</a>{% endif %}</td>
<td>{% if expires_soon|equal:"21" %}<span class="ietf-highlight-y"><a href="/cookies/expires_soon/21">21 days</a></span>{%else%}<a href="/cookies/expires_soon/21">21 days</a>{% endif %}</td>
<td>{% if expires_soon|equal:"30" %}<span class="ietf-highlight-y"><a href="/cookies/expires_soon/30">30 days</a></span>{%else%}<a href="/cookies/expires_soon/30">30 days</a>{% endif %}</td>
<td>{% if expires_soon|equal:"60" %}<span class="ietf-highlight-y"><a href="/cookies/expires_soon/60">60 days</a></span>{%else%}<a href="/cookies/expires_soon/60">60 days</a>{% endif %}</td>
<td>{% if expires_soon|equal:"90" %}<span class="ietf-highlight-y"><a href="/cookies/expires_soon/90">90 days</a></span>{%else%}<a href="/cookies/expires_soon/90">90 days</a>{% endif %}</td>
</tr>
</table>
{% endblock %}

View file

@ -32,6 +32,6 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
{% endcomment %} {% endcomment %}
{% load ietf_filters %}<td class="date">{% if not doc.rfc %}{{ doc.publication_date }}{% else %}{{ doc.publication_date|date:"Y-m" }}{% endif %} {% load ietf_filters %}<td class="date">{% if not doc.rfc %}{{ doc.publication_date }}{% else %}{{ doc.publication_date|date:"Y-m" }}{% endif %}
{% if doc.publication_date|timesince_days|less_than:"14" %}<br/><span class="ietf-small ietf-highlight-y">{% if not doc.rfc%}<a href="http://tools.ietf.org/rfcdiff?url2={{doc.id.draft_name_and_revision}}">new</a>{%else%}new{%endif%}</span>{%endif%} {% if doc.publication_date|timesince_days|new_enough:request %}<br/><span class="ietf-small ietf-highlight-y">{% if not doc.rfc%}<a href="http://tools.ietf.org/rfcdiff?url2={{doc.id.draft_name_and_revision}}">new</a>{%else%}new{%endif%}</span>{%endif%}
{% if doc.id and doc.id.expected_expiration_date and doc.id.expected_expiration_date|timesince_days|greater_than:"-14" %}<br/><span class="ietf-small ietf-highlight-y">expires soon</span>{%endif%} {% if doc.id and doc.id.expected_expiration_date and doc.id.expected_expiration_date|timesince_days|expires_soon:request %}<br/><span class="ietf-small ietf-highlight-y">expires soon</span>{%endif%}
</td> </td>

View file

@ -55,6 +55,7 @@ urlpatterns = patterns('',
(r'^accounts/', include('ietf.ietfauth.urls')), (r'^accounts/', include('ietf.ietfauth.urls')),
(r'^doc/', include('ietf.idrfc.urls')), (r'^doc/', include('ietf.idrfc.urls')),
(r'^wg/', include('ietf.wginfo.urls')), (r'^wg/', include('ietf.wginfo.urls')),
(r'^cookies/', include('ietf.cookies.urls')),
(r'^$', 'ietf.idrfc.views.main'), (r'^$', 'ietf.idrfc.views.main'),
(r'^admin/doc/', include('django.contrib.admindocs.urls')), (r'^admin/doc/', include('django.contrib.admindocs.urls')),