django

Keeping Django Views DRY

I have some code that gets the current logged in user. userID = request.session.get("_auth_user_id") if userID: loggedin_user = User.objects.get(pk=int(userID)) else: loggedin_user = None I want the username to show up on every page. At the moment I am putting the code in every view and passing the user object to e...

TeamCity for Python/Django continuous integration

I've set up TeamCity on a Linux (Ubuntu) box and would like to use it for some of Python/Django projects. The problem is that I don't really see what to do next - I tried searching for a Python specific build agent for TeamCity but without much of the success. How can I manage that? ...

Django: Access request.session from backend.get_user

Hi, first of all: this is not the same as this. The ModelBackend has no request member. I want to access the session of the current user without access to the global request object or his/her session ID. Why? I wrote my own authentication backend, extending ModelBackend. In that I have the function get_user (self, user_id), that gets ...

Dropdown menus in forms containing database primary keys

In a framework like Django or Pylons you can set up function to handle form submissions. If your form involves a dropdown menu (i.e. a select tag) populated with objects from a database you can set the values equal to the primary key for the record like: <select> <option value="1">Volvo</option> <option value="2">Saab</option> <o...

Django Model Inheritance and limit_choices_to

Can anyone tell me how i can limit the choices for the Page model which i inherit from in the following code? class CaseStudy(Page): """ An entry in a fancy picture flow widget for a case study page """ image = models.ForeignKey(Image, limit_choices_to={'is_active': True, 'category__code':'RP'}) def __unicode__(se...

Preserving checkbox states on same page with query results

I'm using django, and have a static webpage with a GET form, and about 30 checkboxes. The user selects various boxes, and clicks search, and a result from a database is returned to the same page in a table. However, all the checkboxes have been cleared, since HTML is stateless. What's the simplest solution to 'remember' the state of t...

Apache Django Mod_Wsgi - auto reload

I am trying to auto reload my django app which uses apache + mod_wsgi on my local windows machine. I'd like to know where do I add this code that's referenced in the following article: http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode def _restart(path): _queue.put(True) prefix = 'monitor (pid=%d):' % os.getpid() ...

django - returning form errors from a generic application view

I am developing a generic application. Let's assume that it handles Foo objects which can be attached to any model. In a template, a Foo form can be shown by the get_foo_form template tag: {% get_foo_form for object as form %} object is the object which foo will be attached to. The form posts to a view in the foos application. if th...

Django file upload input validation and security

I'm creating a very simple django upload application but I want to make it as secure as possible. This is app is going to be completely one way, IE. anybody who uploads a file will never have to retrieve it. So far I've done the following: Disallow certain file extensions (.php, .html, .py, .rb, .pl, .cgi, .htaccess, etc) Set a maxim...

Does get_or_create() have to save right away? (Django)

I need to use something like get_or_create() but the problem is that I have a lot of fields and I don't want to set defaults (which don't make sense anyway), and if I don't set defaults it returns an error, because it saves the object right away apparently. I can set the fields to null=True, but I don't want null fields. Is there any o...

where does django install in ubuntu

I am looking for the init.py file for django. I tried whereis and find, but I get a lot of dirs. ...

what is the right version of django and mysqldb to go with dreamhost?

i am builing website on dreamhost. but found some version of python,django,mysqldb need to be bounded together. real life experience. ...

Incorporate custom template into the django admin interface and session.

Hi I have made a custom formwizard and incorporated it into my admin interface. Basically I have taken the change_form.html and left it under the admin interface url: (r'^admin/compilation/evaluation/add/$', EvaluationWizard([EvaluationForm1, EvaluationForm2])), It works, but the admin "session" is not kept. I can access the pag...

Django editing in place

I would like to display a list of records from my database, then for each record, have two fields which the user can edit in place without needing to be directed to another page for editing. How do I go about this ...

how can I order the results of a query filter?

I have this line of code in my views that allows me to display a group of items by date (I've also reversed the order so the most recent displays first): currentlinks = Current.objects.order_by('date_added').reverse()[:5] this works fine — however, when I concatenate the "order_by" code with a filter... currentsources = Current.objec...

Best way to denormalize data in Django?

I'm developing a simple web app, and it makes a lot of sense to store some denormalized data. Imagine a blogging platform that keeps track of Comments, and the BlogEntry model has a "CommentCount" field that I'd like to keep up to date. One way of doing this would be to use Django signals. Another way of doing this would be to put h...

Why would Django's cache work with locmem but fail with memcached?

Using Django's cache with locmem (with simple Python classes as values stored in lists/tuples/maps) works perfectly but does not work with memcached. Only a fraction of the keys (despite ample memory allocated and large timeouts) make their way into memcached, and none of them appear to have any associated value. When they are retrieve...

Why does Django's built-in "url" tag cause an error when running unit tests?

In my Django templates, I have a couple pieces of code that are like this: <a href="{% url root %}">Root</a> They work properly when rendering the template. However, whenever I run my unit tests using Django's unit testing framework, I get the following error: NoReverseMatch: Reverse for 'mysite.root' with arguments '()' and keywo...

Django RelatedManager's .create() usage?

I have two models: Play and PlayParticipant, defined (in part) as: class PlayParticipant(models.Model): player = models.ForeignKey('Player') play = models.ForeignKey('Play') note = models.CharField(max_length=100, blank=True) A piece of my code has a play p which has id 8581, and I'd like to add participants to it. I'm try...

Converting jsp files to Django templates?

Hi, This is related to this question: how-can-i-port-a-legacy-java-j2ee-website-to-a-modern-scripting-language but with a narrower focus. We're pretty much rewriting our legacy Java app from the ground up for a variety of reasons, but attempting to keep the user interface pretty much the same. In one of the answers, someone said: ...