def avatar(self, size=30): if not app.cfg.user_use_gravatar: return None from MoinMoin.themes import get_current_theme from flask.ext.themes import static_file_url theme = get_current_theme() email = self.email if not email: return static_file_url( theme, theme.info.get('default_avatar', 'img/default_avatar.png')) param = {} param['gravatar_id'] = hashlib.md5(email.lower()).hexdigest() param['default'] = static_file_url( theme, theme.info.get('default_avatar', 'img/default_avatar.png'), True) param['size'] = str(size) # TODO: use same protocol of Moin site (might be https instead of http)] gravatar_url = "http://www.gravatar.com/avatar.php?" gravatar_url += werkzeug.url_encode(param) return gravatar_url
def avatar(self, size=30): if not app.cfg.user_use_gravatar: return None from MoinMoin.themes import get_current_theme from flask.ext.themes import static_file_url theme = get_current_theme() email = self.email if not email: return static_file_url(theme, theme.info.get('default_avatar', 'img/default_avatar.png')) param = {} param['gravatar_id'] = hashlib.md5(email.lower()).hexdigest() param['default'] = static_file_url(theme, theme.info.get('default_avatar', 'img/default_avatar.png'), True) param['size'] = str(size) # TODO: use same protocol of Moin site (might be https instead of http)] gravatar_url = "http://www.gravatar.com/avatar.php?" gravatar_url += werkzeug.url_encode(param) return gravatar_url
def test_theme_include_static(self): app = Flask(__name__) app.config['THEME_PATHS'] = [join(TESTS, 'morethemes')] setup_themes(app, app_identifier='testing') with app.test_request_context('/'): data = render_template('static_parent.html').strip() url = static_file_url('plain', 'style.css') assert data == 'Application, Plain, %s' % url
def test_theme_static(self): app = Flask(__name__) app.config['THEME_PATHS'] = [join(TESTS, 'morethemes')] setup_themes(app, app_identifier='testing') with app.test_request_context('/'): coolurl = static_file_url('cool', 'style.css') cooldata = render_theme_template('cool', 'static.html').strip() assert cooldata == 'Cool Blue v2, %s' % coolurl
def test_static_file_url(self): app = Flask(__name__) app.config['THEME_PATHS'] = [join(TESTS, 'morethemes')] setup_themes(app, app_identifier='testing') with app.test_request_context('/'): url = static_file_url('cool', 'style.css') genurl = url_for('_themes.static', themeid='cool', filename='style.css') assert url == genurl
def absurl(self, fragment): if self.config.get('url') is not None: # If a manual base url is configured, skip any # blueprint-based auto-generation. return super(Environment, self).absurl(fragment) else: try: filename, query = fragment.split('?', 1) query = '?' + query except (ValueError): filename = fragment query = '' if hasattr(self._app, 'blueprints'): try: blueprint, name = filename.split('/', 1) self._app.blueprints[ blueprint] # generates keyerror if no module endpoint = '%s.static' % blueprint filename = name except (ValueError, KeyError): endpoint = 'static' else: # Module support for Flask < 0.7 try: module, name = filename.split('/', 1) self._app.modules[ module] # generates keyerror if no module endpoint = '%s.static' % module filename = name except (ValueError, KeyError): endpoint = '.static' ctx = None if not _request_ctx_stack.top: ctx = self._app.test_request_context() ctx.push() try: if endpoint.startswith('_themes.'): theme, filename = filename.split('/', 1) return static_file_url(theme, filename) + query else: return url_for(endpoint, filename=filename) + query finally: if ctx: ctx.pop()
def absurl(self, fragment): if self.config.get('url') is not None: # If a manual base url is configured, skip any # blueprint-based auto-generation. return super(Environment, self).absurl(fragment) else: try: filename, query = fragment.split('?', 1) query = '?' + query except (ValueError): filename = fragment query = '' if hasattr(self._app, 'blueprints'): try: blueprint, name = filename.split('/', 1) self._app.blueprints[blueprint] # generates keyerror if no module endpoint = '%s.static' % blueprint filename = name except (ValueError, KeyError): endpoint = 'static' else: # Module support for Flask < 0.7 try: module, name = filename.split('/', 1) self._app.modules[module] # generates keyerror if no module endpoint = '%s.static' % module filename = name except (ValueError, KeyError): endpoint = '.static' ctx = None if not _request_ctx_stack.top: ctx = self._app.test_request_context() ctx.push() try: if endpoint.startswith('_themes.'): theme, filename = filename.split('/', 1) return static_file_url(theme, filename) + query else: return url_for(endpoint, filename=filename) + query finally: if ctx: ctx.pop()
get_theme('notthis') except KeyError: pass else: raise AssertionError("Getting a nonexistent theme should " "raised KeyError") class TestStatic(object): def test_static_file_url(self): app = Flask(__name__) app.config['THEME_PATHS'] = [join(TESTS, 'morethemes')] setup_themes(app, app_identifier='testing') with app.test_request_context('/'): url = static_file_url('cool', 'style.css') genurl = url_for('_themes.static', themeid='cool', filename='style.css') assert url == genurl class TestTemplates(object): def test_template_exists(self): app = Flask(__name__) app.config['THEME_PATHS'] = [join(TESTS, 'morethemes')] setup_themes(app, app_identifier='testing') with app.test_request_context('/'): assert template_exists('hello.html') assert template_exists('_themes/cool/hello.html') assert not template_exists('_themes/plain/hello.html')
def resolve_output_to_url(self, target): if target.startswith('_themes/'): theme, filename = target[8:].split('/', 1) return static_file_url(theme, filename) return super(ThemeAwareResolver, self).resolve_output_to_url(target)