Skip to content

Session cover pages #54

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 18 commits into from
Closed

Session cover pages #54

wants to merge 18 commits into from

Conversation

Krejdom
Copy link
Contributor

@Krejdom Krejdom commented Mar 2, 2017

  • created dirs and markdown files,
  • created link in lesson list of the run,
  • prepare for linking with navigation arrows


## [Odkaz na feedback]

[Odkaz na feedback]: http://s.quickmeme.com/img/a8/a8022006b463b5ed9be5a62f1bdbac43b4f3dbd5c6b3bb44707fe5f5e26635b0.jpg
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

naucse/routes.py Outdated
nxt_link = str(next)
nxt_title = next.title

return prv_link, prv_title, nxt_link, nxt_title
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to have a class to group (link, title). Something like a tooltip might be added in the future.
Could you use a namedtuple or SimpleNamespace instead of two variables for each link?

naucse/routes.py Outdated
for prev, current, next in zip([None] + lessons,
lessons,
lessons[1:] + [None]):
if current.slug == lesson.slug:
if prev:
prev = prev.index_page
prv_link = str(prev)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't return the text representation of a page, but an URL. The text representation is a human-readable string that might easily change in the future.
Make prv_next_teller take the subpage_url function as argument if necessary.

<div class="col text-right">
<a href="{{ lesson_url(nxt.lesson, page=nxt.slug) }}">{{ nxt.title }} →</a>
<a href="{{ lesson_url(('/').join(nxt_link.split('/')[:2])) }}">{{ nxt_title }} →</a>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

URL manipulation should be left to the URL converters and @app.route(). Avoid having logic involving / elsewhere – you're making too many assumptions about the structure of the object's str() representation.

</div>
{% endif %}
</div>
{% endif %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be made into a macro. Could you start a template file with utility macros? Docs are here.

naucse/routes.py Outdated

md_content = Markup(convert_markdown(content))

return render_template('session.html', content=md_content, page=page)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A separate render_session function is not necessary. Its functionality is not that well separated from what should be in session_page.

This is unlike session_template_or_404, which has a clear purpose.

It's also unlike render_page, which exists as a separate function because it's called for both the "just a lesson" URL and for lessons in a run – the common code is in a shared function rather than repeated. But render_session is only called from one place.

naucse/routes.py Outdated

def session_template_or_404(run, session, page):
env = app.jinja_env.overlay(loader=session_template_loader)
run_link = str(run).split(" - ")[0]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't parse the string representation of objects – what if someone decides to make it more useful and puts more info into it?
Use the individual properties. (Look into Run.__str__ for their names.)

naucse/routes.py Outdated

def session_url(session):
"""Link to the specific lesson."""
return url_for('session_page', run=run, session=session, page=page)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this session_url function used?

@encukou
Copy link
Member

encukou commented Mar 5, 2017

Last time, I made fairly big changes to make the code look the way I wanted, to make everything ready in time. I'd like to avoid that from now on, and merge as soon as the content for current runs (PyLadies and Python's Libraries) is good to go. I've marked issues for that as blockers.

The pages that aren't linked from current runs are a playground now. Let's iterate on making it as good as it can be, but the iterations can take longer. I'll be happy to merge if non-blocker issues are remaining – that's why there's a red warning on the site, after all.

With that, please consider the points below. Set your priorities. And, don't make a change just because it's here – if you're not convinced, let's discuss.

Page issues

  • (Blocker) When a lesson has sub-pages, their prev/next links are a bit specific. Consider:

    Perhaps the model should be extended to work with the Arrow class (see below for notes on that). Perhaps you can find a better way to achieve this. But the way the arrows point needs to consider subpages.

  • The three links in the footer, (prev, up, next), won't show up properly on small screens when the titles are long. How can that be fixed? I recommend designing for small screens first, then adjusting for bigger ones if needed.

  • My idea was to make each lesson read like a book: the links at the bottom would take thee reader from an introduction, through the content, and finally to a summary. The front page would give the reader an overview of the section – to get them interested, to help them decide if the content is new for them, and to give links to related material. The back page would summarize the session, and prompt the reader to take a break and do some exercises. Without these pages being linked as if they were the first and last lesson, I don't think they are serving the purposes I had in mind as well as they should. We can talk about that, but even if you disagree:

  • It is not clear where to go next from the first page

Possible technical debt

Here are things that won't affect the result, but might make the code more pleasant to work with in the future.

  • Regarding the Arrow namedtuple: functions and classes should preferably be defined on the module level, not inside a function, unless it's necessary (e.g. if local variables of the enclosing function are used, and it'd be cumbersome to pass them as parguments).
  • Let's make the terminology clearer. I've been using the term URL for an address on the Web, and link an element that takes you somewhere (such as to a URL) when you activate it. I think it would be clearer to make the class Link = namedtuple('Link', ['url', 'title']).
  • Could we go easier on the abbreviations? prv and nxt are weird, but (barely) understandable if they occur together. But I don't think sess is meaningful to someone skimming the code. If they were just private local variables of the function, no one would care, but as arguments to the template they deserve better names. How about session_arrow/session_link?
  • There are three navigation links now.
    • Can code that's common to all three be combined?
    • Does passing them around in a tuple still work, or is it time for something with named fields?
  • What's the purpose of the comment ####### SESSION?
  • Do the docstrings on all the functions decorated with @app.route tell the reader something new? Or would function names and associated URLs be enough?
  • Do the docstrings on all the functions decorated with @app.route tell the reader enough? Should they be expanded?
  • The lesson and session templates look very similar. Can the commonalities be factored out?

@Krejdom
Copy link
Contributor Author

Krejdom commented Mar 10, 2017

The index of "Install Python" has no next link; the next page depends on the OS, and is linked from the main text

In this pull request it has the next link to install-editor. When you click on some link in this lesson, it's subpage. When you go through lessons with arrows, you look at index install page, choose subpage and install something or you realize you have already installed these, so you can directly continue to the next page.

The page for Linux, then, links back to its previous subpage.

Again, not in this pull request. Subpage links to the next lesson. Maybe the session link should be replaced with link to chapter (install).

The three links in the footer, (prev, up, next), won't show up properly on small screens when the titles are long. How can that be fixed? I recommend designing for small screens first, then adjusting for bigger ones if needed.

What you mean by "won't show up properly"? I don't see any problem. But if there is a serious problem on small screens, is can be replaced by just arrows ←↑ → there.

It is not clear where to go next from the first page

What you consider as the first page here?

There are three navigation links now.
Can code that's common to all three be combined?

Which common code?

@encukou
Copy link
Member

encukou commented Mar 14, 2017

The index of "Install Python" has no next link; the next page depends on the OS, and is linked from the main text

In this pull request it has the next link to install-editor. When you click on some link in this lesson, it's subpage. When you go through lessons with arrows, you look at index install page, choose subpage and install something or you realize you have already installed these, so you can directly continue to the next page.

OK, that does make sense here.

The page for Linux, then, links back to its previous subpage.

Again, not in this pull request. Subpage links to the next lesson. Maybe the session link should be replaced with link to chapter (install).

On "Install Python for Linux", the links should be:

  • back: "Install Python"
  • forward: the next lesson

The point is that the prv link should point to the index subpage, not to the previous lesson.

The three links in the footer, (prev, up, next), won't show up properly on small screens when the titles are long. How can that be fixed? I recommend designing for small screens first, then adjusting for bigger ones if needed.

What you mean by "won't show up properly"?

This:
scsh

I don't see any problem. But if there is a serious problem on small screens, is can be replaced by just arrows ←↑ → there.

If you can you make it work for all sizes, that would be great!
But it's not a blocker; it can be done after the backend is done.

It is not clear where to go next from the first page

What you consider as the first page here?

The cover page at the beginning of the session.

There are three navigation links now.
Can code that's common to all three be combined?

Which common code?

Mainly in the template.
Again, this is not a priority.

@Krejdom Krejdom assigned Krejdom and unassigned Krejdom Mar 17, 2017
if (page.subpages != None and page.slug in page.subpages.keys()
and "prev" in page.subpages[page.slug].keys() and "next" in page.subpages[page.slug].keys()) :
prev_segments = page.subpages[page.slug]["prev"].split(':')
next_segments = page.subpages[page.slug]["next"].split(':')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm reading correctly, this way the title of the link can't have a colon in it. Is that a reasonable limitation?

The configuration already comes from YAML. Why invent a special format for this field?

prev_segments.append("index")

kwargs['prv'] = models.Navigation(prev_segments[0], prev_segments[1], prev_segments[2])
kwargs['nxt'] = models.Navigation(next_segments[0], next_segments[1], next_segments[2])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the code to create a Navigation is duplicated twice here. Is there a better place for initialization code to go?


Arguments:
title the title of the link location
url <lesson_type>/<lesson>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not really a URL.

@Krejdom Krejdom closed this Apr 7, 2017
frenzymadness added a commit to frenzymadness/naucse.python.cz that referenced this pull request Nov 27, 2019
encukou pushed a commit that referenced this pull request Dec 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants