Re: lazy queryset

2011-10-25 Thread druce
Thanks Karen, I set

DATABASES = {
'default': {
'OPTIONS': {'init_command': 'SET SESSION TRANSACTION ISOLATION
LEVEL READ COMMITTED'},
}
}

At first glance it seemed to do the trick. In fact it seemed to force
the re-query every time I did .filter, without putting the QuerySet
into a list context.

(If it disables QuerySet lazy reads entirely, might not be something
to do in a production Web server without load testing. But on
maintenance jobs I can just use a separate settings.py, and that's
where I'm having the issue.)

Many thanks, I don't think I would have figured that one out!


On Oct 25, 9:10 pm, Karen Tracey  wrote:
> On Tue, Oct 25, 2011 at 7:39 PM, druce  wrote:
> > Tried every other way I could think of. Any idea what I have to do to
> > force it to requery the database?
>
> Sounds like you are a victim of the default REPEATABLE READ MySQL/InnoDB
> transaction isolation level.
>
> See this ticket for more details:https://code.djangoproject.com/ticket/13906, 
> including how to specify an
> init command for the DB that can be used to switch it to use READ COMMITTED,
> for example.
>
> Karen
> --http://tracey.org/kmt/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: lazy queryset

2011-10-25 Thread Karen Tracey
On Tue, Oct 25, 2011 at 7:39 PM, druce  wrote:

> Tried every other way I could think of. Any idea what I have to do to
> force it to requery the database?
>

Sounds like you are a victim of the default REPEATABLE READ MySQL/InnoDB
transaction isolation level.

See this ticket for more details:
https://code.djangoproject.com/ticket/13906, including how to specify an
init command for the DB that can be used to switch it to use READ COMMITTED,
for example.

Karen
-- 
http://tracey.org/kmt/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



lazy queryset

2011-10-25 Thread druce
Having trouble getting a queryset to re-query the database and get
updated results.

Tried evaluating queryset in list and boolean context, no joy, always
get the same results even though the database has changed. A bit of a
newbie - am I missing something simple?

[user@box dspider]# python manage.py shell
Python 2.6.7 (r267:88850, Jun  4 2011, 04:33:59)
[GCC 4.4.4 20100726 (Red Hat 4.4.4-13)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> import spider.models as mymodel
>>> test1=mymodel.Rawurl.objects.filter(actualurlid__isnull = True)
>>> test1.count()
64
>>> test1[0].id
5858L

# so I have 64 matching records, and the first one has id field = 5858
# now I go into SQL in my other window, and set actualurlid to -1 for
that record
# do select count(*) where that field is null and get 63
# now I try again in the shell

>>> test2=mymodel.Rawurl.objects.filter(actualurlid__isnull = True)
>>> test2.count()
64
>>> test2[0].id
5858L
>>> list2 = list(mymodel.Rawurl.objects.filter(actualurlid__isnull = True))
>>> len(list2)
64
>>> list2[0].id
5858L

didn't pick up the change, even when I access queryset in a list
context.
I restart the shell and try again, and this time I get 63 results -
doesn't seem to be a problem with the code, pointing to wrong DB or
something.

Tried every other way I could think of. Any idea what I have to do to
force it to requery the database?

running on Amazon EC2 (CentOS)
python26.i686   2.6.7-1.36.amzn1
mysql-server.i686   5.1.52-1.6.amzn1
MySQL-python.i686   1.2.3-0.3.c1.1.6.amzn1
Django 1.3.1

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Parsing a reStructuredText

2011-10-25 Thread eaman


On Oct 25, 7:04 pm, eaman  wrote:
> On Oct 25, 6:46 pm, "J. Cliff Dyer"  wrote:
> [CUT]> What have you got so far?
I found this tutorial[1] that quite nails it, now I can traverse
through  document
and extract a piece of content.
I guess I'll have to learn to use a transformer -> writer to parse a
node
to some useful mark-up.


[1] http://www.ibm.com/developerworks/library/x-matters24/#code5

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: block behavior does not work as documented with respect to autoescape

2011-10-25 Thread Karen Tracey
On Tue, Oct 25, 2011 at 11:10 AM, psbanka  wrote:

> Am I reading the documentation wrong, or is there a Django error here?
>

There's a bit of an oddity in Django here, that actually has nothing to do
with autoescape. There are three "built-in" tags (block, extends, and
include) that are only made available as built-ins as a side-effect of
importing the loader module within django.template. So you get the error you
noticed if you try to create a Template that uses one of these tags without
ever importing django.template.loader. But if you import loader, all works
as per the doc you pointed to:

Python 2.7.2 (default, Jun 12 2011, 14:24:46) [MSC v.1500 64 bit (AMD64)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> ts = """
... {% autoescape off %}
...   {% block title %}{{ hello }}{% endblock %}
...   {% block content %}
...   {% endblock %}
...   {% endautoescape %}
... """
>>> from django.template import Template, Context
>>> t = Template(ts)
Traceback (most recent call last):
  File "", line 1, in 
  File "C:\Users\kmtracey\django\trunk\django\template\base.py", line 124,
in __init__
self.nodelist = compile_string(template_string, origin)
  File "C:\Users\kmtracey\django\trunk\django\template\base.py", line 152,
in compile_string
return parser.parse()
  File "C:\Users\kmtracey\django\trunk\django\template\base.py", line 269,
in parse
compiled_result = compile_func(self, token)
  File "C:\Users\kmtracey\django\trunk\django\template\defaulttags.py", line
475, in autoescape
nodelist = parser.parse(('endautoescape',))
  File "C:\Users\kmtracey\django\trunk\django\template\base.py", line 267,
in parse
self.invalid_block_tag(token, command, parse_until)
  File "C:\Users\kmtracey\django\trunk\django\template\base.py", line 322,
in invalid_block_tag
(command, get_text_list(["'%s'" % p for p in parse_until])))
TemplateSyntaxError: Invalid block tag: 'block', expected 'endautoescape'
>>> from django.template import loader
>>> t = Template(ts)
>>> t.render(Context({'hello': 'This & that'}))
u'\n\n  This & that\n  \n  \n  \n'
>>>

Karen
-- 
http://tracey.org/kmt/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: VirtualHost/Cache

2011-10-25 Thread Didex
Hi Tom Evans,

Was exactly the ServerName.
Thank you.

:)

On 24 Out, 15:14, Tom Evans  wrote:
> On Fri, Oct 21, 2011 at 10:57 AM, Didex  wrote:
> > Hello everyone,
>
> > I am trying setup a webserver(Centos) with two django sites, but i am
> > havecacheproblems.
>
> > http.config:
>
> > NameVirtualHost *:80
> > WSGIPythonEggs /usr/local/django/eggs
> > WSGIPythonPath /usr/local/django:/usr/local/django/site1:/usr/local/
> > django/site2
>
> > site1.config:
>
> > 
> >        ServerAdmin  "my-e-m...@mail.com"
> >        ServerName site.com
> >        ServerAliaswww.site.com
> >        DocumentRoot /usr/local/django/site1
> >        Alias /media/ /usr/local/django/site1/media/
> >        WSGIScriptAlias / /usr/local/django/site1/site1.wsgi
> > 
>
> > site1.config:
>
> > 
> >        ServerAdmin  "my-e-m...@mail.com"
> >        ServerName site.com
> >        ServerAlias sub.site.com
> >        DocumentRoot /usr/local/django/site2
> >        Alias /media/ /usr/local/django/site2/media/
> >        WSGIScriptAlias / /usr/local/django/site2/site2.wsgi
> > 
>
> > bind(e.g.):
>
> > site.com.       IN      A       192.168.1.2 #e.g.
> > sub.site.com.   IN      A       192.168.1.2 #e.g.
>
> > in the wsgi file i have (x=site1, x=site2):
>
> > import os
> > import sys
>
> > os.environ['DJANGO_SETTINGS_MODULE'] = 'x.settings'
>
> > import django.core.handlers.wsgi
> > application = django.core.handlers.wsgi.WSGIHandler()
>
> > Django settings file:
>
> > site1:
> > CACHE_BACKEND = "locmem:///"
> > CACHE_TIMEOUT = 60*5
> > CACHE_PREFIX = "site:1"
>
> > CACHE_BACKEND = "dummy:///"
> > CACHE_TIMEOUT = 60*5
> > CACHE_PREFIX = "site:2"
>
> > but this is not working.
> > I access the site1 and site2 also changes.
>
> > could anyone tell me what am I doing wrong?
> > Thank you.
>
> Are you sure you are hitting the second vhost? It is incorrect to have
> "ServerName site.com" in both vhosts…
>
> Check by enabling different access logs in each vhost, and see which
> site is logged.
>
> One other possible thing to check is that in 1.3,cachesettings come
> from the settings.CACHES dict, not settings.CACHE_* settings.
>
> Cheers
>
> Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



nested forms?!?

2011-10-25 Thread trubliphone
I am just banging my head against the wall and making no progress with 
this issue.


I am trying to create a view that nests forms of related models.  I had 
thought that inlineformset_factory would do the trick, but I clearly 
don't understand something.


Assume I have the following models:


class Author(models.Model):
name = models.CharField(max_length=100)

class Book(models.Model):
author = models.ForeignKey(Author)
title = models.CharField(max_length=100)


And the following forms:


class AuthorForm(forms.ModelForm):
class Meta:
model = Author

class BookForm(forms.ModelForm):
class Meta:
model = Book

BookInlineFormSet = inlineformset_factory(Author, Book)


Now assume I want to create a view that lets me create a new books, 
along with a new author.  According to various documentation, I ought to 
do something a bit like this:



def new_author(request):
  authorForm = AuthorForm()
  author = Author() # an empty author
  bookFormSet = BookInlineFormSet(instance=author) # since author is 
empty, shouldn't this contain empty forms?

  return render_to_response("new_author.html", {"formset" : bookFormSet, })


But all I get is a set of fields belonging to the BookForm ("title") and 
nothing from the AuthorForm ("name").


Any advice?

Thanks for your help.


--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: User data being exposed with mod_wsgi/apache

2011-10-25 Thread Daniel Roseman
On Monday, 24 October 2011 23:14:40 UTC+1, Jennifer Bell wrote:
>
> On my site, some user data is automatically filled in to a form if a 
> user is logged in by accessing request.user in the view code. 
>
> On deployment, it seems that if *any* user is logged in, forms 
> requested via another browser will be filled in with their data.  The 
> data is not filled in if no user is logged in. 
>
> I'm mystified.  Where is this coming from?  I'm using django 1.3, and 
> caching is not enabled in my settings (though I have set 
> CACHE_MIDDLEWARE_ANONYMOUS_ONLY=True just in case). 
>
> The WSGIDeamonProcess is set up like this: 
> WSGIDaemonProcess lalala user=lalala group=lalala threads=1 
> processes=3 
>
> Is this apache?  mod_wsgi? 
>
> Jennifer


No, it's your code. You've got something somewhere that's providing default 
arguments to your form, but is doing so at the module or class level rather 
than per-request. You'd better show your form and view code.
--
DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/vf2mbcSRJv0J.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: apache and remote_user

2011-10-25 Thread David Fischer
Have you taken a look at the RemoteUserMiddleware?
https://docs.djangoproject.com/en/1.3/howto/auth-remote-user/

On Oct 25, 11:16 am, Tim  wrote:
> Hi,
> I've read the django, wsgi, and apache docs and still making no progress.
> Freebsd 8, Apache2.2.17, Django1.30, Python 2.7.1
>
> I'm inside an intranet hosting my webapp locally within that intranet. I'd
> like to get the REMOTE_USER so people don't have to login again.  My
> problem starts at Apache I'm pretty sure. So I know this is not a Django
> problem, but I'm asking from desperation. Is there anyone out there in the
> same situation (intranet users logged in, but unable to get Apache to
> find/pass the REMOTE_USER)?
>
> In my httpd.conf I have the line:
> WSGIPassAuthorization On
>
> and these lines in my wsgi script:
> def application(environ, start_response):
>     environ['REMOTE_USER'] = environ.get('LOGNAME')
>     return _application(environ, start_response)
>
> thanks for any ideas or pointers.
> --Tim

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Inline element not working as expected.

2011-10-25 Thread jenia ivlev
This is how you do it:
class ItemInline(admin.TabularInline):
model = Category.items.through

class CategoryAdmin(admin.ModelAdmin):
inlines = [
ItemInline,
]
exclude = ('items',)


On Oct 24, 9:48 pm, jenia ivlev  wrote:
> In the admin I want to use inline elements. I want category to display
> the items it is related to.
>
> But I get this error:
> Exception at /admin/store/category/7/
>  has no ForeignKey to  'store.models.Category'>
>
> It's true, of-course, since I chose to use Category to point to the
> items it has.
> But, how can I get the admin to list in-line all the items that a
> given Category has?
> How can I get around this error?
>
> CONTEXT:
>
> class Category:
>     items=models.ManyToManyField(Item,through='Categoryhasitem')'
>
> class Categoryhasitem(models.Model):
>     category = models.ForeignKey(Category, db_column='category')
>     item = models.ForeignKey(Item, db_column='item')
>
> class Item(models.Model):
>     id = models.AutoField(primary_key=True)
>
> This is my admin.py file.
>
> class ItemInline(admin.TabularInline):
>     model=Item
> class CategoryAdmin(admin.ModelAdmin):
>     inlines=[ItemInline,]
> class ItemAdmin(admin.ModelAdmin):
>     pass
> admin.site.register(Category, CategoryAdmin)
> admin.site.register(Item, ItemAdmin)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Revamping and existing project

2011-10-25 Thread jhames
hello,

i am an absolute beginner with web dev, so bear with me here. i need
to make several changes to my campany's django apps. nothing too
complicated. in their settings.py file, i notice that they connect to
a mysql database. i want to be able to view the page as i edit it but
i don't understand how to do this with an existing mysql database. all
the images for the site are stored in this database.

any suggestions on how to get started here?

thank you!
james

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Formwizard - Validation with a database lookup

2011-10-25 Thread youpsla
Hello,
I've done it !!! yooohooo.

But I think this is not the best way because it can be processor time
consuming if I've a lots of suscribers (Wich is not the case now).

Here is the code in forms.py:

class Step1Form(forms.Form):
email_adresse = forms.EmailField(max_length=255)
telephone = forms.CharField(max_length=14)

def clean(self):
"""
   Test if email_adresse is already in the database

"""

if 'email_adresse' in self.cleaned_data :
l = []
for p in Customer.objects.all():
l.append(p.email_adresse)
if self.cleaned_data['email_adresse'] in l:
raise forms.ValidationError(u'Email already exist')
return self.cleaned_data

It works 


I'll try with another method function:

p=Customer.objects.all()
try:
p.objects.filter(Customer__email_adresse__exact=
self.cleaned_data['email_adresse']
raise forms.ValidationError(u'Cette adresse Email est deja
utilisee')
return self.cleaned_data
except:
pass


If you have beter idea.

regards

Alain
Entry.objects.filter(blog__name__exact='Beatles Blog')


On 25 oct, 21:01, youpsla  wrote:
> Hello,
>
> I've setup a 5 steps form (There is only one table in the database).
> In the first step I ask for Email adresse. I ike this to be unique in
> the database.
>
> By putting parameters "unique=True" in models, the error only raise
> when submitting the form at the last step.
>
> Is there a way to do the lookup in the database when going from step 0
> (the one with Email field) to step 1. If Email adress already exist in
> the database, I like the step 0 form to be refreshed. Instead, go to
> step 1.
>
> Can somebody give me a way of doing this ?
>
> Regards
>
> Alain

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Basic Django admin question

2011-10-25 Thread Aaron Spesard
Nevermind.

On Tue, Oct 25, 2011 at 3:22 PM, Aaron Spesard  wrote:

> I've been doing a couple of django tutorials over and over again just learn
> by rote, so to speak. They are the 'Writing your first Django App' and
> 'djangoles-tutorial.pdf. Today I decided to just try and build a similar
> project from scratch and I've run into a couple of problems. When I tried to
> add list_display django is giving me the error: type object 'BudType' has
> no attribute 'fields'
>
> The code is very similar to the tutorial so I don't know why this is
> happening...? Aren't CharField and IntegerField the fields?
>
> any help is appreciated. Below is the models and admin.
>
> thanks,
> Aaron
>
>
> from django.db import models
> import datetime
>
> class BudType(models.Model):
> kind_of_bill = models.CharField(max_length = 255)
> bill_importance = models.IntegerField()
>
> def __unicode__(self):
> return self.kind_of_bill
>
> class Bill(models.Model):
> bill_amount = models.IntegerField()
> date_due = models.DateTimeField('date due')
> title = models.CharField(max_length=255)
> desc = models.CharField(max_length=255)
> bill_type = models.ForeignKey(BudType)
>
> def __unicode__(self):
> return self.title
>
> def due_today(self):
> return self.date_due.date() == datetime.date.today()
>
> and then the admin:
>
> from models import Bill, BudType
> from django.contrib import admin
>
> class BillAdmin(admin.ModelAdmin):
> list_display = ('title', 'date_due')
>
>
> admin.site.register(Bill, BudType)
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Basic Django admin question

2011-10-25 Thread Aaron Spesard
I've been doing a couple of django tutorials over and over again just learn
by rote, so to speak. They are the 'Writing your first Django App' and
'djangoles-tutorial.pdf. Today I decided to just try and build a similar
project from scratch and I've run into a couple of problems. When I tried to
add list_display django is giving me the error: type object 'BudType' has no
attribute 'fields'

The code is very similar to the tutorial so I don't know why this is
happening...? Aren't CharField and IntegerField the fields?

any help is appreciated. Below is the models and admin.

thanks,
Aaron


from django.db import models
import datetime

class BudType(models.Model):
kind_of_bill = models.CharField(max_length = 255)
bill_importance = models.IntegerField()

def __unicode__(self):
return self.kind_of_bill

class Bill(models.Model):
bill_amount = models.IntegerField()
date_due = models.DateTimeField('date due')
title = models.CharField(max_length=255)
desc = models.CharField(max_length=255)
bill_type = models.ForeignKey(BudType)

def __unicode__(self):
return self.title

def due_today(self):
return self.date_due.date() == datetime.date.today()

and then the admin:

from models import Bill, BudType
from django.contrib import admin

class BillAdmin(admin.ModelAdmin):
list_display = ('title', 'date_due')


admin.site.register(Bill, BudType)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Formwizard - Validation with a database lookup

2011-10-25 Thread youpsla
Hello,

I've setup a 5 steps form (There is only one table in the database).
In the first step I ask for Email adresse. I ike this to be unique in
the database.

By putting parameters "unique=True" in models, the error only raise
when submitting the form at the last step.

Is there a way to do the lookup in the database when going from step 0
(the one with Email field) to step 1. If Email adress already exist in
the database, I like the step 0 form to be refreshed. Instead, go to
step 1.

Can somebody give me a way of doing this ?


Regards

Alain

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Integrating Social Auth

2011-10-25 Thread Matías Aguirre
Excerpts from Sachin Gupta's message of 2011-10-24 05:09:15 -0200:
> I have been trying to integrate 
> social-authand it has been  a 
> failure till now. I have done all the steps mentioned on 
> this page, added the backends and the keys but it is not working. I am 
> struggling how to get the templates working. If anyone can help me out that 
> would be great.

Are you using the example application? Any error message? More details would
be really helpful.

Regards,
Matías

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



apache and remote_user

2011-10-25 Thread Tim
Hi,
I've read the django, wsgi, and apache docs and still making no progress. 
Freebsd 8, Apache2.2.17, Django1.30, Python 2.7.1

I'm inside an intranet hosting my webapp locally within that intranet. I'd 
like to get the REMOTE_USER so people don't have to login again.  My 
problem starts at Apache I'm pretty sure. So I know this is not a Django 
problem, but I'm asking from desperation. Is there anyone out there in the 
same situation (intranet users logged in, but unable to get Apache to 
find/pass the REMOTE_USER)?

In my httpd.conf I have the line:
WSGIPassAuthorization On

and these lines in my wsgi script:
def application(environ, start_response):
environ['REMOTE_USER'] = environ.get('LOGNAME')
return _application(environ, start_response)

thanks for any ideas or pointers.
--Tim

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/iqIfiKXHbNYJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Parsing a reStructuredText

2011-10-25 Thread eaman


On Oct 25, 6:46 pm, "J. Cliff Dyer"  wrote:
[CUT]
> What have you got so far?
About 10 documents, longest one is around ~2700 'lines'.
...and I'm reading docutils documentation [1]
and a blog entry quite near my topic [2]

>  If you check out the docutils documentation,
> you might find docutils.core.publish_string() fits your needs.
>
> http://docutils.sourceforge.net/docs/api/publisher.html
Thanks, next on my list TO_READ.

[1] http://docutils.sourceforge.net/docs/ref/doctree.html
[2] http://www.arnebrodowski.de/blog/write-your-own-restructuredtext-writer.html

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Parsing a reStructuredText

2011-10-25 Thread J. Cliff Dyer

On 10/25/2011 11:34 AM, eaman wrote:

I'm developing a web site in django to manage guides / howtos
that I've been writing in reStructuredText.
I'd like to display each section of them in a single page,
how can I parse the reStructuredText to get titles / context of single
sections?

What have you got so far?  If you check out the docutils documentation, 
you might find docutils.core.publish_string() fits your needs.


http://docutils.sourceforge.net/docs/api/publisher.html

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: How to set up Apache to serve up django websites?

2011-10-25 Thread Roger Marcus
Hi Reikje,

FANTASTIC TIP. The configuration in the book is straightforward and
clear.
It was not the 100% solution, but it took Apache out of the equation,
and the focus
was getting mod_wsgi configured and working.

Debugging tip:
the suggested script.wsgi is a great place to debug path issues.
In my case, the script worked using the virtual_env that Andreas
helped me with,
but did NOT work otherwise. By comparing the paths in the two
environments,
I was able to see what was needed to get it all up and running.

For the moment, there is an ugly sys.path = ['lots','of','paths'...],
based upon
===
import sys
print sys.path
==
from the virtual environment.
Judging from the number of 'help! my code doesn't work under apache'
problems listed,
this is a standard problem like CLASSPATH is to java.

I will try to follow up with a summary of what is needed for other
travelers on this road.

thanks,

Roger Marcus


On Oct 25, 11:16 am, Reikje  wrote:
> On a side note, I can recommend this 
> book:http://www.packtpub.com/django-1-1-testing-and-debugging/book
> They have an entire chapter for running Django on Apache.
>
> /Reik
>
> On Oct 24, 8:39 am, Roger Marcus  wrote:
>
>
>
>
>
>
>
> > I have the django project Mezzanine up and working well. They have done a
> > much better job in making it easier for the user
> > to install and run their project.
>
> > I am now fighting to get this all working with apache.
>
> > From the django documentation, chapter 20, i have inserted:
>
> > 
> >     SetHandler python-program
> >     PythonHandler django.core.handlers.modpython
> >     SetEnv DJANGO_SETTINGS_MODULE portal.settings
> >     PythonDebug On
> > 
>
> > Into my apache default settings.
> > Once again, however, I have path problems. Assuming my portal is called
> > portal, when I run another small python web service
> > I get the following traceback error:
>
> >  File 
> > "/home/roger/projects/playground/feincms_env/lib/python2.6/site-packages/dj 
> > ango/core/handlers/base.py", line 39, in load_middleware
> >     for middleware_path in settings.MIDDLEWARE_CLASSES:
>
> >   File 
> > "/home/roger/projects/playground/feincms_env/lib/python2.6/site-packages/dj 
> > ango/utils/functional.py", line 276, in __getattr__
> >     self._setup()
>
> >   File 
> > "/home/roger/projects/playground/feincms_env/lib/python2.6/site-packages/dj 
> > ango/conf/__init__.py", line 42, in _setup
> >     self._wrapped = Settings(settings_module)
>
> >   File 
> > "/home/roger/projects/playground/feincms_env/lib/python2.6/site-packages/dj 
> > ango/conf/__init__.py", line 89, in __init__
> >     raise ImportError("Could not import settings '%s' (Is it on sys.path?): 
> > %s" % (self.SETTINGS_MODULE, e))
>
> > ImportError: Could not import settings 'portal.settings' (Is it on 
> > sys.path?): No module named portal.settings
>
> > I tried to add this to my apache envvars file as:
> > export
> > PATH=/home/roger/projects/playground/feincms_env/bin:/home/roger/projects/p 
> > ortal:$PATH
>
> > Can someone help me resolve this final path problem? Thanks.
> > Roger

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Cross-join

2011-10-25 Thread Daniel Gagnon
I'm having trouble with a particular query under the Django ORM.

I have two models: Ticket and Target which have a many-to-many relationship.
I want to list the cross-product of the two.

For instance let say that Tickets Ref001 and Ref002 are both linked to
Targets Tgt001, Tgt002 and Tgt003, I want a query that returns:

Ref001 Tgt001
Ref001 Tg1002
Ref001 Tgt003
Ref002 Tgt001
Ref002 Tg1002
Ref002 Tgt003

I could simply iterate on either Targets or Tickets but then I would lose
both count and slicing which are very important given the huge volume of
data those models contain.

Is there any way to get the result I want without falling back to raw SQL?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Parsing a reStructuredText

2011-10-25 Thread eaman
I'm developing a web site in django to manage guides / howtos
that I've been writing in reStructuredText.
I'd like to display each section of them in a single page,
how can I parse the reStructuredText to get titles / context of single
sections?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



block behavior does not work as documented with respect to autoescape

2011-10-25 Thread psbanka
In the current Django 1.3 documentation on templates
(https://docs.djangoproject.com/en/1.3/topics/templates/#for-template-
blocks), the documentation mentions the following:

"The auto-escaping tag passes its effect onto templates that extend
the current one as well as templates included via the include tag,
just like all block tags"

And the following example is provided:
   # base.html

   {% autoescape off %}
   {% block title %}{% endblock %}
   {% block content %}
   {% endblock %}
   {% endautoescape %}


However, this doesn't actually seem to work, as illustrated in the
following example,
   a = '''
   {% autoescape off %}
   {% block title %}{{ hello }}{% endblock %}
   {% block content %}
   {% endblock %}
   {% endautoescape %}
   '''
   from django.template import Context, Template, TemplateSyntaxError
   django_template = Template(a)
   context = Context({"hello": 'world'})

   print django_template.render(context)

when encountering the line "django_template = Template(a)", django
throws an exception:
django.template.base.TemplateSyntaxError: Invalid block tag: 'block',
expected 'endautoescape'

Am I reading the documentation wrong, or is there a Django error here?

Thanks,
--psbanka

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: sprintf in python (not strictly django, but used all the time in django webapps)

2011-10-25 Thread Derek
Those can be a bit dry... for some variety, you could also try Doug
Hellman's excellent "Module of the Week":
http://www.doughellmann.com/PyMOTW/

On Oct 24, 4:11 pm, "Cal Leeming [Simplicity Media Ltd]"
 wrote:
> You're correct :L
>
> Thanks for this - I think I might replace my daily break with random Python
> docs pages, rather than 'theregister' for a few weeks!
>
> Cal
>
> On Mon, Oct 24, 2011 at 3:09 PM, Tom Evans  wrote:
> > On Thu, Oct 20, 2011 at 7:17 PM, Cal Leeming [Simplicity Media Ltd]
> >  wrote:
> > > So, just out of curiosity, how many other people didn't realise you
> > > could do this:
>
> >  print '%(language)s has %(number)03d quote types.' % \
> > > ...       {"language": "Python", "number": 2}
>
> > > Instead of this:
>
> > > print "%s has %03d" % ( "python", "2" )
>
> > > 6 years of python development, and I never found this little beauty.
> > Fail.
>
> > > Hope this helps someone else.
>
> > > Cal
>
> > Crikey, if you didn't know about that one, you probably don't know
> > about this one either:
>
> > >>> fmt = "{} shalt thou not count, neither count thou {}, excepting that
> > thou then proceed to {}. {} is right out!"
> > >>> fmt.format('four', 'two', 'three', 'five')
> > 'four shalt thou not count, neither count thou two, excepting that
> > thou then proceed to three. five is right out!'
>
> >http://docs.python.org/library/string.html#format-string-syntax
>
> > Cheers
>
> > Tom
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Field.Choices in Template

2011-10-25 Thread Andre Terra
I remember trying to help you with this on IRC, Kurtis. I've had the
same problem before, but I could never remember that BoundFields have
a field attribute.. If there isn't a note in the docs (or even better,
an example), I'll make sure to write a patch in the next few days.


Cheers,
AT

On 10/25/11, Kurtis  wrote:
> Thank you so much for this, Tom! I've asked this question quite a few
> times in IRC and couldn't come across the answer I was looking for. I
> figured it was possible, I just had no idea how to access it. Much
> appreciation!
>
> On Oct 24, 11:26 am, Tom Evans  wrote:
>> On Thu, Oct 20, 2011 at 8:37 PM, Kurtis  wrote:
>> > Hey,
>>
>> > I'm trying to build a custom template for my ModelForm. My ModelForm
>> > contains several M2M fields. If I run the ModelForm.as_view and then
>> > in my template print {{ form.as_p }} it'll automagically display those
>> > choices.
>>
>> > Now what I want to do is take advantage of that magic and print out
>> > those choices myself in my template. For example:
>>
>> > {% for choice in form.genres.choices %}
>> >    {{ choice }}
>> > {% endfor %}
>>
>> > ... but it doesn't work. it doesn't print anything. I tried reading
>> > through the source code of the forms.py and fields.py from 1.3 but
>> > didn't get very far.
>>
>> When you access a form field from a template, the field returned is a
>> BoundField, not the field attribute from the form class. From the
>> BoundField object, you can access the form field on the field
>> attribute, eg:
>>
>> {% for choice in form.genres.field.choices %}
>>    {{ choice }}
>> {% endfor %}
>>
>> Cheers
>>
>> Tom
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
Sent from my mobile device

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: How to handle apps independently in a Wsgi/Apache deployment

2011-10-25 Thread Andre Terra
Assuming I understood your question, here's a wild guess.

Use different settings files and set the DJANGO_SETTINGS_MODULE on the
fly on your .wsgi script


Cheers,
AT

On 10/25/11, vpetkov  wrote:
> Hi,
>
>   I have the standard Wsgi/Apache deployment with several apps in a
> single project, admin enabled. I would like to keep the apps
> independent in production, so that a possible error in one does not
> bring down the whole wsgi daemon process and leave the other apps
> inaccessible.
>
>   What I found is that after a fresh wsgi start, Django tries to
> import models.py from all registered apps in settings.INSTALLED_APPS,
> which breaks their independence. Moreover the autodiscover function of
> admin in the main urls.py also tries to import admin.py of all
> installed apps.
>
>  Is there any possible way to configure Django to import all relevant
> files to an app on demand, so that a possible error in models.py or
> admin.py does not influence the others?
>
>
> Thanks,
> Venelin
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
Sent from my mobile device

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



How to handle apps independently in a Wsgi/Apache deployment

2011-10-25 Thread vpetkov
Hi,

  I have the standard Wsgi/Apache deployment with several apps in a
single project, admin enabled. I would like to keep the apps
independent in production, so that a possible error in one does not
bring down the whole wsgi daemon process and leave the other apps
inaccessible.

  What I found is that after a fresh wsgi start, Django tries to
import models.py from all registered apps in settings.INSTALLED_APPS,
which breaks their independence. Moreover the autodiscover function of
admin in the main urls.py also tries to import admin.py of all
installed apps.

 Is there any possible way to configure Django to import all relevant
files to an app on demand, so that a possible error in models.py or
admin.py does not influence the others?


Thanks,
Venelin

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: How to set up Apache to serve up django websites?

2011-10-25 Thread Reikje
On a side note, I can recommend this book:
http://www.packtpub.com/django-1-1-testing-and-debugging/book
They have an entire chapter for running Django on Apache.

/Reik

On Oct 24, 8:39 am, Roger Marcus  wrote:
> I have the django project Mezzanine up and working well. They have done a
> much better job in making it easier for the user
> to install and run their project.
>
> I am now fighting to get this all working with apache.
>
> From the django documentation, chapter 20, i have inserted:
>
> 
>     SetHandler python-program
>     PythonHandler django.core.handlers.modpython
>     SetEnv DJANGO_SETTINGS_MODULE portal.settings
>     PythonDebug On
> 
>
> Into my apache default settings.
> Once again, however, I have path problems. Assuming my portal is called
> portal, when I run another small python web service
> I get the following traceback error:
>
>  File 
> "/home/roger/projects/playground/feincms_env/lib/python2.6/site-packages/django/core/handlers/base.py",
>  line 39, in load_middleware
>     for middleware_path in settings.MIDDLEWARE_CLASSES:
>
>   File 
> "/home/roger/projects/playground/feincms_env/lib/python2.6/site-packages/django/utils/functional.py",
>  line 276, in __getattr__
>     self._setup()
>
>   File 
> "/home/roger/projects/playground/feincms_env/lib/python2.6/site-packages/django/conf/__init__.py",
>  line 42, in _setup
>     self._wrapped = Settings(settings_module)
>
>   File 
> "/home/roger/projects/playground/feincms_env/lib/python2.6/site-packages/django/conf/__init__.py",
>  line 89, in __init__
>     raise ImportError("Could not import settings '%s' (Is it on sys.path?): 
> %s" % (self.SETTINGS_MODULE, e))
>
> ImportError: Could not import settings 'portal.settings' (Is it on 
> sys.path?): No module named portal.settings
>
> I tried to add this to my apache envvars file as:
> export
> PATH=/home/roger/projects/playground/feincms_env/bin:/home/roger/projects/portal:$PATH
>
> Can someone help me resolve this final path problem? Thanks.
> Roger

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Fixtures and FileField

2011-10-25 Thread Tomek Paczkowski
Hello, I'm looking for some way of bundling files from FileFields into 
fixtures. There is clear void of information on this subject.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/Wm9x3JXJ97YJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: How to make a foreign key field of type other than int?

2011-10-25 Thread Kayode Odeyemi
On Mon, Oct 24, 2011 at 6:30 PM, Carl Meyer  wrote:

> Hi,
>
> On Oct 24, 10:53 am, Kayode Odeyemi  wrote:
> > I'm sorry but it doesn't just seem to work for me. I have tried
> >
> > possibilities like:
> >
> > self.fields['branch_name'].choices =
> > Branch.objects.all().values('name_branch', 'name_branch')
> > self.fields['branch_name'].choices =
> > Branch.objects.all().values('name_branch')
>
> I don't think you've read Tom's responses carefully. You're still
> trying to use ".values()" here, resulting in a ValuesQuerySet which
> returns dictionaries instead of a regular QuerySet which returns model
> objects. That simply won't ever work. And that is the reason for the
> "need more than one value to unpack" error; it has to do with the
> format of the results returned, nothing to do with how many results
> are returned by the query.
>
> Thanks Carl.

I was able to resolve it with this:

class TransactionUpdateForm(forms.ModelForm):
branch_name = ChoiceField(required=True)
def __init__(self, *args, **kwargs):
super(TransactionUpdateForm, self).__init__(*args, **kwargs)
br = [obj.name_branch for obj in Branch.objects.all()]
pos = [b for b in range(len(br))]
self.fields['branch_name'].choices = zip(pos, br)

Thanks Tom


-- 
Odeyemi 'Kayode O.
http://www.sinati.com. t: @charyorde

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: redirect problems

2011-10-25 Thread nicolas HERSOG
God you'r right !

Thanks to your answer i found why my "named" url didn't work.

I wrote this in my urls.py :
(r'^article/(?P\d+)/$', myAppFront.views.article, name='article'),
instead of :
   *url*(r'^article/(?P\d+)/$', myAppFront.views.article,
name='article'),

AND, you'r right, i didn't use the name i defined (here 'article') in my
redirection.

Thx you Tom :)

On Mon, Oct 24, 2011 at 5:52 PM, Tom Evans  wrote:

> On Mon, Oct 24, 2011 at 12:34 PM, nicolas HERSOG 
> wrote:
> > Hi everyone,
> > I digged more but i'm still stuck.
> > I understood that i have to use namespaceURL.
> > So i modified my url.py this way :
> > from myAppFront.views import article
> > url (r'^article/(?P\d+)/$',
> > myAppFront.views.article,
> > name='article'),
>
> Note: this doesn't namespace it, it gives it the explicit name
> 'article'. If you gave it a name like 'myApp:article' it would be in
> the myApp namespace, or if the entire urlconf is included in the main
> urlconf with a namespace, but you don't mention doing that.
>
> > and this is my addComment view :
> > ...
> > #return HttpResponseRedirect(reverse('myAppFront.views.article',
> > args=(id,)))
> > return HttpResponseRedirect(reverse('myAppFront.views.article',
> > kwargs={'id': id}))
>
> Having named it, you can (and should) use the name when reversing the
> URL, not the view definition, eg:
>
>  return HttpResponseRedirect(reverse('article', args=(id,)))
>
> You could also use the dict syntax as well, I prefer the tuple version
> for simple single argument URLs like this.
>
> Hope that helps
>
> Cheers
>
> Tom
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.