Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
django CMS 2.1 final was just released!
django CMS 2.1 final was just released! -
nabuco - Nomadblue Blog - Tweaking URLconf (2 named URLs, 1 view)
Introduction Update: I realized I didn't fully explained the whole picture of the issue I am describing here, so I have added a few lines more in the introduction section. In a project with an application named concerts that lists concerts from european cities, consider a classic two-level URLconf where the root urls.py module "includes" (i.e. uses the include method from django.conf.urls.defaults) a second URLconf module. urls.py from django.conf.urls.defaults import * urlpatterns = patterns('', (r'^concerts/', include('concerts.urls')) ) concerts/urls.py from django.conf.urls.defaults import * urlpatterns = patterns('concerts.views', url(regex=r'^list/$', view='my_view', name='concerts_list_all') ) Let's say you want to extend the URLconf and have two kinds of URL to call the same view, the first to display all concerts, the second for concerts in a given city: /concerts/list/ /barcelona/concerts/list/ /london/concerts/list/ /paris/concerts/list/ There are two situations we want to overcome in this scenario. First, only one view must be used, so a little bit of business logic must be implemented. The function behaves differently if it receives the location keyword argument or not: concerts/views.py def my_view(request, location=None): if location is not None: # filter concerts QuerySet by location, for example else: # query all concerts return render_to_response('base.html', {'location': location}, context_instance=RequestContext(request)) The second one is the one … -
django-rbac
I just released my first version of a Role-Based Access Control system for permissions in Django. Development code can be found in BitBucket: http://bitbucket.org/nabucosound/django-rbac/ The project's page is here First of all, I would like to show some drawbacks of Django's current permission system: Permissions are tied directly to the User model from django.contrib.auth, so you cannot use any other existing model in your application. The task of mantaining this list of permissions in the current Django system is responsibility of a superuser or some other kind of centralized entity. You can certainly assign permissions to Group model instances, but all users in this group will share the same permissions. Last, but not least, until Django v1.2 will come and ticket #11010 implemented, the permission system is model-level -- it doesn't allow granular permissions (row-level), which means you can give a user authorization to do something based on all instances of a model class, but not to a single model instance (an object). Many applications, and specially today's web applications -- which involve concepts as collaboration or content driven by the users -- need the flexibility to support delegation of permission granting to objects by other trusted agents. A clear … -
Template tags in django-rbac
It's been a month since the initial release of django-rbac and so far it turned out to be pretty useful for many people. I am therefore happy to have contributed another grain of sand to the open source Django community beach. In Django, as in any MVC oriented framework, developers have to choose which side to put the logic on: a model method or function, inside a view or in a template tag. Although many recommend putting as little logic as possible in template tags, I know sometimes it is good to have one at hand to keep a healthy equilibrium, otherwise views can grow up fat or methods can spread like lemmings in your models and managers. I have recently added two template tags to django-rbac, to request for permission at model or object_level (RBACGenericPermission or RBACPermission, respectively). For example, a template rendering a profile page for a user can decide whether or not to show some personal information at rendering time, using the if_rbac_permission tag: {% if_rbac_permission owner model_inst operation roles %} <p>Pau Casals, 45 years old, male</p> {% else %} <p>You cannot view this information</p> {% endif_rbac_permission %} I updated the app documentation, there you can find … -
Dan Carroll | Blog | Setting up a cron job to run a Django management command in a Python virtualenv
-
django-nbskel
Well it was time already to give some more code into the public domain and the community, so I decided to release my personal way of starting new django projects. I call it django-nbskel ("nb" for nomadblue and "skel" for skeleton). Development code can be found, along with my other apps, in Bitbucket: http://bitbucket.org/nabucosound/django-nbskel/ The project page is here. The purpose if this application is to contain a basic django project and help you out configure it to speed up the process of starting up a new development, be it a quick hack or a long project. I often need to produce new django projects and I don't enjoy doing repetitive things. They start basically with the same structure so with this app I can wrap all the first steps into a couple of actions. It also makes me feel secure because I always tend to forget to initialize settings, include files, import modules, and so on, so with django-nbskel I am sure I am beginning to develop upon a tested and stable code. Please be warned this is code that automates stuff for me, so you will be probably modifying it to fit your django configuration, tools, and deployment … -
Using InfinitePaginator to improve Django paging performance
One of my favorite Django projects is django-pagination. It provides some tools to make it incredibly easy to add paging support for long lists of objects. There are, however, a few considerations to make before using it in an application. Using it requires adding additional middleware, which imparts additional overhead to all of the requests and responses processed by a Django app. Also, in order to calculate the number of pages, django-pagination counts the number of rows in the model's table every time. While my site does not necessarily require screaming performance, I do like to squeeze as much out of my server as possible. For my paging needs, I do not need an exact count on the number of pages available. I provide a monthly archive on the site's sidebar, so for paging I only really care whether there is a previous or next page available. Using InfinitePaginator Luckily, django-pagination provides another option. I took the InfinitePaginator and InfinitePage classes from paginator.py. These allow for easy paging in the cases where it does not matter how many pages there are. To determine if there are any additional pages, it simply performs another SELECT query for one additional object past … -
Django translations for lazy programmers
I came to a dirty but practical solution for one minor project I had to develop for a client who wanted a website with i18n capabilities and also needed to have the different translations for each candidate values each in a different field, in the same model. That is, one field for each language. Here in this post I explain how to achieve it. Let's say we have some models with some fields we want to be duplicated, one for each language. In this example, we will store english (en), spanish (es) and french (fr): class MyObject(models.Model): name = models.CharField(max_length=50) title_en = models.CharField(max_length=50) title_es = models.CharField(max_length=100) title_fr = models.CharField(max_length=100) description_en = models.CharField(max_length=100) description_es = models.CharField(max_length=100) description_fr = models.CharField(max_length=100) class MyOtherObject(models.Model): name = models.CharField(max_length=50) content_en = models.CharField(max_length=200) content_es = models.CharField(max_length=200) content_fr = models.CharField(max_length=200) Notice we append a suffix to each field consisting of an underscore plus the language code. It is important to set the field names this way, as we are going to use a template tag that uses this suffix to find the proper translated field. Next thing to do is add a new TRANSLATION_FIELDS setting that will contain all the field names for ALL your model fields that … -
Extending and improving InfinitePaginator
In the previous entry, I explained how to use the InfinitePaginator class from the django-pagination project. I wanted that article to focus strictly on integrating the functionality into another application, leaving out the additional tweaks I had made. Setting up template context When it comes time to writing a template for a paged object list, there are numerous pieces of data needed: the objects on the page, whether there is a previous page, and whether there is a next page. We can get all of that information from the InfinitePage object in each view and manually add all of it to the template context, or we could directly access that data from the page object itself from the template. Personally, I wanted a consistent experience, so I added a helper method to the InfinitePage class. def create_template_context(self): return { 'object_list': self.object_list, 'has_next': self.has_next(), 'has_previous': self.has_previous(), 'next': self.next_link(), 'previous': self.previous_link(), } This function returns a dictionary with the contents of the page, boolean values specifying whether there are previous or next pages, and strings specifying the URLs to the previous and next pages. Then it is easy to call this function whenever you need to set up the template context: return … -
Setting up a Linux virtual machine for easy web development on Windows
Being a Windows user can be a real drag when trying to use technologies originally designed for the Unix world. This hardship is especially prominent in web development. While I do admire ASP.NET MVC, and enjoy being able to develop in C# as much as possible, my real passion right now is using Python with the Django framework. For simple applications, I often start out using Cygwin, the Django development server, and a sqlite database (side note: have you ever tried to get the MySQLdb library installed in Cygwin? What a mess!). But that setup can only take me so far. Not only is development a little tricky on a Windows box, but deployment and testing can be a mess. Most of the time, my web apps will be running on a Linux server. Ideally, I would be able to test everything locally in an environment as close to production as possible (and as a personal choice, without switching my development machine to run Linux). For a while, I tried to set up my Windows machine to run Apache and MySQL. That's fairly easy to do with something like XAMPP. The hard part is finding all of the necessary extensions … -
My thoughts on DjangoCon Berlin 2010
During this past week I attended DjangoCon, which took place in Berlin thanks to the German Django Association, a non-profit organization founded by german djangonauts. Interesting talks about Django, WSGI, NoSQL, testing, CouchDB, MongoDB, South or front-end design, to name a few. And in the evening or night, geeks gathered in Berlin pubs for beers and fun. I found a relief in meeting so many other people using Django, we djangonauts are a sort of lonely rangers here in Spain. The community is expanding, at the same pace that Django project is growing. In fact, it has already become a grown up in the open source ecosystem, and I think this fact is one of the main reasons that brought Jacob Kaplan-Moss give the first talk in the opening day about how we, Django users/developers/commiters, have to behave with the project itself and to the eyes of the others. The pony, a silly mascot that can be embarrassing to somebody (picture a girl asking her parents to buy her a pony, or a gay decorating his bedroom with stuffed animals, and you won't find the scene much related to guys with beards, pirates, ninjas or geeks hacking python) is precisely … -
Accessing and debugging the Django development server from another machine
In continuing my series about setting up a Linux virtual machine for Django development (see parts one and two), I wanted to share another tip for accessing the VM from the host machine. Set up development server to listen to external requests By default, when using the Django management runserver command, the development server will only listen to requests originating from the local machine (using the loopback address 127.0.0.1). Luckily, the runserver command accepts an IP address and port. Specifying 0.0.0.0 will allow the server to accept requests from any machine: python manage.py runserver 0.0.0.0:8000 I do not have to worry about security issues with the development server listening to all requests, since the VM is protected from external access by a firewall. Set up server to send debug information to local network While the first step will allow us to access the development server from the host machine, we will not be able to see debugging information (for example, the django-debug-toolbar will not be displayed on the host machine, even if DEBUG is set to True). Django uses another setting, INTERNAL_IPS, to determine which machines are allowed to view debugging information. For a typical installation, I set INTERNAL_IPS to … -
New release of django-nomadblog
My Django blogging app, django-nomadblog, is sporting a new look after I added many features I needed for some of my present and future project developments. Mainly, I wanted to turn this app into a multiple blogging system, which means I am able to create and manage multiple blogs from the same installation, via admin interface. The implementation of this followed some improvements in the code and the modularity of the app itself. To upgrade this django blog to the new version of django-nomadblog, I should have created a migration using South, for example. But considering the small size of the database and the project inn general, I went the lazy way and created a fixture from the old database, edited by hand to meet the new models and relationships, and imported it to a fresh database. My punishment for being lazy was missing to update django.contrib.sites to replace the default example.com with nomadblue.com, and to include the data related to the projects site section in the fixture. I'll never learn. -
LFS website goes online
It's done. The website is online. On this place we plan to publish information about LFS in short intervals. If you want to keep informed you can subscribe to our news feed and/or follow us with Twitter. If you have questions or suggestions please don't hesitate to contact the team behind LFS. -
Quellcode is published
Der source code of LFS has been published on Google Code. The code is under the BSD license and can be redistributed and used (also commercial) by everyone. -
Load time in practice
Two reportings of the Bearcounty Gartenhaus Shop show: The performance of LFS approves in practical experience. The reports display the average load time of a category page. (Source: Sitealert, http://www.sitealert.de/) Load time of last 24 hours: Load time of last seven days -
LFS News
Some updates about the progress of LFS: Using South We started to using South for migrations. Works like a charm here. Better PayPal integration Michael Thornhill joined the developer team and started to integrate django-paypal. I'm really happy about it as the package looks clean and well thought. Michael's integration is already up and running. He has created a branch and a buildout. Fixed several bugs We fixed several bugs recently. Thanks to Martin Mahner who reported several issues and provided the patches for them. Smart product suggestions Jens Zeidler (a colleague) started his master thesis. He is developing an application for product suggestions (and more) based on customer behaviour with the help of some AI, which will end within LFS at the end of this year. Adding Portlets We started to add portlets to LFS. We are using django-portlets which is planned to be a standalone application in near future once we are done. Multiple languages support Troels Rønnow (and colleagues) plans to add multiple language support to LFS. We are looking forward to that. That's all for today, next week there will be more news about LFS. If you haven't tried it yet, consider to check it out. The installation will just last a few minutes. Update: … -
This week in LFS (22)
Google group We created a Google group for LFS. Don't hesitate to post there if you have any questions. Portlets engine A first version of portlets integration is available within trunk. There has to be done a lot of work, though. For instance: A decent method to inherit / block portlets from parent objects Transform existing portlets (inclusion tags) to Portlet objects Within that scope we published django-portlets - a generic portlets engine for Django (documentation will follow soon). Fixed issues Again Martin Mahner provided several issues and fixes. Thanks for this. -
This week in LFS (29)
This are the LFS news for week 29. New Shop: In the last couple of weeks we migrated http://www.demmelhuber.net/shop from EasyShop (Plone - http://www.geteasyshop.com) to LFS. Demmelhuber is a (inofficially) top-500 shop in germany and has >1000 unique visits per day. This give LFS a lot of requirements and use cases from a power user (e.g. interfaces to ERP, ebay, amazon, price comparing portals a powerful management interface, etc.). Products: Display and find only active products. Variants: Variants can now be sorted within the product. Some improvements concerning data inheritance from the base product. Criteria: We added some more criteria: combined length and girth, valid shipping/payment methods (which opens some powerful possibilities to make shipping/payment methods dependent from each other) and some others. Addresses/Localization: Michael created a branch for the dynamic display of certain address fields, like state and country. This is (could be) a start for some kind of localization (addresses, currencies, etc.). We need some more insights and discussions. So if you are interested don't hesitate to get in touch. Carts: Added first simple views to manage carts (this needs more improvements). Bugfixes / Cleanups: A lot of template cleanups. Several bugfixes concerning to variants. Several bugfixes concerning to the checkout page. SWFUpload: I still don't get SWFUpload with lighttpd … -
This week in LFS (23)
GetLFS.com We added some screenshots of the management interface. Code Some bugfixes concerning property groups and properties Unified breadcrumbs More information can be found on Google Code. Talk I'm going to hold a talk about LFS at the Python User Group Leipzig (Germany) next weekon June 9. From the agenda: The presentation gives an overview of LFS: used technologies, development status, next releases, existing and planned features as well as a live demo. Everybody who uses Python, plans to do so or is interested in learning more about the language is encouraged to participate. Food and soft drinks are provided. Please send a short confirmation mail to info at python-academy dot de, so we can prepare appropriately. More information can be found here: http://www.python-academy.com/user-group/index.html And that's all for this week ... -
This week in LFS (24)
Code Michael Thornhill has merged the django-paypal branch into trunk, adapted the documentation and the buildouts. Thanks Michael! Troel Roennow started a branch to implement multi language support. We integrated SWFUpload for mass upload of product images. The same thing for files will follow next week. We finished the first working version of portlets. It's now possible to block the portlets of the parent object per slot. We will convert the existing portlets (which are based on templatetags) to the new engine next week. Talk The slides of my talk are online (sorry, only german at the moment) And that's all for this week ... -
This week in LFS (26)
This are the LFS news for week 26. Portlets The portlets story goes on. At the moment there are almost all portlets ported to the portlet engine: cart, categories, pages, recent product, related products, text and topseller. Some of them need some love, though. Additionally for all portlets there are also inclusion tags to render the portlet within templates. So you don't have to use the engine if you don't need this kind of flexibility. You can also easily register your own portlets and slots (by default there is a left and a right slot). Design The design has been refactored. We are using a tableless base template with the help of blueprint now. Also some simplification has been taken place (this is an ongoing process at the moment) Shops We are working on the migration of demmelhuber.net to LFS. demmlhuber.net is a german top 500 shop with more than 30.000 unique visitors per month. This surely will give us some new use cases and experiences for the future. Next week I will work with some designers on a new shop. I expect some insights from their perspective which will flow positively into the template structure. Issues I found out that SWFUpload (which we are using for mass upload … -
This week in LFS (34)
Sorry for being quite for such a long time. We'll try to be more regular in future. There has been a lot of progress in the last couple of weeks. Here are the important things: Improvements A more generic and flexible category tree (added start level and expand level) Better manage views for products, customer, orders, carts, reviews Improved topseller portlet Removed all URLs from Javascript Bugfixes Calculation of average rating Calculation of delivery time for variants Take care of non active products at several places (e.g. product navigation). New stuff Pluggable credit cart handling (needs some improvements though) Pluggable generic export of products And that's all for this week. Next week there will be more about LFS. -
DjangoCon 09 or Bust
In early September I'll be heading out to Portland, OR to join a bunch of smart people talking about all things Django. This year I snuck myself into the mix. I'm honored to have been selected to give a 15 minute how-to talk on "How to name your open source Django project after a famous Jazz musician, and concepts behind Django-Mingus, a project leveraging only reusable apps." The how-to will focus primarily on the latter topic, but don't you worry, I plan on making sure we cover the former in full as well. The talk itself is a spin-off on the lightening talk I gave at the July Django-NYC meetup where I first introduced the open source Django blog engine, Django-Mingus. If you haven't attended a DjangoCon yet, I suggest you go buy yourself a ticket asap - it's a terrific learning and networking experience, and a very organized and well run conference. Purchase your DjangoCon tickets before its too late, and you miss out on all the good times. Now it's time to get everything in order to make a 1.0 release of Mingus before DjangoCon! I will probably use this blog as a forum to talk about making … -
THis week in LFS (42)
After some time here are some news about LFS: Misc The code has been moved to bitbucket: http://bitbucket.org/diefenbach/django-lfs/ There is a first public release on PyPi: http://pypi.python.org/pypi/django-lfs. (Please note that LFS is still in alpha, though) There is also a new buildout to make installation even easier: http://bitbucket.org/diefenbach/lfs-buildout-quickstart/. To install a whole shop one has just to do the following four steps: $ hg clone http://bitbucket.org/diefenbach/lfs-buildout-quickstart/ $ cd lfs-buildout-quickstart $ python bootstrap.py $ bin/buildout -v There is another buildout for development: http://bitbucket.org/diefenbach/lfs-buildout-development/ Documentation Goeff Kelsall provided some documentation on how to install LFS on Windows and some stuff on how to get started: http://code.google.com/p/django-lfs/wiki/InstallationWindowsTest http://code.google.com/p/django-lfs/wiki/GettingStartedDesign http://code.google.com/p/django-lfs/wiki/GettingStartedShop New Stuff Send rating mails: the shop owner is now able to ask customers to rate their bought products after the order has been closed for some time.