knowledge-repo icon indicating copy to clipboard operation
knowledge-repo copied to clipboard

Issue 103 dynamic template

Open jbao opened this issue 8 years ago • 11 comments

This automatically generates the current timestamp in the template and resolves #103

Auto-reviewers: @NiharikaRay @matthewwardrop @earthmancash @danfrankj

jbao avatar Dec 19 '16 15:12 jbao

Hi @jbao,

Thanks for your contribution!

Can you perhaps use jinja2 templating like we are doing for the site pages itself? Thus, rather than "&current_date" you would use "{{ current_date }}", and do the substitution in the knowledge_repo script using something like:

with open('<template_name>') as f:
   result = jinja2.Template(f.read()).render(current_date=...)

This simplifies the code a lot.

In the testing, you can then use the knowledge_repo create command to do the substitution, which will also act as a good test that this mechanism is working appropriately.

Thanks again! Little fixes for nits like this are a great help, as we are often so busy with the "bigger" stuff that we lose sight of these sorts of things which can have a big effect on user experience.

M

matthewwardrop avatar Dec 20 '16 06:12 matthewwardrop

Just thinking too: maybe you can add support for automatically populating the author too?

Should be as easy as passing in author = os.getlogin() to the Template.render method; and adding {{ author }} to the templates.

matthewwardrop avatar Dec 20 '16 08:12 matthewwardrop

Hi @matthewwardrop , that's a great idea.

It seems that Travis doesn't like os.getlogin() though, with the automatic author rendering, I got the error

Inappropriate ioctl for device

This needs further investigation.

jbao avatar Dec 20 '16 09:12 jbao

@jbao How are you getting on here? Does something like the following help?

import pwd
import os


def get_login():
    """
    Try to retrieve the user login to in a
    """
    try:
        user_login = os.getlogin()
    except OSError:
        user_login = pwd.getpwuid(os.geteuid()).pw_name
    return user_login

matthewwardrop avatar Feb 23 '17 00:02 matthewwardrop

:x: Build knowledge-repo 1.0.845 failed (commit https://github.com/airbnb/knowledge-repo/commit/a617fc4b8a by @naoyak)

AppVeyorBot avatar May 28 '20 08:05 AppVeyorBot

:x: Build knowledge-repo 1.0.846 failed (commit https://github.com/airbnb/knowledge-repo/commit/5bb13cfa98 by @naoyak)

AppVeyorBot avatar May 28 '20 08:05 AppVeyorBot

:x: Build knowledge-repo 1.0.847 failed (commit https://github.com/airbnb/knowledge-repo/commit/d63b08987c by @naoyak)

AppVeyorBot avatar May 28 '20 08:05 AppVeyorBot

:x: Build knowledge-repo 1.0.848 failed (commit https://github.com/airbnb/knowledge-repo/commit/aa4d1eb3c5 by @naoyak)

AppVeyorBot avatar May 28 '20 09:05 AppVeyorBot

:x: Build knowledge-repo 1.0.849 failed (commit https://github.com/airbnb/knowledge-repo/commit/fa489dbdfb by @naoyak)

AppVeyorBot avatar May 28 '20 09:05 AppVeyorBot

:x: Build knowledge-repo 1.0.860 failed (commit https://github.com/airbnb/knowledge-repo/commit/95e17f801d by @naoyak)

AppVeyorBot avatar May 30 '20 00:05 AppVeyorBot

@naoyak We're planning a deployment in our data science group, and the author and date templating are features we discussed as "nice to have", so I'm surprised to find that this functionality already exists in this pull request. Is there anything I can do to get this through the door and merged to master? Thanks!

mdshw5 avatar Jun 07 '21 15:06 mdshw5