Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Travis CI Presentation
Here’s the presentation I gave about using Travis CI and Django. If you haven’t used TravisCI yet I strongly suggest doing so. If you don’t have any tests for your application to warrant such a program than why are you reading this? Go out and write tests! Related posts: Welcome to ProcrastinatingDev -
Taking command
Commands are the bread and butter of any game. Commands are the instructions coming in from the player telling the game (or their avatar in the game) to do stuff. This post will outline the reasoning leading up to Evennia's somewhat (I think) non-standard way of handling commands.In the case of MUDs and other text games commands usually come in the form of entered text. But clicking on a graphical button or using a joystick is also at some level issuing a command - one way or another the Player instructs the game in a way it understands. In this post I will stick to text commands though. So open door with red key is a potential command. Evennia, being a MUD design system, needs to offer a stable and extensive way to handle new and old commands. More than that, we need to allow developers pretty big freedom with developing their own command syntax if they so please (our default is not for everyone). A small hard-coded command set is not an option.Identifying the commandFirst step is identifying the command coming in. When looking at open door with red key it's probably open that is the unique command. The other … -
Django Requirements 2012-08-15
A little over three months ago I blogged about my preferred requirements list. It's now nearly the eve of Django Dash, and I feel it's time to update the list. I'm going to bump the versions on some of the existing packages and add some new ones to the list. New Packages django-braces==0.1.3 Want to use Django Class Based Views but unhappy with the missing components like LoginRequiredMixin, SelectRelatedMixin, and even StaffuserRequiredMixin? Not to worry, as this library will make Django CBVs 134% easier to use. django-secure==0.1.2 Django is rather secure, but there is a checklist of things that the security experts want you to do. Save yourself forgetting something and use this library to do all those little things. django-profiletools==0.1.3 Have you ever used the django-debug-toolbar and noticed that you did that same request.user.get_profile() call a dozen times? Ever want to just call that once? This library, by yours truly, resolves the issue. It loads the user's profile object once, and then passes it down the request chain. Existing Packages Django==1.4.1 If you need sessions, forms, templates, and relational database models, then I can argue you've got the ideal Django project. Make certain you are running the latest Django … -
Django Requirements 2012-08-15
A little over three months ago I blogged about my preferred requirements list. It's now nearly the eve of Django Dash, and I feel it's time to update the list. I'm going to bump the versions on some of the existing packages and add some new ones to the list. New Packages django-braces==0.1.3 Want to use Django Class Based Views but unhappy with the missing components like LoginRequiredMixin, SelectRelatedMixin, and even StaffuserRequiredMixin? Not to worry, as this library will make Django CBVs 134% easier to use. django-secure==0.1.2 Django is rather secure, but there is a checklist of things that the security experts want you to do. Save yourself forgetting something and use this library to do all those little things. django-profiletools==0.1.3 Have you ever used the django-debug-toolbar and noticed that you did that same request.user.get_profile() call a dozen times? Ever want to just call that once? This library, by yours truly, resolves the issue. It loads the user's profile object once, and then passes it down the request chain. Existing Packages Django==1.4.1 If you need sessions, forms, templates, and relational database models, then I can argue you've got the ideal Django project. Make certain you are running the latest Django … -
Dutch Python meeting on *friday* 21 september in Utrecht
The Dutch Python meeting ("PUN") in september will be on a FRIDAY evening instead of the customary wednesday evening because one of the speakers can't come on regular weekdays, so we're trying it out on this alternative day! I guess some people cannot come on a friday, but probably lots of others can come especially because it is a friday. Please add your name on the wiki page (or alternatively email me) if you think you'll come, that way I can have an idea of how many people will show up. (You can come anyway even if you don't add your name, it is just to help me plan the drinks). The location is conveniently in the center of Utrecht, close to the central station, at Nelen & Schuurmans (same location as January last year, for those that were there). So you can get there easily. If you come by car, there's a car park very close at hand just behind the "Bijenkorf". So... Look at the agenda for the two main talks and start adding a lighting talk of your own! (p.s. we've got a python/django job opening. Just a few days left, though. See my previous blog post.) -
Django Requirements 2012-08-15
A little over three months ago I blogged about my preferred requirements list. It's now nearly the eve of Django Dash, and I feel it's time to update the list. I'm going to bump the versions on some of the existing packages and add some new ones to the list. New Packages django-braces==0.1.3 Want to use Django Class Based Views but unhappy with the missing components like LoginRequiredMixin, SelectRelatedMixin, and even StaffuserRequiredMixin? Not to worry, as this library will make Django CBVs 134% easier to use. django-secure==0.1.2 Django is rather secure, but there is a checklist of things that the security experts want you to do. Save yourself forgetting something and use this library to do all those little things. django-profiletools==0.1.3 Have you ever used the django-debug-toolbar and noticed that you did that same request.user.get_profile() call a dozen times? Ever want to just call that once? This library, by yours truly, resolves the issue. It loads the user's profile object once, and then passes it down the request chain. Existing Packages Django==1.4.1 If you need sessions, forms, templates, and relational database models, then I can argue you've got the ideal Django project. Make certain you are running the latest Django … -
DjangoCon 2012 - Metro
The DC area has a commuter rail called the Metro. It's pretty easy to use in my opinion. Still, I've had to give enough impromptu lessons to tourists to know it's not completely intuitive. The Map Do yourself a favor and get a copy of the Metro's rail map now, whether you store it on your phone or in your backpack. They have one of these maps on every car and in every station, but sometimes people stand in front of them. Lines are indicated by color (that part should be intuitive). Stops are indicated by circles. If a stop appears on more than one line, then you can transfer there. Why are some of the stops double circles? Because they're the first or last place you can transfer to a new line. They're not the only places you can transfer. Any circle on any color (even those that run under two other lines of color) are transfer stations. For example, at L'Enfant Plaza you can transfer to orange, blue, green, and yellow lines. Something to keep in mind: The map is not to scale. Some stops, you can get off and walk to the next stop with no issues. … -
AJAX and Django Views
It seems that cleanly and easily doing AJAX views in Django is an area that gives a lot of people trouble. We like to do views as straight HTTP if at all possible, but there are always interactions that would be better served by not having a page load. We're also big fans of django-tastypie but it's a whole other ball of wax on its own, especially if you want to have views that write to the database. So, for the purposes of getting everyone up to speed doing AJAX with Django, we'll ignore Tastypie for now and just stick with ordinary views. Django automatic CSRF To start things off, put this bit of Javascript from the Django docs into a script that's loaded on all the pages where you'll be needing to perform AJAX views. This allows you to ignore the CSRF token for AJAX views, but it will be added as a request header. We previously said this could be seen as a security loophole and that same-origin came into effect. Both of these statements are wrong. AJAX & Form Field Errors Before we get to the Django side, there are a few small scripts that we recycle … -
Generic Layouts in Crispy Forms
Just a quick tip and sanity check, today, about something I ran into with django-crispy-forms, the awesome new form library from Miguel Araujo. This morning, I converted the project we've been building for a client (currently some 1,700 or so files, counting templates, CSS, and icons) from django-uni-form to django-crispy-forms. It's a pretty painless transition, actually. Just do some find-and-replace across your files, basically changing any instance of uni- to crispy- (well, and form to forms), and you're good to go. Then, however, I wanted to convert two large forms that we have, which share 90% of their fields, to using the sharable Layout objects that django-crispy-forms gives us. Basically, the forms looked like this: class FirstForm(GenericAppFormForTheExample): ... def __init__(self, *args, **kwargs): ... self.helper = FormHelper() self.helper.layout = Layout( "field1", "field2", "special-field", [field3 through field20] class SecondForm(GenericAppFormForTheExample): ... def __init__(self, *args, **kwargs): ... self.helper = FormHelper() self.helper.layout = Layout( "field1", "field2", "special-field2", [field3 thorugh field20] Obviously that was a lot of repetition that we could cut out now that these inheritable layouts exist. By the way, I'm pretty sure this would have been possible in django-uni-form but likely not as friendly. First I started off by creating the shared resources. … -
Our Custom Mixins
UPDATE: We've released a Github repo and a PyPI package with our mixins. Feel free to fork and submit new ones through a pull-request. Let's just start out and say it, Class Based Views. Ooohhhh. Unfortunately the topic of class based views is thought of as somewhat of a dark art in the Django community. It doesn't help that the documentation is still lacking but I find a lot of people, especially on Reddit, refuse to use them. For whatever reason, it's a hard pill for some to swallow. Before DjangoCon 2011, we started playing with class-based views. At first they seemed like a nightmare and without decent docs, we got frustrated really quickly. Skip forward to today and I can't imagine writing old function-based views again. Some argue that the generic views are only for generic applications and that, somehow, their work is far too custom and complex to be handled in a generic class-based view. Based on my experience, 99% of the time, they would be wrong. We plan on covering generic class-based views extensively with GSWD. Today, I'd like to share some mixins we have cooked up, on a rather large client project, that have helped us … -
User-friendlier model forms
Recently, in our large client project, we had need of fields, in a model form, that accepted multiple types of input, but sanitized the data for the model. For example, the rent field, on the form, needs to handle a rent range (e.g. 900-1200), a single amount, or be overridden or extended by other bits of information, like "call for details" or "on approved credit". Obviously we don't want to have to parse this out every time we read the data. So, enter our fields that tear data apart and put it together every time it passes through. Model Let's go over our Rent model first. It's an abstract model so we can use it in multiple places (we have more than one logical model in the system that needs to deal with rent, this way we can use it multiple places without having to hold on to a huge amount of joins). We have several other abstract models that perform the same actions as our Rent model, but I won't show them here. from django.core.exceptions import ValidationError from django.db import models class Rent(models.Model): rent_low = models.PositiveIntegerField() rent_high = models.PositiveIntegerField(blank=True, null=True) rent_percent_income = models.FloatField(blank=True, null=True) rent_oac = models.BooleanField(default=False) rent_call_for_details = … -
How to Setup an Upload Handler for Redactor
Yesterday, I posted about how I was having fun with redactorjs and promised to follow up with how to hook up the ability to upload and embed images. Well, I am pleased to be able to show you how with a few lines of Python and Django. Specifically, we are talking about how to hook up redactor so the image button on the toolbar presents a functioning modal like so: There are two parts to this dialog that we are going to hook up. First, the ability to upload an image, and secondly, the ability choose one that we have previously uploaded. The Model There is a single, super simple model to store the files that get uploaded. The boolean flag indicating whether or not the file is an image is for the support I am going to add to be able to upload regular files as well. It's probably best for me to store an inspected mimetype, but this should suffice for now in case I want to reuse these objects elsewhere in order to know how to display them. import datetime from django.db import models class File(models.Model): upload = models.FileField(upload_to="uploads/%Y/%m/%d/") date_created = models.DateTimeField(default=datetime.datetime.now) is_image = models.BooleanField(default=True) The Views There are two views … -
Alternatives to using Celery
I’ve found some candidates for replacing Celery in my company’s product. (My reasons for replacing it are elucidated here, here, and here.) I got these from web trawling, blog comments, and some e-mail. At first blush, none of the candidates have any disqualifying attributes, except for lacking subtasks. Celery is the only Python-friendly asynchronous task technology with subtask support, so I’ll need to bend on that if I want any alternatives to consider. (If I’m wrong on this point, please let me know in the comments!) I’m not saying that these candidates will definitely satisfy all (sans subtasks) of my requirements. Right now they’ve just passed my initial sniff test. The next step will be to read documentation in detail, assess the health/activity of its community and developers, and try some sample code. The candidates Huey: Web-accessible docs are here. (What is it with projects using Read the Docs? Read the Docs irks me. The stupid icon in the bottom right corner laughs at me.) Doesn’t have subtasks, and the management API amounts to reading the queue from Redis and pawing through it… Gearman with python-gearman and/or django-gearman: Configuration seems more complex than Huey, but with little effort I found … -
Having Fun with the Redactor WYSIWYG Editor
I have been having a blast with redactorjs and will soon be buying a developer license. This past weekend I rewrote my blog to use this new editor instead of the custom Django admin markdown-based editor I had been using. I really love the experience of authoring content in exactly the the same style that it will appear in the site. Unlike other HTML editors, this one is clean and simple and just gets out of the way. -
DjangoCon 2012 - Eating in DC
A caveat: When I'm eating in DC, it's usually because there's a Capitals game going on. I have very deep knowledge of the food options near the Verizon center and that's about it. Happily, DC people are heavy users of Yelp and such, so finding the good places isn't too difficult. I highly recommend making reservations if you can. DC is unpredictable. I've walked into a restaurant on Friday night and found it dead. I've gone back a few weeks later on a Tuesday, and it's jammed. You don't know when conferences will be in town, so just save yourself some heartache and use Open Table. That said, here's my list of places to eat and drink in DC! Near the hotel The hotel is near quite a bit of food. Some of the restaurants are chains (though higher-quality chains) and some are family owned. My favorites: Kabob Place - As many commenters from my last post said, OH MY GOD. This place is awesome. Fantastic kabobs, and now they have a sit-down restaurant along side the original. You get a ton of food, but prepare to wait. Ted's Montana Grill- A chain, but I've yet to be disappointed there. Get the … -
Django-photologue: a new release, and a new maintainer
The django-photologue project gets a new maintainer... me! -
(NL) Python/Django vacature in Utrecht
Note for English speakers: due to the nature of the work, you'll only be really happy if you can speak Dutch, so I'm sticking to Dutch for the rest of this post. Door vakantie ben ik er niet aan toegekomen het eerder te posten, maar... we zoeken weer versterking. Want ik ben er ook niet aan toe gekomen omdat het druk is qua werk :-) En de deadline is maandag 20 augustus 's ochtends vroeg. Da's dus rap. Zie de officiele vacature. Je mag lekker aan de slag met Python en Django, dat zal tenminste de hoofdmoot zijn. Verder heeft iedereen bij ons wel iets extra's. De een is ook goed in serverbeheer. Of in automatiseren. Of coffeescript. Of css'en. Binnenkort zullen we ook meer met NoSQL gaan doen voor een die-krijgen-we-hopelijk grote opdracht. Of misschien optimaliseer je graag een postgresql database. Python en Django zijn dan wel de hoofdmoot, maar lang niet iedereen die bij ons begint te werken is ermee bekend. Beiden zijn snel aan te leren. Dus als je snel een nieuwe taal op kunt pikken is het ook goed. Sowieso maakt het niet heel veel uit of je nou heel ervaren bent of niet: Als je … -
Django-photologue: a new release, and a new maintainer
The django-photologue project gets a new maintainer... me! -
Django urlpattern nested regex groups
Had one of those annoying things that I could not figure out why it was not working; learned something about how django's url routing works along the way. I created a new view for within the admin, that provides a summary of the permissions associated with a group, or set of groups. For our purposes, a company can have a number of groups associated with it, so I wanted to be able to optionally provide a company id: if it was provided, it would only show the groups+permissions for that company; if not provided it should show all of the groups and their permissions. So, I had the urlpattern like: {% highlight python %} # Included under '/company/...' url(r'^((?P\d+)?/)?groups/$', 'group_perms', name='company_group_permissions'), {% endhighlight %} This resolves fine. All of these variations work as expected: http://example.com/company/10/groups/ http://example.com/company/groups/ http://example.com/company//groups/ However, I wanted to put a link in the admin change page for the company class, but was getting resolution errors, so I tried reverse directly: {% highlight python %} reverse('group_perms', kwargs={'company': 10}) # -> NoReverseMatch: Reverse for 'group_perms' with # arguments '()' and keyword arguments '{}' not found. {% endhighlight %} That's odd. Maybe I was getting the name or something wrong: … -
My requirements for replacing Celery
I’m ready to start looking at candidates to replace Celery in my company’s product. (The reasons are elucidated here, here, and here.) Our SaaS product provides data mining and visualization for intellectual property. A 10-second elevator pitch is, it’s as though we attached Microsoft Excel’s chart wizard to US and international patent offices. (“As though” = “We didn’t do that, and in fact we go way beyond that, but I’m giving you a simple description.”) Our code is 100% Django and Python. I looked at how we use Celery in our codebase. The reality of how we use it is much simpler than our ideas when we started two years ago. Combining our existing features with our product roadmap, I know with high confidence what features we need for our asynchronous tasks. And which ones are nice to have but not required, and which ones we’ll probably never need. Here are my Celery replacement requirements. Except for the “I don’t need” or “Tasks don’t have to…” statements, they’re all about equally important. The non-deprecated section of the API does not change often. New code releases have one of two attributes: They’ll be 100% backwards compatible, or they’ll have clear instructions … -
Nodejsconf 2012
Nodejsconf 2012 (italian version below) Here we are, again! Last year, as you probably know, we organized the first Italian conference about NodeJS. We had over 200 participants from across Europe and sessions by international speakers such as Sergi Mansilla (Cloud9IDE ), Arnout Kazemier (Socket.io), Ian Jorgensen (pubsub.io), Gabriele Lana, Golo Roden, Andy Kent (Forward) and Oleg Podsechin. During the conference there was also a workshop held by Gabriela Lana, focused on creating the game "Rock, paper, scissor, lizard, Spock" with nodejs. Based on last year success and the continuously growing interest in NodeJs, WEBdeBS decided to go at it again: the Second Edition of the NodeJs Conference will be held on November 10th 2012 in Brescia. The cfp is open, till September 10th: https://github.com/WEBdeBS/nodejsconf2012 When/Where? The second Italian NodejsConf will be held in Brescia(north of Italy, 70 km from Milan ) Saturday the 10th of November. The same day the Nodeknockout event will start, so we will be providing a room where you can hack with node. At the end of the conference the hackathon will continue in TalentGarden a coworking space, where GrUSP, jsDay organizer, will provide food and beverage. How you can help us? We are looking for speakers and sponsorship that can help us … -
Nodejsconf 2012
Nodejsconf 2012 body,.backgroundTable{ background-color:#eeeeee; } #contentTable{ border:0px none #000000; margin-top:10px; } .headerTop{ background-color:#26292e; border-top:0px none #000000; border-bottom:0px none #FFCC66; text-align:center; padding:0px; } .adminText{ font-size:10px; color:#333333; line-height:200%; font-family:Helvetica; text-decoration:none; } .headerBar{ background-color:#26292e; border-top:0px none #333333; border-bottom:0px none #FFFFFF; padding:0px; } .headerBarText{ color:#333333; font-size:30px; font-family:Helvetica; font-weight:normal; text-align:left; } .postcardBarText{ color:#333333; font-size:30px; font-family:Helvetica; font-weight:normal; text-align:center; } .title{ font-size:24px; font-weight:bold; color:#4A8797; font-family:Helvetica; line-height:150%; } .subTitle{ font-size:14px; font-weight:bold; color:#000000; font-style:normal; font-family:Helvetica; } .defaultText{ font-size:12px; color:#333333; line-height:150%; font-family:Helvetica; background-color:#FFFFFF; padding:20px; border:0px none #FFFFFF; } .footerRow{ background-color:#26292e; border-top:0px none #FFFFFF; padding:20px; } .footerText{ font-size:10px; color:#666666; line-height:100%; font-family:Helvetica; } a,a:link,a:visited{ color:#17488a; text-decoration:underline; font-weight:normal; } .headerTop a{ color:#26292e; text-decoration:none; font-weight:normal; } .footerRow a{ color:#465F5D; text-decoration:underline; font-weight:normal; } body,.backgroundTable{ background-color:#26292e; } (italian version below) Here we are, again! Last year, as you probably know, we organized the first Italian conference about NodeJS. We had over 200 participants from across Europe and sessions by international speakers such as Sergi Mansilla (Cloud9IDE ), Arnout Kazemier (Socket.io), Ian Jorgensen (pubsub.io), Gabriele Lana, Golo Roden, Andy Kent (Forward) and Oleg Podsechin. During the conference there was also a workshop held by Gabriela Lana, focused on creating the game "Rock, paper, scissor, lizard, Spock" with nodejs. Based on last year success and the continuously growing … -
Changing Django cache backend between test cases
Changing Django cache backend between test cases It’s a good practice to run tests for a Django project with a dummy cache backend. This eliminates side effects of one test from affecting the results of other tests. Here’s how to activate the dummy backend in a Django settings file: CACHES = { 'default': { 'BACKEND': 'django.core.cache.backends.dummy.DummyCache' } } However, sometimes it’s also necessary to test how an application uses the cache. In this article, we’ll show how to replace the dummy cache with a real cache backend separately for individual test cases. We’ll use the trivial myapp/mymodule.py below as example code under test: 1 2 3 4 5from django.core.cache import cache def myfunc(key): cache.set(key, 'myvalue') The obvious (but alas, wrong) way One solution is to create a separate test suite with its own test settings. The drawback is that it must be run separately even if the tests belong logically together with the rest of the tests. Django 1.4 makes it easy to override settings on a test-by-test basis (see Overriding settings in the testing section of Django’s documentation). It feels natural that the @override_settings decorator should do the trick of enabling caching separately for individual test cases: 1 2 … -
Thoughts after attending the UNICEF Rwanda mHealth Conference
This past July, I had the pleasure of attending the UNICEF Rwanda Conference in Kigali, Rwanda. The conferences focus was on developing a comprehensive eHealth suite for numerous nations to implement. Mobile technology is changing the landscape of public health in Africa, and SMS messaging is leading the way. Conference goers were tasked with organizing the existing mHealth technical infrastructure to reduce redundancy in the existing applications. The goal was to create a comprehensive mHealth software suite for maternal, newborn and child health, nutrition and ending Mother to Child transmission of HIV (eMTCT). The conference also hoped to improve the interoperability of key existing platforms to provide functionality that is currently not possible by using one software tool. Caktus was very excited to take part in this conference and learn more about how developers can assist in these efforts. Recently, Tobias McNulty and I have become RapidSMS community coordinators. In this new leadership role, our goals are to strengthen the existing code infrastructure and help write extensive documentation. The main goal for the RapidSMS project is to be fully usable by UNICEF country offices and other users without sustained support from outside software consultants. Through attending the UNICEF Rwanda conference … -
DjangoCon 2012 - Life in DC
As long as you're in town, you might as well see some of the sights, right? Smithsonian When people come into town, I always point them at the Smithsonian. It's an awesome set of museums that are completely free. You can spend a week going through them and still not see all of the exhibits. They're also only closed two days a year, and neither of those days are during the conference. Some important notes: You have to go through security to get in. They're going to poke around in your bag with a stick. Some places have metal detectors. The art museums are super-uppity about what you can bring in. If you think about it, this makes sense. Their exhibits aren't behind glass. They have a bag check so you can stash your stuff if needed. The museums open at 10am. One of the buildings, the castle, opens early, but there's not much to do there besides drink a coffee and sit in the garden. Pictures are allowed! Bring your cameras and camcorders! Almost all of the museums ring the Mall. The Mall is a big strip of grass in front of the Washington Monument. It does not have …