-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshortcuts.py
43 lines (35 loc) · 1.09 KB
/
shortcuts.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from django.core.mail import send_mail
from django.template import loader, Context
from datetime import *
def template_mail(title,template,context,addr_from,addr_to,fail_silently=False):
template = loader.get_template(template)
context = Context(context)
send_mail(
title,
template.render(context),
addr_from,
addr_to,
fail_silently=fail_silently)
def pair_map(f,list):
vals = []
for item in list:
vals.append((item,f(item)))
return vals
def current_year():
from compsoc.memberinfo.models import Term
return Term.objects.filter(start_number=1).order_by('start_date').reverse()[0].start_date.year
def get(tuples,key):
for (s,l) in tuples:
if s == key:
return l
raise ValueError
notime = time(0,0,0)
def begin_week(of):
try:
return datetime.combine((of - timedelta(days=of.weekday())).date(),notime)
except AttributeError:
return of - timedelta(days=of.weekday())
def flatten(list):
return map(lambda (x,):x,list)
def path_processor(request):
return {'path': request.path}