Skip to content
Permalink
Browse files

Fixing flask_login stuff

  • Loading branch information...
Depado committed Oct 27, 2015
1 parent 4ae4fac commit 42fdfd6f177e1eea94e57d83335b5469440ecb6d
Showing with 65 additions and 64 deletions.
  1. +1 −1 app/models/mixins.py
  2. +1 −2 app/models/post.py
  3. +2 −2 app/modules/blog/utils.py
  4. +3 −3 app/templates/blog/blog_menu.html
  5. +58 −56 app/utils/markdown.py
@@ -5,4 +5,4 @@

class AuthMixin(object):
def is_accessible(self):
return not current_user.is_anonymous() and current_user.is_superuser()
return not current_user.is_anonymous and current_user.is_superuser
@@ -63,9 +63,8 @@ def content_as_html(self, index=False):
except Exception as e:
return content
else:
# renderer.reset_toc()
renderer.reset_toc()
content = markdown_renderer.render(self.content)
# renderer.render_toc(level=3)
return content

def content_as_ansi(self):
@@ -27,12 +27,12 @@ def generate_background_css(blog_user=None):

if blog_user:
if blog_user.blog_bg and blog_user.blog_bg_public:
if current_user.is_authenticated() and current_user.blog_bg and current_user.blog_bg_override:
if current_user.is_authenticated and current_user.blog_bg and current_user.blog_bg_override:
chosen = current_user
else:
chosen = blog_user
else:
if current_user.is_authenticated() and current_user.blog_bg and current_user.blog_bg_everywhere:
if current_user.is_authenticated and current_user.blog_bg and current_user.blog_bg_everywhere:
chosen = current_user

if chosen:
@@ -12,18 +12,18 @@
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
{% if user.is_authenticated() %}
{% if user.is_authenticated %}
<li><a href="{{ url_for('index') }}"><i class="fa fa-search"></i>&nbsp;&nbsp;Explore</a></li>
<li><a href="{{ url_for('blog.index', user_slug=user.blog_slug) }}"><i class="fa fa-comment"></i>&nbsp;&nbsp;My Blog</a></li>
<li><a href="{{ url_for('new') }}"><i class="fa fa-file-text"></i>&nbsp;&nbsp;New Article</a></li>
<li><a href="{{ url_for('settings') }}"><i class="fa fa-cogs"></i>&nbsp;&nbsp;Settings</a></li>
{% endif %}
{% if user.is_anonymous() %}
{% if user.is_anonymous %}
<li><a href="{{ url_for('index') }}"><i class="fa fa-home"></i>&nbsp;&nbsp;Home</a></li>
<li><a href="{{ url_for('explore') }}"><i class="fa fa-search"></i>&nbsp;&nbsp;Explore</a></li>
{% endif %}
</ul>
{% if user.is_authenticated() %}
{% if user.is_authenticated %}
<ul class="nav navbar-nav navbar-right">
<li><a href="{{ url_for('logout') }}"><i class="fa fa-power-off"></i> Logout</a></li>
</ul>
@@ -195,62 +195,64 @@ def latex_environment(self, name, text):
def inline_math(self, text):
return '$%s$' % text

# def reset_toc(self):
# self.toc_tree = []
# self.toc_count = 0
#
# def header(self, text, level, raw=None):
# rv = '<h%d id="toc-%d">%s</h%d>\n' % (
# level, self.toc_count, text, level
# )
# self.toc_tree.append((self.toc_count, text, level, raw))
# self.toc_count += 1
# return rv
#
# def render_toc(self, level=3):
# """Render TOC to HTML.
# :param level: render toc to the given level
# """
# return ''.join(self._iter_toc(level))
#
# def _iter_toc(self, level):
# first_level = None
# last_level = None
#
# yield '<ul id="table-of-content">\n'
#
# for toc in self.toc_tree:
# index, text, l, raw = toc
#
# if l > level:
# # ignore this level
# continue
#
# if first_level is None:
# # based on first level
# first_level = l
# last_level = l
# yield '<li><a href="#toc-%d">%s</a>' % (index, text)
# elif last_level == l:
# yield '</li>\n<li><a href="#toc-%d">%s</a>' % (index, text)
# elif last_level == l - 1:
# last_level = l
# yield '<ul>\n<li><a href="#toc-%d">%s</a>' % (index, text)
# elif last_level > l:
# # close indention
# yield '</li>'
# while last_level > l:
# yield '</ul>\n</li>\n'
# last_level -= 1
# yield '<li><a href="#toc-%d">%s</a>' % (index, text)
#
# # close tags
# yield '</li>\n'
# while last_level > first_level:
# yield '</ul>\n</li>\n'
# last_level -= 1
#
# yield '</ul>\n'
def reset_toc(self):
self.toc_tree = []
self.toc_count = 0

def header(self, text, level, raw=None):
rv = '<h%d id="toc-%d">%s</h%d>\n' % (
level, self.toc_count, text, level
)
self.toc_tree.append((self.toc_count, text, level, raw))
self.toc_count += 1
return rv

def render_toc(self, level=3):
"""Render TOC to HTML.
:param level: render toc to the given level
"""
print(self.toc_count)
return ''.join(self._iter_toc(level))

def _iter_toc(self, level):
first_level = None
last_level = None

yield '<ul id="table-of-content">\n'

for toc in self.toc_tree:
index, text, l, raw = toc

if l > level:
# ignore this level
continue

if first_level is None:
# based on first level
first_level = l
last_level = l
yield '<li><a href="#toc-%d">%s</a>' % (index, text)
elif last_level == l:
yield '</li>\n<li><a href="#toc-%d">%s</a>' % (index, text)
elif last_level == l - 1:
last_level = l
yield '<ul>\n<li><a href="#toc-%d">%s</a>' % (index, text)
elif last_level > l:
# close indention
yield '</li>'
while last_level > l:
yield '</ul>\n</li>\n'
last_level -= 1
yield '<li><a href="#toc-%d">%s</a>' % (index, text)

# close tags
if last_level and first_level:
yield '</li>\n'
while last_level > first_level:
yield '</ul>\n</li>\n'
last_level -= 1

yield '</ul>\n'

renderer = HighlighterRenderer(escape=False)
markdown_renderer = MarkdownWithMath(renderer=renderer)

0 comments on commit 42fdfd6

Please sign in to comment.
You can’t perform that action at this time.