-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathfilter.py
55 lines (45 loc) · 1.46 KB
/
filter.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
44
45
46
47
48
49
50
51
52
53
54
55
# coding: utf-8
import re
import markdown as Markdown
from jinja2.utils import urlize, escape
import urllib, hashlib
def markdown(value):
return Markdown.markdown(value)
def md_body(value):
value = urlize(value,32,True)
return markdown(value)
def tags_name_tag(tags,limit = 0):
html = []
if not tags: return ""
if limit > 0:
tags = tags[0:limit]
for tag in tags:
html.append('<a class="tag" href="/tag/%s">%s</a>' % (tag,tag))
return ",".join(html)
def user_name_tag(user):
return '<a href="/%s" class="user">%s</a>' % (user.login,user.name)
def strftime(value, type='normal'):
if type == 'normal':
format="%Y-%m-%d %H:%M"
elif type == 'long':
format="%Y-%m-%d %H:%M:%S"
else:
format="%m-%d %H:%M"
return value.strftime(format)
def strfdate(value,type='normal'):
if type == 'normal':
format="%Y-%m-%d"
elif type == "long":
format="%Y-%m-%d"
else:
format="%m-%d"
return value.strftime(format)
# check value is in list
def inlist(value,list):
if list.count(value) > 0:
return True
return false
def avatar(user, size = 40):
gravatar_url = "http://www.gravatar.com/avatar/" + hashlib.md5(user.email).hexdigest() + "?"
gravatar_url += urllib.urlencode({'s':str(size)})
return "<a href=\"/%s\" class=\"avatar\"><img src=\"%s\" style=\"width:%dpx;\" title=\"%s\" /></a>" % (user.login,gravatar_url,size,user.name)