Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Pypi and externally-hosted distributions
There's a whopping huge discussion on Python's catalog-SIG mailinglist about deprecating external links on PyPI (the Python Package Index). What is the problem? Well, my colleague has this now: $ pip install mercurial Downloading/unpacking mercurial ^C^C^C^C An endless wait for downloading mercurial from PyPI. Bad PyPI, right? No, actually not. Pip (or buildout) looks at http://pypi.python.org/simple/Mercurial/ This page is full of download URLs like http://mercurial.selenic.com/release/mercurial-1.6.3.tar.gz . Which have been failing for a couple of hours now because currently the mercurial website is down (it will probably be up again if you read this later). What I want to see is PyPI-hosted download links like http://pypi.python.org/packages/source/z/zest.releaser/zest.releaser-3.27.tar.gz#md5=f670b3b35b6a4e432fc97fc9659e95df . PyPI reliability has been really good lately. But if you have a PIP requirements file or a buildout with many dependencies, two or three of those dependencies will be on external non-PyPI servers, like mercurial's. So instead of the reliable PyPI, you now have three servers that can be down... Andreas said it best: I give a shit at the arguments pulled out every time by package maintainers using PyPI only for listing their packages. Some arguments might be valid, but these projects are, taken as one group, actively breaking pip and buildout regularly. … -
Django 1.5 ya está aquí
Se acaba de lanzar Django 1.5. La nueva versión incluye interesantes mejoras decritas en las release notes. Éstos son algunos de los aspectos más destacados: Django 1.5 introduce soporte para un modelo de usuario configurable. El modelo básico de usuario de Django sigue presente, pero ahora el framework soporta especificar nuestro propio modelo y que el sistema de autenticación de Django la use. Django 1.5 es la primera versión de Django con soporte para Python 3 (específicamente, Python 3.2 y posteriores). El soporte para Python 3 todavía se considera experimental, pero hay disponible una guía para portar nuestro código a Python 3 y los bugs de compatibilidad con Python 3 se considerarán bloqueantes para futuras versiones... -
A Weekend In Russia
This past weekend I had the opportunity to attend Russia’s first ever PyCon. If you’re not familiar, PyCon is the name used for several Python programming conferences. The event itself was set at a holiday lodge in Yekaterinburg and had somewhere between 200 and 300 attendees. It’ … -
A Weekend In Russia
This past weekend I had the opportunity to attend Russia's first ever PyCon. If you're not familiar, PyCon is the name used for several Python programming conferences. The event itself was set at a holiday lodge in Yekaterinburg and had somewhere between 200 and 300 attendees. It's not often I g... -
A Weekend In Russia
This past weekend I had the opportunity to attend Russia's first ever PyCon. If you're not familiar, PyCon is the name used for several Python programming conferences. The event itself was set at a holiday lodge in Yekaterinburg and had somewhere between 200 and 300 attendees. It's not often I g... -
Djangocon.eu in Warsaw: I'm coming!
Yeah, I booked my ticket this afternoon. I'm in! The final batch (40% of the tickets) went on sale at 16:00 CET and our secretary got my ticket in at 16:05, except that my boss's credit card didn't work. So I had to grab my own, but I'm in. I'm happy that the company that I work for (Nelen & Schuurmans) pays for my ticket. Going to a conference is an essential part of keeping my knowledge up-to-date. I told them that during my job interview. That's actually a funny story. I'm a civil engineer by education, so I don't have an official IT background. Lots of experience, but no official IT education. So the second question I got during my job interview was something like: we were actually looking for a real solid IT programmer and now we're getting a civil engineer again. We already have one :-). So... how do you learn? How do you keep your knowledge up to date? I liked the question. I had no problem pointing at my experience (which they knew about: of course they googled me beforehand). And what about learning and keeping my knowledge up-to-date? Well, two things, I answered: Reading … -
Django: Log and block brute force attempts
Here is a very simple mechanism for wrapping a decorator around your views to protect them against brute force attempts. For instance, if you have a secret file download available only with the right secret (/view/id/secret-hash/), you expose your view to simple brute force attempts. Simply put, this decorator will log a 404 response object or Http404 exception, count pr. IP and return status=400 and send you an email whenever a new block is put into place. Model class IllegalLookup(LogModifications): """Log and block illegal lookups""" created = models.DateTimeField( verbose_name=_(u'created'), auto_now_add = True, ) modified = models.DateTimeField( verbose_name=_(u'created'), auto_now = True, ) ip_address = models.CharField( max_length=16, null=True, blank=True, verbose_name=_(u'IP address'), ) path = models.CharField( max_length=255, null=True, blank=True, verbose_name=_(u'path'), help_text=_(u'First attempted path is always logged'), ) count = models.PositiveIntegerField( default=1, ) @classmethod def log_lookup(cls, ip_address, path): try: now = timezone.now() expired = now - timedelta(minutes=settings.BLOCK_EXPIRY) lookup = cls.objects.get(ip_address=ip_address, modified__gte=expired) lookup.count += 1 lookup.save() except cls.DoesNotExist: # Delete old entries first cls.objects.filter(ip_address=ip_address).delete() lookup = cls.objects.create(ip_address=ip_address, path=path) lookup.save() @classmethod def is_blocked(cls, ip_address): try: now = timezone.now() expired = now - timedelta(minutes=settings.BLOCK_EXPIRY) lookup = cls.objects.get(ip_address=ip_address, modified__gte=expired) if lookup.count == settings.BLOCK_ATTEMPTS: mail_admins("IP blocked", "{0} is now blocked, IllegalLookup id: {1}".format(ip_address, lookup.id)) if lookup.count > … -
Using Django flatpages content in other (class-based) views
The flatpages application that ships with Django is both (intentionally) simple and useful. In previous projects I’ve found myself both extending the models (to add data like meta tags) and duplicating the whole application (when I wanted to add a whole bunch of extra details, multiple content sections, or a WYSIWYG editor). In a recent project I had the need to editable (by administrators) content in other views, and I turned to flatpages again for my solution. What I did was to create a class-based view mixin to find the flatpage for a given URL (defaulting to the one defined in request.path), and include the resulting object in the context (once the title and content had been marked safe of course): from django.contrib.flatpages.models import FlatPage class FlatPageMixin(object): """ Retrieves the FlatPage object for the specified url, and includes it in the context. If no url is specified, request.path is used. """ url = None def get_context_data(self, **kwargs): if not self.url: self.url = self.request.path context = super(FlatPageMixin, self).get_context_data(**kwargsG) try: flatpage = FlatPage.objects.get(url=self.url) flatpage.title = mark_safe(flatpage.title) flatpage.content = mark_safe(flatpage.content) context["flatpage"] = flatpage except FlatPage.DoesNotExist: context["flatpage"] = None return context Then you just need to ensure a flatpage exists for the expected (or … -
Better UI prototyping with a Django twist
As part of our new appreciation for start-up organizations and their love of Django, we thought we’d share how we approach the concept of rapid UI prototyping.Early stage start-up companies often need a proof of concept to help convey the vision of the new business model. Yes, there ... -
Team Django Update
Reflections on my Progess Team Django is progressing nicely so far. We have provided a variety of contributions to Django. If you proceed to our Contributions page on the team wiki can you view each contribution. So far the team has contributed 4 documentation changes, one bug report, and fixed a bug and provided a regression test for the fix. I feel the team is working well together, and I am content with our current progress. Not to say areas could not be improved, but that is the nature of all things. As we progress we are attempting to increase the difficulty in the scale of our contributions, so I am unsure if the current progress will be maintained. To ease the transition to tackling more difficult tickets, team members will need to have a better understanding of the Django codebase.Thus I am proposing we read through the code and focus on the unit tests. Yes, I did say focus on the unit tests. As one of the hosts pointed out in the 25th episode of Programming Throwdown, well written unit tests serve as great documentation of the program's code. So by reading through unit tests, developers new to the … -
Nice Django sprint in Utrecht
Last weekend I joined in the world wide Django sprint. Nice! I went to Utrecht (NL), which is just half an hour from my doorstep :-) We could use the offices of the Dutch game garden for free, for they want to support initiatives like a Django sprint. It was a nice place in a former bank office right in the center of Utrecht. On saturday some 50 people attended, on sunday 25 (both my estimate). Three core committers were there: Jannis Leidel, Aymeric Augustin and Florian Apolloner. That's really a tip when you're organizing a sprint: get one or more core committers on board for questions, tips and for the occasional nudge to accept pull requests. It just makes the whole process work much smoother. By design, Django's community process is pretty much centered on the double handful of active core committers (at least to my eyes; by comparison I'm used to 80 committers to the core Plone code). For me, getting to know a couple of people better (amongst them two core committers I hadn't met that way) was the highlight of the weekend. Github talks about "social coding": they really have a point. Don't underestimate the social … -
The restful Marketplace
While the Firefox Marketplace is being built, we are starting to make some fundamental changes in the way the Marketplace is constructed behind the scenes. In the beginning there was one big Django site that served all the requests back to the users. Over the course of the last few months that has changed to being a smaller number of services that provide APIs to each other. We’ve got separate services for payments (and this), statistics (and this) and a new front end client and plans for more. The main communication mechanism between them is going to be REST APIs. For REST APIs in Django we are currently using Tastypie, which does a pretty good job of doing a lot of things you’d need. There are a few frustrations with Tastypie and going forward I’m extremely tempted by Cornice, which we currently use for statistics. When you ask people about consuming REST APIs in Python, lots of people tell me “we just use requests“. Requests is a great library for making HTTP calls, but when you are developing against a REST API having all the overhead of coping with HTTP is a bit much. Coping with client errors versus HTTP … -
Django staticfiles documentation
At the Django sprint in Utrecht (NL), I'm working on the Django staticfiles documentation (see ticket 19582). To get my own thoughts sorted out, I'm trying to rewrite the existing HOWTO here in this blog entry :-) Very short, of course. Mostly to figure out a working structure. A funny thing happened when writing it: I learned new things. We're sprinting on the staticfiles docs with four people and each one sees different new things. I personally didn't know the {% static "app/logo.png" %} template tag existed to help you with custom backends. And I did take a look at those custom storage backends at the same time as I hadn't really looked at them before. Anyway, here's a short howto on Django's staticfiles: Managing static files (css, javascript, jpg) Your website will probably include images and css files. Django provides django.contrib.staticfiles to help you manage them. Note: the term static files differentiates them from the files that are uploaded to your site (though FileField, for instance). Those uploaded files are called media files. You'll see the difference in some of the settings. Using django.contrib.staticfiles By default, Django looks for static files in directories called static/ inside your apps and … -
Getting vagrant box networking working again after wifi change
I'm using vagrant for my osx python/django work. There's one big problem I had: networking would stop working when I switched between work and home. Probably because of a different wifi. Pretty irritating, as I'd have to do a full vagrant halt and vagrant up dance. In the end, the solution was pretty obvious and simple. I didn't think of it myself though :-) The solution was on stackoverflow. Inside the VM, execute: sudo /etc/init.d/networking restart Hurray! (I've of course added it as a shell script to my personal tool/scripts/whatever collection.) -
Another scoop of Django testing
Two scoops of Django is a good book, and I recommend it to anyone who's working with Django. So when I finally got around to using travis-ci I turned to the packaging and testing chapters, but couldn't find anything that would really help me. Travis is a continuous integration service and is free for open source projects. Travis itself is also open source, so you can run your own servers in-house if necessary. Why would you want to use it? It allows you to test your applications against different OS configurations, so you can make sure your code will work on other setups, and not only on your own developement box. Even if you already test on two or three different systems, Travis will probably be an improvement. Travis-ci supports many languages other than Python, a variety of databases and even xvfb for GUI tools, which is handy for in-browser testing. Self-contained tests I always thought a package should have self-contained tests, so that you can run them without adding the app to a local project. The book focuses on doing project-wide testing. I used to use an approach of including a minimal test project in the package's source tree … -
Another scoop of Django testing
Two scoops of Django is a good book, and I recommend it to anyone who's working with Django. So when I finally got around to using travis-ci I turned to the packaging and testing chapters, but couldn't find anything that would really help me. Travis is a continuous integration service and is free for open source projects. Travis itself is also open source, so you can run your own servers in-house if necessary. Why would you want to use it? It allows you to test your applications against different OS configurations, so you can make sure your code will work on other setups, and not only on your own developement box. Even if you already test on two or three different systems, Travis will probably be an improvement. Travis-ci supports many languages other than Python, a variety of databases and even xvfb for GUI tools, which is handy for in-browser testing. Self-contained tests I always thought a package should have self-contained tests, so that you can run them without adding the app to a local project. The book focuses on doing project-wide testing. I used to use an approach of including a minimal test project in the package's source tree … -
Android Fragments 101
_**Prerequisite**: You are already aware of the [basics of building a HelloWorld](http://developer.android.com/training/index.html) in Android and know [how to use the APIs provided in the support library](http://developer.android.com/training/basics/fragments/support-lib.html)._ _The code example is available on [github](http://github.com/iontech/Fragments_Example "Fragments Example")._ _____________________________________________________________ Ever wanted a code snippet from an Activity to be available to other activities? Perhaps a Button or a ListView, maybe a Layout or any View/ViewGroup for that matter? Fragments let us do just that. Necessity is the mother of invention. Before understanding what Fragments are and how they work, we must first realize their existence in the first place. The Problem ----------- Suppose we have an Android app with two Activities- [*FirstActivity*](https://github.com/iontech/Fragments_Example/blob/master/src/main/java/com/github/iontech/fragments_example/FirstActivity.java) and [*SecondActivity*](https://github.com/iontech/Fragments_Example/blob/master/src/main/java/com/github/iontech/fragments_example/SecondActivity.java). *FirstActivity* contains two Views, a `TextView` (*textView*) and a `Button` (*button1*); and *button1* has an `onClick()` callback that `Toast`'s a simple message "Button pressed". *SecondActivity* contains both the Views present in *FirstActivity* and a `Button` (*button2*). Now we want to utilize the two layout components(Views) of *FirstActivity* in *SecondActivity*, we can go about this with two approaches: 1. Copy and Paste the xml elements of the two Views. 2. Create a separate layout for common Views and reuse it using `` layout element. More about this [here](http://developer.android.com/training/improving-layouts/reusing-layouts.html). Electing the … -
Todo List App: Open Sourced
Announcement: We are open sourcing a few tools we developed recently. Here is the first one. *[Todo List Chrome App](https://github.com/agiliq/to-do-list-chrome-app)* This is a simple todo app - with the key feature that it is completely offline. ### Features 1. Create todo list 2. Create todo 3. Mark as done 4. Delete 5. Totally offline [Get the source](https://github.com/agiliq/to-do-list-chrome-app) or [install the app](https://chrome.google.com/webstore/detail/to-do-list/pmpdkgedikcgfpjbcafckjabeeialdel). -
Password Generator App: Open Sourced
Announcement: We are open sourcing a few tools we developed recently. Here is the second one. [Password Generator Chrome Extension](https://github.com/agiliq/forgot-me-password) [Install it from chrome webstore](https://chrome.google.com/webstore/detail/password-generator/nnjgaeekiplalipomfgacalgehhcckbp) Here are the docs ### Summary A completely client side password generator. ### What is it Its a chrome app to generate unique passwords for each site. Depending upon the domain and a master password a unique password is generated. It doesn't need any server and everything happens on the client side. ### Why? I want to use a unique password for each website. However, I don't want to use lastpass/1password as I find their interface confusing and overkill, and I don't want my password stored on remote servers. I use a simple passwording scheme. I have one master password. For each site, I append the first two letters of the domain to master password and use that as the site password. This is sub-optimal as its easy to understand this scheme, if say two of my passwords are leaked. I want to algorithmically generate the password on the client side, with a chrome app. ### How does it work? password_1 = SHA256(masterpassword+domain) password = take_first_8_letters(password_1) This will generate a per domain password with 8 … -
Tutorial: Building a Chrome app
This is a hands on tutorial about How to build chrome apps, with examples of two Chrome apps we published recently. Lets get started. Chrome apps are of two types: Extensions : They extend the functionality of Google chrome and the websites. They have little or no UI. Ex:Password Generator . Source code : Github Apps: These are separate apps and appear just like any other website. Ex: To Do List. Source Code : Github Depending on our requirement, we need to decide what kind of app we need to build. Extension: Password Generator Installation : Visit the link Password Generator using google-chrome browser and click 'Add To Chrome' button on the top-right corner. Then an extra icon will appear right to the address bar of the browser. If you cant see any icons, try clicking the 'down arrow' that is visible between the address bar and the settings icon. Or just drag and decrease the size of the address bar to see the icons. (see screenshot from the app). Click the icon and a small popup will be opened which is the required app ! What it does : It gets the domain of the currently opened webpage and … -
MoreApps - Android Library Project: Open Sourced
If you have a portfolio of apps, you probably want to cross promote them. We are open sourcing an Android Library Project to make this possible. [Get the code](https://github.com/agiliq/MoreApps). This provides an Activity which you can show with a Grid of your apps. How to use it ------------- Add this MoreAppsLibrary project(library) as a dependency in the Android Application project you are implementing. Add the following code in your `AndroidManifest.xml`: Perform an `Intent` to start the `MoreAppsActivity`; make sure to `putExtra("package", getPackageName());`, this ensures that if the your app is in the list of apps being showcased then your app won't be shown. Intent intent = new Intent(this, MoreAppsActivity.class); intent.putExtra("package", getPackageName()); startActivity(intent); You can refer the **sample** code for a live example. Where does the data come from ----------------------------- The data here is the list of *icons*, the *titles* and the *package names* of the apps. All we do is update the `query` field in `GetAppsDetails` class of the **GetAppsDetails** java app and run this app to get the *icons* and a string resource *xml* file. This xml file contains the titles and package names. *Note: The `query` string would be the same as what you enter in the search … -
Easy client side form validations for Django: Django Parsley
Parsleyjs is a JavaScript library to do client side data validations. It does this in a non-intrusive way via adding a data-* attributes to form fields. Check it out, it's really slick. Django forms do a great job of server side data validations. By integrating Parsley with Django form, you get good client side data validations as well. Get the app here. Some design considerations When I started writing this app I wanted to make it really easy to use. My first thought was to make this a filter or a template tag which would have allowed you to do: {{ form|parsleyfy }} However, I use Django-crispy-forms in all my projects. If parsley was a filter, it would have made piping to |crispy impossible as the render step would already have been completed. Hence parsleyfy is class decorator. Django-crispy-forms and family will play well with parsleyfy. Here is the readme. What is it? Parsleyjs is a JavaScript library to do client side data validations. It does this in a non-intrusive way via adding a data-* attributes to form fields. When you define a Django form, you get server side validations for free using the form field attributes. Django-parsley adds these … -
Introduction to Python Workshop on February 15th, 2013
We are conducting an **"Introduction to Python"** workshop at `our office`_ on **February 15th, 2013 (Friday)** between **5-8PM IST**. This workshop is geared towards those who are planning to learn python. Topics: * Language features * Variables * Built in data structures * Functions * Object Oriented Programming * Demo writing a simple program Prerequisites to attend this session: * A laptop with any linux flavour (OR) a laptop with Python installed in it. Register_ for the workshop by filling up the form. .. _`our office`: http://agiliq.com/contactus#map .. _Register: http://bit.ly/Yf0eiH -
Two Scoops of Django: Review
Two scoops of Django is the new book on Django best practices by Daniel Greenfeld and Audrey Roy. I just finished reading it and found it extremely useful. The book is a collection of tips, their justification and code organized in logical areas. I have been using Django since 2008, but I still found a few tips which were new to me and many which served as good reminder. At about 200 pages, its comprehensive but not overwhelming. If you are an advanced Djangonaut, you can read it in a weekend (And you probably are using all its recommendations anyway). If you are just getting started, putting all the tips to use will keep you busy for month. A random sampling of tips (The book has more than 50 of them.) Use pip, virtualenv and virtualenvwrapper Don't keep your virtualenv inside the project folder Apps should be small and do one thing well Use relative modules, prefer from .models import foo All settings file should be versioned - local_settings.py is an anti-pattern Every settings module should have a corresponding requirements.txt Don't hardcode your paths SingleTable model inheritance is good, multi table model inheritance is bad. Create custom managers, but don't … -
arango: ArangoDB Driver for Python (updated Feb 24, 2013)
Past year I've heard about new database - ArangoDB. I was not able to test it using my daily tools - there was no driver for Python. So, I've decided to create it. I've tried to create really good one - high code coverage, well documented and easy API initially was a must.Yesterday, I've released it - now available on PyPi and on github ToolchainHere is list of basic tools which I've used to create the drivernose - for executing tests, integration and unit. ArangoDB driver contain 103 testscoverage - to have clear metric how many code lines was covered by tests. Now it's 89%sphinx - to have good documentation it's a must. Also .. testcode:: and .. doctest :: directives is very useful to keep code examples usable. PerformanceInitially, I've used requests library as main HTTP transport tool. But at some point I've get a letter from ArangoDB team about python driver performance. Here is most important quote:The guys told me that PHP took 0,5 seconds, JS about a second and our Python script 5 seconds I've start digging and found that requests is slow. Fast tests shows that urllib2 2x faster than requests, and pycurl 3x faster. Here is performance tests …