Skip to content

Commit 23cfcbe

Browse files
committed
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 ddd9b6f
1 parent 2e07520 commit 23cfcbe

7 files changed

Lines changed: 131 additions & 2 deletions

File tree

ietf/cookies/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Copyright The IETF Trust 2010, All Rights Reserved
2+

ietf/cookies/urls.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Copyright The IETF Trust 2010, All Rights Reserved
2+
3+
from django.conf.urls.defaults import patterns
4+
from ietf.cookies import views
5+
6+
urlpatterns = patterns('',
7+
(r'^$', views.settings),
8+
(r'^new_enough/(?P<days>.*)$', views.new_enough),
9+
(r'^new_enough/', views.new_enough),
10+
(r'^expires_soon/(?P<days>.*)$', views.expires_soon),
11+
(r'^expires_soon/', views.expires_soon),
12+
)

ietf/cookies/views.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Copyright The IETF Trust 2010, All Rights Reserved
2+
3+
from django.http import HttpResponse
4+
from django.shortcuts import render_to_response as render, get_object_or_404
5+
from django.template import RequestContext
6+
7+
def settings(request, new_enough = -1, expires_soon = -1):
8+
if new_enough < 0:
9+
if "new_enough" in request.COOKIES:
10+
new_enough = int(request.COOKIES["new_enough"])
11+
else:
12+
new_enough = 14
13+
if expires_soon < 0:
14+
if "expires_soon" in request.COOKIES:
15+
expires_soon = int(request.COOKIES["expires_soon"])
16+
else:
17+
expires_soon = 14
18+
return render("cookies/settings.html",
19+
{
20+
"new_enough" : new_enough,
21+
"expires_soon" : expires_soon
22+
}, context_instance=RequestContext(request))
23+
24+
def new_enough(request, days="14"):
25+
try:
26+
days = int(days)
27+
except:
28+
days = 0
29+
if days == 0:
30+
days = 14
31+
response = settings(request, days, -1)
32+
response.set_cookie("new_enough", days)
33+
return response
34+
35+
def expires_soon(request, days="14"):
36+
try:
37+
days = int(days)
38+
except:
39+
days = 0
40+
if days == 0:
41+
days = 14
42+
response = settings(request, -1, days)
43+
response.set_cookie("expires_soon", days)
44+
return response

ietf/idtracker/templatetags/ietf_filters.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import re
1414
import datetime
1515
import types
16+
from django.template import RequestContext
1617

1718
register = template.Library()
1819

@@ -339,6 +340,22 @@ def unescape(text):
339340
text = text.replace("<br/>", "\n")
340341
return text
341342

343+
@register.filter(name='new_enough')
344+
def new_enough(x,request):
345+
if "new_enough" in request.COOKIES:
346+
days = int(request.COOKIES["new_enough"])
347+
else:
348+
days = 14
349+
return x < days
350+
351+
@register.filter(name='expires_soon')
352+
def expires_soon(x,request):
353+
if "expires_soon" in request.COOKIES:
354+
days = int(request.COOKIES["expires_soon"])
355+
else:
356+
days = 14
357+
return x > -days
358+
342359
@register.filter(name='greater_than')
343360
def greater_than(x, y):
344361
return x > int(y)
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{# Copyright The IETF Trust 2010, All Rights Reserved #}
2+
{% extends "base.html" %}
3+
{% load ietf_filters %}
4+
{% block title %}User settings{% endblock %}
5+
{% block content %}
6+
7+
<h2>Cookie settings for the ietf datatracker.</h2>
8+
9+
<p> Following settings are implemented using cookies, so if you have
10+
cookies disabled then you are not able to change the settings
11+
(everything still continues to work by using default settings).</p>
12+
13+
<table id="settings">
14+
<tr class="setting-header">
15+
<td colspan="6">
16+
<h2 class="ietf-divider">How many days is considered new</h2>
17+
</td>
18+
<tr>
19+
<tr class="setting-description">
20+
<td colspan="6">
21+
<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>
22+
</td>
23+
</tr>
24+
<tr class="settings-values">
25+
<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>
26+
<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>
27+
<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>
28+
<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>
29+
<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>
30+
<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>
31+
</tr>
32+
33+
<tr class="setting-header">
34+
<td colspan="6">
35+
<h2 class="ietf-divider">How many days is considered soon</h2>
36+
</td>
37+
<tr>
38+
<tr class="setting-description">
39+
<td colspan="6">
40+
<p>This setting tells what is considered soon when showing document which is going to be expire soon. Default setting is 14 days.</p>
41+
</td>
42+
</tr>
43+
<tr class="settings-values">
44+
<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>
45+
<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>
46+
<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>
47+
<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>
48+
<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>
49+
<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>
50+
</tr>
51+
</table>
52+
{% endblock %}
53+

ietf/templates/idrfc/date_column.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@
3232
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3333
{% endcomment %}
3434
{% load ietf_filters %}<td class="date">{% if not doc.rfc %}{{ doc.publication_date }}{% else %}{{ doc.publication_date|date:"Y-m" }}{% endif %}
35-
{% 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%}
36-
{% 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%}
35+
{% 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%}
36+
{% 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%}
3737
</td>

ietf/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
(r'^accounts/', include('ietf.ietfauth.urls')),
5656
(r'^doc/', include('ietf.idrfc.urls')),
5757
(r'^wg/', include('ietf.wginfo.urls')),
58+
(r'^cookies/', include('ietf.cookies.urls')),
5859

5960
(r'^$', 'ietf.idrfc.views.main'),
6061
(r'^admin/doc/', include('django.contrib.admindocs.urls')),

0 commit comments

Comments
 (0)