|
a/Allura/allura/lib/helpers.py |
|
b/Allura/allura/lib/helpers.py |
|
... |
|
... |
4 |
import difflib
|
4 |
import difflib
|
5 |
import urllib
|
5 |
import urllib
|
6 |
import re
|
6 |
import re
|
7 |
import json
|
7 |
import json
|
8 |
import logging
|
8 |
import logging
|
|
|
9 |
import cPickle as pickle
|
9 |
from hashlib import sha1
|
10 |
from hashlib import sha1
|
10 |
from datetime import datetime
|
11 |
from datetime import datetime
|
11 |
|
12 |
|
12 |
import tg
|
13 |
import tg
|
13 |
import genshi.template
|
14 |
import genshi.template
|
|
... |
|
... |
24 |
|
25 |
|
25 |
from webhelpers import date, feedgenerator, html, number, misc, text
|
26 |
from webhelpers import date, feedgenerator, html, number, misc, text
|
26 |
|
27 |
|
27 |
from pymongo import bson
|
28 |
from pymongo import bson
|
28 |
|
29 |
|
|
|
30 |
from ming.orm import state
|
|
|
31 |
|
29 |
from allura.lib import exceptions as exc
|
32 |
from allura.lib import exceptions as exc
|
30 |
# Reimport to make available to templates
|
33 |
# Reimport to make available to templates
|
31 |
from .security import has_neighborhood_access, has_project_access, has_artifact_access
|
34 |
from .security import has_neighborhood_access, has_project_access, has_artifact_access
|
32 |
|
35 |
|
33 |
re_path_portion = re.compile(r'^[a-z][-a-z0-9]{2,}$')
|
36 |
re_path_portion = re.compile(r'^[a-z][-a-z0-9]{2,}$')
|
34 |
|
37 |
|
35 |
def monkeypatch(obj):
|
38 |
def monkeypatch(obj):
|
36 |
def patchit(func):
|
39 |
def patchit(func):
|
37 |
setattr(obj, func.__name__, func)
|
40 |
setattr(obj, func.__name__, func)
|
38 |
return patchit
|
41 |
return patchit
|
|
|
42 |
|
|
|
43 |
def site_style_link(neighborhood=None):
|
|
|
44 |
from allura import model as M
|
|
|
45 |
theme = None
|
|
|
46 |
base = '/nf/site_style.css'
|
|
|
47 |
if neighborhood is not None:
|
|
|
48 |
theme = M.Theme.query.get(neighborhood_id=neighborhood._id)
|
|
|
49 |
base = neighborhood.url_prefix + 'site_style.css'
|
|
|
50 |
if theme is None:
|
|
|
51 |
theme = M.Theme.query.get(name='forge_default')
|
|
|
52 |
s_state = pickle.dumps(state(theme).document.deinstrumented_clone())
|
|
|
53 |
checksum = sha1(s_state).hexdigest()
|
|
|
54 |
return tg.url(tg.config.get('cdn.url_base', '')+base, dict(s=checksum))
|
39 |
|
55 |
|
40 |
def really_unicode(s):
|
56 |
def really_unicode(s):
|
41 |
if s is None: return u''
|
57 |
if s is None: return u''
|
42 |
# try naive conversion to unicode
|
58 |
# try naive conversion to unicode
|
43 |
try:
|
59 |
try:
|