Browse Source

adding list view (doesn't yet work with filters)

joel
Simon Bowie 1 year ago
parent
commit
b080cbf414
6 changed files with 79 additions and 50 deletions
  1. +13
    -10
      web/app/book.py
  2. +8
    -5
      web/app/main.py
  3. +5
    -3
      web/app/practice.py
  4. +21
    -13
      web/app/templates/index.html
  5. +16
    -6
      web/app/templates/resources.html
  6. +16
    -13
      web/app/tool.py

+ 13
- 10
web/app/book.py View File

@@ -20,20 +20,23 @@ book = Blueprint('book', __name__)
# route for displaying all books in database
@book.route('/books')
def get_books():
view = request.args.get('view')
type = 'book'
books = Resource.query.filter_by(type=type).all()
for key in request.args.keys():
if key == 'practice':
books = Resource.query.join(Relationship, Relationship.first_resource_id == Resource.id, isouter=True).filter(Resource.type==type, Relationship.second_resource_id==request.args.get(key)).all()
also_books = Resource.query.join(Relationship, Relationship.second_resource_id == Resource.id, isouter=True).filter(Resource.type==type, Relationship.first_resource_id==request.args.get(key)).all()
books = books + also_books
else:
kwargs = {'type': type, key: request.args.get(key)}
books = Resource.query.filter_by(**kwargs).all()
if key != 'view':
if key == 'practice':
books = Resource.query.join(Relationship, Relationship.first_resource_id == Resource.id, isouter=True).filter(Resource.type==type, Relationship.second_resource_id==request.args.get(key)).all()
also_books = Resource.query.join(Relationship, Relationship.second_resource_id == Resource.id, isouter=True).filter(Resource.type==type, Relationship.first_resource_id==request.args.get(key)).all()
books = books + also_books
else:
kwargs = {'type': type, key: request.args.get(key)}
books = Resource.query.filter_by(**kwargs).all()
# get number of books
count = len(books)
# append relationships to each book
append_relationships_multiple(books)
if view != 'list':
# append relationships to each book
append_relationships_multiple(books)
# get filters
# practices
practices_filter = Resource.query.filter_by(type='practice').with_entities(Resource.id, Resource.name)
@@ -41,7 +44,7 @@ def get_books():
year_filter = get_filter_values('year', type)
# typology
typology_filter = get_filter_values('typology', type)
return render_template('resources.html', resources=books, type=type, practices_filter=practices_filter, year_filter=year_filter, typology_filter=typology_filter, count=count)
return render_template('resources.html', resources=books, type=type, practices_filter=practices_filter, year_filter=year_filter, typology_filter=typology_filter, count=count, view=view)

# route for displaying a single book based on the ID in the database
@book.route('/books/<int:book_id>')

+ 8
- 5
web/app/main.py View File

@@ -19,17 +19,20 @@ main = Blueprint('main', __name__)
# route for index page
@main.route('/')
def index():
view = request.args.get('view')
tools = Resource.query.filter_by(type='tool').order_by(func.random()).limit(6).all()
# append relationships to each tool
append_relationships_multiple(tools)
if view != 'list':
# append relationships to each tool
append_relationships_multiple(tools)
books = Resource.query.filter_by(type='book').order_by(func.random()).limit(6).all()
# append relationships to each book
append_relationships_multiple(books)
if view != 'list':
# append relationships to each book
append_relationships_multiple(books)
with open('content/home.md', 'r') as f:
text = f.read()
text = markdown.markdown(text)
book_showcase = get_full_resource('69')
return render_template('index.html', text=text, tools=tools, books=books, book=book_showcase)
return render_template('index.html', text=text, tools=tools, books=books, book=book_showcase, view=view)

# route for profile page
@main.route('/profile')

+ 5
- 3
web/app/practice.py View File

@@ -19,12 +19,14 @@ practice = Blueprint('practice', __name__)
# route for displaying all practices in database
@practice.route('/practices')
def get_practices():
view = request.args.get('view')
practices = Resource.query.filter_by(type='practice').all()
# get number of practices
count = len(practices)
# append relationships to each practice
append_relationships_multiple(practices)
return render_template('resources.html', resources=practices, type='practice', count=count)
if view != 'list':
# append relationships to each practice
append_relationships_multiple(practices)
return render_template('resources.html', resources=practices, type='practice', count=count, view=view)

# route for displaying a single practice based on the ID in the database
@practice.route('/practices/<int:practice_id>')

+ 21
- 13
web/app/templates/index.html View File

@@ -7,6 +7,10 @@

<div class="ml-[13rem] text my-8 meta max-w-[30rem]">
{{ text|safe }}

<br/>
<a href="{{ url_for(request.endpoint, view='list') }}">LIST VIEW</a>

</div>
<div class="h-full ">
<div class="flex h-full gap-8 justify-start items-center ">
@@ -19,32 +23,36 @@
</div>
</div>
</div>
{% for tool in tools %}

{{ resource_with_related(tool, loop, false) }}
{% if view == 'list' %}
THIS IS LIST VIEW
{% else %}
{% for tool in tools %}

{% endfor %}
{{ resource_with_related(tool, loop, false) }}

{% for book in books %}
{% endfor %}

{{ resource_with_related(book, loop, false) }}
{% for book in books %}

{% endfor %}
{{ resource_with_related(book, loop, false) }}

{% for tool in tools2 %}
{% endfor %}

{{ resource_with_related(tool, loop, false) }}
{% for tool in tools2 %}

{% endfor %}
{{ resource_with_related(tool, loop, false) }}

{% for book in books2 %}
{% endfor %}

{{ resource_with_related(book, loop, false) }}
{% for book in books2 %}

{% endfor %}
{{ resource_with_related(book, loop, false) }}

{% endfor %}

{% endif %}

</div>
{% endblock %}

+ 16
- 6
web/app/templates/resources.html View File

@@ -25,6 +25,10 @@
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam ultricies egestas felis at dignissim. Morbi ut bibendum
nisl. Integer ac sollicitudin risus. Vivamus et est est. Ut vitae lacus nec justo tincidunt interdum. Fusce sapien odio,
commodo nec est et, interdum varius risus. Curabitur vehicula consequat auctor.

<br/><br/>
<a href="{{ url_for(request.endpoint, view='list') }}">LIST VIEW</a>

</div>
<div class="h-full ">
<div class="flex h-full gap-8 justify-start items-center ">
@@ -57,7 +61,7 @@
<div class="filter-options my-4" x-show="expandFilters">
{% for practice in practices_filter %}
<div {% if request.args.get('practice')==practice[0]|string %} class="active" {% endif %}>
<a href="/{{type + 's'}}?practice={{practice[0]}}" hx-target="#resources" hx-select="#resources">{{ practice[1] }}</a>
<a href="{{ url_for(request.endpoint, practice=practice[0]) }}" hx-target="#resources" hx-select="#resources">{{ practice[1] }}</a>
</div>
{% endfor %}
</div>
@@ -69,7 +73,7 @@
<div class="filter-options my-4" x-show="expandFilters">
{% for year in year_filter %}
<div {% if request.args.get('year')==year %} class="active" {% endif %}>
<a href="/books?year={{year}}" hx-target="#resources" hx-select="#resources">{{ year }}</a>
<a href="{{ url_for(request.endpoint, year=year) }}" hx-target="#resources" hx-select="#resources">{{ year }}</a>
</div>
{% endfor %}
</div>
@@ -81,7 +85,7 @@
<div class="filter-options my-4" x-show="expandFilters">
{% for typology in typology_filter %}
<div {% if request.args.get('typology')==typology %} class="active" {% endif %}>
<a href="/books?typology={{typology}}" hx-target="#resources" hx-select="#resources">{{ typology }}</a>
<a href="{{ url_for(request.endpoint, typology=typology) }}" hx-target="#resources" hx-select="#resources">{{ typology }}</a>
</div>
{% endfor %}
</div>
@@ -93,7 +97,7 @@
<div class="filter-options my-4" x-show="expandFilters">
{% for language in languages_filter %}
<div {% if request.args.get('scriptingLanguage')==language %} class="active" {% endif %}>
<a href="/tools?scriptingLanguage={{language}}" hx-target="#resources" hx-select="#resources">{{ language }}</a>
<a href="{{ url_for(request.endpoint, scriptingLanguage=language) }}" hx-target="#resources" hx-select="#resources">{{ language }}</a>
</div>
{% endfor %}
</div>
@@ -105,7 +109,7 @@
<div class="filter-options my-4" x-show="expandFilters">
{% for license in licenses_filter %}
<div {% if request.args.get('license')==license %} class="active" {% endif %}>
<a href="/tools?license={{license}}" hx-target="#resources" hx-select="#resources">{{ license }}</a>
<a href="{{ url_for(request.endpoint, license=license) }}" hx-target="#resources" hx-select="#resources">{{ license }}</a>
</div>
{% endfor %}
</div>
@@ -114,9 +118,15 @@
</div>

<div>
{% if view == 'list' %}
THIS IS LIST VIEW
{% else %}

{% for resource in resources %}
{{ resource_with_related(resource, loop) }}
{% endfor %}
{% endfor %}

{% endif %}
</div>
</div>
</div>

+ 16
- 13
web/app/tool.py View File

@@ -20,23 +20,26 @@ tool = Blueprint('tool', __name__)
# route for displaying all tools in database
@tool.route('/tools')
def get_tools():
view = request.args.get('view')
type = 'tool'
tools = Resource.query.filter_by(type=type).all()
for key in request.args.keys():
if key == 'practice':
tools = Resource.query.join(Relationship, Relationship.first_resource_id == Resource.id, isouter=True).filter(Resource.type==type, Relationship.second_resource_id==request.args.get(key)).all()
also_tools = Resource.query.join(Relationship, Relationship.second_resource_id == Resource.id, isouter=True).filter(Resource.type==type, Relationship.first_resource_id==request.args.get(key)).all()
tools = tools + also_tools
elif key == 'scriptingLanguage':
regex = request.args.get(key) + "$|" + request.args.get(key) + "\s\/"
tools = Resource.query.filter_by(type=type).filter(Resource.scriptingLanguage.regexp_match(regex)).all()
else:
kwargs = {'type': type, key: request.args.get(key)}
tools = Resource.query.filter_by(**kwargs).all()
if key != 'view':
if key == 'practice':
tools = Resource.query.join(Relationship, Relationship.first_resource_id == Resource.id, isouter=True).filter(Resource.type==type, Relationship.second_resource_id==request.args.get(key)).all()
also_tools = Resource.query.join(Relationship, Relationship.second_resource_id == Resource.id, isouter=True).filter(Resource.type==type, Relationship.first_resource_id==request.args.get(key)).all()
tools = tools + also_tools
elif key == 'scriptingLanguage':
regex = request.args.get(key) + "$|" + request.args.get(key) + "\s\/"
tools = Resource.query.filter_by(type=type).filter(Resource.scriptingLanguage.regexp_match(regex)).all()
else:
kwargs = {'type': type, key: request.args.get(key)}
tools = Resource.query.filter_by(**kwargs).all()
# get number of tools
count = len(tools)
# append relationships to each tool
append_relationships_multiple(tools)
if view != 'list':
# append relationships to each tool
append_relationships_multiple(tools)
# get filters
# practices
practices_filter = Resource.query.filter_by(type='practice').with_entities(Resource.id, Resource.name)
@@ -45,7 +48,7 @@ def get_tools():
licenses_filter = get_filter_values('license', type)
# language
languages_filter = get_filter_values('scriptingLanguage', type)
return render_template('resources.html', resources=tools, type=type, practices_filter=practices_filter, licenses_filter=licenses_filter, languages_filter=languages_filter, count=count)
return render_template('resources.html', resources=tools, type=type, practices_filter=practices_filter, licenses_filter=licenses_filter, languages_filter=languages_filter, count=count, view=view)

# route for displaying a single tool based on the ID in the database
@tool.route('/tools/<int:tool_id>')

Loading…
Cancel
Save