Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Follow-Up to Weighted Sorting in Python
The activity on my latest blog post has been tremendous! I never expected that much activity within an hour or two of posting the article. The aim of this article is to provide an alternative solution to my weighted sort when you're after increased performance. It might just be useful to those who came here in search of a way to do weighted sorting in Python. I need to give a shout out to Jeremy Brown for suggesting this solution. He's so awesome :P While the example I posted in my previous article addressed my needs just fine, it is definitely not the fastest option. A better solution would be to completely remove the special IDs from the object list altogether and just place them in front of the list: import itertools import random object_ids = [random.randint(0, 100) for i in range(20)] special_ids = [random.choice(object_ids) for i in range(5)] not_special_ids = (i for i in object_ids if i not in special_ids) for i in itertools.chain(special_ids, not_special_ids): # do stuff with each ID pass This solution is quite different from my weighted sort, as there's no sorting going on at all, just a simple generator and using itertools to chain two … -
Simple Weighted Sort in Python
Last night I found myself in need of a simple weighted sort function in Python. I had a list of integers which represented object IDs in my project. Some of the objects needed to be processed before the others while iterating over the list of integers, and I already knew which object IDs those were. The order the rest of the object IDs were processed didn't matter at all. I just wanted the special object IDs to arrive at the beginning of the list, and the remaining object IDs could be in any order. I was surprised at how simple it was to produce such a weighted sort. Here's an example of what I did: import random object_ids = [random.randint(0, 100) for i in range(20)] special_ids = [random.choice(object_ids) for i in range(5)] print 'Object IDs:', object_ids print 'Special IDs:', special_ids object_ids.sort(key=special_ids.__contains__, reverse=True) print 'Object IDs:', object_ids And some sample output: Object IDs: [13, 97, 67, 5, 77, 58, 24, 99, 29, 20, 29, 75, 100, 31, 79, 5, 27, 11, 6, 1] Special IDs: [13, 1, 27, 6, 67] Object IDs: [13, 67, 27, 6, 1, 97, 5, 77, 58, 24, 99, 29, 20, 29, 75, 100, 31, 79, 5, … -
Building Cursors for the Disqus API
This last week we've been implementing cursors for the Disqus API (3.0). If you're not familiar, the concept is like cursors in your database: create a marker for where you are with your result set so you can iterate through a large set of results efficiently. Think of it like a snapshot. A marke... -
Building Cursors for the Disqus API
-
Cleaning Your Django Project With PyLint And Buildbot
There are a number of tools for checking whether your Python code meets a coding standard. These include pep8.py, PyChecker and PyLint. Of these, PyLint is the most comprehensive and is the tool which I prefer to use as part of my buildbot checks that run on every commit. PyLint works by parsing the Python [...] -
Comentário sobre Configurando um projeto Django no UOL Host – segunda parte por admin
Você precisa repetir o processo de configuração do .htaccess para cada pasta. Mas não pode haver um .htaccess no public_html, apenas em subpastas. public_html/mysite/.htaccess public_html/mysite2/.htaccess O que dá para fazer é colocar um index.html com redirect para o projeto default dentro do public_html. Caso vc queria deixar um projeto de default. public_html/index.html Não sei se ficou claro :P -
Comentário sobre Configurando um projeto Django no UOL Host – segunda parte por Bruno Rodrigues
Excelente Tutorial!!!! O Melhor que eu achei! O suporte da uolhost é horrível. Como você faz pra utilizar subpastas? -
django-mediasync 2.1 for Django 1.3
Earlier today we released django-mediasync 2.1 in anticipation of Django's upcoming 1.3 release. The Django 1.3 RC was released last night so the final version should be coming any day now. This release changes the way static files are handled and breaks previous versions of mediasync. The old MEDIA_URL and MEDIA_ROOT settings are now meant to handle media uploaded by users while two new settings, STATIC_URL and STATIC_ROOT, handle static site content. Mediasync will first try to use STATIC_* settings and fall back to MEDIA_* if not found. This ensures that mediasync will work regardless of the version of Django being used. Find the package on PyPI and the source on GitHub. And as always, if you use mediasync please indicate it on Django Packages. -
django CMS 2.2 roadmap update
django CMS 2.2 roadmap update -
Help desk software?
I’m looking for some help-desk style software with some very specific features: Users create new help requests by emailing a support@example.com-style email. There should be some sort of concept of “support queues” with each queue having an associated email address. So there might be a “sales” queue by emailing sales@example.com, a client-specific queue at client-a@clients.example.com, etc. New issues (i.e. new emails) get automatically assigned to one of a pool of support staff. -
nashvegas 0.6 released
nashvegas 0.6 was released tonight to address a fairly critical bug. I ran into this bug tonight working on a project where I was making use of ContentTypes and realized that there were a bunch of expected ones missing. I quickly got the sinking feeling that this was a major bug in nashvegas so I set about to isolate and find the root cause so that I could fix it. I opened up the Django source code and took a look at what the syncdb command was doing as when I ran syncdb all the ContentType objects were created properly. I quickly noticed this code in the handle_noargs method: # Import the 'management' module within each installed app, to register # dispatcher events. for app_name in settings.INSTALLED_APPS: try: import_module('.management', app_name) except ImportError, exc: # This is slightly hackish. We want to ignore ImportErrors # if the "management" module itself is missing -- but we don't # want to ignore the exception if the management module exists # but raises an ImportError for some reason. The only way we # can do this is to check the text of the exception. Note that # we're a bit broad in how we … -
nashvegas 0.6 released
nashvegas 0.6 was released tonight to address a fairly critical bug. I ran into this bug tonight working on a project where I was making use of ContentTypes and realized that there were a bunch of expected ones missing. I quickly got the sinking feeling that this was a major bug in nashvegas so I set about to isolate and find the root cause so that I could fix it. I opened up the Django source code and took a look at what the syncdb command was doing as when I ran syncdb all the ContentType objects were created properly. I quickly noticed this code in the handle_noargs method: # Import the 'management' module within each installed app, to register # dispatcher events. for app_name in settings.INSTALLED_APPS: try: import_module('.management', app_name) except ImportError, exc: # This is slightly hackish. We want to ignore ImportErrors # if the "management" module itself is missing -- but we don't # want to ignore the exception if the management module exists # but raises an ImportError for some reason. The only way we # can do this is to check the text of the exception. Note that # we're a bit broad in how we … -
nashvegas 0.6 released
nashvegas 0.6 was released tonight to address a fairly critical bug. I ran into this bug tonight working on a project where I was making use of ContentTypes and realized that there were a bunch of expected ones missing. I quickly got the sinking feeling that this was a major bug in nashvegas so I set about to isolate and find the root cause so that I could fix it. I opened up the Django source code and took a look at what the syncdb command was doing as when I ran syncdb all the ContentType objects were created properly. I quickly noticed this code in the handle_noargs method: # Import the 'management' module within each installed app, to register # dispatcher events. for app_name in settings.INSTALLED_APPS: try: import_module('.management', app_name) except ImportError, exc: # This is slightly hackish. We want to ignore ImportErrors # if the "management" module itself is missing -- but we don't # want to ignore the exception if the management module exists # but raises an ImportError for some reason. The only way we # can do this is to check the text of the exception. Note that # we're a bit broad in how we … -
Creating a Custom Panel for the Django Debug Toolbar
Sometimes you work on stuff you don’t really control, eg. when interacting with some mysterious SOAP server accross the Internets, and you’d appreciate a little help from the Django ecosystem to ease debugging. That’s — you guessed it — my case currently, and I really appreciated being able to create my own custom panel for adding specific debugging capabilities to the awesome Django Debug Toolbar. Here’s how I did, learning mainly from the code of the panels shipping with the DJT. I’m supposing you have installed and configured the DJT in your project already. First of all, create a panels.py module within one of your app (or wherever you want as it’s in your python path) and create a DebugPanel derivated class, like this: from debug_toolbar.panels import DebugPanel from django.template.loader import render_to_string from django.utils.translation import ugettext_lazy as _ class MyUsefulDebugPanel(DebugPanel): name = 'MyUseful' has_content = True def nav_title(self): return _('Useful Infos') def title(self): return _('My Useful Debug Panel') def url(self): return '' def content(self): context = self.context.copy() context.update({ 'infos': [ {'plop': 'plip'}, {'plop': 'plup'}, ], }) return render_to_string('panels/my_useful_panel.html', context) The debug panel class methods and code should be self-explanatory enough. Just note you have to create a template, here panels/my_useful_panel.html … -
Disqus experience - cache of model's related fields
Very interesting tricks from Disqus: Scaling The World’s Largest Django ApplicationThe main idea to retrieve related fields by two requests instead of 1 + 25 sql requests using post.userSuch situation caused in several projects simultaneously so I working on optimization things right now.# cacheposts = Post.objects.all()[0:25]users = dict( (u.pk, u) for u in \ User.objects.filter(pk__in=set(p.user_id for p in posts)))for p in posts: p.__user_cache = users.get(p.user_id)And don't forget about SQL indexes - in all cases when field used in ORDER or WHERE sql statements it will increase performance a lot -
django-meio-easytags 0.4 released!
I just released the version 0.4 of the django-meio-easytags. I added a subclass of django’s default template tags Library. And now it’s easier to create a template tag. Take a look. Projects page Read the Docs Download from Github -
Basic Python Logging in Django 1.2: Debugging Made Simple
When I was deploying my new social shopping site Wantbox a couple of month ago, I discovered that I couldn’t use the Django print command in my live Dreamhost (Passenger WSGI) environment like this: print "Hello world!" As a new site, I was still debugging a few persistent nits and really needed to print out messages when certain areas of the code were accessed. A few sites recommended that I try the Django debug toolbar, but I was having trouble getting that to work reliably in my Dreamhost setup. I searched around a bit more and after consuming many web pages, finally discovered a dead simple solution using the built-in Python logging module. Python Logging in Django, Step-by-Step: Open your “settings.py” file and add this code to the bottom: # setup logger import logging PROJECT_DIR = os.path.dirname(__file__) PARENT_DIR = os.path.dirname(PROJECT_DIR) logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)s %(message)s', filename=os.path.join(PARENT_DIR, 'django.log'), filemode='a+')</pre> Create a file called “django.log” at the same level as your project, my setup looks like: . .. .htaccess django.log passenger_wsgi.py passenger_wsgi.pyc public tmp wantbox (my django project) In the view where you need to “print” add the following: import logging logging.debug("hello world!") logging.info("this is some interesting info!") logging.error("this is an error!") Now … -
django-meio-easytags 0.4 released!
I just released the version 0.4 of the django-meio-easytags. I added a subclass of django’s default template tags Library. And now it’s easier to create a template tag. Take a look. Projects page Read the Docs Download from Github -
JSHint Edition Update: 2011-03-01
-
Django CMS 2.2 features that I want to see
… this is the “Post on request” for February 2011 Preface: I have to admit that I was expecting a bigger interest in the “Post on request” topic but probably my blog is too young for this but I think I will try again(soon or not). The more important thing is that Jonas Obrist is [...] -
Django-mockups, l’application mi moquette, mi ketchup
Malgré le fait que le mois de février ne fasse que 28 jours, malgré le fait que j'ai maintenant une petiote qui gazouille gentiment en me regardant avec ses grands yeux bleus, malgré le fait que les journées au boulot ne se finissent jamais, même le week-end, je réussi donc la prouesses de sortir ... -
Karma
Aquests dies estic bastant engrescat i enfeinat amb projectes molt relacionats amb Python i Django. Per una banda estam definit i creant el que serà la segona fase del projecte Clickote, una aproximació simpàtica a les reserves d'hotel en la qual estam passant molt de gust fent-hi feina. Per una altra banda estam migrant un aplicació web feta inicialment amb ezPublish, un CMS dels de tota la vida, cap a Django. Clickote és un projecte en el qual m'està agradant molt fer-hi feina perquè a més del projecte i la tecnologia en sí, ve a demostrar que client i proveïdor de serveis no són antagonistes, sinó que són col·laboradors. Amb l'equip de Clickote ens hi sentim molt bé fent-hi feina. Hem topat amb gent que no tan sols coneix el negoci, sinó que a més és conscient de la part tecnològica i de les implicacions en temps i esforç del que demanen, i sempre hem arribat a solucions beneficioses per al projecte. La migració d'un lloc web des del CMS ezPublish cap a un CMS fet a mida amb Django és també tot un repte i representa també tot una aposta de futur per part del client. A les primeres … -
0.2 release plans
Right, back to it then. Plans for 0.2 are underway, and there’s a bunch of stuff up now on the issue tracker. Looking to address permissions & authentication in this next release. The main planned features are: Throttling. Implemented as … Continue reading → -
Team of experienced Django devs looking for remote contract work
Three month ago I decided to become a freelancer. As of 31 January 2011 I stopped working for Open-E company where I spent last 3 years as Python/Django developer. Now I join forces together with my friend Bartosz Burclaf under name of eFabryka.com. We are a small, agile and goal oriented, distributed developers team operating out of Poland. In our daily work we strongly believe in KISS and DRY principles. While designing and writing our code we follow TDD/BDD approach. We are looking for interesting projects to dive into - find out more on: www.efabryka.com -
django-meio-easytags 0.3 released!
I released today the version 0.3 of django-meio-easytags. Now it supports template tags that accepts positional arguments (*args) and keyword arguments (**kwargs). If you don’t know how to use this, take a look at Python FAQ. In this release I included some documentation and created a page for the project. Any doubts, suggestions, feature requests, feel [...]