Moya Posts

19 posts tagged with moya

I like to imagine components of a Python web framework as personalities. Here's how I would imagine a conversation between a typical view and template would go down:

View Here's that data I just looked up.

Template Don't like it.

View What's wrong with it?

Template Format's wrong.

View You can change the format if you like.

Template Don't wanna. You change it.

View OK. Fine. I'll change it for you.

Which is why I wanted Moya templates to be very capable in processing data, but still keep them designer friendly. If the template data is sane then the template should be able to deal with it, without going back to the back-end developer. continue reading…

I'd like to announce version 2.0.0 of PyFilesystem, which is now available on PyPi.

PyFilesystem is a Python module I started some time in 2008, and since then it has been very much a part of my personal standard library. I've used it in personal and professional projects, as have many other developers and organisations.

If you aren't familiar with PyFilesystem; it's an abstraction layer for filesystems. Essentially anything with files and directories (hard-drive, zip file, ftp server, network filesystems etc.) may be wrapped with a common interface. With it, you can write code that is agnostic as to where the files are physically located.

Here's a quick example that recursively counts the lines of code in a directory: continue reading…

This SO post prompted me to think about how you would go about customizing a entire Django site (not just an app). Particularly if it is a third party project, still in development.

Forking the site repository is a solution, but the more customizations you make, the more awkward it becomes to merge upstream fixes and features. The problem is compounded if you have multiple deploys, with custom templates, assets, and settings.

I wanted to do a quick write-up of how this would be done in Moya, where customization is more of a first-class concept.

I'll briefly go over how you would serve a Moya site with a custom template, without modifying any of the original files. The project I'll be customizing is Moya Techblog which power this blog. continue reading…

The Django code in this post comes from the official Django tutorial.

I've tried not to be disingenuous with the comparison, and I'm only going to compare like with like, so I can show code from both frameworks and let you draw your own conclusions. I'll cover the areas where they differ in another post.

Both Moya and Django use models to map databases on to familiar data structures. In the case of Moya, the mapping is done with SQLAlchemy. Django uses its own ORM.

Here's the models.py from the Django tutorial and a Moya version: continue reading…

Have you ever needed to test multiple user accounts in your web app?

If you need to check your permissions are working correctly, you might find you are constantly switching users by logging in and logging out. Or you could have an admin user signed in to Chrome, and another user signed in to Firefox. Either way, its a bit of a pain.

Here's a simpler solution; define multiple aliases to 127.0.0.1 in your /etc/hosts file. That way you can have one tab open at http://adminuser:8000/ and another open at http://user1:8000/ with two entirely different user accounts.

This assumes of course that you have a development server running locally, and that your app is configured to serve to these 'domains'.

For example (append this to /etc/hosts):

I spent an evening adding 'progressive' loading of the title images to my blog.

The title images for this blog are 3840 × 2160 and a hefty ~650K each. That's entirely intentional; as a photographer I wanted them to look as sharp as possible and take advantage of high pixel density screens.

The only downside of hi-res photos is that even with a good internet connection, you can still see the photo loading as the browser reads the JPEG. It's visually jarring and way too reminiscent of the web, circa 2000s.

A reasonable solution is to first download a smaller lower-resolution version, then load the full resolution image on top of that. So the user sees something relatively quickly, without the visual contrast of an image loading on a blank background. continue reading…

I'm happy to announce release 0.6.0 of Moya.

Moya is a web-application platform written in Python. In that respect it is a lot like other Python frameworks such as Django, Pyramid, Flask, Bottle etc. Moya has versatile URL routing, a fast template language, an ORM, a forms library, i18n support, image processing, and a variety of other tools to build a modern web app. Where Moya differs from other Python frameworks in that Python is not required to make use of these features. continue reading…

Raspberry Pis are useful little computers. I own several, since I work with them in my day job, and I thought it was about time I put one to use.

I also happen to keep tropical insects. Specifically, beetles. These are not your garden variety beetles, unless you happen to live in a rain forest. The ones I have at the moment are elephant beetles which come from Central and South America. Here's a photo:

Male elephant beetle. Banana for scale.

These insects are mostly nocturnal. During the day they tend to burrow under their bedding material (moss), or hang out on a branch. But during the night, they can be quite active. I know this because in the morning they have re-arranged the branches in their tank. continue reading…

Moya's template language is a spiritual successor to Django, and Jinja templates. It borrows a number of constructs from both, and adds a few of its own.

There is a slight difference in the syntax in that variables are substituted with ${variable} rather than {{ variable }}, but tags still use the familiar {% tag %} syntax.

Template languages are generally quite extensible, so there is probably nothing that Moya templates can do that Django / Jinja can't (via a plugin or extension), but there are a few things which are I think are more elegant in Moya's templates language (and built-in). I'm going to talk about a few of them in this post.

How often have you written code like this? continue reading…

A few weeks ago I built a little web application to store notes, which encrypts your notes in the browser and stores them in the cloud (yeah, I hate that term). The idea was that even if the server was compromised, nobody could read the notes without a password.

From the server logs it looks like a few people at least are actively using it, even though there is a big warning saying it is for testing only. No idea for what of course, because even in the admin all I can see is a string of random characters.

This is how notes are stored in the database.

I've jumped straight to version 1.0.0 with the latest release, since it has been running quite happily for quite some time with no issues. It's still 'use at your own risk', but it is such a simple application that there is so little to go wrong. continue reading…