tag views filtered by date, alpha, numeric
Last active
March 22, 2017 23:51
-
-
Save shane0/c9941f0fb9ee34aeaaa88816f046381b to your computer and use it in GitHub Desktop.
flask flatpage tag list view
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% extends "layout.html" %} {% block content %} | |
<hr> {% include "flatpages/tag-menu.html" %} | |
<hr> | |
<p><a class="btn btn-default" href="/flatpages/taglist/"> list of tags</a> {% include "workflow/workflow-journal-menu.html" %} | |
</p> | |
<hr> | |
<div class="dropdown"> | |
<button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"> | |
Filter | |
<span class="caret"></span> | |
</button> | |
<ul class="dropdown-menu" aria-labelledby="dropdownMenu1"> | |
<li><a href="http://10.0.0.145:8004/flatpages/tagdates/">Dates</a></li> | |
<li><a href="http://10.0.0.145:8004/flatpages/tagalpha/">Alpha</a></li> | |
<li><a href="http://10.0.0.145:8004/flatpages/tagnumeric/">Numeric</a></li> | |
<li><a href="http://10.0.0.145:8004/flatpages/taglist/">All</a></li> | |
</ul> | |
</div> | |
<br> | |
<div class="panel panel-success"> | |
<div class="panel-heading"> | |
<h3> | |
<a href="/flatpages/tagdates/">Dates</a> | |
<span class="badge"> | |
{{datematches|length}} | |
</span> | |
</h3> | |
</div> | |
<div class="panel-body"> | |
{% for t in datematches|sort() %} | |
<a class="btn btn-link" href="/flatpages/tag/{{t}}">{{t}}</a> {% endfor %} | |
</div> | |
</div> | |
<div class="panel panel-info"> | |
<div class="panel-heading"> | |
<h3> | |
<a href="/flatpages/tagalpha/">Alpha</a> | |
<span class="badge"> | |
{{othermatches|length}} | |
</span> | |
</h3> | |
</div> | |
{%for t in othermatches|sort()%} | |
<a class="btn btn-link" href="/flatpages/tag/{{t}}">{{t}}</a> {%endfor%} | |
</div> | |
<div class="panel panel-warning"> | |
<div class="panel-heading"> | |
<h3> | |
<a href="/flatpages/tagnumeric/">Numeric</a> | |
<span class="badge"> | |
{{uniqboxtags|length}} | |
</span> | |
</h3> | |
</div> | |
<div class="panel-body"> | |
<br> {%for t in uniqboxtags|sort()%} | |
<a class="btn btn-link" href="/flatpages/tag/{{t}}">{{t}}</a> {%endfor%} | |
</div> | |
</div> | |
{% endblock content %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@blueprint.route('/tag/<string:tag>/') | |
@login_required | |
def tag(tag): | |
tagged = [p for p in pages if tag in p.meta.get('tags', [])] | |
print(tagged) | |
return render_template('flatpages/tag.html', pages=tagged, tag=tag) | |
@blueprint.route('/taglist/') | |
@login_required | |
def taglist(): | |
""" show a list of tags by box and date""" | |
now = datetime.datetime.now() | |
ymd = now.strftime("%Y-%m-%d") | |
uniqtags = [] | |
uniqboxtags = [] | |
datematches = [] | |
othermatches = [] | |
for p in pages: | |
print(p) | |
t = p.meta.get('tags') | |
if t: | |
for ttag in t: | |
""" all """ | |
uniqtags.append(ttag) | |
""" is a box but not a date put in box """ | |
if type(ttag) is not datetime.date: | |
if (re.findall('\d{4,5}(?!-)',ttag, re.MULTILINE)): | |
uniqboxtags.append(ttag) | |
else: | |
""" not box or date put in other""" | |
if (re.findall('[A-Z|a-z]', ttag, re.MULTILINE)): | |
othermatches.append(ttag) | |
""" convert to sets for unique matches """ | |
uniqboxtags = set(uniqboxtags) | |
uniqtags = set(uniqtags) | |
othermatches = set(othermatches) | |
for t in uniqtags: | |
""" get dates """ | |
if (re.findall('\d{4}-\d{2}-\d{2}', t, re.MULTILINE)): | |
datematches.append(t) | |
datematches = set(datematches) | |
return render_template('flatpages/taglist.html', pages=pages, uniqtags=uniqtags, uniqboxtags=uniqboxtags, datematches=datematches, othermatches=othermatches, ymd=ymd) | |
@blueprint.route('/tagdates/') | |
@login_required | |
def taglistdates(): | |
""" show a list of tags by box and date""" | |
now = datetime.datetime.now() | |
ymd = now.strftime("%Y-%m-%d") | |
uniqtags = [] | |
uniqboxtags = [] | |
datematches = [] | |
othermatches = [] | |
for p in pages: | |
print(p) | |
t = p.meta.get('tags') | |
if t: | |
for ttag in t: | |
""" all """ | |
uniqtags.append(ttag) | |
""" is a box but not a date put in box """ | |
if type(ttag) is not datetime.date: | |
if (re.findall('\d{4,5}(?!-)',ttag, re.MULTILINE)): | |
uniqboxtags.append(ttag) | |
else: | |
""" not box or date put in other""" | |
if (re.findall('[A-Z|a-z]', ttag, re.MULTILINE)): | |
othermatches.append(ttag) | |
""" convert to sets for unique matches """ | |
uniqboxtags = ''#set(uniqboxtags) | |
uniqtags = set(uniqtags) | |
othermatches = ''#set(othermatches) | |
for t in uniqtags: | |
""" get dates """ | |
if (re.findall('\d{4}-\d{2}-\d{2}', t, re.MULTILINE)): | |
datematches.append(t) | |
datematches = set(datematches) | |
return render_template('flatpages/taglist.html', pages=pages, uniqtags=uniqtags, uniqboxtags=uniqboxtags, datematches=datematches, othermatches=othermatches, ymd=ymd) | |
@blueprint.route('/tagalpha/') | |
@login_required | |
def taglistalpha(): | |
""" show a list of tags by box and date""" | |
now = datetime.datetime.now() | |
ymd = now.strftime("%Y-%m-%d") | |
uniqtags = [] | |
uniqboxtags = [] | |
datematches = [] | |
othermatches = [] | |
for p in pages: | |
print(p) | |
t = p.meta.get('tags') | |
if t: | |
for ttag in t: | |
""" all """ | |
uniqtags.append(ttag) | |
""" is a box but not a date put in box """ | |
if type(ttag) is not datetime.date: | |
if (re.findall('\d{4,5}(?!-)',ttag, re.MULTILINE)): | |
uniqboxtags.append(ttag) | |
else: | |
""" not box or date put in other""" | |
if (re.findall('[A-Z|a-z]', ttag, re.MULTILINE)): | |
othermatches.append(ttag) | |
""" convert to sets for unique matches """ | |
uniqtags = set(uniqtags) | |
uniqboxtags = ''#set(uniqboxtags) | |
othermatches = set(othermatches) | |
for t in uniqtags: | |
""" get dates """ | |
if (re.findall('\d{4}-\d{2}-\d{2}', t, re.MULTILINE)): | |
datematches.append(t) | |
datematches = ''#set(datematches) | |
return render_template('flatpages/taglist.html', pages=pages, uniqtags=uniqtags, uniqboxtags=uniqboxtags, datematches=datematches, othermatches=othermatches, ymd=ymd) | |
@blueprint.route('/tagnumeric/') | |
@login_required | |
def taglistnumeric(): | |
""" show a list of tags by box and date""" | |
now = datetime.datetime.now() | |
ymd = now.strftime("%Y-%m-%d") | |
uniqtags = [] | |
uniqboxtags = [] | |
datematches = [] | |
othermatches = [] | |
for p in pages: | |
print(p) | |
t = p.meta.get('tags') | |
if t: | |
for ttag in t: | |
""" all """ | |
uniqtags.append(ttag) | |
""" is a box but not a date put in box """ | |
if type(ttag) is not datetime.date: | |
if (re.findall('\d{4,5}(?!-)',ttag, re.MULTILINE)): | |
uniqboxtags.append(ttag) | |
else: | |
""" not box or date put in other""" | |
if (re.findall('[A-Z|a-z]', ttag, re.MULTILINE)): | |
othermatches.append(ttag) | |
""" convert to sets for unique matches """ | |
uniqtags = set(uniqtags) | |
uniqboxtags = set(uniqboxtags) | |
othermatches = ''#set(othermatches) | |
for t in uniqtags: | |
""" get dates """ | |
if (re.findall('\d{4}-\d{2}-\d{2}', t, re.MULTILINE)): | |
datematches.append(t) | |
datematches = ''#set(datematches) | |
return render_template('flatpages/taglist.html', pages=pages, uniqtags=uniqtags, uniqboxtags=uniqboxtags, datematches=datematches, othermatches=othermatches, ymd=ymd) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment