Re: Fail after upgrade to Django 1.2

2010-03-04 Thread eXt
Ok, I've reopened a ticket here http://code.djangoproject.com/ticket/12883
adding some required informations.

On 5 Mar, 00:41, Russell Keith-Magee  wrote:
> On Thu, Mar 4, 2010 at 9:54 PM, eXt  wrote:
> > Hi!
>
> >   I've upgraded my Django to 1.2 (1.2-beta-1, tried also trunk) and
> > after that my application has started to throw an exception:
> > ValueError: Cannot add "": instance is on database
> > "default", value is is on database "None".
>
> > The code causing the problem is:
>
> > (...)
> > project = form.save()
> > admin_profiles =
> > Member.objects.select_related().filter(group__name='Admin')
> > for admin_profile in admin_profiles:
> >    project.users.add(admin_profile.user)
>
> > It is just adding users to a project.users which is m2m to auth.User.
> > Error report is:
>
> > Traceback (most recent call last):
>
> >  File "/var/www/django/someapp/parts/django/django/core/handlers/
> > base.py", line 101, in get_response
> >   response = callback(request, *callback_args, **callback_kwargs)
>
> >  File "/var/www/django/someapp/webshare/utils.py", line 21, in wrapper
> >   context = view_func(*args, **kwargs)
>
> >  File "/var/www/django/someapp/webshare/apps/projects/views.py", line
> > 100, in add_project
> >   project.users.add(admin_profile.user)
>
> >  File "/var/www/django/someapp/parts/django/django/db/models/fields/
> > related.py", line 465, in add
> >   self._add_items(self.source_field_name, self.target_field_name,
> > *objs)
>
> >  File "/var/www/django/someapp/parts/django/django/db/models/fields/
> > related.py", line 525, in _add_items
> >   (obj, self.instance._state.db, obj._state.db))
>
> > ValueError: Cannot add "": instance is on database
> > "default", value is is on database "None"
>
> > Everything is ok when I go back to Django 1.1.1. Is there something
> > I've missed in my configuration or it's a bug?
>
> Sounds like an edge case that has been missed to me. This error
> message that is being reported shouldn't be an problem - the value
> should be assignable to default.
>
> Please open a ticket, and assign it to the 1.2 milestone.
>
> Yours,
> Russ Magee %-)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Internationalization problems in Django 1.2 (beta 1 SVN-12678)

2010-03-04 Thread Alex
Posting this question made me rethink the problem... And it was a very
small mistake: {% trans "..." %} is not able to mark multilined...
Just use one line and everything will work.

Hope this helps someone :-)

Alex

On 5 Mrz., 04:19, Alex  wrote:
> I've got some very simply templates in which marking strings as
> translatable is not working. For example:
>
> --- snip
>
> {% extends "base.html" %}
> {% load i18n %}
>
> {% block content %}
>
> {% trans "Password reset successful" %}
>
> {% trans "You successfully resetted your password. A confirmation mail
> has been sent. Check your inbox for further instructions." %}
>
> {% endblock %}
>
> --- snip
>
> For example for this template, the first text is being translated. The
> second one is just printed like {% trans "The text..." %}.
>
> I'm using the trans-tag in a very simple way and exactly how I used it
> numerous times without running into problems. Do you have an idea on
> this? I tried everything that came to my mind - the problem persists.
> Could it be a problem of the development version? I didn't find
> anything on the tickets and bug reports...
>
> Hoping that I did not miss something very obvious :-)
>
> Thanks in advance
>
> Alex

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Adding a new convenience filter 'contains_any'

2010-03-04 Thread aditya bhargava
Not quite, because 'in' does exact matching, and I'm looking for the inexact
matching that 'contains' provides. Here's one way to simulate a
'contains_any' filter:

t = ["acrylic","watercolors"]   # my list of tags

q = Q(tags__name__contains=t[0])
for i in range(1,len(t)):
q = q | Q(tags__name__contains=t[i])

o = Image.objects.filter(q) # o is the result of the contains_any filter


This works fine, but here is the ideal way I'm hoping to write the same
thing:
o = Image.objects.filter(tags__name__contains_any=t)


But I'm not sure how to go about adding that new filter.


Aditya

On Thu, Mar 4, 2010 at 3:52 PM, Peter Herndon  wrote:

> On Mar 4, 2010, at 2:56 PM, aditya wrote:
>
> > I would like to add a new filter for models to my django build that
> > can be used as follows:
> >
> > tags = ['tag1','tag2','tag3''tagn']
> > i = Image.objects.filter(tags__contains_any=tags)
> >
> >
> > Essentially, instead of passing a string, I pass a list and get a set
> > of valid objects that match *any* of the items in the list. I'm a loss
> > for where to look for the relevant code, thoughI'm trying to find
> > where the 'contains' filter has been implemented, so that I can take a
> > look at how its written. Currently I'm looking at db.models.query and
> > db.models.query_utils.  Where should I be looking?
> >
> Hi Aditya,
>
> Won't the "in" filter do exactly what you need?
>
> http://docs.djangoproject.com/en/1.1/ref/models/querysets/#in
>
> ---Peter
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: best practices for creating a template/theming layer for users in a django app

2010-03-04 Thread gdup
Thanks! Ill give it a try

On Mar 4, 11:04 am, Nick  wrote:
> sorry, let me rewrite that last part
>
> render_to_response ('%s/index.html' u'theme', {'dictionary':
> dictionary})
>
> On Mar 4, 12:11 am, Nick  wrote:
>
> > It seems like this would be best handled at the view level, you could
> > pass a url variable in the render_to_response portion, maybe something
> > like
>
> > def theme(request):
> >     # a bunch of view display stuff
> >    theme = ThemeModel.objects.get('template__name')
> >    if theme:
> >        render_to_response('%s' u'path', {'dictionary': dictionary}
> >    else:
> >        render the default theme
>
> > The path is the directory extension of theme.  Probably just make a
> > foreign key relationship in the blogs settings Model and link it to a
> > template Model with name, thumbnail, etc. etc. etc..
>
> > On Mar 3,u 6:12 pm, gdup  wrote:
>
> > > O crap! that sounds about right. I was thinking of media_url in terms
> > > of only static files, didnt think of {{ templatename }} variable.
>
> > > As for the templating part in an app like shopify , i am not familar
> > > with rails, but i assume it allows you to create custom template tags
> > > like django. I doubt this is the method they are using? Are they
> > > probably just using a custom template system from scratch?
>
> > > On Mar 3, 5:30 pm, Nick  wrote:
>
> > > > If I'm understanding what you're asking, it should be as simple as
> > > > adding an entry per user that designates the template/theme you'd like
> > > > to use and then passing that as a variable (ex. {{ MEDIA_URL }}
> > > > {{ templatename }} where template name would be the directory name of
> > > > the template.  Let me know if I have that right.
>
> > > > On Mar 3, 5:17 pm, gdup  wrote:
>
> > > > > Hello all,
>
> > > > > I would really aprreciate it if someone could point me in the right
> > > > > direction of creating a themeing and template layer for an application
> > > > > written in django, similar to what tumblar and shopify do.
>
> > > > > I can almost put my finger on the whole concept. I know u can somehow
> > > > > serve the MEDIA_URL variable per user to serve static files, but what
> > > > > about themeing (and views)? Would u create your own tags  or just use
> > > > > djangos?
>
> > > > > Knowing django, I wont be surprised if there is already an app for
> > > > > this. Any direction would be greatly appreciated.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: ListField() wanted or how to use iterable fields in forms

2010-03-04 Thread coco
It works! Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Internationalization problems in Django 1.2 (beta 1 SVN-12678)

2010-03-04 Thread Alex
I've got some very simply templates in which marking strings as
translatable is not working. For example:

--- snip

{% extends "base.html" %}
{% load i18n %}

{% block content %}

{% trans "Password reset successful" %}

{% trans "You successfully resetted your password. A confirmation mail
has been sent. Check your inbox for further instructions." %}

{% endblock %}

--- snip

For example for this template, the first text is being translated. The
second one is just printed like {% trans "The text..." %}.

I'm using the trans-tag in a very simple way and exactly how I used it
numerous times without running into problems. Do you have an idea on
this? I tried everything that came to my mind - the problem persists.
Could it be a problem of the development version? I didn't find
anything on the tickets and bug reports...

Hoping that I did not miss something very obvious :-)

Thanks in advance

Alex

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Generate Admin Interface web pages statically

2010-03-04 Thread Fabian Ezequiel Gallina
2010/3/4 Alejandro Recarey :
> Hello all!
>
> I'm new to Django, and loving it! The documentation is fantastic, and
> I've had no problems so far.
>

That's great to hear.

> The admin interface does 95% of what I need, but I've gone really deep
> into the documentation, and the remaining 5% eludes me. This is fine
> as I've decided to write "regular" django pages for the
> administration. However, I'm hesitant to do the 95% of the job django
> already does for me.
>

Well, what's that 5% left? The admin interface can be modified fairly
enough to achieve almost anything you can think of.

> The question: Is there any way to access the Admin Interface so that
> the output is generated in a file? By this I mean some script or
> anything of the sort, that, given a django data model would generate
> the html, css, javascript and python code that makes up the admin
> interface page. This would allow me to modify the page instead of
> writing it from scratch.
>

I don't think so, but I'm pretty confident you can find how to achieve
what you need using the admin interface itself.

> This has to be done internally at some point by django itself, so I'm
> wondering if the functionality is exposed.
>

You can find all the magic of the admin interface at
django/contrib/admin in your PYTHONPATH.



-- 
Fabián E. Gallina
http://www.from-the-cloud.com

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Generate Admin Interface web pages statically

2010-03-04 Thread Alejandro Recarey
Hello all!

I'm new to Django, and loving it! The documentation is fantastic, and
I've had no problems so far.

The admin interface does 95% of what I need, but I've gone really deep
into the documentation, and the remaining 5% eludes me. This is fine
as I've decided to write "regular" django pages for the
administration. However, I'm hesitant to do the 95% of the job django
already does for me.

The question: Is there any way to access the Admin Interface so that
the output is generated in a file? By this I mean some script or
anything of the sort, that, given a django data model would generate
the html, css, javascript and python code that makes up the admin
interface page. This would allow me to modify the page instead of
writing it from scratch.

This has to be done internally at some point by django itself, so I'm
wondering if the functionality is exposed.

Thanks for your help!!

Alex

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Form initial data is not dynamic

2010-03-04 Thread NaMaK
Hi,

I am using Django 1.1. When I create a form, the initial data is set
when the class is created. It does not get updated when an object is
created. The following can demonstrate:

>>>
>>> import datetime
>>> from django import forms
>>>
>>> datetime.datetime.now()
datetime.datetime(2010, 3, 4, 20, 11, 33, 477095)
>>>
>>>
>>> class DateTest(forms.Form):
... in_date=forms.DateTimeField(initial=datetime.datetime.now())
...
>>>
>>> datetime.datetime.now()
datetime.datetime(2010, 3, 4, 20, 13, 5, 308900)
>>>
>>>
>>> foo = DateTest()
>>>
>>> foo.as_p()
u'In date: '
>>>
>>>
>>> datetime.datetime.now()
datetime.datetime(2010, 3, 4, 20, 13, 52, 540813)
>>>
>>>
>>>
>>> bar = DateTest()
>>>
>>> bar.as_p()
u'In date: '
>>>
>>>
>>> datetime.datetime.now()
datetime.datetime(2010, 3, 4, 20, 15, 9, 644799)
>>>
>>>


So as you can see, when the class was created, the tile was 20:12:58,
and this was stored as initial data. Any new form object created after
this time maintained the time of when the class was first initialized
in memory rather than re-initializing whenever an object is created.

I want this field to reflect the time of the object creation as
opposed to the time of class creation. Is there any other way of doing
this apart from setting the class variable at each object creation
manually? In other words, is there a class initialization option that
I can use, or settings option? Or do I by default just set the class
variable by either overriding the __init__ constructor or setting it
manually after object creation?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Multiple views files

2010-03-04 Thread Wiiboy
So I've got that the consensus here is to add a 'views' folder, and
add my views files in that.

Thanks for the 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-us...@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: Django and database user column update privileges

2010-03-04 Thread Karen Tracey
I answered your question in the other thread you had asking the exact same
thing.
Karen

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: ImportError: Could not import settings 'mysite.settings'

2010-03-04 Thread Karen Tracey
On Thu, Mar 4, 2010 at 7:13 PM, RocB  wrote:

> [snip]
> I have check the python path, I even printed our sys.path from "/usr/
> lib/python2.6/site-packages/django/conf/__init__.py, it looks like:
>
> ['/home/mycode', ...
>

So based on your config I'm assuming you have a mysite directory under
/home/mycode and in that mysite directory you have settings.py? If so, then
the path looks OK.


> I have also chown and chmod the /home/mycode directory.  It is
> readable by all.
>
> My system is Fedora 12, apache 2.2.14, djanjo 1.1.1, python 2.6.2
>
>
Fedora 12 has the security-enhanced linux kernel. If this is active on your
system then chown/chmod may not be doing what you expect. I only know enough
about selinux to tell you that much; how to configure it to enable Apache to
access /home directories is beyond me. But I do recall others on this list
have run into this type of problem when setting up machines that use
selinux.

Karen

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Update a single column of a row in a Model

2010-03-04 Thread Karen Tracey
On Thu, Mar 4, 2010 at 2:24 PM, Ken  wrote:

> Thanks for your example, but whilst you're correct about Person.id not
> getting updated, all the other columns do get changed (even if it is
> to the same value).
>
> Here's my code...
>
> class TcsDetectionListsForm(forms.Form):
>name = forms.CharField()
>
> def candidateWithForm(request, tcs_transient_objects_id):
>detectionListRow = TcsDetectionLists.objects.get(pk=0)
>
>
   if request.method == 'POST':
>form = TcsDetectionListsForm(request.POST)
>if form.is_valid(): # All validation rules pass
>detectionListRow.name = form.cleaned_data['name']
>detectionListRow.save()
>else:
>form = TcsDetectionListsForm(initial={'name':
> detectionListRow.name })
>
> Here's what happened in the database (from the DB log):
>
> 223592 QueryUPDATE `tcs_detection_lists` SET `name` = 'rubbish',
> `description` = 'Bad Candidates' WHERE `tcs_detection_lists`.`id` = 0
>
> We shouldn't be updating the 'description' column.  If my security
> settings were in place, this query would fail, because my DB user only
> has update access to the 'name' column.
>

TcsDetectionLists.objects.filter(pk=0).update('name'=form.cleaned_data['name'])

will produce an SQL UPDATE that only touches the name column.

Karen

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Django and database user column update privileges

2010-03-04 Thread Ken
Folks

I need to get my users to submit a form, the result of which is a an
update of one column of one row of my database table.  For security
reasons the Django database user only has privileges to update a
single column of this table (and select privs on the rest).

However, when I submit the form, I note that the database UPDATE
command that was received updated ALL columns except the primary key,
which was used in the WHERE clause.

Here is some very simple Form code (I'm new to Forms, so bear with
me...  Thanks for your help Shawn...)

class TcsDetectionListsForm(forms.Form):
name = forms.CharField()

def candidateWithForm(request):
detectionListRow = TcsDetectionLists.objects.get(pk=0)
if request.method == 'POST':
form = TcsDetectionListsForm(request.POST)
if form.is_valid(): # All validation rules pass
detectionListRow.name = form.cleaned_data['name']
detectionListRow.save()
else:
form = TcsDetectionListsForm(initial={'name':
detectionListRow.name })

Here's what happened in the database (from the DB log):

223592 QueryUPDATE `tcs_detection_lists` SET `name` = 'rubbish',
`description` = 'Bad Candidates' WHERE `tcs_detection_lists`.`id` = 0

We shouldn't be updating the 'description' column.

If my security settings were in place, the above query would fail,
because the Django DB user only has update access to the 'name' column
for this table.

The actual table that will be updated eventually has a much larger set
of columns, with lots of doubles & floats.  I really don't want to be
re-writing the entire row and I really don't want to have to resort to
raw SQL.  Any ideas (preferably with an example)?

Cheers,

Ken

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Adding a new convenience filter 'contains_any'

2010-03-04 Thread Phlip

> >  Entry.objects.filter(id__in=[1, 3, 4])
>
> > ...couldn't id=[] overload if the target is a list?
>
> I suppose it could if it were written that way, but it isn't.  The filter 
> form "filter(=)" is shorthand for the form 
> "filter(__exact=)".  To my knowledge, no one has written an 
> operator overload

Sorry, I didn't say "operator overload" (which are either spot-on or
sophomoric, when they work).

I just meant Entry.objects.filter(id = [1, 3, 4]).

Because, IIRC, no SQL database can store arrays ('list's) in fields,
the =[] event is free to be "overloaded" by its type.

So id=[] would resolve to id__in=[], id=Scalar to id__exact=Scalar,
and the explicit versions are available if you suspect that
overloading is fragile.

(I also disagree with leaving out the spaces around =, but obviously
obeying a team style guide supersedes improving it...)

--
  Phlip

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



ImportError: Could not import settings 'mysite.settings'

2010-03-04 Thread RocB
Following instructions at
http://www.howtoforge.com/how-to-install-django-on-fedora9-apache2-mod_python
and
http://docs.djangoproject.com/en/1.1/howto/deployment/modpython/

I cannot get past the error:

ImportError: Could not import settings 'mysite.settings' (Is it on
sys.path? Does it have syntax errors?): No module named
mysite.settings


I have check the python path, I even printed our sys.path from "/usr/
lib/python2.6/site-packages/django/conf/__init__.py, it looks like:

['/home/mycode', '/usr/lib/python2.6/site-packages/django', '/usr/
lib64/python26.zip', '/usr/lib64/python2.6', '/usr/lib64/python2.6/
plat-linux2', '/usr/lib64/python2.6/lib-tk', '/usr/lib64/python2.6/lib-
old', '/usr/lib64/python2.6/lib-dynload', '/usr/lib64/python2.6/site-
packages', '/usr/lib64/python2.6/site-packages/PIL', '/usr/lib64/
python2.6/site-packages/gst-0.10', '/usr/lib64/python2.6/site-packages/
gtk-2.0', '/usr/lib64/python2.6/site-packages/webkit-1.0', '/usr/lib/
python2.6/site-packages']


I have also chown and chmod the /home/mycode directory.  It is
readable by all.


My system is Fedora 12, apache 2.2.14, djanjo 1.1.1, python 2.6.2

I added to python.conf, the following:


SetHandler python-program
PythonPath "['/home/mycode', '/usr/lib/python2.6/site-packages/
django'] + sys.path"
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE mysite.settings
PythonDebug On
PythonOption djanjo.root /mycode


Any thoughts ?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Fail after upgrade to Django 1.2

2010-03-04 Thread eXt
Thanks for your answer. Unfortunatelly I get the same error using
DATABASES dict.

It is actually very strange. After I had used pdb and went through the
code slowly there were no error! However during normal execution there
is still a problem. I found that something goes wrong inside
allow_relation method in django.db.utils. Last line of this function
is:
return obj1._state.db == obj2._state.db

But when I print these variables i get:

without pdb:
obj1._state.db:  None
obj2._state.db:  default

with pdb (I mean step by step execution):
obj1._state.db:  default
obj2._state.db:  default

:/


On 4 Mar, 15:48, Matt McCants  wrote:
> Check out your database settings. 1.2 adds Multi-DB support and with it a
> new way of specifying databases, now it shouldn't be causing issues, since
> the pre-1.2 way of specifying a database is going to be supported until 1.4,
> it would still be where I started my debugging since it looks like Django
> thinks your objects are on two different databases.
>
> Check 
> out:http://docs.djangoproject.com/en/dev/releases/1.2-alpha-1/#specifying...
> andhttp://docs.djangoproject.com/en/dev/ref/settings/#databases
>
>
>
> On Thu, Mar 4, 2010 at 8:54 AM, eXt  wrote:
> > Hi!
>
> >   I've upgraded my Django to 1.2 (1.2-beta-1, tried also trunk) and
> > after that my application has started to throw an exception:
> > ValueError: Cannot add "": instance is on database
> > "default", value is is on database "None".
>
> > The code causing the problem is:
>
> > (...)
> > project = form.save()
> > admin_profiles =
> > Member.objects.select_related().filter(group__name='Admin')
> > for admin_profile in admin_profiles:
> >    project.users.add(admin_profile.user)
>
> > It is just adding users to a project.users which is m2m to auth.User.
> > Error report is:
>
> > Traceback (most recent call last):
>
> >  File "/var/www/django/someapp/parts/django/django/core/handlers/
> > base.py", line 101, in get_response
> >   response = callback(request, *callback_args, **callback_kwargs)
>
> >  File "/var/www/django/someapp/webshare/utils.py", line 21, in wrapper
> >   context = view_func(*args, **kwargs)
>
> >  File "/var/www/django/someapp/webshare/apps/projects/views.py", line
> > 100, in add_project
> >   project.users.add(admin_profile.user)
>
> >  File "/var/www/django/someapp/parts/django/django/db/models/fields/
> > related.py", line 465, in add
> >   self._add_items(self.source_field_name, self.target_field_name,
> > *objs)
>
> >  File "/var/www/django/someapp/parts/django/django/db/models/fields/
> > related.py", line 525, in _add_items
> >   (obj, self.instance._state.db, obj._state.db))
>
> > ValueError: Cannot add "": instance is on database
> > "default", value is is on database "None"
>
> > Everything is ok when I go back to Django 1.1.1. Is there something
> > I've missed in my configuration or it's a bug?
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-users+unsubscr...@googlegroups.com > groups.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-us...@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: Adding a new convenience filter 'contains_any'

2010-03-04 Thread Peter Herndon

On Mar 4, 2010, at 6:07 PM, Phlip wrote:

> Peter Herndon wrote:
> 
>> Won't the "in" filter do exactly what you need?
>> 
>> http://docs.djangoproject.com/en/1.1/ref/models/querysets/#in
> 
> Why do you need even __in? Given...
> 
>  Entry.objects.filter(id__in=[1, 3, 4])
> 
> ...couldn't id=[] overload if the target is a list?

I suppose it could if it were written that way, but it isn't.  The filter form 
"filter(=)" is shorthand for the form 
"filter(__exact=)".  To my knowledge, no one has written an 
operator overload for a Django filter operation.  I could of course be mistaken 
about that, but in my opinion, such overloading would go against the Python 
philosophy that "explicit is better than implicit."  Since an "in" operator 
already exists, and is a direct analog of the SQL "IN" operator, using that 
seems preferable.  Again, assuming I'm properly understanding the original 
poster's problem.

I believe, from reading your recent back-and-forth with James, that you are 
looking for ways to reduce the amount of code you need to type.  Neither Python 
nor Django are oriented towards code brevity as their primary motivation; 
instead, ensuring that code can be easily read and understood is primary.  
Occasionally, legibility clashes with brevity, as you've pointed out.  I 
personally find this emphasis to be a pleasant release from being forced to 
interpret code that is obfuscated by its brevity.  But that's just my 
preference.  

---Peter

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Fail after upgrade to Django 1.2

2010-03-04 Thread Russell Keith-Magee
On Thu, Mar 4, 2010 at 9:54 PM, eXt  wrote:
> Hi!
>
>   I've upgraded my Django to 1.2 (1.2-beta-1, tried also trunk) and
> after that my application has started to throw an exception:
> ValueError: Cannot add "": instance is on database
> "default", value is is on database "None".
>
> The code causing the problem is:
>
> (...)
> project = form.save()
> admin_profiles =
> Member.objects.select_related().filter(group__name='Admin')
> for admin_profile in admin_profiles:
>    project.users.add(admin_profile.user)
>
> It is just adding users to a project.users which is m2m to auth.User.
> Error report is:
>
> Traceback (most recent call last):
>
>  File "/var/www/django/someapp/parts/django/django/core/handlers/
> base.py", line 101, in get_response
>   response = callback(request, *callback_args, **callback_kwargs)
>
>  File "/var/www/django/someapp/webshare/utils.py", line 21, in wrapper
>   context = view_func(*args, **kwargs)
>
>  File "/var/www/django/someapp/webshare/apps/projects/views.py", line
> 100, in add_project
>   project.users.add(admin_profile.user)
>
>  File "/var/www/django/someapp/parts/django/django/db/models/fields/
> related.py", line 465, in add
>   self._add_items(self.source_field_name, self.target_field_name,
> *objs)
>
>  File "/var/www/django/someapp/parts/django/django/db/models/fields/
> related.py", line 525, in _add_items
>   (obj, self.instance._state.db, obj._state.db))
>
> ValueError: Cannot add "": instance is on database
> "default", value is is on database "None"
>
>
> Everything is ok when I go back to Django 1.1.1. Is there something
> I've missed in my configuration or it's a bug?

Sounds like an edge case that has been missed to me. This error
message that is being reported shouldn't be an problem - the value
should be assignable to default.

Please open a ticket, and assign it to the 1.2 milestone.

Yours,
Russ Magee %-)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: build URL based on fields for admin change form

2010-03-04 Thread dogfuel
Thanks for the quick response, but I am truly lost ... This logically
seems like part of a view - should I create a custom view extending
the normal admin view and add code as you suggested?  If not, where
would this go.

Sorry to be slow,
J

On Mar 4, 5:34 pm, Shawn Milochik  wrote:
> Get the URL, preferably by using an absolute_url method of the model.
>
> Then do something like this:
>
> from urllib import urlencode
>
> attrs = {
>         'latitude': address.latitude,
>         'longitude': address.longitude,
>
> }
>
> map_link =  "%s?%s" % (urlencode(attrs),)
>
> Shawn
>
> On Mar 4, 2010, at 5:23 PM, dogfuel wrote:
>
> > My model for a location has attributes for latitude and longitude -
> > when the admin change form is used for editing, I'd like to include a
> > url assembled from these attributes i.e.:
> > "http://www.myserver.com/map/map.py?lat=&lon= > here>"
>
> > The (non-django) page map.py already exists, I just want to build the
> > link and shoe it as an URL.
>
> > How is the best way to do this?  I'd like to avoid adding a field to
> > the database.
>
> > Thanks for humoring a newbee!
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://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-us...@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: Adding a new convenience filter 'contains_any'

2010-03-04 Thread Phlip
Peter Herndon wrote:

> Won't the "in" filter do exactly what you need?
>
> http://docs.djangoproject.com/en/1.1/ref/models/querysets/#in

Why do you need even __in? Given...

  Entry.objects.filter(id__in=[1, 3, 4])

...couldn't id=[] overload if the target is a list?

--
  Phlip

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Django and Online Payment Systems

2010-03-04 Thread Chris Moffitt
Satchmo is a full implementation of an ecommerce solution -
http://www.satchmoproject.com/

More recently, Bruce has been working to split out the payment modules to
django-bursar - http://bitbucket.org/bkroeze/django-bursar/overview/ which
might be more of what you are looking for in this case.

-Chris

On Thu, Mar 4, 2010 at 4:50 PM, MauroCam  wrote:

> Hi,
>
> has anyone got any pointers on good - preferably localisable -
> integrations between a Django web-site and online payment system?
>
> Thanks
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@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-us...@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: Django and Online Payment Systems

2010-03-04 Thread bax...@gretschpages.com
I think it really depends on the payment system. Most all of them I've
dealt with have some sort of API. Tap into that, and away you go.
Localizable could be interesting, though, just due to currencies and
such. I built one that handled shipping to different areas (US,
Canada, Intl), but all funds had to be US.

On Mar 4, 4:50 pm, MauroCam  wrote:
> Hi,
>
> has anyone got any pointers on good - preferably localisable -
> integrations between a Django web-site and online payment system?
>
> Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: upgrade to released version 1.1.1 problems

2010-03-04 Thread mendes.rich...@gmail.com
Hello Karen,

On my computer at home i indeed had installed a very old version,
I think it was the 0.97-pre-svn version.

Because al the applications i build were on external servers i don't
have to worry about code changes fortunately.
But i thought it was strange that when i installed the newest version
and created a new project it gave those errors.
Apparently some settings got mixed up between the new and old
version.

About the middleware_classes those should be correct, it was
complaining about the SessionMiddleware.

Hope everything get fixed after a new install.

thanks for you comments.

Richard


On Mar 4, 5:42 pm, Karen Tracey  wrote:
> On Wed, Mar 3, 2010 at 4:07 PM, mendes.rich...@gmail.com <
>
> mendes...@gmail.com> wrote:
> > Hello Django Users,
>
> > I just tried to upgrade my django version towards the last official
> > release Django 1.1.1 and ran into some trouble after the install.
> > When i do a runserver first it complained about an AttributeError:
> > 'Settings' that didn't have certain attributes.
>
> > To solve this is added the following settings:
> > LOCALE_PATHS = tuple()
> > DEFAULT_INDEX_TABLESPACE = ''
> > DEFAULT_TABLESPACE = ''
>
> These are things you should not have had to do and indicate something is
> seriously broken in your install. Proceeding to attempt to patch it up by
> manually adding mysteriously missing bits is probably not the best approach.
> I recommending starting over by completing removing the existing install and
> re-installing.
>
> Note the oldest of those settings -- LOCALE_PATHS -- was added to the global
> settings file nearly 2.5 years ago: how old is the version you were
> upgrading from? (If you are really upgrading from a release that old there
> are going to be code changes you'll need to make to adjust to the
> differences between Django 0.96 and Django 1.0.)
>
> Karen

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Django and Online Payment Systems

2010-03-04 Thread MauroCam
Hi,

has anyone got any pointers on good - preferably localisable -
integrations between a Django web-site and online payment system?

Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Query to collect objects in a hierarchical model structure.

2010-03-04 Thread iliveinapark
Hello all,

So I'm making a sort of FAQ, with a hierarchical category structure:

 28 class
SupportCategory(models.Model):
 29 title =
models.CharField(max_length=100)
 30 slug =
models.CharField(max_length=100)
 31 parent = models.ForeignKey('self', blank=True,
null=True,
 32 related_name='children')

And Questions can belong to many categories:

 55 class
Question(models.Model):
 56 timestamp =
models.DateTimeField(auto_now=True)
 57 question =
models.TextField()
 58 answer =
models.TextField()
 59 categories =
models.ManyToManyField(SupportCategory,
 60
related_name='questions')
 61 keywords =
models.ManyToManyField(Keyword,
 62
related_name='questions')
 63 attachments =  models.ManyToManyField(Attachment,
blank=True,
 64
related_name='questions')
 65 related_questions = models.ManyToManyField('self', blank=True)

Obviously, for a given category, cat.questions.all() will return all
questions assigned to cat. How can I write a query (or even better, a
manager) which will return all questions belonging to cat and all of
it's ancestors (cat.children, and their children, etc).

Thanks in advance for any suggestions.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: shortest way to recover from a QuerySet "object not found"

2010-03-04 Thread Shawn Milochik
If the question is answered to your satisfaction, why don't we drop the thread 
now and avoid the personal stuff? 

There is nothing to be gained by arguing with a respected core Django 
developer, and nothing the rest of us will learn from it.

Thanks,
Shawn


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: build URL based on fields for admin change form

2010-03-04 Thread Shawn Milochik
Get the URL, preferably by using an absolute_url method of the model.

Then do something like this:


from urllib import urlencode

attrs = {
'latitude': address.latitude,
'longitude': address.longitude,
}

map_link =  "%s?%s" % (urlencode(attrs),)


Shawn





On Mar 4, 2010, at 5:23 PM, dogfuel wrote:

> My model for a location has attributes for latitude and longitude -
> when the admin change form is used for editing, I'd like to include a
> url assembled from these attributes i.e.:
> "http://www.myserver.com/map/map.py?lat=&lon= here>"
> 
> The (non-django) page map.py already exists, I just want to build the
> link and shoe it as an URL.
> 
> How is the best way to do this?  I'd like to avoid adding a field to
> the database.
> 
> Thanks for humoring a newbee!
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@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-us...@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: shortest way to recover from a QuerySet "object not found"

2010-03-04 Thread Phlip
> The only condescension I've seen in this thread is from you. And, to
> be fair, if I wanted to be condescending I'd have simply pointed you
> at Tony Hoare's explanation of null values

That's why I said NullObject, in the first post.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



build URL based on fields for admin change form

2010-03-04 Thread dogfuel
My model for a location has attributes for latitude and longitude -
when the admin change form is used for editing, I'd like to include a
url assembled from these attributes i.e.:
"http://www.myserver.com/map/map.py?lat=&lon="

The (non-django) page map.py already exists, I just want to build the
link and shoe it as an URL.

How is the best way to do this?  I'd like to avoid adding a field to
the database.

Thanks for humoring a newbee!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: segfault with mod_wsgi / mod_python after Python upgrade on Gentoo

2010-03-04 Thread Graham Dumpleton
Start by reading:

  http://code.google.com/p/modwsgi/wiki/InstallationIssues
  http://code.google.com/p/modwsgi/wiki/ApplicationIssues
  http://code.google.com/p/modwsgi/wiki/DebuggingTechniques

Various reasons for crashes are documented and also pointers to how to
configure Apache/mod_wsgi to get more logging etc about what is going
on.

Graham

On Mar 5, 8:42 am, Facundo Casco  wrote:
> Hi, I'm having a problem after upgrading from Python 2.5 to 2.6
>
> I'm using Gentoo and running a Django app with Apache 2 and mod_python.
> After the upgrade I started getting a segfault when I try to access
> the site, Apache starts fine and can serve static pages.
>
> I've tried moving the site to mod_wsgi and still get the segfault.
> I've tried reinstalling Apache, Apr, mod_python, mod_wsgi.
> I've tried revdep-rebuild, python-updater. I've removed Python 2.5
> from the system.
> The site works when I run it from Django's development server.
>
> I'm lost, I just don't know how to fix this. Any help would be appreciated.
> Thanks in advance.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Adding a new convenience filter 'contains_any'

2010-03-04 Thread Peter Herndon
On Mar 4, 2010, at 2:56 PM, aditya wrote:

> I would like to add a new filter for models to my django build that
> can be used as follows:
> 
> tags = ['tag1','tag2','tag3''tagn']
> i = Image.objects.filter(tags__contains_any=tags)
> 
> 
> Essentially, instead of passing a string, I pass a list and get a set
> of valid objects that match *any* of the items in the list. I'm a loss
> for where to look for the relevant code, thoughI'm trying to find
> where the 'contains' filter has been implemented, so that I can take a
> look at how its written. Currently I'm looking at db.models.query and
> db.models.query_utils.  Where should I be looking?
> 
Hi Aditya,

Won't the "in" filter do exactly what you need?

http://docs.djangoproject.com/en/1.1/ref/models/querysets/#in

---Peter

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



segfault with mod_wsgi / mod_python after Python upgrade on Gentoo

2010-03-04 Thread Facundo Casco
Hi, I'm having a problem after upgrading from Python 2.5 to 2.6

I'm using Gentoo and running a Django app with Apache 2 and mod_python.
After the upgrade I started getting a segfault when I try to access
the site, Apache starts fine and can serve static pages.

I've tried moving the site to mod_wsgi and still get the segfault.
I've tried reinstalling Apache, Apr, mod_python, mod_wsgi.
I've tried revdep-rebuild, python-updater. I've removed Python 2.5
from the system.
The site works when I run it from Django's development server.

I'm lost, I just don't know how to fix this. Any help would be appreciated.
Thanks in advance.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: shortest way to recover from a QuerySet "object not found"

2010-03-04 Thread James Bennett
On Thu, Mar 4, 2010 at 1:43 PM, Phlip  wrote:
> And again the condescension. As a programmer, I should be able to
> easily chose between statements that throw and ones that efficiently
> deal with branching conditions. A record-not-found is not a crisis, it
> is just a branching condition. 5 excess lines of code do not make my
> program more robust.

The only condescension I've seen in this thread is from you. And, to
be fair, if I wanted to be condescending I'd have simply pointed you
at Tony Hoare's explanation of null values (which he originally
introduced into ALGOL, way back at the dawn of time) as a
"billion-dollar mistake" ;)

In general, though, Django optimizes for the most common cases.
Experience has shown that, in the case of a record not being found,
there are two things people most often want to do:

1. Bail out and return an HTTP 404 response.
2. Create a record which matched the specified conditions.

As a result, Django provides one-line shortcuts which implement both
of those use cases (get_object_or_404() and get_or_create()). Creating
a null object to pass around, meanwhile, is less common and -- as
mentioned -- is more of an anti-pattern to be discouraged. As for why
get() raises an exception, well, it *is* an exceptional case; usually,
when you're that specific in asking for an object, you expect it to be
there.

> Oh, look! "123"[:7] ! The string doesn't have 7 characters! Gee,
> shouldn't that throw an exception?

See my comments above about condescension.


-- 
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: template dir locale

2010-03-04 Thread Alessandro Ronchi
2010/3/4 Alessandro Ronchi :
> I have a template dir in common with different projects, outside the
> projects dir.
>
> Those templates have a locale dir with translations.
>
> In my projects  I have only the templates that differs from the common.
>
> The problem is that it cannot use the locale inside the original
> template dir, but If I make a simbolic link from
>
> /common/templates/locale
>
> to
> /myproject/templates/locale
>
> it works.
>
> it is possible to avoid the simbolic link, and have in each dir only
> translations of its contents?

I searched all the day, without any other solution.
Is it possible to make a translation of a template dir outside the
project? It don't read  locale if I put it inside the template dir.

-- 
Alessandro Ronchi

http://www.soasi.com
SOASI - Sviluppo Software e Sistemi Open Source

http://hobbygiochi.com
Hobby & Giochi, l'e-commerce del divertimento

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



generic relations with admin

2010-03-04 Thread Simon Davies
Hi

I have a shopping cart application, where by each cart can hold
several kinds of objects,  I have therefore used generic relations to
model the application along the lines of below, whereby each cart can
have many cartitems which are linked by a standard foreign key
relationship, the cartitems are in turn linked to the individual item
models by a GenericForeignKey:

class Cart(models.Model):
invoice = models.PositiveIntegerField(max_length=50, null=True,
unique=True)
datetime_added = models.DateTimeField(auto_now_add=True)
etc

class CartItem(models.Model):
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
content_object = generic.GenericForeignKey('content_type',
'object_id')
cart = models.ForeignKey(Cart, related_name="items")

class AccessoryOrder(models.Model):
   cart_item = generic.GenericRelation(CartItem)

class BikePart(UsedItem):
partType = models.ForeignKey(PartType)
cart_item = generic.GenericRelation(CartItem)

class UsedBike(UsedItem):
bike = models.ForeignKey(Bike)
cart_item = generic.GenericRelation(CartItem)

This works fine, but I can't figure out a way to get what I want in
the admin app.  I have created the AccessoryOrderInline class
subclassing GenericStackedInline, but the inlines don't work in
reverse even where you have added the generic.GenericRelation
attribute to the model. The relevant parts of admin.py are:

class AccessoryOrderInline(generic.GenericStackedInline):
model = AccessoryOrder

class CartItemInline(admin.StackedInline):
model = CartItem
exclude = ('content_type', 'object_id')
extra = 0
fields = ('content.object',)
inlines = [
AccessoryOrderInline,
]

class CartAdmin(admin.ModelAdmin):
date_hierarchy = 'datetime_added'
form = CartForm
inlines = [
CartItemInline,
]

The issue is that when I click on a cart to view in admin, I the
CartItem objects but not the Accessory objects themselves,  or any
other types of item.  With the model design the way it is, I don't see
a way of getting the admin app to do what I want,  so is my model
design flawed and is there a better way of doing this using generic
relations.

Thanks

Simon

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: dynamic inlines (svn #12297) and older template logic breaking down

2010-03-04 Thread ben
Update - it seems that excluding the prefix elements can be done by
excluding forloop.last in addition to formsets that are data bound.
the stacked.html template in contrib mirrors this. While it doesn't
seem to be the futureproof solution I'd hoped for, it does work.
Perhaps the best move would be to allow the 1.2 release to settle out
and revisit the logic later.

workaround:

{% for inline_admin_form in inline_admin_formset %}
{% if inline_admin_form.original or forloop.last %}
{% else %}
{% include "admin/edit_inline/gallery_image.html" %}
{% endif %}
{% endfor %}

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Please criticise this storage architecture...

2010-03-04 Thread Petite Abeille

On Mar 4, 2010, at 12:12 AM, Andy Robinson wrote:

> So, why don't I hear about architectures like this?

Perhaps because it just work.

>  Why would I want to use more complex things (CouchDB, ZODB, 
> blobs-in-RDBMS-tables)?

Perhaps you would not want to.

> Has anyone built a nontrivial system this way, and what happened?

Nothing happened. It just worked.

Tangentially related:

The Spirit of the Tool
http://www.pragprog.com/articles/the-spirit-of-the-tool

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: shortest way to recover from a QuerySet "object not found"

2010-03-04 Thread Shawn Milochik
Just create your own Manager and override the default (named 'objects') in your 
models. Have 'get' behave any way you like.

http://docs.djangoproject.com/en/1.1/topics/db/managers/

Shawn

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: shortest way to recover from a QuerySet "object not found"

2010-03-04 Thread Phlip
> Just create your own Manager and override the default (named 'objects') in 
> your models. Have 'get' behave any way you like.
>
> http://docs.djangoproject.com/en/1.1/topics/db/managers/
>
> Shawn

Ding! 
http://docs.djangoproject.com/en/1.1/topics/db/managers/#adding-extra-manager-methods

luv that Open Closed Principle, huh?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: shortest way to recover from a QuerySet "object not found"

2010-03-04 Thread Phlip
> Most likely, yes. And those people, believe it or not, designed
> Django's APIs based on their experiences. This is why there are
> shortcuts available, like the get_or_create() method (which fetches an
> object or, if none matches, creates a valid one, populated with
> default values you supply, for you), and why these sorts of methods
> are covered in Django's documentation.

I want a NullObject - not "create", which (correctly) implies a save()

> In general, though, it appears you're trying to apply an anti-pattern:
> silencing an exception which told you that something went wrong, and
> then passing a "null" object into other code to try to compensate.
> This is an approach more likely to create bugs than to solve them, and
> so if implementing it is a bit harder than you'd like, perhaps that's
> why.

And again the condescension. As a programmer, I should be able to
easily chose between statements that throw and ones that efficiently
deal with branching conditions. A record-not-found is not a crisis, it
is just a branching condition. 5 excess lines of code do not make my
program more robust.

Oh, look! "123"[:7] ! The string doesn't have 7 characters! Gee,
shouldn't that throw an exception?

--
  Phlip

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: HTML & Django (Google App Engine)

2010-03-04 Thread slenno1
I have yet to try your suggestion, but this looks great! I am really
looking forward to trying it, thanks!!

On Mar 3, 4:54 pm, Jervis  wrote:
> On Mar 3, 3:51 pm, slenno1  wrote:
>
> > Hey everyone,
> >      I am currently working with a section of a site that takes user
> > input usingDjangoforms:
>
> >   description = forms.CharField(widget=forms.Textarea(attrs={'rows':
> > '10', 'cols': '80'}))
>
> > The only problem however is that this ignores anyhtmltags that are
> > added in by the user and just prints them along with the text entered
> > in by the user. For example, a user may type in "The quick brown fox
> > jumps over the lazy dog", with the word 'jumps' intended to be
> > bold, but thehtmltags are just printed a long with the text. Is this
> > because I am possibly using the wrong widget? Any feedback is greatly
> > appreciated, thanks!
>
> Hi, in your template where you have placed {{ model.description }}Djangowill 
> automatically escape thehtmltags you place have input.
> The effect is what you are seeing now, they are displayed as text,
> rather than being interpreted ashtmltags. You can selectively turn
> this default behaviour off by marking the text as "safe"
>
> {{ model.description|safe }}
>
> The use of the word "safe" here implies that you are entirely sure
> that the content of "description" won't contain anything that will
> harm your website or your  customers. The discussion about what can be
> considered "safe" has been had many times and it may pay you well to
> do some light reading on the matter. Many people use intermediate
> markup languages that don't have the full power ofhtml,Djangoitself
> provides template tags that can aid in rendering 
> themhttp://docs.djangoproject.com/en/dev/ref/contrib/#markupan example of
> on is herehttp://en.wikipedia.org/wiki/Textile_(markup_language).
>
> Best of luck.
>
> Jervis

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Update a single column of a row in a Model

2010-03-04 Thread Ken
Thanks for your example, but whilst you're correct about Person.id not
getting updated, all the other columns do get changed (even if it is
to the same value).

Here's my code...

class TcsDetectionListsForm(forms.Form):
name = forms.CharField()

def candidateWithForm(request, tcs_transient_objects_id):
detectionListRow = TcsDetectionLists.objects.get(pk=0)

if request.method == 'POST':
form = TcsDetectionListsForm(request.POST)
if form.is_valid(): # All validation rules pass
detectionListRow.name = form.cleaned_data['name']
detectionListRow.save()
else:
form = TcsDetectionListsForm(initial={'name':
detectionListRow.name })

Here's what happened in the database (from the DB log):

223592 QueryUPDATE `tcs_detection_lists` SET `name` = 'rubbish',
`description` = 'Bad Candidates' WHERE `tcs_detection_lists`.`id` = 0

We shouldn't be updating the 'description' column.  If my security
settings were in place, this query would fail, because my DB user only
has update access to the 'name' column.

Ken



On 4 Mar, 18:35, Shawn Milochik  wrote:
> 1. Doing Person.save() will NOT update every field in your model.
>
> 2. Your snippet uses a ModelForm. Mine used a Form. There's a huge difference.
> If you use a ModelForm you're going to have to exclude all the fields you 
> don't want.
>
> 3. If you use a ModelForm and instantiate it with request.POST, don't send an 
> argument
> for 'instance' as well. One or the other.
>
> Look at my example again. It does exactly what you want.
> It seems that all your problems are due to not understanding the difference 
> between a Form and a ModelForm.
>
> Read the Django book ("The Definitive Guide").
>
> Shawn
>
> On Mar 4, 2010, at 1:29 PM, Ken wrote:
>
>
>
> > Thanks Shawn
>
> > My problem is that Person.save() will do an update of all my columns.
> > Even though they are all identical, apart from the changed value, this
> > will violate my minimum privileges requirement of only allowing the
> > application access to the columns that it is allowed to change - hence
> > your original suggestion of using ModelForms (and only specified
> > fields).
>
> > Maybe if I try something like this...
>
> > #Use a ModelForm for Person..
> > class PersonForm(forms.ModelForm):
> >    model=Person
> >    fields = ('age')
>
> > #When the user submits the form:
> > person = Person.objects.get(pk = 123)
> > person_form = PersonForm(request.POST, instance = person)
> > if person_form.is_valid()
> >        person_form.save()
>
> > Would that work...?  I'll attempt to hack an example in my code and
> > tell you what happens...
>
> > Thanks for your time...
>
> > Ken
>
> > On 4 Mar, 17:28, Shawn Milochik  wrote:
> >> Here's a simple example. It could be improved, but it's meant to be very 
> >> simple.
>
> >> #Make a simple form.
>
> >> class AgeForm(forms.Form):
> >>     age = forms.IntegerField()
>
> >> #When the user submits the form:
>
> >> age_form = AgeForm(request.POST)
>
> >> if age_form.is_valid()
>
> >>         #get the pk however you need to
> >>         person = Person.objects.get(pk = 123)
> >>         person.age = age_form.cleaned_data['age']
> >>         person.save()
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://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-us...@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: shortest way to recover from a QuerySet "object not found"

2010-03-04 Thread James Bennett
On Thu, Mar 4, 2010 at 12:59 PM, Phlip  wrote:
> Doesn't anyone in Django-land have experience with the platforms that
> make this problem incredibly easy?

Most likely, yes. And those people, believe it or not, designed
Django's APIs based on their experiences. This is why there are
shortcuts available, like the get_or_create() method (which fetches an
object or, if none matches, creates a valid one, populated with
default values you supply, for you), and why these sorts of methods
are covered in Django's documentation.

In general, though, it appears you're trying to apply an anti-pattern:
silencing an exception which told you that something went wrong, and
then passing a "null" object into other code to try to compensate.
This is an approach more likely to create bugs than to solve them, and
so if implementing it is a bit harder than you'd like, perhaps that's
why.


-- 
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: shortest way to recover from a QuerySet "object not found"

2010-03-04 Thread Phlip
> from django.core.exceptions import ObjectDoesNotExist

txbut... >sigh< I was hoping to head that off - Python's condescending
attitude is in fact the core of the problem.

Even if you wrap all your try: except: up in a method, so it's at
least DRY, is you must consign that method to use .get().

So to squeeze my attempt into one line, we get foo =
(list(Foo.objects.filter(name='bar')) + [Foo()])[0], which is way too
much typing.

Doesn't anyone in Django-land have experience with the platforms that
make this problem incredibly easy?

--
  Phlip

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Update a single column of a row in a Model

2010-03-04 Thread Shawn Milochik
1. Doing Person.save() will NOT update every field in your model.

2. Your snippet uses a ModelForm. Mine used a Form. There's a huge difference.
If you use a ModelForm you're going to have to exclude all the fields you don't 
want.

3. If you use a ModelForm and instantiate it with request.POST, don't send an 
argument
for 'instance' as well. One or the other.

Look at my example again. It does exactly what you want. 
It seems that all your problems are due to not understanding the difference 
between a Form and a ModelForm.

Read the Django book ("The Definitive Guide"). 

Shawn





On Mar 4, 2010, at 1:29 PM, Ken wrote:

> Thanks Shawn
> 
> My problem is that Person.save() will do an update of all my columns.
> Even though they are all identical, apart from the changed value, this
> will violate my minimum privileges requirement of only allowing the
> application access to the columns that it is allowed to change - hence
> your original suggestion of using ModelForms (and only specified
> fields).
> 
> Maybe if I try something like this...
> 
> 
> #Use a ModelForm for Person..
> class PersonForm(forms.ModelForm):
>model=Person
>fields = ('age')
> 
> #When the user submits the form:
> person = Person.objects.get(pk = 123)
> person_form = PersonForm(request.POST, instance = person)
> if person_form.is_valid()
>person_form.save()
> 
> Would that work...?  I'll attempt to hack an example in my code and
> tell you what happens...
> 
> Thanks for your time...
> 
> Ken
> 
> 
> On 4 Mar, 17:28, Shawn Milochik  wrote:
>> Here's a simple example. It could be improved, but it's meant to be very 
>> simple.
>> 
>> #Make a simple form.
>> 
>> class AgeForm(forms.Form):
>> age = forms.IntegerField()
>> 
>> #When the user submits the form:
>> 
>> age_form = AgeForm(request.POST)
>> 
>> if age_form.is_valid()
>> 
>> #get the pk however you need to
>> person = Person.objects.get(pk = 123)
>> person.age = age_form.cleaned_data['age']
>> person.save()
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@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-us...@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: Update a single column of a row in a Model

2010-03-04 Thread Ken
Thanks Shawn

My problem is that Person.save() will do an update of all my columns.
Even though they are all identical, apart from the changed value, this
will violate my minimum privileges requirement of only allowing the
application access to the columns that it is allowed to change - hence
your original suggestion of using ModelForms (and only specified
fields).

Maybe if I try something like this...


#Use a ModelForm for Person..
class PersonForm(forms.ModelForm):
model=Person
fields = ('age')

#When the user submits the form:
person = Person.objects.get(pk = 123)
person_form = PersonForm(request.POST, instance = person)
if person_form.is_valid()
person_form.save()

Would that work...?  I'll attempt to hack an example in my code and
tell you what happens...

Thanks for your time...

Ken


On 4 Mar, 17:28, Shawn Milochik  wrote:
> Here's a simple example. It could be improved, but it's meant to be very 
> simple.
>
> #Make a simple form.
>
> class AgeForm(forms.Form):
>     age = forms.IntegerField()
>
> #When the user submits the form:
>
> age_form = AgeForm(request.POST)
>
> if age_form.is_valid()
>
>         #get the pk however you need to
>         person = Person.objects.get(pk = 123)
>         person.age = age_form.cleaned_data['age']
>         person.save()

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



dynamic inlines (svn #12297) and older template logic breaking down

2010-03-04 Thread ben
I was updating to the latest SVN and encountered some odd behavior
with a custom gallery image admin inline template. I've narrowed it
down to some dynamic inlines development released in 12297. The
problem is that I don't really know if it merits a feature request or
if I'm missing something.

The issue boils down to the "add new" loop with "extra" set to 1 (only
one image can be added per save), specifically the use of the
"original" property in differentiating between existing and new
gallery images. The goal is to be able to determine which are bound to
the database from those that are adds.

{% for inline_admin_form in inline_admin_formset %}
{% if inline_admin_form.original %}
{% else %}
{% include "admin/edit_inline/gallery_image.html" %}
{% endif %}
{% endfor %}

The above template admittedly has the problem where the underlying
django can not create other formsets which are not "original" without
it breaking, and this is indeed what seems to be happening.

In a fresh gallery admin with no images saved --
#12296
1 gallery image add option - galleryimages-0-image only
#12297
2 gallery image add options - galleryimages-0-image and galleryimages-
__prefix__-image

Under current SVN is there a way to excude the __prefix__ instance
within the template? If not, would it be worth submitting a feature
request to enable the ability to discern between the two kinds of non-
original inlines?

Thanks!
Ben

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Update a single column of a row in a Model

2010-03-04 Thread Shawn Milochik
Here's a simple example. It could be improved, but it's meant to be very simple.




#Make a simple form.

class AgeForm(forms.Form):
age = forms.IntegerField()


#When the user submits the form:

age_form = AgeForm(request.POST)

if age_form.is_valid()

#get the pk however you need to
person = Person.objects.get(pk = 123)
person.age = age_form.cleaned_data['age']
person.save()





-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: shortest way to recover from a QuerySet "object not found"

2010-03-04 Thread rebus_
On 4 March 2010 18:02, Phlip  wrote:
> Djangoids:
>
> Consider this line:
>
>   foo = Foo.object.get(name='bar')
>
> If foo is not found, I want it to contain a NullObject, such as an
> empty Foo(). In the parlance, that could be like this:
>
>   foo = Foo.object.get(name='bar', _default=Foo())
>
> I naturally don't expect (v 1.1.1) of Django to support my magic
> _default keyword.
>
> What's the absolute shortest stretch of code which pops a NullObject
> into my foo if the record 'bar' is not found?
>
> --
>  Phlip
>  http://c2.com/cgi/wiki?ZeekLand
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@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.
>
>

I'd say:

from django.core.exceptions import ObjectDoesNotExist
try:
  foo = Foo.object.get(name='bar')
except ObjectDoesNotExist:
  foo = bar()

but then again, there are all kinds of magic out there. :)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Creating a custom form field that uses an AND

2010-03-04 Thread Emil Ivanov
Good day Reinhardt followers,

Short: How can I make a field that renders itself as a pair of input
fields and a custom (not controlled by the user) label.

Long: I am trying to write a new custom field. I will use it for a
captcha-like service. The service works by requesting a question -
then receiving one and a token. The validation happens by sending the
answer along with the token. I want to write a form field that
encapsulates this logic. The elements should render (IMO) like




And on submit I need the value of _token to validate the answer.

Thanks,
Emil

--
http://bolddream.com


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Update a single column of a row in a Model

2010-03-04 Thread Ken
Thanks

Unfortunately I'm very new to Forms/ModelForms, and I'm having a lot
of difficulty understanding the Django examples.

All I want is to allow my users to make one change to one column.  I
don't want them to see the ID, just a text box and a submit button.
Hitting Submit should take them back to exactly the same page, with
the text field pre-populated to what they entered.

The database update should only change one column of the relevant row
in the database table.

This would take 30 seconds to do in PHP.

Can anyone point me to some simple examples (other than the Django
site).

Cheers,

Ken


On 3 Mar, 00:31, Shawn Milochik  wrote:
> Use a forms.ModelForm and exclude all the fields except one, or use a  
> forms.Form with one field and use its value in a queryset .update()  
> call.
>
> Shawn
>
> Sent from my iPhone
>
> On Mar 2, 2010, at 7:11 PM, Ken  wrote:
>
>
>
> > Folks
>
> > This is a bit of a newbie question on Model updates.  I've been
> > happily using Django to give my users a read-only view of the database
> > for nearly a year, but now I'd like my users to be able to update a
> > row in one of my tables.
>
> > We're told in the Model documentation that "Django knows best" when it
> > comes to talking to the database.
>
> > However, I want my users to ONLY update ONE column in one row in my
> > database, but Django seems to insist on updating all the columns.  (A
> > related problem is that I'd also like the database user only to be
> > allowed to update a subset of columns of my table - mostly because I'm
> > paranoid.)
>
> > If you don't specify the column value, and the column is nullable, the
> > unspecified columns get set to NULL instead of left alone.
>
> > Here's an example...
>
> > select * from tcs_detection_lists;
> > ++---+-+
> > | id | name      | description         |
> > ++---+-+
> > |  0 | garbage   | Bad Candidates      |
> > |  1 | confirmed | Confirmed SNe       |
> > |  2 | good      | Good Candidates     |
> > |  3 | possible  | Possible Candidates |
> > |  4 | pending   | Not Yet Eyeballed   |
> > ++---+-+
>
> > I want to update the word 'garbage' to 'bad'.
>
> > Here's my simplistic Django code...
>
> > dl = views.TcsDetectionLists(id=0, name ='bad')
> > dl.save()
>
> > select * from tcs_detection_lists;
> > ++---+-+
> > | id | name      | description         |
> > ++---+-+
> > |  0 | bad       |                     |
> > |  1 | confirmed | Confirmed SNe       |
> > |  2 | good      | Good Candidates     |
> > |  3 | possible  | Possible Candidates |
> > |  4 | pending   | Not Yet Eyeballed   |
> > ++---+-+
>
> > I only wanted the user to change one column, but Django has assumed
> > None for the rest of the columns and therefore deleted my
> > 'description' field.
>
> > The update that I want is:
>
> > update tcs_detection_lists
> > set name = 'bad'
> > where id = 0;
>
> > Note that some of my tables have many columns (>50) with a lot of
> > floating point data and I certainly don't want my users inadvertently
> > deleting data.
>
> > Do I need to specify something in my Model columns to get Django to
> > behave the way I want it to...?  I really don't want to have to resort
> > to a bit of custom SQL...
>
> > Thanks in advance,
>
> > Ken
>
> > --
> > You received this message because you are subscribed to the Google  
> > Groups "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com
> > .
> > For more options, visit this group 
> > athttp://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-us...@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.



shortest way to recover from a QuerySet "object not found"

2010-03-04 Thread Phlip
Djangoids:

Consider this line:

   foo = Foo.object.get(name='bar')

If foo is not found, I want it to contain a NullObject, such as an
empty Foo(). In the parlance, that could be like this:

   foo = Foo.object.get(name='bar', _default=Foo())

I naturally don't expect (v 1.1.1) of Django to support my magic
_default keyword.

What's the absolute shortest stretch of code which pops a NullObject
into my foo if the record 'bar' is not found?

--
  Phlip
  http://c2.com/cgi/wiki?ZeekLand

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: upgrade to released version 1.1.1 problems

2010-03-04 Thread Karen Tracey
On Wed, Mar 3, 2010 at 4:07 PM, mendes.rich...@gmail.com <
mendes...@gmail.com> wrote:

> Hello Django Users,
>
> I just tried to upgrade my django version towards the last official
> release Django 1.1.1 and ran into some trouble after the install.
> When i do a runserver first it complained about an AttributeError:
> 'Settings' that didn't have certain attributes.
>
> To solve this is added the following settings:
> LOCALE_PATHS = tuple()
> DEFAULT_INDEX_TABLESPACE = ''
> DEFAULT_TABLESPACE = ''
>

These are things you should not have had to do and indicate something is
seriously broken in your install. Proceeding to attempt to patch it up by
manually adding mysteriously missing bits is probably not the best approach.
I recommending starting over by completing removing the existing install and
re-installing.

Note the oldest of those settings -- LOCALE_PATHS -- was added to the global
settings file nearly 2.5 years ago: how old is the version you were
upgrading from? (If you are really upgrading from a release that old there
are going to be code changes you'll need to make to adjust to the
differences between Django 0.96 and Django 1.0.)

Karen

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Organizing a model's properties and methods - best practices

2010-03-04 Thread Masklinn
On 4 Mar 2010, at 16:46 , filias wrote:
> 
> Hi,
> 
> I have a model which starts to have "too many" properties and methods.
> I dont know if this is normal or if there are better ways to deal with
> increasing complexity of a model.
> 
> In the beginning there were just 4 or 5 properties and methods but
> with the news demands of the app they started to grow. I am afraid
> this becomes unreadable and "too big".
> 
> I would like to read about your best practices related to this topic:
> having a model with lots of properties and methods.
> 
> Thanks!


Maybe the object itself is growing too big in its suit and should be split in a 
bunch of smaller models? Or maybe you need some kind of facade giving you a 
simpler interface to your model?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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 audit which user made changes

2010-03-04 Thread Shawn Milochik
This helped me:

http://code.djangoproject.com/wiki/CookBookThreadlocalsAndUser

Shawn

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Organizing a model's properties and methods - best practices

2010-03-04 Thread Matt McCants
I find it's pretty normal. Some of my models get quite large as well. For
one of my projects I did something like this:

Split models.py into multiple files.
Create a models directory in the app's directory.
Move the model files to that directory.
Create an __init__.py in app/models/

So the structure looked like this:

largemodels/
...fixtures/
...models/
..__init__.py
..ReallyFakeModel.py
..ReallyFakeModelTwo.py
..ReallyFakeModelThree.py
...templates/
...urls.py
...views.py
...admin.py
...YouGetThePoint

In __init__.py:

from largemodels.models.ReallyFakeModel import ReallyFakeModel
from largemodels.models.ReallyFakeModelTwo import ReallyFakeModelTwo
from largemodels.models.ReallyFakeModelThree import ReallyFakeModelThree

Then in your code you can still do things like
from largemodels.models import *
or
from largemodels.models import ReallyFakeModel

I'm not sure if this is the best way to go, but I liked the result myself.
I'd also love to see how other people do this. Or hear if what I've done is
terrible =)

Matt

On Thu, Mar 4, 2010 at 10:46 AM, filias  wrote:

> Hi,
>
> I have a model which starts to have "too many" properties and methods.
> I dont know if this is normal or if there are better ways to deal with
> increasing complexity of a model.
>
> In the beginning there were just 4 or 5 properties and methods but
> with the news demands of the app they started to grow. I am afraid
> this becomes unreadable and "too big".
>
> I would like to read about your best practices related to this topic:
> having a model with lots of properties and methods.
>
> Thanks!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@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-us...@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: best practices for creating a template/theming layer for users in a django app

2010-03-04 Thread Nick
sorry, let me rewrite that last part

render_to_response ('%s/index.html' u'theme', {'dictionary':
dictionary})

On Mar 4, 12:11 am, Nick  wrote:
> It seems like this would be best handled at the view level, you could
> pass a url variable in the render_to_response portion, maybe something
> like
>
> def theme(request):
>     # a bunch of view display stuff
>    theme = ThemeModel.objects.get('template__name')
>    if theme:
>        render_to_response('%s' u'path', {'dictionary': dictionary}
>    else:
>        render the default theme
>
> The path is the directory extension of theme.  Probably just make a
> foreign key relationship in the blogs settings Model and link it to a
> template Model with name, thumbnail, etc. etc. etc..
>
> On Mar 3,u 6:12 pm, gdup  wrote:
>
> > O crap! that sounds about right. I was thinking of media_url in terms
> > of only static files, didnt think of {{ templatename }} variable.
>
> > As for the templating part in an app like shopify , i am not familar
> > with rails, but i assume it allows you to create custom template tags
> > like django. I doubt this is the method they are using? Are they
> > probably just using a custom template system from scratch?
>
> > On Mar 3, 5:30 pm, Nick  wrote:
>
> > > If I'm understanding what you're asking, it should be as simple as
> > > adding an entry per user that designates the template/theme you'd like
> > > to use and then passing that as a variable (ex. {{ MEDIA_URL }}
> > > {{ templatename }} where template name would be the directory name of
> > > the template.  Let me know if I have that right.
>
> > > On Mar 3, 5:17 pm, gdup  wrote:
>
> > > > Hello all,
>
> > > > I would really aprreciate it if someone could point me in the right
> > > > direction of creating a themeing and template layer for an application
> > > > written in django, similar to what tumblar and shopify do.
>
> > > > I can almost put my finger on the whole concept. I know u can somehow
> > > > serve the MEDIA_URL variable per user to serve static files, but what
> > > > about themeing (and views)? Would u create your own tags  or just use
> > > > djangos?
>
> > > > Knowing django, I wont be surprised if there is already an app for
> > > > this. Any direction would be greatly appreciated.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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 audit which user made changes

2010-03-04 Thread mr tom
hi,

i'm looking into using AuditTrail (http://code.djangoproject.com/wiki/
AuditTrail) for a project.
it has a system of callbacks to track extra information such as which
user made the changes but it only passes the current instance being
modified and not the request.

my question is therefore: how can i get the user data if i don't have
the request object?

thx in advance,

 thomas

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Organizing a model's properties and methods - best practices

2010-03-04 Thread filias
Hi,

I have a model which starts to have "too many" properties and methods.
I dont know if this is normal or if there are better ways to deal with
increasing complexity of a model.

In the beginning there were just 4 or 5 properties and methods but
with the news demands of the app they started to grow. I am afraid
this becomes unreadable and "too big".

I would like to read about your best practices related to this topic:
having a model with lots of properties and methods.

Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Changing template variables

2010-03-04 Thread Kevin Renskers
I'll explain a bit more what precisely it is what I want to do: Django
1.2 comes with a new messages framework that allows for each message
to have a different "level" (succes, error, warning, etc). I want to
see if a form has errors, and if so, make a message for each error so
all my notices and errors are displayed in the same way in my
application.

But I think I just came up with a solution: make a new template tag in
my base template, always give it the form variable (whether it exists
or not), and from there create the new messages.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Changing template variables

2010-03-04 Thread Bill Freeman
Write your new view so that it can be used generically.

On Thu, Mar 4, 2010 at 10:22 AM, Kevin Renskers  wrote:
> Well yes, but I do not want to change all of my views. I want a
> generic solution to change template variables before they get
> rendered.
>
>
> On Mar 4, 4:14 pm, Bill Freeman  wrote:
>> Write your own view instead of using direct_to_template.
>>
>>
>>
>> On Thu, Mar 4, 2010 at 10:06 AM, Kevin Renskers  wrote:
>> > Hi,
>>
>> > I am wondering if it is possible to change template variables before
>> > they get rendered in a template.
>>
>> > For example, I use something like this in my template:
>> > return direct_to_template(request, template='index.html',
>> > extra_context={'form':form})
>>
>> > I would like to extend this form variable before the index.html
>> > template gets rendered.
>>
>> > My first though was making a template context processor, but I can't
>> > seem to be able to access template variables from it. My next thought
>> > was creating a piece of middleware with a process_response function,
>> > but also from this function it seems impossible to access the template
>> > variables.
>>
>> > Anyone got an idea on how to do this?
>>
>> > Thanks in advance,
>> > Kevin
>>
>> > --
>> > You received this message because you are subscribed to the Google Groups 
>> > "Django users" group.
>> > To post to this group, send email to django-us...@googlegroups.com.
>> > To unsubscribe from this group, send email to 
>> > django-users+unsubscr...@googlegroups.com.
>> > For more options, visit this group 
>> > athttp://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-us...@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-us...@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: Changing template variables

2010-03-04 Thread Kevin Renskers
Well yes, but I do not want to change all of my views. I want a
generic solution to change template variables before they get
rendered.


On Mar 4, 4:14 pm, Bill Freeman  wrote:
> Write your own view instead of using direct_to_template.
>
>
>
> On Thu, Mar 4, 2010 at 10:06 AM, Kevin Renskers  wrote:
> > Hi,
>
> > I am wondering if it is possible to change template variables before
> > they get rendered in a template.
>
> > For example, I use something like this in my template:
> > return direct_to_template(request, template='index.html',
> > extra_context={'form':form})
>
> > I would like to extend this form variable before the index.html
> > template gets rendered.
>
> > My first though was making a template context processor, but I can't
> > seem to be able to access template variables from it. My next thought
> > was creating a piece of middleware with a process_response function,
> > but also from this function it seems impossible to access the template
> > variables.
>
> > Anyone got an idea on how to do this?
>
> > Thanks in advance,
> > Kevin
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://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-us...@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: Django and WordPress together?

2010-03-04 Thread Tim Langeman
Here's another post about a how to connect to wordpress mysql tables
from within Django.
  http://uswaretech.com/blog/2010/01/wordpress-and-django-best-buddies/

The author has done all the work of setting up the django models for
you.

With multi-db available in Django 1.2, it is now possible to connect
to mysql wordpress tables from within a Postgres-db-based Django app.

-Tim


On Mar 3, 6:41 pm, John Griessen  wrote:
> Does anyone run Django and WordPress together?
>
> I like the P2 theme of WordPress, so I'm wanting to use it with links to 
> documents
>   in a P2 blog, but I want it all searchable from Django apps.
>
> Anyone do that where Django is the main admin interface to a site's pages and
> WordPress is just for a subdomain?  If you do this, is it easy access the 
> WordPress
> database via Django?
>
> I found this about what I'm asking:  
> http://geekscrap.com/2010/02/integrate-wordpress-and-django/
>
> Know any other write ups?
>
> Thanks,
>
> John

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Changing template variables

2010-03-04 Thread Bill Freeman
Write your own view instead of using direct_to_template.

On Thu, Mar 4, 2010 at 10:06 AM, Kevin Renskers  wrote:
> Hi,
>
> I am wondering if it is possible to change template variables before
> they get rendered in a template.
>
> For example, I use something like this in my template:
> return direct_to_template(request, template='index.html',
> extra_context={'form':form})
>
> I would like to extend this form variable before the index.html
> template gets rendered.
>
> My first though was making a template context processor, but I can't
> seem to be able to access template variables from it. My next thought
> was creating a piece of middleware with a process_response function,
> but also from this function it seems impossible to access the template
> variables.
>
> Anyone got an idea on how to do this?
>
> Thanks in advance,
> Kevin
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@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-us...@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.



Changing template variables

2010-03-04 Thread Kevin Renskers
Hi,

I am wondering if it is possible to change template variables before
they get rendered in a template.

For example, I use something like this in my template:
return direct_to_template(request, template='index.html',
extra_context={'form':form})

I would like to extend this form variable before the index.html
template gets rendered.

My first though was making a template context processor, but I can't
seem to be able to access template variables from it. My next thought
was creating a piece of middleware with a process_response function,
but also from this function it seems impossible to access the template
variables.

Anyone got an idea on how to do this?

Thanks in advance,
Kevin

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Fail after upgrade to Django 1.2

2010-03-04 Thread Matt McCants
Check out your database settings. 1.2 adds Multi-DB support and with it a
new way of specifying databases, now it shouldn't be causing issues, since
the pre-1.2 way of specifying a database is going to be supported until 1.4,
it would still be where I started my debugging since it looks like Django
thinks your objects are on two different databases.

Check out:
http://docs.djangoproject.com/en/dev/releases/1.2-alpha-1/#specifying-databases
and
http://docs.djangoproject.com/en/dev/ref/settings/#databases



On Thu, Mar 4, 2010 at 8:54 AM, eXt  wrote:

> Hi!
>
>   I've upgraded my Django to 1.2 (1.2-beta-1, tried also trunk) and
> after that my application has started to throw an exception:
> ValueError: Cannot add "": instance is on database
> "default", value is is on database "None".
>
> The code causing the problem is:
>
> (...)
> project = form.save()
> admin_profiles =
> Member.objects.select_related().filter(group__name='Admin')
> for admin_profile in admin_profiles:
>project.users.add(admin_profile.user)
>
> It is just adding users to a project.users which is m2m to auth.User.
> Error report is:
>
> Traceback (most recent call last):
>
>  File "/var/www/django/someapp/parts/django/django/core/handlers/
> base.py", line 101, in get_response
>   response = callback(request, *callback_args, **callback_kwargs)
>
>  File "/var/www/django/someapp/webshare/utils.py", line 21, in wrapper
>   context = view_func(*args, **kwargs)
>
>  File "/var/www/django/someapp/webshare/apps/projects/views.py", line
> 100, in add_project
>   project.users.add(admin_profile.user)
>
>  File "/var/www/django/someapp/parts/django/django/db/models/fields/
> related.py", line 465, in add
>   self._add_items(self.source_field_name, self.target_field_name,
> *objs)
>
>  File "/var/www/django/someapp/parts/django/django/db/models/fields/
> related.py", line 525, in _add_items
>   (obj, self.instance._state.db, obj._state.db))
>
> ValueError: Cannot add "": instance is on database
> "default", value is is on database "None"
>
>
> Everything is ok when I go back to Django 1.1.1. Is there something
> I've missed in my configuration or it's a bug?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@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-us...@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: {% url %} not working

2010-03-04 Thread Alex Robbins
I think the issue is the "|" characters in your url here:
http://bitbucket.org/codethief/pybsd/src/e3b41c08ed90/devices/urls.py#cl-7

>From 
>http://docs.djangoproject.com/en/dev/topics/http/urls/#django.core.urlresolvers.reverse

The reverse() function can reverse a large variety of regular
expression patterns for URLs, but not every possible one. The main
restriction at the moment is that the pattern cannot contain
alternative choices using the vertical bar ("|") character. You can
quite happily use such patterns for matching against incoming URLs and
sending them off to views, but you cannot reverse such patterns.

Hope that helps,
Alex

On Mar 4, 2:13 am, codethief  wrote:
> Hello dear Django community,
>
> I'm desperately trying to get the url template tag working. This is my
> template's source 
> code:http://bitbucket.org/codethief/pybsd/src/e3b41c08ed90/tpl/devices/ger...
> And here are my URL 
> settings:http://bitbucket.org/codethief/pybsd/src/e3b41c08ed90/urls.py
> andhttp://bitbucket.org/codethief/pybsd/src/e3b41c08ed90/devices/urls.py
>
> Surprisingly, I don't even get a NoReverseMatch exception but a
> TemplateSyntaxError when trying to 
> visithttp://localhost:8000/devices/geraetegruppen:
>
> TemplateSyntaxError at /devices/geraetegruppen
> Caught an exception while rendering: Reverse for
> 'pybsd.devices.views.html.geraete' with arguments '()' and keyword
> arguments '{'geraetegruppe': 104}' not found.
> In template /home/simon/projekte/pybsd/tpl/devices/
> geraetegruppen.xhtml, error at line 26
>
> ... which is the line: {% for geraetegruppe in geraetegruppen %}
> (Shouldn't line 33 get highlighted? BTW: Please ignore the #s which I
> added to commit a working version.)
>
> By the way: I also tried {% url devices.views.html.geraete ... %}, {%
> url views.html.geraete ... %}, {% url html.geraete ... %} and named
> URL patterns. None of this worked.
>
> Thanks in advance!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: open()

2010-03-04 Thread Bill Freeman
And you might be confused about what the current working directory is.
 It is not,
in general, the directory containing the .py file in which you are
running at the time.
It is (unless explicitly changed) the working directory of the shell
at the time python
was started.  For example, if your current directory is /home/me and
you type, at
the shell, "tmp/foo.py", or "/home/me/tmp/foo.py", and foo executes os.getcwd(),
it will get "/home/me", not "/home/me/tmp".   So when using the development
server, os.getcwd() will typically return the directory containing
manage.py (the
"project directory").  I'm not sure about the modwsgi case.

Bill

On Wed, Mar 3, 2010 at 9:05 AM, andreas schmid  wrote:
> zubin71 wrote:
>> >From a method defined in a view i need to get the source of an html
>> file in the templates directory. This is how i tried it out. An error
>> occurs at the line,
>>
>> f = open(os.path.join(os.getcwd(), '../templates/test.html'), 'r') ;
>>
> the output of your os.path.join is something like
> '/your/current/workingdir/../templates/test.html'
>> However, this causes an error, "File or directory not found".
>>
>> What do i do? Please help.
>>
> if you want to get a dir a level over your actual workingdir you should
> maybe slice the output of os.getcwd() and add the right from there on..
>
>> thankx in advance,
>> zubin71
>>
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@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-us...@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: Unicode and localized characters in view

2010-03-04 Thread Tom Evans
On Thu, Mar 4, 2010 at 1:15 PM, Joakim Hove  wrote:
> Thank you for answering; I had a feeling that some autoescape magic
> might be at work.
> ...
> File "/var/www/Django/devel/sleipner/main/license.py" in __init__
>  36.                 productList.append( (p.id , "%s %s %6.0f %s" %
> (type.localized_name(country.id) ,
> dur.localized_duration(country.id) , total_price , currency )) )
> -
>
> The return value from the function "dur.localilized_duration( )"
> contains a "å" and that is what it brings it down. I have certainly
> declared encoding in the source file which contains the implementation
> of this function (which contains a literal "å"), but come to think of
> it I might have forgotten to declare endcoding of the source file
> which is actually running when it crashes?
>
> Joakim
>

When you do

"%s" % some_val

you are creating a python string literal, which has some rules about
the encoding[1]. Basically, the encoding of the string literal is that
of the file that it is mentioned in (so 'sleipner/main/license.py in
this case). If no encoding is specified, it is assumed to be ASCII,
and there is no "å" in ASCII.

Even if the file is specified in a encoding that does have "å", I
think you are going the wrong way around this. Django has quite good
unicode handling support, so I would ensure that you generate unicode
strings rather than string literals. This is simple; simply specify
your literals with a preceeding u, eg:
productList.append( (p.id , u"%s %s %6.0f %s" %
(type.localized_name(country.id), dur.localized_duration(country.id) ,
total_price , currency )) )

Ensure that the return values of your localized_* methods return
unicode strings (eg u"å"), and ensure that your editor is configured
to edit files in UTF-8, and everything will Just Work.

Cheers

Tom

[1] http://docs.python.org/reference/lexical_analysis.html#strings

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Multiple views files

2010-03-04 Thread Kenny Meyer
Tom Evans (tevans...@googlemail.com) wrote:
> On Thu, Mar 4, 2010 at 10:39 AM, Kenny Meyer  wrote:
> > ...
> > I would probably have an app tree structure like this:
> >
> > test_app/
> > |-- __init__.py
> > |-- models.py
> > |-- tests.py
> > |-- view
> > |   |-- __init__.py
> > |   |-- blog_form_view.py
> > |   `-- blog_view.py
> > `-- views.py
> >
> > Where my views.py simply imports the views in the ``view`` folder.
> > I think it's essential that you keep the views.py, when you're not
> > running a personalized fork of Django and writing reusable apps. ;)
> >
> 
> I don't think this is necessary. I use this structure:
> (hope unicode line-drawing characters come through!)
> 
> app
> ├── __init__.py
> ├── models.py
> ├── tests.py
> ├── urls.py
> └── views
> ├── __init__.py
> ├── general.py
> └── users.py
> 
> I don't run a personal fork of django, and this app is perfectly
> reusable. In urls.py, I refer to the specific views like so:
> 
> urlpatterns = patterns('app.views.general',
>   url(),
>   )
> 
> I don't have to modify or alter any part of django to work like so.
> 
> 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-us...@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.
>

Tom, that makes absolute sense.

I'll take back, what I said earlier in this thread. [1]_

.. [1] I think it's essential that you keep the views.py, when you're not
running a personalized fork of Django and writing reusable apps. ;)

Very best regards,
Kenny

-- 
  Kenny Meyer
  Software Geek | http://kenny.alwaysdata.net

  Shoot for the moon, even if you miss, you'll land amongst the stars..
- Les Brown

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Fail after upgrade to Django 1.2

2010-03-04 Thread eXt
Hi!

   I've upgraded my Django to 1.2 (1.2-beta-1, tried also trunk) and
after that my application has started to throw an exception:
ValueError: Cannot add "": instance is on database
"default", value is is on database "None".

The code causing the problem is:

(...)
project = form.save()
admin_profiles =
Member.objects.select_related().filter(group__name='Admin')
for admin_profile in admin_profiles:
project.users.add(admin_profile.user)

It is just adding users to a project.users which is m2m to auth.User.
Error report is:

Traceback (most recent call last):

 File "/var/www/django/someapp/parts/django/django/core/handlers/
base.py", line 101, in get_response
   response = callback(request, *callback_args, **callback_kwargs)

 File "/var/www/django/someapp/webshare/utils.py", line 21, in wrapper
   context = view_func(*args, **kwargs)

 File "/var/www/django/someapp/webshare/apps/projects/views.py", line
100, in add_project
   project.users.add(admin_profile.user)

 File "/var/www/django/someapp/parts/django/django/db/models/fields/
related.py", line 465, in add
   self._add_items(self.source_field_name, self.target_field_name,
*objs)

 File "/var/www/django/someapp/parts/django/django/db/models/fields/
related.py", line 525, in _add_items
   (obj, self.instance._state.db, obj._state.db))

ValueError: Cannot add "": instance is on database
"default", value is is on database "None"


Everything is ok when I go back to Django 1.1.1. Is there something
I've missed in my configuration or it's a bug?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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 fill foreign key hidden field with reference to request user in django 1.0

2010-03-04 Thread André
Hi,

I'm using django 1.0 and I have in my model a foreign key to the User
table. I want to fill this with the user which is creating the entry
and I understood I can do it in the save_model method:

http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.save_model

my problem is that before calling the save_model, a validation is
performed on the form and the field related to the foreign key (which
is not showed in the form) generates a validation error because no
value is filled.

How can I skip the validation of such a field since anyway the correct
value will be inserted before saving in the save_model method?

Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Cassandra back end for Django

2010-03-04 Thread Florian Leitner
One possible solution: write your own Cassandra "O-non-R-M API"
separtely from Django and use the Django DB backend only for less
high-volume data - or not at all - and the Django web framework to
display the data (i.e., only implement views, forms, etc. in Django).
An example of such a layout (not using models at all) was set up by
Eric Florenzano for a "twitter clone site", twissandra:

http://github.com/ericflo/twissandra

Not sure that's what you want, but maybe it inspires. Otherwise, there
are some guys working on implementing a Django object mapper for
Cassandra, I _think_, but I have no idea about the stage of that
project.

--fnl

On 3 March 2010 17:32, Oshadha  wrote:
> Hia fellas,
>
> I'm kind of new to Django framework.as far as I know Django only
> supports four major database engines.I have a requirement to use
> Cassandra(http://incubator.apache.org(/cassandra/) as the database
> backend,but I couldn't find any good resources on the net that give a
> helping hand.So I need a help form you guys.If anyone know a good
> resources for implementing Cassandra with Django framwork please post
> it here and share your experience on these technologies if you have
> any.
>
> Thanks.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@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-us...@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: Unicode and localized characters in view

2010-03-04 Thread Joakim Hove
Thank you for answering; I had a feeling that some autoescape magic
might be at work.


Unfortunately I do not have the code here, but the django traceback
goes like this:


Environment:

Request Method: GET
Request URL: http://devel.pc-horse.com/NewLicense/47/
Django Version: 1.2 beta 1 SVN-12494
Python Version: 2.5.2
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'sleipner.config',
 'sleipner.main',
 'sleipner.transactions',
 'sleipner.DIBS']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware')


Traceback:
File "/usr/lib/python2.5/site-packages/django/core/handlers/base.py"
in get_response
  101. response = callback(request,
*callback_args, **callback_kwargs)
File "/var/www/Django/devel/sleipner/main/license.py" in new
  58. form = NewLicenseForm( country )
File "/var/www/Django/devel/sleipner/main/license.py" in __init__
  36. productList.append( (p.id , "%s %s %6.0f %s" %
(type.localized_name(country.id) ,
dur.localized_duration(country.id) , total_price , currency )) )
-

The return value from the function "dur.localilized_duration( )"
contains a "å" and that is what it brings it down. I have certainly
declared encoding in the source file which contains the implementation
of this function (which contains a literal "å"), but come to think of
it I might have forgotten to declare endcoding of the source file
which is actually running when it crashes?

Joakim


On 4 Mar, 08:48, Daniel Roseman  wrote:
> On Mar 4, 6:45 am, Joakim Hove  wrote:
>
> > About every once a year I am forced out on the internet to read about
> > "encodings and such"; while reading about it all makes sense, but when
> > actually trying to get things to work I always go through a period of
> > swearing and frustration - I never really get it :-(
>
> > Now, in a Django view I have a selectionlist, and one of the seletions
> > should contain the Norwegian problem child 'å'. I have tried the
> > following:
>
> > 1, I have explicitly used the HTML syntax å - however in this
> > case Django ended up rendering the '&' as '&', i.e. as if I wanted
> > a literal '&'.
>
> Nothing to do with encodings, this is autoescaping at work. 
> Seehttp://docs.djangoproject.com/en/1.1/topics/templates/#id2
>
> > 2. I just entered the 'å' in the Python source code for the view. Then
> > a get a Python run.-time error stating that I must declare an encoding
> > when using non-ASCII characters. I then tried declaring the encoding
> > 'latin-1' in the top of the source file of the view, this gave a
> > UnicodeDecodeError triggered by Django:
>
> >         'ascii' codec can't decode byte 0xe5 in position 14: ordinal
> > not in range(128)
>
> > Any hints?
>
> Please show the code.
> --
> DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Unicode and localized characters in view

2010-03-04 Thread Peter Murphy
On Mar 4, 4:45 pm, Joakim Hove  wrote:
> About every once a year I am forced out on the internet to read about
> "encodings and such"; while reading about it all makes sense, but when
> actually trying to get things to work I always go through a period of
> swearing and frustration - I never really get it :-(
>
>
> 2. I just entered the 'å' in the Python source code for the view. Then
> a get a Python run.-time error stating that I must declare an encoding
> when using non-ASCII characters. I then tried declaring the encoding
> 'latin-1' in the top of the source file of the view, this gave a
> UnicodeDecodeError triggered by Django:
>
>         'ascii' codec can't decode byte 0xe5 in position 14: ordinal
> not in range(128)
>
> Any hints?

Joakin,

If your editor can handle utf-8, then perhaps use the utf-8 encoding:

#!/usr/bin/python
#-*- coding: UTF-8 -*-

Another pitfall you might have is that you are using the str rather
than the unicode type. Don't forget to declare your string constants
with a u in front. For example:

problem_child = u"å".

I hope this helps.

Best regards,
Peter

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



template dir locale

2010-03-04 Thread Alessandro Ronchi
I have a template dir in common with different projects, outside the
projects dir.

Those templates have a locale dir with translations.

In my projects  I have only the templates that differs from the common.

The problem is that it cannot use the locale inside the original
template dir, but If I make a simbolic link from

/common/templates/locale

to
/myproject/templates/locale

it works.

it is possible to avoid the simbolic link, and have in each dir only
translations of its contents?


-- 
Alessandro Ronchi

http://www.soasi.com
SOASI - Sviluppo Software e Sistemi Open Source

http://hobbygiochi.com
Hobby & Giochi, l'e-commerce del divertimento

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: building a form with multiple filters

2010-03-04 Thread David De La Harpe Golden

On 03/03/10 22:10, Nick wrote:

I am trying to build a search form with multiple filters/input
objects. Basically, i want to be able to allow for a simple searhc
based on one criteria or multiple. So if someone searches the name
field(q) they can filter by political party, or city, etc.  Also, I
would like to be able to return results without a search in the name
field(q)



Have you checked out django-filter?  It works well.

http://github.com/alex/django-filter






--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-us...@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: Restricting Access to Uploaded Files

2010-03-04 Thread David De La Harpe Golden

On 03/03/10 23:35, Merrick wrote:

I wanted to give users who are authenticated the ability to upload
files, that's the easy part that I can handle.

What I cannot figure out is how to restrict the viewing/downloading of
files.

Links, tips, code are appreciated.


This is become quite the FAQ...

That depends where the files are uploaded, but assuming the out-of-box 
django behaviour of putting them somewhere in the filesystem: Basically, 
one good option is to do the auth with django, then have django instruct 
the hosting web server to send a file to the client as the response from 
a restricted location, rather than just exposing the file directly 
through the web server without authentication.


You do this by setting certain magic headers, though exactly which one 
and what to set it to and what web server config is necessary depends 
heavily on what web server you're using. See e.g. a recent thread 
regarding "Best practices for restricting media?"

http://groups.google.com/group/django-users/browse_thread/thread/a55b1b827849efee/eec041421c11a167

Which will introduce you to X-Sendfile, X-Accel-Redirect, Location...

Another option is to just serve the file back out through django. Rather 
less efficient, but depending on your application, file sizes and load 
it may not matter, and is certainly easy to get working...



--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-us...@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: Get id attribute in a form

2010-03-04 Thread Sam Lai
On 25 February 2010 07:05, leoz01  wrote:
> Hello,
>
> i have a simple question, how can i get the id attribute (which
> correspond to html id) from a form's field ?

I have this problem too when I wrote my wrapper for my django-ckeditor
app. It seems like an odd oversight, and from what I've read in the
source code, there's no clean way of getting it. I'm saying it is an
oversight because having a definitive way of getting the final html id
of a widget is important when using javascript widgets that replace
the form widget.

In my case, I was rendering a custom widget (derived from
widgets.Textarea), so I overrode the render method of that class, and
used the following code to get the id attribute -

# determine id of widget if possible, otherwise use name
identifier = attrs.get('id')
if identifier == None:
identifier = name

I'm not quite sure what edge case caused the attrs dict to not have an
'id' attribute; just the first line might work for you.

Note that the attrs dictionary is generated right before render is
called, so there is no way of accessing it prior to that (it is quite
entwined with the rest of the form code).

Once I had the html id attribute value in the 'identifier' variable, I
added it to a template context and rendered my widget from there.

If someone has a better solution, I'd be happy to hear it.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: formatting results of search

2010-03-04 Thread gintare
Thanks,

How about values in database?
Than i am retrieving data from database i am getting:
(3, u' ANN I. PERSSON1', u' MAGNUS W. LARSSON2, STIG STENSTR\xd6M3, B.
JONAS OHLSSON1, LARS SAMUELSON1 AND L. REINE WALLENBERG2 ', u' nature
materials', u' ..

Is it possible to write to databse normal string without preceding
u'  ?
I am using smart_unicode() function to be able to save special
characters in database.

#Ath.html





#view.py
def search1(request):
Lq,stitles, query = [ ] , string_column _names,
request.GET.get( 'q','')
Lq=query.split('<')
   my_custom_sql( Lq, Ltitles)

def my_custom_sql( Lq, stitles):
from django.db import connection, transaction
cursor = connection.cursor()
for i in range(len(Lq)): stLq=stLq+'\"'+smart_unicode(Lq[i],
encoding='utf-8', strings_only=False, errors='strict')+'\"'+' , '
st2='insert into Ath_aref'+ ' ( ' + stitles + ' ) values ' + '(' +
stLq+ '); '
cursor.execute(st2);
transaction.commit_unless_managed()


regards,
gintare





On Feb 22, 1:15 am, Dennis Kaarsemaker  wrote:
> On wo, 2010-02-17 at 05:32 -0800,gintarewrote:
>
> > @@in *.html
> > @@using line  {{ word|escape }}
>
> > @@i am getting printed answer :(u'moi',)  instead of moi.
> > @@I need only word moi (without any brakets, quatations) be visible in
> > a webpage.
>
> In this case you want word.0|escape
>
> values() always returns a sequence of tuples.
> --
> Dennis K.
>
> The universe tends towards maximum irony. Don't push it.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Multiple views files

2010-03-04 Thread Tom Evans
On Thu, Mar 4, 2010 at 10:39 AM, Kenny Meyer  wrote:
> ...
> I would probably have an app tree structure like this:
>
> test_app/
> |-- __init__.py
> |-- models.py
> |-- tests.py
> |-- view
> |   |-- __init__.py
> |   |-- blog_form_view.py
> |   `-- blog_view.py
> `-- views.py
>
> Where my views.py simply imports the views in the ``view`` folder.
> I think it's essential that you keep the views.py, when you're not
> running a personalized fork of Django and writing reusable apps. ;)
>

I don't think this is necessary. I use this structure:
(hope unicode line-drawing characters come through!)

app
├── __init__.py
├── models.py
├── tests.py
├── urls.py
└── views
├── __init__.py
├── general.py
└── users.py

I don't run a personal fork of django, and this app is perfectly
reusable. In urls.py, I refer to the specific views like so:

urlpatterns = patterns('app.views.general',
  url(),
  )

I don't have to modify or alter any part of django to work like so.

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-us...@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.



Logging into django admin site via wget and/or wkhtmltopdf

2010-03-04 Thread Emma F
Has anyone ever had any success accessing the django admin site via
either of these tools?

I'm working on a view that will convert a particular dynamically-
generated page in my site to a PDF file, which can then be downloaded
from the server.  I originally tried to do this using this reportlab/
pisa method described in the documentation, but it couldn't cope with
the formatting required, so I'm on to plan B: wkhtmltopdf, run as a
command-line tool via subprocess.Popen in the django view.   If I
can't get that to work, I will have the view mirror the page with wget
(again using Popen) and then run wkhtmltopdf off that local copy on
the server.

Both methods work perfectly with a local copy of the page I've saved
from my browser. However, I'm having difficulties making it work
automatically from the view, with live pages from the application. I'm
trying to use the --post option of wkhtmltopdf to log in via the login
form and then convert the page.  I can get this method to work with
various other sites on the web, but something goes wrong when I try
with my django admin site.

I'm using the standard authentication that comes with the django admin
site, and on examing the code for the login form fields, it looks like
so:



 
  
 
 
 

I've tried to translate the names and values of those fields into
wkhtmltopdf --post commands.  (I'm not too sure about the hidden
post_data field with the value of "", so that could be where the
problem lies: I've tried leaving it out altogether, leaving the second
argument to that --post blank, using "" and using + to stand in for a
space, but the result is always the same.)

Here's what I plug in:

wkhtmltopdf --post username myname --post password mypassword --post
this_is_the_login_form 1 --post post_data +[or whatever I'm using]
http://www.server.com/mysite/admin index.pdf

And the result is a pdf of a django debug page, telling me:

**
 Exception Type: MultiPartParserError
 Exception Value: Invalid boundary in multipart: None
 Exception Location: /usr/local/lib/python2.5/site-packages/django/
http/multipartparser.py in __init__, line 65

**

Using the alternative method - wget to try and mirror the file, I
translate the form like this:

wget -m --post-
data='username=myname&password=mypassword&this_is_the_login_form=1&post_data=
+'  http://www.server.com/mysite/admin

And get an "Error 500: Internal Server Error" method in the command
line.


Can anyone suggest what might be going wrong here - is it something to
do with the way I'm handling the hidden, valueless "post_data" form
field? Or something else I'm doing wrong?... Or is there some inherent
feature of the django admin authentication that is going to prevent
this process working?

Thank you to anyone who can 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-us...@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: Multiple views files

2010-03-04 Thread andreas schmid
Kenny Meyer wrote:
> Wiiboy (jordon...@gmail.com) wrote:
>   
>> Hi guys,
>> I'm thinking about making multiple views files.  I'm just wondering
>> whether:
>> a. There's any problems with that
>> b. many people do it.
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To post to this group, send email to django-us...@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.
>>
>> 
>
> Hi wiiboy,
>
> You mean having more than one module for your views?
>
>   
>> a. There's any problems with that
>> 
> Since it's all Python I don't think there should be any problems with
> that.
>
> I would probably have an app tree structure like this:
>
> test_app/
> |-- __init__.py
> |-- models.py
> |-- tests.py
> |-- view
> |   |-- __init__.py
> |   |-- blog_form_view.py
> |   `-- blog_view.py
> `-- views.py
>
> Where my views.py simply imports the views in the ``view`` folder. 
> I think it's essential that you keep the views.py, when you're not
> running a personalized fork of Django and writing reusable apps. ;)
>
>   
>> b. many people do it.
>> 
> AFAIK I don't know many Django developers who do that (if any). But why
> not do it?
>   
im using this approach because my app is a bigger than the usual app and
its ieasier to keep track of the all views for a specific model.
my urls.py are splitted too. and there is no problem involved with
splitting the functions into multiple files
> Large views modules can be quite readable and browseable if your
> editor supports intelligent code folding.
>
> Correct me if I got something wrong.
>
> Cheers,
> Kenny
>
>   

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: what has to be changed after project.db deletion and new empty project.db file creation manually

2010-03-04 Thread gintare
Thanks
now it works,

In time i posted the question syncdb did not generated database file
"referenc.db".
Thats i posted the question.
Now it works normally again.

regards,
gintare

On Mar 3, 6:02 pm, Matt McCants  wrote:
> For sqlite3, you don't even need to create an empty db. Just put the desired
> filename in your settings.py for the database name and run
>
> python manage.py syncdb
>
> and the database will be created along with all the tables based on the
> models for all the installed apps. You don't actually need to run the sql
> command unless you're just interested in what Django is going to do when you
> run syncdb. Or you're going to manually run the SQL or modify it to alter
> existing structure.
>
> I'm not sure if I'm misunderstanding, but it sounds like you made the
> changes in the database without making the changes to your models. It's all
> about the models! Make the changes there then re-run syncdb. Hope this helps
> some. There really aren't any lines to change, just a process to follow.
>
> On Wed, Mar 3, 2010 at 1:47 AM, gintare  wrote:
> > Hello.
>
> > to summarize the question is
>
> > which lines has to be changed when the database file i.e, referenc.db
> > is deleted and later created manually as empty database?
>
> > The problem is that i created whole project a week before.
> >  Later i modified modules, added new tables and new fields (Rrest
> > column was added for sure in table Areferenc_aref).
> >  I deleted empty database file referenc.db, created new database file
> > referenc.db manually expecting that new tables will be generated with
> > additional fields for hem.
>
> > Nevertheless the django finds only old columns.
>
> > besides i made one check:
>
> > 1) first of all i totally deleted referenc.db again. For big surprise
> > command manage.py syncdb runs without mistakes.
>
> > Besides python manage.py sql Areferenc  generates tables for non
> > existing database.
>
> > ^Cworking:/opt/pages/referenc# python manage.py sql Areferenc
>
> > BEGIN;
> > CREATE TABLE "Areferenc_aref" (
> >    "id" integer NOT NULL PRIMARY KEY,
> >    "Rfirstauthor" varchar(500) NOT NULL,
> >     "Rauthors" varchar(500) NOT NULL,
> >    "Rjournal" varchar(500) NOT NULL,
> >    "Rrest" varchar(500) NOT NULL,
> >    "Rpage" varchar(500) NOT NULL,
> >    "Rissue" integer NOT NULL,
> >     "Rvolume" integer NOT NULL,
> >    "Ryear" integer NOT NULL,
> >    "Rtitle" varchar(500) NOT NULL,
> >    "Rkeyw" varchar(500) NOT NULL,
> >    "Rurl" varchar(200) NOT NULL,
> >     "Rindex" varchar(500) NOT NULL,
> >    "Rname" varchar(500) NOT NULL,
> >    "Rdoi" varchar(500) NOT NULL,
> >    "Rlink" varchar(100) NOT NULL,
> >    "Rmail" varchar(75) NOT NULL,
> >     "Rconcl" text NOT NULL,
> >    "Rexists" bool NOT NULL,
> >    "Rinst" varchar(500) NOT NULL
> > )
> > ;
> > CREATE TABLE "Areferenc_experimental" (
> >    "id" integer NOT NULL PRIMARY KEY,
> >     "Rexp" varchar(500) NOT NULL
> > )
> > ;
> > CREATE TABLE "Areferenc_characterization" (
> >    "id" integer NOT NULL PRIMARY KEY,
> >    "Rchar" varchar(500) NOT NULL
> > )
> > ;
> >  CREATE TABLE "Areferenc_devices" (
> >    "id" integer NOT NULL PRIMARY KEY,
> >    "Rdev" varchar(500) NOT NULL
> > )
> > ;
> > CREATE TABLE "Areferenc_calculations" (
> >    "id" integer NOT NULL PRIMARY KEY,
> >     "Rcal" varchar(500) NOT NULL
> > )
> > ;
> > CREATE TABLE "Areferenc_afieldorder" (
> >    "id" integer NOT NULL PRIMARY KEY,
> >    "Rorder" varchar(500) NOT NULL
> > )
> > ;
> > CREATE TABLE "Areferenc_aref_Rexperimental" (
> >     "id" integer NOT NULL PRIMARY KEY,
> >    "aref_id" integer NOT NULL REFERENCES "Areferenc_aref" ("id"),
> >    "experimental_id" integer NOT NULL REFERENCES
> > "Areferenc_experimental" ("id"),
> >     UNIQUE ("aref_id", "experimental_id")
> > )
> > ;
> > CREATE TABLE "Areferenc_aref_Rcharacterization" (
> >    "id" integer NOT NULL PRIMARY KEY,
> >    "aref_id" integer NOT NULL REFERENCES "Areferenc_aref" ("id"),
> >     "characterization_id" integer NOT NULL REFERENCES
> > "Areferenc_characterization" ("id"),
> >    UNIQUE ("aref_id", "characterization_id")
> > )
> > ;
> > CREATE TABLE "Areferenc_aref_Rdevice" (
> >     "id" integer NOT NULL PRIMARY KEY,
> >    "aref_id" integer NOT NULL REFERENCES "Areferenc_aref" ("id"),
> >    "devices_id" integer NOT NULL REFERENCES
> > "Areferenc_devices" ("id"),
> >     UNIQUE ("aref_id", "devices_id")
> > )
> > ;
> > CREATE TABLE "Areferenc_aref_Rcalculation" (
> >    "id" integer NOT NULL PRIMARY KEY,
> >    "aref_id" integer NOT NULL REFERENCES "Areferenc_aref" ("id"),
> >     "calculations_id" integer NOT NULL REFERENCES
> > "Areferenc_calculations" ("id"),
> >    UNIQUE ("aref_id", "calculations_id")
> > )
> > ;
> > COMMIT
>
> > 2) Secondly I created referenc.db in  ./referenc manually again.
>
> > generated tables with command mentioned in step1 with the same output
> > (table Areferenc_aref contains column Rrest )
>
> > performed manage.py syncdb, which went fluently witho

Re: Multiple views files

2010-03-04 Thread Kenny Meyer
Wiiboy (jordon...@gmail.com) wrote:
> Hi guys,
> I'm thinking about making multiple views files.  I'm just wondering
> whether:
> a. There's any problems with that
> b. many people do it.
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@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.
> 

Hi wiiboy,

You mean having more than one module for your views?

> a. There's any problems with that
Since it's all Python I don't think there should be any problems with
that.

I would probably have an app tree structure like this:

test_app/
|-- __init__.py
|-- models.py
|-- tests.py
|-- view
|   |-- __init__.py
|   |-- blog_form_view.py
|   `-- blog_view.py
`-- views.py

Where my views.py simply imports the views in the ``view`` folder. 
I think it's essential that you keep the views.py, when you're not
running a personalized fork of Django and writing reusable apps. ;)

> b. many people do it.
AFAIK I don't know many Django developers who do that (if any). But why
not do it?

Large views modules can be quite readable and browseable if your
editor supports intelligent code folding.

Correct me if I got something wrong.

Cheers,
Kenny

-- 
  Kenny Meyer
  Software Geek | http://kenny.alwaysdata.net

  Shoot for the moon, even if you miss, you'll land amongst the stars..
- Les Brown

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: ListField() wanted or how to use iterable fields in forms

2010-03-04 Thread Tom Evans
On Thu, Mar 4, 2010 at 3:08 AM, coco  wrote:
> Hello,
> Is it possible to get some kind of ListField() for some
> django.forms.Form fields ?
>
> Here is a typical example problem involving this. Let's try to make
> the following kind of form (forms.py):
>
> class mytable(forms.Form):
>    tags = forms.CharField()
>    x = forms.FloatField()
>    y = forms.FloatField()
>    z = forms.FloatField()
>
> Now, I want to link it with an editable html table like this (4
> columns x multiple rows):
>
> tags    x          y           z
> "pt1"   0.0       0.0       0.0
> "pt2"   1.3       2.1       5.0
> "pt3"   2.0       4.5       6.1
> and so on...
>
> The FloatField() in mytable() are inapropriates. One need some kind of
> FloatList() or TableGrid widget in order to stay DRY : I want to avoid
> hardcoding all the fields (x1,x2,x3,x4,x5,x6,... y1,y2,y3,...), but
> instead using some kind of (x[i], y[i], z[i]   or  data(i,j)). I can't
> figure how to do that. I do not want to use models, neither database
> system, but some direct handling like this snippet in views.py:
>
> def myfunct(request):
>    if request.method == 'POST':
>        form = mytable(request.POST)
>        if form.is_valid():
>            cd = form.cleaned_data
>            for i in range(len(cd['tags']))
>                print cd['x'][i] + cd['y'][i] + cd['z'][i]
>            f = mytable(cd)
>            return render_to_response('mytemplate.html', {'form': f})
>    else:
>        form = mytable()
>    return render_to_response('mytemplate.html', {'form': form})
>
> Does anyone know how to achieve this ? Thanks,
>

Use formsets [1].

Cheers

Tom

[1] http://docs.djangoproject.com/en/1.1/topics/forms/formsets/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: upgrade to released version 1.1.1 problems

2010-03-04 Thread Kenny Meyer
mendes.rich...@gmail.com (mendes...@gmail.com) wrote:
> Hello Django Users,
> 
> I just tried to upgrade my django version towards the last official
> release Django 1.1.1 and ran into some trouble after the install.
> When i do a runserver first it complained about an AttributeError:
> 'Settings' that didn't have certain attributes.
> 
> To solve this is added the following settings:
> LOCALE_PATHS = tuple()
> DEFAULT_INDEX_TABLESPACE = ''
> DEFAULT_TABLESPACE = ''
> 
> This solved this issue but i immediately ran into another one when i
> actually wanted to access the admin page.
> The message i get is:
> 
> File "/Library/Python/2.5/site-packages/django/core/handlers/base.py",
> line 42, in load_middleware
> raise exceptions.ImproperlyConfigured, 'Error importing middleware
> %s: "%s"' % (mw_module, e)
> ImproperlyConfigured: Error importing middleware
> django.contrib.sessions.middleware: "No module named simple"
> 
> Did anyone experience something similar and know how to solve this ?
> 
> best regards,
> 
> Richard
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@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.
> 

Hi,

The traceback probably says it all:
> File "/Library/Python/2.5/site-packages/django/core/handlers/base.py",
> line 42, in load_middleware
> raise exceptions.ImproperlyConfigured, 'Error importing middleware
> %s: "%s"' % (mw_module, e)
> ImproperlyConfigured: Error importing middleware
> django.contrib.sessions.middleware: "No module named simple

You're trying to import a Middleware class which doesn't exist.
Compare your MIDDLEWARE_CLASSES with this working example:

MIDDLEWARE_CLASSES = ( 
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
)

Hope this helps.

-- 
  Kenny Meyer
  Software Geek | http://kenny.alwaysdata.net

  Shoot for the moon, even if you miss, you'll land amongst the stars..
- Les Brown

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Multiple views files

2010-03-04 Thread Tom Evans
On Thu, Mar 4, 2010 at 3:08 AM, Wiiboy  wrote:
> Hi guys,
> I'm thinking about making multiple views files.  I'm just wondering
> whether:
> a. There's any problems with that
> b. many people do it.
>

We do this. It depends on how many views each app has whether it is
necessary or not. I can't recall any major issues with doing so (not
like splitting the models up).

mkdir views
touch views/__init__.py
mv views.py views/general.py

You may have to touch up your urls.py to find the new location of your views.

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-us...@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.



formsets management_form

2010-03-04 Thread gregor kling
Hello,

I may do something, what the formsets are not intended for.

I have forms which assort data of several different Models.
This is because of aggregating data in logical blocks in the UI.
Additionally I have some fields, which have to be filled dynamically.
There is as well the possibility for the user in the UI, to generate
new blocks of data (Javascript).
The thing goes as follow.
Having for each logical data group a form,because there can be
blocks from 1 to n, using a formset for each.
Because I have a bunch of different set of those blocks, I have
several formsets.
Example:
The form:
class F(forms.Form):
foo = forms.CharField(choices=())
bar = forms.ChoiceField(choices=())

def __init__(self,*args,**kwargs):
foo = None
bar = None
if kwargs.has_key('foo'):
foo = kwargs.pop('foo')
if kwargs.has_key('bar'):
bar = kwargs.pop('bar')
super(F,self).__init__(*args,**kwargs)
if foo and bar:
self.fields['foo'] = forms.ChoiceField(choices=foo)
self.fields['bar'] = forms.ChoiceField(choices=bar)

class BaseFS(formsets.BaseFormSet):
def __init__(self,*args,**kwargs):
   if kwargs.has_key('foo'):
  self.foo = kwargs.pop('foo')
   if kwargs.has_key('bar'):
  self.bar = kwargs.pop('bar')
   super(BaseFS,self).__init__(*args,**kwargs)

def _construct_forms(self):
self.forms = []
for i in xrange(self.total_form_count()):
  self.forms.append(self._construct_form(i,foo=self.foo,
bar=self.bar))

The view:
def newd(request):
foo = [ (x,x) for x in Foo.objects.all() ]
bar = [ (x,x) for x in Bar.objects.all() ]
NFS = formset_factory(F,formset=BaseFS)
OtherFS = formset_factory(OtherF,formset=BaseOtherFS)
if request.method == 'POST':
fs = NFS(request.POST,foo=foo,bar=bar)
ofs = OtherFS(request.POST,foo=foo,bar=bar)
if fs.is_valid():
# get the data,distribute to the right model
return HttpResponse("valid really")
else:
return render_to_response('error.html',{'fs' : fs,'ofs'
: ofs})
else:
fs = NFS(foo=foo,bar=bar)
ofs = OtherFS(foo=foo,bar=bar)
return render_to_response('newd.html',{'fs' : fs,'ofs' : ofs})

This seems generally to work.But now comes the twist.
May be there are other twists in (my) code, which I do not see.
But this is one is a detail.

In the template:
{{ fs.management_form }}
{{ ofs.management_form }}
which produces








So,regrettably, therefore I can't differentiate between the count of
different formset data, which I have to.

I can't even prefix the values of the id.
There is no idea of this in,e.g.
django.forms.formsets.BaseFormSet._management_form:
else:
form = ManagementForm(auto_id=self.auto_id,
prefix=self.prefix, initial={
TOTAL_FORM_COUNT: self.total_form_count(),
INITIAL_FORM_COUNT: self.initial_form_count(),
MAX_NUM_FORM_COUNT: self.max_num
})

I hope the structure of my setup and the problem is clear to
understand...

Maybe someone has some hints in any direction.

gfk

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



{% url %} not working

2010-03-04 Thread codethief
Hello dear Django community,

I'm desperately trying to get the url template tag working. This is my
template's source code: 
http://bitbucket.org/codethief/pybsd/src/e3b41c08ed90/tpl/devices/geraetegruppen.xhtml
And here are my URL settings: 
http://bitbucket.org/codethief/pybsd/src/e3b41c08ed90/urls.py
and http://bitbucket.org/codethief/pybsd/src/e3b41c08ed90/devices/urls.py

Surprisingly, I don't even get a NoReverseMatch exception but a
TemplateSyntaxError when trying to visit 
http://localhost:8000/devices/geraetegruppen:

TemplateSyntaxError at /devices/geraetegruppen
Caught an exception while rendering: Reverse for
'pybsd.devices.views.html.geraete' with arguments '()' and keyword
arguments '{'geraetegruppe': 104}' not found.
In template /home/simon/projekte/pybsd/tpl/devices/
geraetegruppen.xhtml, error at line 26

... which is the line: {% for geraetegruppe in geraetegruppen %}
(Shouldn't line 33 get highlighted? BTW: Please ignore the #s which I
added to commit a working version.)

By the way: I also tried {% url devices.views.html.geraete ... %}, {%
url views.html.geraete ... %}, {% url html.geraete ... %} and named
URL patterns. None of this worked.

Thanks in advance!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.