I am a newbie and I am using basic HTML to render and check. No JSON at the moment. With that said, I’m having a hard time conceptualizing organization of a group of matching series (e.g. a series that falls under a given number, say 1) into a single link that expands into the subseries (say, 1a, 1b, 1c...) for a detailed list; this second portion would be found on a separate page.
Ideally (here is a sketch):
HTML page showing all the series:
<a href= ‘MicroSeries 1’>
This link opens to a separate HTML page with the matching subseries:
Subseries 1a, 1b, 1c, 1d
<a href= 'MicroSeries 2'>
Same logic as above.
I think my idea is the way to attack the problem, but please feel free to recommend a better approach. I have a former question that reveals more of what I initially created: link. However, I believe I may have attacked the issue incorrectly. I also think I've confused myself pretty bad.
As of right now, having a single link that opens up to the subseries does not exist for each microseries without manual code (as you one can tell below).
Using: Python 2.7, Pyramid (JINJA2 templates), SQLAlchemy
Route (init.py):
config.add_route('assessments', '/assessments')
config.add_route('assessment', '/assessments/{id:\d+}')
config.add_route('view_subseries', '/assessments/{microseries}')
View Code:
@view_config(route_name='assessments', request_method='GET', renderer='templates/unique_assessments.jinja2')
def view_unique_microseries_group(request):
all_assessments = api.retrieve_assessments() #all assessments in a list
assessments_by_microseries = {} #dictonary
for x in all_assessments:
if x.microseries in assessments_by_microseries:
print("Already seen this microseries: %s" % x.microseries)
else:
assessments_by_microseries[x.microseries] = x
unique_assessments = sorted(assessments_by_microseries.values()) #.values() method to get the, err, values of the dict.
print 'unique_assessments:', unique_assessments
#a = HTTPSeeOther(location=request.route_url('view_subseries'))
return {'logged_in': logged_in_userid, 'unique_assessments': unique_assessments}
@view_config(route_name='view_subseries', request_method='GET', renderer='templates/assessments.jinja2')
def view_microseries_subseries(request):
all_assessments = api.retrieve_assessments() #all assessments in a list
series1 = []
series2 = []
series3 = []
series4 = []
series5 = []
for x in all_assessments:
if x.microseries ==1:
series1.append(x)
#print 'series1 ', series1
elif x.microseries ==2:
series2.append(x)
#print 'series2', series2
elif x.microseries ==3:
series3.append(x)
#print 'series3', series3
elif x.microseries ==4:
series4.append(x)
#print 'series4', series4
elif x.microseries ==5:
series5.append(x)
#print 'series5', series5
else:
raise HTTPNotFound
return {'logged_in': logged_in_userid, 'series1': series1, 'series2': series2, 'series3':series3, 'series4':series4, 'series5':series5, 'all_assessments': all_assessments}
HTML for showing all subseries (assessments.jinja2):
<div class="container">
<table class="table table-striped">
<thead class='tablename'>
<h2>Microseries subseries</h2>
<tr>
<td> </td>
<td> SubSeries </td>
</tr>
</thead>
<tbody>
<tr>
{% for a in series1 %} # needs to grab a matching subseries... maybe used hidden instead ? this does not work for each set
{% if a in all_assessments %}
<td><a href="{{ '/assessments/%s'%a.microseries|urlencode }}"><button type='button' class='btn outline btn-primary'>Play</button></a></td>
<td>{{ a }}</td>
</tr>
{% endif %}
{% endfor %}
</tbody>
</table>
</div>