Posts about python (old posts, page 46)

2013-08-08 21:44

New project: Nikola Event Kit

The Python Argentina group organizes lots of events. Like, half a dozen every year, or more. Those include multi-day events like PyCamp, larger conferences like PyCon, and several PyDays.

PyDays are special, they are usually single-track, just one day (obviously), free, and organized at universities, for students, and often by students. And one stumbling block is usually how to setup the web infrastructure for one. There is a web2py app created by Mariano Reingart, but I feel it's overkill. Also, setting up hosting, databases, customizations, etc. is a lot of work!

So, I decided, prodded by Juan Rodriguez Monti, to see how much can be done without setting up complex things. And I think it's quite a lot. Based on Nikola my static site generator, I created a template site for small events, like PyDays, called Nikola Event Kit

The goal is that you should be able to setup basic content, signup form, schedule, and the obvious needed things in one day. And then you can allocate another day or more for customizing the look of the site.

And then you are done, no need to deploy anything other than plain HTML.

If you want to test-drive it, here's a demo site and here is the code ready for you to fork into your own event's site.

Have fun!

2013-07-30 06:10

New Nikola Feature: SVG Charts via Pygal

I can't sleep, so I just whipped together a docutils directive that wraps pygal for Nikola, my static site and blog generator.

So, how do you use it? LIke this:

.. chart:: Bar
    :title: 'Browser usage evolution (in %)'
    :x_labels: ["2002", "2003", "2004", "2005", "2006", "2007"]

    'Firefox', [None, None, 0, 16.6, 25, 31]
    'Chrome',  [None, None, None, None, None, None]
    'IE',      [85.8, 84.6, 84.7, 74.5, 66, 58.6]
    'Others',  [14.2, 15.4, 15.3, 8.9, 9, 10.4]

Read more…

2013-06-22 16:08

Nikola Themes Repo is Now Official

As of 1 minute ago, Nikola github master's "install_theme" command pulls themes from http://themes.nikola.ralsina.me

So, suddenly, instead of 2 themes for download, you have ~65 (although of course, most of them are bootswatch variations in 2 themes, jinja-default looks exactly like default, and orphan is useless ;-)

And you can contribute themes now!

How?

  1. Give me a pull request at https://github.com/getnikola/nikola-themes

    All you have to do is add your theme in themes/ and pull request.

  2. Send me a zip of your theme and I'll do it.

Contributing themes will take a while because the theme has to be examined for malicious code in the templates, but I will process them, slowly but surely. If you have sent me a theme in the past and I have not done it, I am terribly sorry and hope you can find it in you to try one more time :-)

The themes site itself is not exactly awesome, but it is functional, and you can get themes from there too, and see demo sites for each theme, and even look at autogenerated screenshots (which sadly don't show webfonts)

2013-06-19 15:41

MinCSS is amazing

I had this issue open in the bug tracker for Nikola (my static site generator) for a long time: "Add mincss support".

Well, no, it doesn't have it yet, but I did some research on whether it would be worth adding. And boy, mincss impressed the heck out of me.

You see, Nikola's themes tend to use unadultered bootstrap, which means they carry a large number of things that are not used in their CSS. Besides, it uses several stylesheets from docutils, pygments, and more.

What mincss does is examine your HTML and your CSS, and remove all the unused CSS. So, I wrote a script that examines the Nikola output and overwrites the CSS files with the minimal things that are actually needed there.

And the result?

Here is the before/after for each CSS file in Nikola's demo site:

bootstrap-responsive.min.css  16849  3251
bootstrap.min.css            106059 14737
code.css                       3670  2114
colorbox.css                   6457   774
rst.css                        6559  2581
theme.css                      1287  1061
-----------------------------------------
                             140881 24518

But wait, Nikola supports bundling all those files into a single large CSS file to avoid network requests (using webassets). Does it work in that case too?

Well yes:

all-nocdn.css                167457 29496

But that is not all. The mincss files are not minified. Passing all-nocdn.css through Yui-compressor shrinks it further to 20599 bytes. Which, gzipped, is a paltry 4801 bytes. That means the complete styling of the whole site is a single CSS file less than 5KB in size.

That, is impressive.

2013-06-03 00:31

Deploying Django Into My Cheap VPS

I am preparing to open my cheap site-and-blog-hosting service to the public at some point, so I needed to do some groundwork into deployment. Consider that the host that will run it will have very limited resources, so I needed to find lean and cheap solutions when possible, but at the same time, I want to achieve reasonable reliability and ease of deployment.

Since this is a testing server, I want it to have git master deployed. I don't want automatic deployment, but I want to deploy often, meaning several times daily.

I preferred simple tools instead of complex tools, lightweight tools with just enough features instead of heavier, more fully-featured tools. Your choices on each step could and probably should be different than mine, depending on your situation, requirements and personal preferences.

So, here's my notes from how it's done currently. This is not meant as a HOWTO, just a description of what seems to be working well enough so far.

Read more…

2013-05-28 14:26

(Re)Introducing Alva, a Nikola Server

Over a year ago (time flies!) I posted something about a project called Alva. Let me quote myself:

Alva is almost the opposite of Nikola. If Nikola is about making static sites, Alva is a dynamic site. However, as Hegel suggests, from the thesis and the antithesis comes the synthesis.

So, Alva is about dynamically creating static sites. If you want to have Nikola in your server instead of in your own computer, and have the convenience of an online tool, that's the niche Alva tries to fill.

So, you would install Alva, and use it like any other web-based blogging tool. Yet, behind the scenes, you would have Nikola, and all the performance and security benefits of static sites.

And maybe someday, I (or someone) will put up a multi-user version of Alva, and you will be able to get hosted blogs, knowing all the data is yours and you can leave anytime and do your own thing.

The approach I was taking at the time proved to be unsuccessful, and there were a few other failures along the way. Of course, the problem was in how I was approaching the task. So I did the right thing, and learned how to do it "right".

Still not usable, still not hosted anywhere, but already semi-functional: Alva lives now

There's a lot of work still to be done. But I now know how to do it. To prevent the usual arguments, here is a little explanation of motivation, tooling, etc.

Motivation

I want a way to host blogs very cheaply. How cheaply? I want at least 1000 reasonably active users in a $5 VPS. That would make Alva a reasonable alternative to hosted multi-user wordpress, which means it would be a reasonable solution (if setup is easy enough) for small-to-medium organizations which don't want to setup expensive infrastructure yet want to own their data (think schools, small businesses, FLOSS projects, etc.) I also want to provide that service, for free. Which is why another reason I want it to be super cheap.

How does Alva help provide this super-cheap blog hosting?

  1. It needs to scale following the number of edits not views.
  2. If it gets too busy with edits, changes take longer to appear, but the site itself doesn't get any slower.
  3. Editing and serving can be provided by separate services, so I can use some super-fast static file server and a super-configurable WSGI deployment.
  4. Individual pages can be heavily optimized so that they download fast

Tools

One of the guiding principles here is that to deliver this sort of thing, in my spare time, the development process needs to be stingy with the most limited resource: me. I can't spend a lot of me here. I need to be careful and not over-promise.

So, whenever there was a 3rd-party tool that saves a significant amount of time, that's what I am using.

Django
Because it has a much stronger 3rd-party toolset than Flask or any micro-framework. For example, the Flask equivalent of django-allauth broke my will to live. Because the admin interface means I can start adding data to see if it makes sense before I write all the required views.
Django-allauth
Because I don't want you to have to create accounts here unless you want to, this provides (optional) social login and registration. This was easy to setup and works almsost out-of-the-box
Bootstrap and Django-bootstrap-toolkit
Nikola is already heavily invested in bootstrap, so it just made sense to go further down that road. I understand bootstrap, and django-boostrap-toolkit is easy enough (although I can't make their datepicker work)
Django-datetime-widget
Because fighting is boring.
Django-debug-toolbar
Because Django's mechanisms to find templates and static files are many and confuse me.
Redis + RQ + django-rq
It's crucial for the whole approach to use job queues in order to detach the rendering from the actual Django app. This combination makes job dispatching ridiculously easy, setup is trivial (install everything, start redis, a few lines of config, ./manage.py rqworker and off you go) and they provide a django admin page where I can see the failed jobs, which is awesome.
South
Because it's easy enough, and allows me some freedom exploring data organization in my models without committing to it forever or recreating databases with test data all the time.
Gatling
I will probably serve the generated sites via gatling just like my current sites because it has the simplest named domain configuration possible, it's fast and very light in resource usage.
Markitup
A cool, simple editor with live previews that supports almost every markup. Not WYSIWYG or even WYSIWYM so possibly I will have to add an alternative. I started using django-markitup but it's not a good idea (it uses a old version of markitup which requires JQuery < 1.9) and am in the process of just using Markitup manually.

So, feel free to give Alva a try and/or give me a hand, comments welcome.

2013-04-16 10:26

Here's a very big gun, there's your foot: PHP support in Nikola

I am a very big proponent of static site generators. I would not have bothered writing Nikola otherwise. But there is always that feeling that maybe there is some little thing which is hard to implement, like a contact form.

And let's face it, the easiest way to solve some of those things is by sticking a few lines of PHP in your HTML.

So, if you really want to, you can do it. I think Nikola (github master) is the first static site generator that supports php code. Here's how:

  1. Add php to your page_compilers (because I will never put it there by default):

    post_compilers = {
        "rest": ('.txt', '.rst'),
        "markdown": ('.md', '.mdown', '.markdown'),
        "textile": ('.textile',),
        "txt2tags": ('.t2t',),
        "bbcode": ('.bb',),
        "wiki": ('.wiki',),
        "ipynb": ('.ipynb',),
        "html": ('.html', '.htm'),
        "php": ('.php'),
    }
    
  2. Add php posts or pages to your post_pages:

    post_pages = (
        ("posts/*.txt", "posts", "post.tmpl", True),
        ("posts/*.php", "posts", "post.tmpl", True),
        ("stories/*.txt", "stories", "story.tmpl", False),
        ("stories/*.php", "stories", "story.tmpl", False),
    )
    
  3. Create a php post:

    nikola new_post posts/foo.php
    
  4. Put php in there:

    <!--
    .. date: 2013/04/16 09:57:09
    .. title: php test
    .. slug: foo
    -->
    
    <?php
    Print "Hello, World!";
    ?>
    

Build the site as usual, and you should end up with a page with PHP extension, that has that PHP in the "content" area, so it will follow your site's theme. Of course you can't do things like add HTTP headers and such, but hey, read the title.

2013-04-15 11:04

Nikola version 5.4.4 is out!

Yes, version 5.4.4 of Nikola, my static site/blog generator is just published at the usual place, including the following improvements:

Features

  • New Japanese translation.
  • Nikola check exists with 1 if there is an error
  • New HIDE_UNTRANSLATED_POSTS option that ensures you don't have mixed-language pages (Issue #373)
  • New theme "site-planetoid" for use with the planetoid plugin.
  • New 'retired' tag for posts that should no longer be in feeds.

Bugfixes

  • Added post data as a uptodate check for mustache (Issue #456)
  • Rebuild post pages when the post's translation list changes (Issue #458)
  • Handle "-h" (Issue #460)
  • Added correct help for console command (Issue #460)
  • Escape twittercard data (Issue #452)
  • Added missing "twittercard" in story template
  • Added support for per-language tags (Issue #450)
  • Fix wrong path splitting (Issue #434)
  • Remember locale even when set_locale failes (Issue #446)
  • Decode path argument in new_post (Issue #442)
  • task_indexes had missing config dependencies (Issue #441)
  • Removed bogus links to slides assets that were removed
  • Compressed files were seen as unknown by "nikola check"
  • local search and mustache plugins must be disabled by default (Issue #437)
  • Avoid failure if there are no tags and USE_GZIP is enabled (Issue #439)
  • Fix aspect ratio detection in Vimeo videos (Issue #440)
  • Blogger importer was passing wrong options to "nikola init" (Issue #408)

Contents © 2000-2018 Roberto Alsina