Inheritance at runtime (per model instance)

2009-08-12 Thread Thomas Guettler

Hi,

I am writing a workflow engine. The base workflow is stored in the DB.
But some code needs to written for most workflows.

This means I need code for a model instance (an not code per mode class).

To make this most pythonic, how could this be done?

My idea: since I want the workflow to be portable to several installations, I 
don't use
serial IDs for primary keys, but slug-fields. The slug-field could be a 
importable
classname like 'foo.workflow.MyClass'.

Now I want that the Workflow model instance inherits from MyClass. This must
be done at runtime. I think this could be done with a custom manager.

Does someone have a better approach, or feedback?

  Thomas


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

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



Re: Populating a form from the database

2009-08-05 Thread Thomas Guettler

Hi,

if you use ModelForm, the data from the database are the initial
form data.

If you create a new record with ModelForm, you could use the "initial"
parameter to supply some default values. More can be found in the docs.

  Thomas

Magnus Valle schrieb:
> Short:
> How do I populate a form with data from the database?
> Fx. if I want to let users edit the data they have entered.
> 
> Long:
> Currently, I have a form where the user(if logged in) will enter data 
> and when it is submitted some extra data is entered to the form before 
> it is saved, a time-stamp and the request.user .
> 
> But is there a way to open the form, looking to see if the user already 
> has entered some data, then populate the form with that data. But if the 
> user does not have a entry in the database, then presenting an empty form. ?


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

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



Re: Admin: raw-id: Link to edit page

2009-08-03 Thread Thomas Guettler

Thank you Peter.

But list_display does not get used on the edit page of an object.

If you use raw_id the ID of the foreign key gets displayed right to the
input field. It would be nice to make it a hyperlink.

  HTH,
Thomas

Peter Bengtsson schrieb:
> 
> 
> On 3 Aug, 10:12, Thomas Guettler <h...@tbz-pariv.de> wrote:
>> Hi,
>>
>> How can I display a link to the edit page of a foreign key?
>>
>> Example:
>>
>> class Place:
>> city=models.ForeignKey(City)
>>
>> In the admin page of the place I want a link to the city admin page.
>>
> 
> class PlaceAdmin(admin.ModelAdmin):
> list_display = ('city_special',)
> def city_special(self, obj):
>  return '%s' % \
>   (obj.id, obj.name)
> city_special.short_description = u'City'
> city_special.allow_tags = True
> 
> That should get you started. I don't know if there is a more correct
> way to get the admin edit url for an object.


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

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



Admin: raw-id: Link to edit page

2009-08-03 Thread Thomas Guettler

Hi,

How can I display a link to the edit page of a foreign key?

Example:

class Place:
city=models.ForeignKey(City)

In the admin page of the place I want a link to the city admin page.

Regards,
  Thomas Güttler

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

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



Missing Roles (group of groups)

2009-07-30 Thread Thomas Guettler

Hi,

The models from django.contrib.auth look like unix /etc/passwd and /etc/groups
files.

But roles are more flexible: A role contains roles. A user is a role.

Are there any other django coders who miss this?

I know that this can be implemented with only a few lines. But a reusable
solution would be better.

  Thomas

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

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



Re: No serial primary key and admin interface

2009-07-23 Thread Thomas Guettler

I am sorry for the noise: The slug primary key of the inline model
needs to be displayed. Now it works. Nevertheless silently ignoring
errors like admin does sometimes is bad.

Thomas Guettler schrieb:
> ... replying to myself
> 
> In django trunk this was fixed.
> http://code.djangoproject.com/ticket/10992
> 
> Still looking for a solution in 1_0_X. Unfortunately I don't get a stacktrace,
> but the inlines are just missing.
> 
> TEMPLATE_STRING_IF_INVALID does not get used.
> 
>   Thomas
> 
> 
> Thomas Guettler schrieb:
>> Hi,
>>
>> today I created a model with a slug field as primary key.
>> I discovered that it brings problems in the admin interface.
>>
>> 1. Inlines are not possible. The don't get displayed and if I submit I get 
>> "ManagementForm data is missing or has been
>> tampered with".
>>
>> Both ("parent" and inline) models have a slug field as primary key. Any 
>> change to get the
>> admin interface working?
>>
>> I use the django svn 1_0_X branch
>>
>>   Thomas
>>
> 

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

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



Re: No serial primary key and admin interface

2009-07-23 Thread Thomas Guettler

... replying to myself

In django trunk this was fixed.
http://code.djangoproject.com/ticket/10992

Still looking for a solution in 1_0_X. Unfortunately I don't get a stacktrace,
but the inlines are just missing.

TEMPLATE_STRING_IF_INVALID does not get used.

  Thomas


Thomas Guettler schrieb:
> Hi,
> 
> today I created a model with a slug field as primary key.
> I discovered that it brings problems in the admin interface.
> 
> 1. Inlines are not possible. The don't get displayed and if I submit I get 
> "ManagementForm data is missing or has been
> tampered with".
> 
> Both ("parent" and inline) models have a slug field as primary key. Any 
> change to get the
> admin interface working?
> 
> I use the django svn 1_0_X branch
> 
>   Thomas
> 

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

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



Re: Django 1.0.2 Thread safety

2009-06-30 Thread Thomas Guettler

Hi,

I hit this bug some time ago, too. If you run SVN 1.0.X you get the
bug fixes for free.

  Thomas

Miles schrieb:
> There should be a little warning in the 1.0.2 docs or on
> http://code.djangoproject.com/wiki/DjangoSpecifications/Core/Threading
> that it is *not* thread safe.
> 
> I've hit http://code.djangoproject.com/ticket/10470 on production,
> applied the patches manually. Please make sure you apply both
> http://code.djangoproject.com/changeset/10036 and
> http://code.djangoproject.com/changeset/10040, the first one contains
> a bug which will deadlock the server.

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

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



Re: changes to views and forms are not reflected in browser

2009-06-18 Thread Thomas Guettler

Hi,

Does restarting apache or fast cgi server help? Do you access the page
through a proxy?

 Thomas

neri...@gmail.com schrieb:
> Hello,
> 
> I'm trying to make changes to views and forms but when I refresh the
> browser to view/try the changes nothing seems to have changed. I
> normally do "touch dispatch.fcgi" which is working with templates and
> urls but with views and forms I get nothing different. I tried other
> browsers and cleared my cache as well.


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

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



Re: Problem to deploy on production server

2009-06-15 Thread Thomas Guettler

Hi,

do you use the cache module? Be sure, that both projects use
different ones.

Maybe you need to set SESSION_COOKIE_NAME if the domain name is the
same.

Do you use one database or two? (Is settings.DATABASE_NAME the same?)

  Thomas

Francis schrieb:
> Hi,
> 
> I have completed one web site and I am now ready to deploy it in
> production, but I have serious issues where I can't find any
> information/clue on the django web site, in the book or on IRC. I have
> no idea how I can solve my problem
> 
> What I want to achieve is the following:
> 1 site under http without admin acces
> 1 site under https + admin acces
> 
> My config
> python 2.5
> django 1.0.2
> postgresql
> mod_wsgi (i'm using it because djapian doesn't work with mod_python)
> 
> So what I did was to create two mod_wsgi on two project repositories.
> One configured with the admin apps installed (https) an one without
> (http).
> Results:
> When I save an entry to a model, it saves it and redirects to the non
> secure http service instead of the secure one, throwing a 404.
> 
> So I tried to enable the admin apps on both services.
> Results:
> Now I get a proxy error on the https service and a timeout on the http
> service.
> Some tables show no result on the http service but show them all on
> the other one.
> 
> If I shut down the https service, some entries can be saved and others
> don't.
> The same tables that wrongly display nothing are still empty.
> 
> I tried to give each site a different site_id, but it doesn't help.
> 
> Help would be very much appreciated,
> 
> Thank you
> 
> Francis


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

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



Re: Logging to Database while using @transaction.commit_manually decorator

2009-06-08 Thread Thomas Guettler



Chris Stoyles schrieb:
> Hi Thomas,
> 
> The reason I want to be able to rollback (but still commit by log entries)
> is because it is sometimes valid for this particular view to throw an
> exception and fail. If this happens, I need to rollback any model objects
> that have been created and saved up to the point at which the view fails
> (again, except for any logging that has been done). The view contains a big
> try/except statement and the rollback is in the "except" part.

You can't do this with SQL transaction. If you rollback, logging rows created 
with the
same database connetion will roll back, too.


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

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



Re: Logging to Database while using @transaction.commit_manually decorator

2009-06-08 Thread Thomas Guettler

Hi Chris,

please explain in more depth what you want to do. If you
do rollback, all changes won't be written to the database. Even
all savepoints won't be stored.

Why do you want to rollback? If you want your changes
to get saved, you need to call transaction.commit() at the end.

ChrisStoyles schrieb:
> Hi All,
> 
> I just wanted to quickly reach out to the group for ideas as to why I
> cannot get this to work:
> 
> @transaction.commit_manually
> def some_view(request):
> # some view logic goes here
> 
> sid = transaction.savepoint()
> le = models.LogEntry()
> le.message = 'A test log message'
> le.save()
> transaction.savepoint_commit(sid)
> 
> transaction.rollback()
> 
> My database back end is Postgres 8.3 and the engine I am using is
> postgresql_psycopg2. Any ideas as to why my LogEntry would not be
> committed to the database? I am not getting any exceptions being
> raised, the code executes as though it has all worked perfectly.


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

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



Re: model form validation always failing

2009-05-19 Thread Thomas Guettler

Maybe you form misses this: enctype="multipart/form-data"


watad schrieb:
> dear all
...
> i can see the fileds but when i try to submit , the rusume validation
> is always failing (This field is required.)
> although i upload the file, and i was able to add data usign the admin
> interface without any problems


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

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



Re: What debugger do you use?

2009-05-12 Thread Thomas Guettler

Hi,

I use Emacs for editing and assert and logging for debugging.

Joshua Russo schrieb:
> I'm currently using Netbeans 6.5 with the Python plugin. I was just
> wondering what everyone else is using because NB is a bit buggy with
> the Python plugin at the moment.


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

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



Re: django CommaSeparatedStringField component

2009-05-06 Thread Thomas Guettler

Hi Joshua,

I have coded this some time ago. I uploaded it to djangosnippets for you (and 
other people):

   http://www.djangosnippets.org/snippets/1491/

Thomas

Joshua Partogi schrieb:
> Dear all,
> Does anybody know a good CommaSeparatedStringField for django? The one that
> I expect is sort of like the CommanSeparatedIntegerField that comes with
> django, but for String.
> 
> Thank you very much in advance.
> 

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

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



Cookie based Messages

2009-04-22 Thread Thomas Guettler

Hi,

I was running a session based middleware based on patches on #4604, but
discovered that the session column is a hot spot in the database.

Some users work quick and/or double click where they should not.

I got deadlocks from postgres where several processes tried to
save the session for a single user.

I created a cookie based middleware:
   http://www.djangosnippets.org/snippets/1459/

Happy Hacking,
  Thomas Güttler

#4604 Session based Middleware: http://code.djangoproject.com/ticket/4604

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

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



Re: Fieldlookup: NOT

2009-04-17 Thread Thomas Guettler

Christian Joergensen schrieb:
> Thomas Guettler wrote:
>> Hi,
>>
>>
>> For forms which display a list of results I use:
>> form=QueryForm(request.GET)
>> 
>> queryset=MyModel.objects.filter(**form.cleaned_data)
>>
>> But, now I need to use exclude() instead of filter().
>  >
>> I looked at the queryset API, but it seems that there is no
>> alternative to qs.exclude().
> 
> What's wrong with exclude() as it is now?

Not much, but I need two dictionaries, where one would be enough:

"form" displays fields for making queries on MyModel. It displays a
paginated result list:

MyModel.objects.filter(**form.get_filter_dict()).exclude(**form.get_exclude_dict())

  Thomas

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

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



Fieldlookup: NOT

2009-04-16 Thread Thomas Guettler

Hi,


For forms which display a list of results I use:
form=QueryForm(request.GET)

queryset=MyModel.objects.filter(**form.cleaned_data)

But, now I need to use exclude() instead of filter().

I looked at the queryset API, but it seems that there is no
alternative to qs.exclude().

Wouldn't it be nice to have a "not" field lookup? Example:

MyModel.objects.filter(field__not=...)
MyModel.objects.filter(field__not__in=...)

  Thomas


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

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



Re: how to connect postgresql

2009-04-09 Thread Thomas Guettler

Hi,

this is not a django or python problem.

I guess you get more help from a java list. Maybe news:comp.lang.java is the
right place.

  Thomas


NK B schrieb:
> hello friends
> i'm work with django. but i create the reports in java
> how to link java and postgresql.please help me...
> 
> i'm try following code but driver found not connect with db what do
> to
> 
> import java.sql.DriverManager;
> import java.sql.Connection;
> import java.sql.SQLException;
> 
> public class Example1 {
>   public static void main(String[] argv) {
>   System.out.println("Checking if Driver is registered with
> DriverManager.");
> ...


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

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



Re: Merging apps

2009-04-01 Thread Thomas Guettler



Dids schrieb:
> Hi,
> 
> I have a handful of application running on the same apache server.
> 
> More are on the way and it's starting to get messy to manage.
> 
> I'd like to "merge" all the applications into one but I'm not sure how
> to go about it.
> [What I want is, a single entry in my apache.conf file, not one per
> app as I have now]

Please use django terms: One *project* contains one or many *applications*.
Example: settings.py is part of the project. While most views and models.py
are part of the applications.

I think you should have one entry in apache.conf for every *project*.

> 
> I initially tried to write some sort of a portal that would link to
> each app, but I can't get Django to switch to the different databases.
> 
> How would you guy go about it?

Don't put code into projects, python logic should be in applications. A project
is quite small. It is just a container and configuration for several 
applications.

> Do I have to bite the bullet and merge the databases , views files,
> settings etc etc?

Does every project have its own user management?


HTH,
  Thomas

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

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



Re: Counting queries and query execution time

2009-03-31 Thread Thomas Guettler

Hi,

I have written an SQLLogMiddleware:
  http://www.djangosnippets.org/snippets/344/

Maybe this helps you. But it only works if settings.DEBUG is true.

Ceph schrieb:
> Under settings.DEBUG=True, django.db.connection.queries is an array of
> all queries executed. Obviously storing every query in text is a
> memory hog. Would it still thrash as much if I wrote my own wrapper
> around a DB connection class via settings.DATABASE_ENGINE that
> implemented its own DebugCursorWrapper that timed and counted queries,
> but did not store the query text? Would the perf hit be as bad? I can
> see it adding up on views with many queries, but that's my goal:
> collect stats about actual production views where the query count/view
> time/rendering time may vary from development.
> 
> Or even better: does anyone have this written? I didn't see it on
> django snippets.


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

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



Re: Updating a model method

2009-03-31 Thread Thomas Guettler



Graham Dumpleton schrieb:
> 
> 
> On Mar 31, 1:43 am, Thomas Guettler <h...@tbz-pariv.de> wrote:
>> Hi,
>>
>> If you only change the method, but no model, you don't need to call 'syncdb'.
>>
>> If your webserver is configured correct, then you just need to hit ctrl-r 
>> (reload
>> in firefox).
>>
>> This should work if you use the development server of django. If
>> you use apache with mod_wsgi you need to set  maximum-requests=1. This will 
>> reload
>> you code for every request. Of course the production server should have a 
>> different
>> value.
> 
> Don't use 'maximum-requests=1' for mod_wsgi daemon mode processes. It
> is a really bad idea and has performance which is much worse than CGI.
> This is because of the way that Apache parent process only polls once
> a second for child processes that have shutdown.

I use daemon mode and maximum-requests=1 for development very long. I can
only speak of my experience, and this is very good.

The key sequence:
  ctrl-x s Alt Tab ctrl-r (save file in emacs, change focus to firefox, reload 
page)
gets typed very quick. I guess a monitor script which checks for code changes 
every
second, won't detect the change every time before firefox reloads the page.

In the long run polling source files again and again will keep your CPU from 
sleeping.
I guess this will use more energy and create more CPU fan noise.
If you use inotify for detecting source changes this might be different.

The performance of "reload daemon for every request" might be worse than CGI,
but it is fast enough for my development setup.

I know that you (Graham) are the apache and wsgi expert. I read the links you 
sent. But
I don't see a need to change away from maximum-requests=1.

  Thomas



-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

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



Re: Updating a model method

2009-03-30 Thread Thomas Guettler

Hi,

If you only change the method, but no model, you don't need to call 'syncdb'.

If your webserver is configured correct, then you just need to hit ctrl-r 
(reload
in firefox).

This should work if you use the development server of django. If
you use apache with mod_wsgi you need to set  maximum-requests=1. This will 
reload
you code for every request. Of course the production server should have a 
different
value.

 HTH,
   Thomas


Miguel schrieb:
> Hi all,
> 
> I have a model where I have defined a method :
> 
> def print_html(self):
> [...]
> 
> 
> 
> I have changed this method but no change is observed in the web page. It is
> still working the old model method.
> How can update this?
> python manage.py sqlall
> and
> python manage.py syncdb
> 
> doesn't seem to work. Could anybody help me?
> 
> 

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

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



Re: dynamic url pattern

2009-03-26 Thread Thomas Guettler

Alessandro Ronchi schrieb:
> I want to make a regxep in my urls.py that takes the name of the view from
> the url.
> Something like:
> 
> 
> (r'^views/(?P\w+)/', 'myproject.database.reports.' + name),
> 
> is it possible? I've a lot of views with the same rule and I want to make
> them be available without duplicate names 3 or 4 times.

That's possible, but you need a wrapper:


 (r'^views/(?P\w+)/', 'myproject.views.wrapper'),

# views.py (untested)
def wrapper(request, name):
module=__import__("myproject.database.reports.%s" % name, globals(), 
locals(), [name])
method=getattr(module, name)
    return method(request)


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

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



Re: Foreign keys in admin

2009-03-26 Thread Thomas Guettler

Hi,

google for raw_id_fields

Leonel Nunez schrieb:
> Hello :
> 
> I have this  model :
> 
> class Rel(models.Model):
>   n = models.ForeignKey(MASTER)
>   r = models.ForeignKey(MASTER,null=True,related_name='child_set',
>  blank=True)
> 
> 
> But in the admin gets too slow since this model tries to fill the SELECTs
> with all the posible values and the  MASTER table is BIG .
> 
> Is there a way to make this faster ??
> 
> Thank you


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

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



Re: Working With ModelForms

2009-03-24 Thread Thomas Guettler

Hi,

my guess: You need to redirect after POST.

if you give request.POST to the Form, it will overwrite the values
from the model with the values from request.POST. If you do a redirect
after POST, the value from the model will be displayed, since POST
is empty after the redirect.

BTW, I often do it like this:

def view(request):
if request.POST:
data=request.POST
else:
data=None
form=MyForm(data)

Why do you access 'build_release' in POST? It would be better
the create a Field for it and access form.cleaned_data['build_release']

 HTH,
   Thomas

DarrenM schrieb:
> ...
> elif request.POST['build_release']:
> f = BuildForm(request.POST)
> new_build = f.save(commit=False)
> new_build.build_path = FindPath(request.POST
> ['build_release'])
> new_build.save()
> return render_to_response('bmi/newbuild.htm',

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

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



Re: inconsistency between remove() and clear()?

2009-03-24 Thread Thomas Guettler

Hi,

book2.publisher is an attribute which was created before you deleted it.
If you get book2 again from Book.objects, this attribute would not exist
anymore.

I have not looked at the underlaying django source, but I guess that
remove(obj) removes the attribute from obj.

But clear() can't do this, since it does not have a reference to all
affected objects.

  Thomas

Margie schrieb:
> It seems to me there is an inconsistency between clear() and remove
> ().  After a remove() I find that the related object set no longer
> contains the specified object (as expected), and the specified object
> also no longer points to the related set (this also is what I'd
> expect).  However, in the case of clear(), I find that the related
> object set is now cleared out (as I'd expect), but the objects that
> used to be in the set still point to the set (not what I'd expect).
> Is this difference intentional?
> 
> I also find that after exiting the shell and then going back in, now
> the objects that used to be in the set no longer point to the set.
> IE, the inconsistent clear behavior goes away if I exit the django
> shell and then re-enter.
> 
> class Publisher(models.Model):
> name = models.CharField(max_length=100)
> 
> class Book(models.Model):
> title = models.CharField(max_length=100)
> publisher = models.ForeignKey(Publisher, blank=True, null=True)
> 
>>>> pub = Publisher.objects.create(name="pub1")
>>>> book1 = pub.book_set.create(title="title1")
>>>> pub.book_set.all()
> []
>>>> book2 = pub.book_set.create(title="title2")
>>>> pub.book_set.all()
> [, ]
>>>> book1.publisher
> 
>>>> book2.publisher
> 
> 
> # after using remove() to remove book1, book1.publisher is empty
>>>> pub.book_set.remove(book1)
>>>> book1.publisher
>>>> pub.book_set.all()
> []
> 
> # Now book2 references pub.  After using clear(), book2.publisher
> still references pub
> # This seems inconsistent with the remove() behavior above.
>>>> pub.book_set.clear()
>>>> book2.publisher
> 
> 
> Any comments from those in-the-know?
> 
> Margie
> 


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

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



Re: Reverse tag of safe

2009-03-24 Thread Thomas Guettler

Hi,

google for "entity resolver python". I recall that I did something like this.

You could ask on comp.lang.python, too.

If you got it working in python you can create a template tag.

 Thomas

Alessandro Ronchi schrieb:
> I need to translate html entities on utf-8 characters, like  to à
> is there any template tag filter which can do that?
> 

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

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



Re: ModelChoiceField - large lookup tables

2009-03-24 Thread Thomas Guettler

Hi,

for the Admin Interface there is raw_id_fields.

In the code of my application I use my ButtonWidget.
It renders itself as a hidden Input field and a button. If you
click on the button you get a query page to search for the related
object. After selection it writes the value back to the hidden field
with JS opener.document.getElementById(...);

That's my way, I guess there exist better solutions.

  Thomas

PNM schrieb:
> Before I re-invent the wheel: is there any generally accepted or
> recommended generic way to handle ModelChoiceFields with very large
> datasets in Django?
> 
> My current example is an address>post/ZIP-code relationship where
> Django's automatic field creation pulls in the whole postcode table
> with thousands of rows into a ModelChoiceField.
> 
> The postcode field changes relatively seldom, so a sensible solution
> would seem to be some sort of passive display-only field which mirrors
> the choice field's functionality (show the link's __unicode__ and hold
> the link's pk for form validation), and that the mechanism for pulling
> in a new value is put somewhere else (eg. a button to open a search-
> and-select window). A ModelLookupField?
> 
> This must be such a common scenario that I'd be interested in hearing
> how other people solve it. I can't find anything in the documenation
> on it.

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

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



Re: request object needed in form methods

2009-03-19 Thread Thomas Guettler

>> Why not store the request
>> object (in a thread safe way) on module level?
...
> The biggest con is encourages bad design practices, the way Python works is
> you have a global and local scope, if you want something in your local scope
> you pass it to it.
> 
> If you really want to have the request object stored you can write a custom
> middleware to do it, but I wouldn't.

I don't want to enable this for all parts. Just for a single, complex form.

{{{
class MasterForm(object):
... contains several sub forms which need request

class SubForm(form.Form):
def clean(self):
if threadlocal.request.user .

threadlocal=threading.local()
def view(request):
threadlocal.request=request
mform=MasterForm()
}}}



-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

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



request object needed in form methods

2009-03-19 Thread Thomas Guettler

Hi,

I know that you can pass the request object to form like this:

class MyForm(forms.Form):
def __init__(self, request, *args, **kwargs):
self.request=request
forms.Form.__init__(self, *args, **kwargs)

Somehow I am tired of rewriting this. Why not store the request
object (in a thread safe way) on module level?

I recall that someone said this is not good. What are the pro and
contra arguments?

Most of the time I need request.user to hide some input fields.

  Thomas

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

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



Re: Adding a field to a form during runtime

2009-03-19 Thread Thomas Guettler

Sorry, I can't help you here, since I don't create classes
at runtime (*). I think using __init__() is better, and I guess
you can solve your problem with it, too.

(*) type('ContactForm', (forms.BaseForm, ), { 'base_fields': fields})

Marek W schrieb:
> Thanks for your response. Probably the reason was I didn't update a
> database, because now(after making syncdb) it works correctly. But by the
> time I've found a second problem:
> 
> while to create a dynamic form this way:
> 
> def make_car_form(extra):
> fields = { 'carType' : forms.CharField() }
> if extra:
> fields['extraField'] = forms.CharField()
> return type('ContactForm', (forms.BaseForm, ), { 'base_fields': fields
> })
> 
> 
> View method:
> (...)
> carForm = make_car_form(True)
> (...)
> 
> then on the page there aren't any fields, whether calling make_car_form with
> extra=True or extra=False.


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

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



Re: Adding a field to a form during runtime

2009-03-18 Thread Thomas Guettler

Hi,

your code looks correct.

You can try to debug it. Maybe insert
 assert False, self.fields into __init__()
Do the fields from the model exist?

  Thomas

Marek W schrieb:
> Hi, I would like to add a field to a form dynamically. I'm using Django
> 1.0.2.
> 
> Here's my view code:
> 
> class CarForm(ModelForm):
> def __init__(self, *args, **kwargs):
> super(CarForm, self).__init__(*args, **kwargs)
> self.fields['extraField'] = forms.CharField()
> 
> class Meta:
> model = Car
...

> I took this idea from
> http://www.b-list.org/weblog/2008/nov/09/dynamic-forms/.  When I try to view
> the page, when there's my own __init__ method in CarForm class, then the car
> form doesn't contain any field. When i remove the __init__ method,
> everything works correctly.  How to add a field to a form during a runtime ?


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

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



on delete set null

2009-03-16 Thread Thomas Guettler

Hi,

I have a foreign key from MyModel to contrib.auth.models.User which can
be null.

Unfortunately if you delete the user, the MyModel instance gets deleted, too.

I found an open ticket[1], but nevertheless don't know how to get the "on 
delete set null"
done.

One solution would be this: subclass User and override delete() and use this 
class for
as foreign key.
But I would prefer a different solution.


[1] http://code.djangoproject.com/ticket/7539
Add ON DELETE and ON UPDATE support to Django

  Thomas

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

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



Re: [OFFTOPIC]: msiexec and Python 2.6.1 on Windows

2009-03-13 Thread Thomas Guettler

Hi,

this does not answer your question, but some weeks ago I
used py2exe and wix to create a msi. I have not used windows
for years and py2exe and wix were new for me. But it took only some ours
to get it working.

HTH,
  Thomas


cjl schrieb:
> I am in the process of updating my little django project,
> instantdjango.com, and I'm running into a little problem with my
> 'build' script, which is a script I hacked together to create the
> instant django portable environment, without me having to do
> everything 'by hand'.
> 
> With previous versions of the Python Windows msi installer, for
> example 2.5.4, I could run the following command from the windows cmd
> prompt (or from inside my build script):
> 
> msiexec /a C:\python-2.5.4.msi /qn TARGETDIR=C:\python
...


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

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



Combine several Forms to one class

2009-03-12 Thread Thomas Guettler

Hi,

I often have several forms in on  tag. Like FormSet,
it would be nice to have a class which combines several forms.

But FormSet can only deal with several forms of one class.

This MultiForm class should do this:

 - validate/clean all sub forms on clean(). Not just until
   the first one fails, since the user should see all errors.
 - Simple dependency: Example: FormB should be cleaned only if FormA
   cleans successfully. (Since FormB requires data from FormA).
 - join Media attributes.

Do you understand what I want?

I don't think it is difficult, but maybe there is already something
like this.

  Thomas

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

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



Re: traceback - no local variables

2009-03-12 Thread Thomas Guettler
Hi,

I attached a HandleExceptionMiddleware I use. You need to modify it
to your needs. It attaches the html page of cgitb and the django
debug page to the email.

  Thomas


George Lund schrieb:
> We have a live server crash issues for which we are receiving emails
> from Django from our server, which is great.
> 
> But I'm having trouble debugging the problem because the local
> variables don't seem to be included in the email.  All I can see is
> call stack followed by a  object - but nothing else.
> 
> Does anyone know how to make Django supply all the variables in the
> email?
>

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

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

# -*- coding: iso-8859-1 -*-
# $Id: HandleExceptionMiddleware.py 246 2009-01-21 15:13:09Z tguettler $
# $HeadURL: svn+ssh://svnserver/svn/djangotools/trunk/middleware/HandleExceptionMiddleware.py $

# Python Imports
import os
import re
import logging

# Django
import django.http
from django.utils.encoding import force_unicode, smart_unicode

from django.conf import settings
from djangotools.utils import responseutils

EMAIL_HOST='localhost'

class HandleExceptionMiddleware:

def process_response(self, request, response):
if response.status_code in [404]: # "Page not found" ist für uns wie eine Exception
self.error(request, msg='Page not found')
return response

def process_exception(self, request, exception):
'''
Im Fehlerfall: Email an uns verschicken.
'''
if isinstance(exception, responseutils.HttpResponseException):
return exception.args[0]
logging.error('Exception: %r %r' % (request.path, request.user), exc_info=True)
logging.error('GET: %s' % request.GET)
logging.error('POST: %s' % request.POST)
#logging.info('connection.queries: %s' % connection.queries)
try:
self.error(request, exception)
except Exception:
logging.error('Fehler Email konnte nicht versendet werden: %s' % request.path, 
  exc_info=True)

def error(self, request, exception=None, msg=''):
exception_str=smart_unicode(exception, errors='replace')
logging.error('%s %r %r %r' % (
request.user, request.path, exception_str, msg))

import sys
import datetime
import django.views.debug

if request.user:
username=request.user.username
else:
username='user-unset'

exception_dir=os.path.join(settings.HOME, 'log', 'exceptions')

now=datetime.datetime.now()
body=[]
body.append(u'URL: %s' % (request.build_absolute_uri()))
body.append(u'Uhrzeit: %s' % now)

attachments=[]
msgs=[]
if exception:
msgs.append(exception_str)
try:
html=force_unicode(django.views.debug.technical_500_response(request, *sys.exc_info()), errors='replace')
attachments.append(('traceback-django.html', html, 'text/html'))
logfile=os.path.join(exception_dir, '%s-%s-django.html' % (
now.isoformat(), username))
fd=open(logfile, 'wt')
fd.write(html.encode('utf8'))
fd.close()
except UnicodeError, exc:
body.append(u'Django Debug Template failed: %s' % exc)
class FD:
def __init__(self):
self.content=[]
def write(self, text):
self.content.append(text)
def __str__(self):
return ''.join(self.content)
import cgitb
fd=FD()
cgitb.Hook(file=fd).handle()
html=str(fd)
attachments.append(('traceback-cgitb.html', html, 'text/html'))
logfile=os.path.join(exception_dir, '%s-%s-cgitb.html' % (
now.isoformat(), username))
fd=open(logfile, 'wt')
fd.write(html)
fd.close()

import traceback
import cStringIO
(exc_type, exc_value, tb) = sys.exc_info()
exc_file = cStringIO.StringIO()
traceback.print_exception(exc_type, exc_value, tb, file=exc_file)
body.append(u'Traceback:\n%s' % smart_unicode(exc_file.getvalue(), errors='replace'))


# Bei Entwicklungssystemen keine Fehleremail
# versenden.
 

Re: Getting stuck in transactions

2009-03-12 Thread Thomas Guettler

Hi,

here some thoughts how to debug this:

In postgres enable the logging of the executed statements.
On my system they go to /var/log/messsages.
Which statement is the last?

Are there any other db clients which access the database? Or are
you connecting from the same python script? Which transaction
isolation level do you use?

I use commit_on_success only once per call stack. This means,
there are the real methods which don't have the decorator. They
can be called from the web (here the transaction middleware does
the commit/rollback). And you have a simple command line python
script with a wrapper which has the commit_on_success decorator.

If you use unix, start the script with "strace -f" to see in which
system call the process stops.

 HTH,
   Thomas


Tom Davis schrieb:
> I have a command-line script that uses Django's ORM. For reasons
> beyond my comprehension, it has a tendency to get "stuck" in
> transactions. When I check the postgre server status, it simply shows
> a connection that is "idle in transaction" and never completes. The
> script ends up hitting this wall seemingly randomly, as far as I can
> tell. Sometimes it makes it through 1000 iterations before it happens,
> sometimes it makes it through 10.
> 
> I've tried using transaction decorators, such as
> `transaction.commit_on_success`. Decorating every orm-using function
> with this increased the successful number of iterations, but it didn't
> fix the problem. The script doesn't do anything fancy; some simple
> filter()s, beyond that just save() and delete(). Short of replacing
> every ORM usage with straight psycopg2, I'm not really sure what to do
> here.
> 
> Just to reiterate, this isn't an issue with orphaned connections or
> anything like that. The script loops through some files, parses them,
> and makes ORM calls. Sooner or later, it stops looping and gets stuck
> in a transaction and the only way to fix it is to terminate the script.

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

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



Re: Why serializing to JSON doesn't work?

2009-03-04 Thread Thomas Guettler



Jeff FW schrieb:
> The serializers are for serializing querysets/models.  I'm surprised
> you're not getting an error message there--are you catching all
> exceptions?
> 
> What you want is in django.utils.simplejson:
> 
> from django.utils.simplejson import encoder
> encoder.JSONEncoder().encode(ret)

Or this:

>>> from django.utils import simplejson
>>> simplejson.dumps(...)

But unfortunately this does not encode datetime objects.

  Thomas


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

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



cache backend file: No need for cull

2009-02-25 Thread Thomas Guettler

Hi,

I profiled my application and discovered, that it spends
a lot of time in _cull() and get_num_entries() in the file
cache backend.

It is very easy to have a cron job which cleans the directory
by deleting all files older than N minutes. There is no need to cull during
request time.

I suggest that if you set max_entries to zero, _cull() is not called.

Before I open a ticket, I ask for feedback.

Anyone?

 Thomas


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

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



Re: Some questions on using Django

2009-02-11 Thread Thomas Guettler

koranthala schrieb:
> Hi all,
>Please excuse me if this is a naive question. I am a developer/
> programmer who is now into web development for the first time.
>I have read through Django tutorial and I have a moderate
> understanding of how Django works.
>
>I have two major questions, which is bugging me quite a lot. I will
> try to put it succinctly.
>
> (1)
>One problem is that in my site, I am not using templates very much
> - My understanding is that on using templates quite a bit only one can
> unlock the full efficiency of Django.
>However, when I am designing my site, I find that I am not using
> templates too much.
>
>   
I don't use templates much, too. But I use auto escape in python code (some
small wrapper around mark_safe() and join())

> (2)
> Another question that I have is - is it usual to have no major
> architecture in the web coding? i.e. When I used to do C programming,
> I used to use all sort of design patterns etc. Now I am into web
> programming using Django, and now I dont find the need to have a
> complex architecture.
Simple applications can be written in some hours if you are familiar with
django. And very complex things can be done, too:
   Welcome to python and django

  Thomas

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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



Re: Django Get/POST problem

2009-02-03 Thread Thomas Guettler

Hi,

I would use the forms library, even if the form has only one input element.
I would use django.http.HttpResponseRedirect() to the list view, after
successful
deletion.


Aldo schrieb:
> Hi folks,
>
> MY URL is x.y.z/list
> It shows a list of objects. They have link buttons to delete/update
> for each object.
>
> When I click delete for an object I go to a URL via POST with the
> object id in the url
> This brings me to a "Are you sure you want to delete this object
> page".
> MY URL is x.y.z/list/3
>
> I click submit and it deletes the object and brings me back to the URL
> page at the top /list.
>
> My problem is my delete function :
>
> def delete(request,  id):
> if request.method == 'POST':
> if verify(id):
> MyObject.objects.get(pk=id).delete()
> #Go back to the list
> return render_to_response('html/list.html',
> {'objects':MyObjects.objects.all())
> if request.method == 'GET':
> if verify(id):
>return render_to_response('html/delete.html',
> {'token':token, 'id':id})
> return render_to_response('html/404.html')
>
> Is there a neater way of doing this - rather than finding the request
> type and behaving differently depending.
>
> I am doing a similar thing for my update and it just seems off.
>
> Please help.
>
>
>
>
>
>
>
> >
>   


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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



Re: How do I correctly format a Querydict derived list in a url?

2009-02-02 Thread Thomas Guettler

Alfonso schrieb:
> Thanks Alex,
>
> I tried that but no joy - the problem is I just can't get django to
> nicely capture the list's values - it's really stumped me!
>
> location_filter = request.POST.getlist("location")  does give me a
> python list of location variables. But I can't get this resultant
> [u'ireland', u'nireland'] list to become iterable where I can just
> drop the values into a HttpResponseRedirect url like /ireland-
> nireland/
>
> I think I am approaching this incorrectly - If I try request.POST
> ["location"]  It all works but only with the last item in the
> QueryDict.
>   
Hi,

I would send the list as GET data:
   http://?location=a=b
Then you can use this URL for a redirect, too.

You can use urlencode:

from django.utils.http import urlencode

to create the string after the question mark.

BTW, I think urlencode has a bug:
 http://code.djangoproject.com/ticket/9089

  Thomas


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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



admin: list users of a group

2009-01-30 Thread Thomas Guettler

Hi,

sometimes it would be nice to see all users of a group. I think
it would be nice to have this in the admin page.

Do other django users miss this, too?

I know that it is very easy to write a view for this, but it would be
even better if it is a part of the django admin.

  Thomas

PS: Of course this would be nice for all N:M relations.

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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



Re: Performance using session, passing data from one request to another, use js or not? Best practice?

2009-01-29 Thread Thomas Guettler

Tim Daniel schrieb:
> Thanks for the answer, I was already getting worried about my
> 'session' way. No caching for know although it doesn't seem difficult
> to implement. And yes the way you do it would have that advantage, but
> mine has beautiful urls!! ^^
> thanks again,
>
>   
URLs are beautiful if they don't change (you can bookmark them) or send
as them link.

Sessions get deleted sooner or later.

 Thomas

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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



Re: how to avoid hardcoding of logfile path in logging.conf file

2009-01-27 Thread Thomas Guettler

Rama schrieb:
> please look at the below logging.conf file.
> ...
> can any one  guide me on how to avoid hardcoding of log file path ?
>
>   
Hi,

I am not a logging expert, maybe there is a solution, but if you
do your setup with python code, you can use e.g. os.environ['HOME'] or
settings.FOO.

I never used a logging.conf file.

HTH,
  Thomas

BTW: This is a pure python question. You get more and better answers
on the newsgroup comp.lang.python.



-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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



Re: Performance using session, passing data from one request to another, use js or not? Best practice?

2009-01-26 Thread Thomas Guettler

Tim Daniel schrieb:
> Thanks for making this clear!
> But do you think/know that this is the best way to do it? I haven't
> done it these way until now because in most cases it causes large and
> ugly urls(I only had to show the page number). Is the way I'm doing it
> till now a maybe ineficiente and thus not recommended way? I'm
> interested for that, because soon I'm going to deploy my django-app on
> a production server.
>
>   

I am happy with this way. If your site gets much traffic, you can add
caching.

My approach (without data in the session) would be better for
caching, since all users share one cache:

example:

if the first user calls this:
http://.../myprojec/.../page_number=1=abc
and a other user calls the same URL, you could use a cache
for the second request.

  Thomas


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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



Re: Performance using session, passing data from one request to another, use js or not? Best practice?

2009-01-25 Thread Thomas Guettler

Tim Daniel schrieb:
>
> On 22 ene, 16:17, Thomas Guettler <h...@tbz-pariv.de> wrote:
>   
>> Tim Daniel schrieb:> I read something that it would be more
>> 
>>> efficient to store only the query and doing pickle?? I don't know how
>>> to do that, I've been looking in the docs and other posts but no clear
>>> explanation. So what I really want to know: which is the best way of
>>> handling this problem?
>>>   
>> I have my own paginator, too.
>> 
> [snipped]
>   
>> Thomas Guettler,http://www.thomas-guettler.de/
>> E-Mail: guettli (*) thomas-guettler + de
>> 
>
> Well the problem is not with the paginator itself(it works well), the
> real problem is with the data to be displayed, it's about being
> efficient to store data(like a queryset) in the request.session
> variable. Does anybody know if this is the good way(I don't think so)?
> And if it's not, which is the right way to handle this problem then?
>
>   
Sorry, I didn't say this in my last post: I don't store anything in the
session for pagination.
The query string (request.GET) is used to display the current result
page. This URL
can be stored in a bookmark or send to someone. The query gets evaluated on
each request. The next pagination page gets the same GET dictionary, but
"page_number" gets increased.

 HTH,
   Thomas


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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



Re: Performance using session, passing data from one request to another, use js or not? Best practice?

2009-01-22 Thread Thomas Guettler

Tim Daniel schrieb:
> I read something that it would be more
> efficient to store only the query and doing pickle?? I don't know how
> to do that, I've been looking in the docs and other posts but no clear
> explanation. So what I really want to know: which is the best way of
> handling this problem?
I have my own paginator, too.

I use request.GET and create a new URL with the item
'page_number' changed.

Here is a snippet. It disables the [next] link, if there is no next page.


qs=dict(request.GET)
def qs2url(qs):
new={}
for key, value in qs.items():
if isinstance(value, (list, tuple)):
value=[v.encode('utf8') for v in value]
elif isinstance(value, (int, long)):
value=str(value)
else:
value=value.encode('utf8')
new[key]=value
return escape(django.http.urlencode(new, doseq=True))
if page.has_next():
qs['page_number']=page_number+1
next='' % qs2url(qs)
qs['page_number']=paginator.num_pages
last='' % qs2url(qs)
else:
next=''
last=''
if page.has_previous():
qs['page_number']=page_number-1
prev='' % qs2url(qs)
qs['page_number']=1
first='' % qs2url(qs)
else:
prev=''
first=''
   
first=mark_safe(first)
prev=mark_safe(prev)
next=mark_safe(next)
last=mark_safe(last)


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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



Re: Pre-filling form data without submission?

2009-01-20 Thread Thomas Guettler

Hi,

at python level you can do it like this (untested):

def myview(request, ...):
form=MyForm(..., initial={'email': request.user.email})

or

form.fields['email'].initial=request.user.email


shogunm...@googlemail.com schrieb:
> Hi Thomas,
>
> Thanks for your quick reply!
>
> I had a look at the docs, but it seems I have to enter the initial
> values at the Form definition level. However, I am interested in
> entering dynamic data depending on who is viewing the form. For
> instance, in my case I want the user's email address to be displayed
> in the form when they view the page. Since the form definition doesn't
> have access to the request object, I presume this is not possible.
>
>   


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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



Re: Pre-filling form data without submission?

2009-01-20 Thread Thomas Guettler

shogunm...@googlemail.com schrieb:
> Hi guys,
>
> I've hunted around the docs and googled this (it's quite a niche
> scenario so a bit hard to find!) and I'm still a bit stuck! I was
> hoping somebody might be able to help out!
>
> Can anyone tell me how to pre-fill form data without the form
> automatically calling submit on the form so that the validation
> messages don't appear in the rendered template?
>
>
>   
Hi,

Check the docs for "initial".

  Thomas

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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



session.save() after failed request

2009-01-16 Thread Thomas Guettler

Hi,

I think it is bad that request.session.save() is called, if
the DEBUG-View gets returned on an uncaught exception.

I looked at the django source, but could not find a good patch for django
or my code.

What is bad about this: The debug view is not returned, since a second
happens
on request.session.save():

[Fri Jan 16 11:16:57 2009] [error] [client 172.17.6.34] mod_wsgi
(pid=5165): Exception occurred processing WSGI script
'/localhome/fo/foork_abc/apache/django_wsgi.py'.
[Fri Jan 16 11:16:57 2009] [error] [client 172.17.6.34] Traceback (most
recent call last):
[Fri Jan 16 11:16:57 2009] [error] [client 172.17.6.34]   File
"/localhome/fo/django/core/handlers/wsgi.py", line 243, in __call__
[Fri Jan 16 11:16:57 2009] [error] [client 172.17.6.34] response =
middleware_method(request, response)
[Fri Jan 16 11:16:57 2009] [error] [client 172.17.6.34]   File
"/localhome/fo/django/contrib/sessions/middleware.py", line 35, in
process_response
[Fri Jan 16 11:16:57 2009] [error] [client 172.17.6.34]
request.session.save()
[Fri Jan 16 11:16:57 2009] [error] [client 172.17.6.34]   File
"/localhome/fo/django/contrib/sessions/backends/db.py", line 56, in save
[Fri Jan 16 11:16:57 2009] [error] [client 172.17.6.34] sid =
transaction.savepoint()
[Fri Jan 16 11:16:57 2009] [error] [client 172.17.6.34]   File
"/localhome/fo/django/db/transaction.py", line 188, in savepoint
[Fri Jan 16 11:16:57 2009] [error] [client 172.17.6.34]
connection._savepoint(sid)
[Fri Jan 16 11:16:57 2009] [error] [client 172.17.6.34]   File
"/localhome/fo/django/db/backends/__init__.py", line 37, in _savepoint
[Fri Jan 16 11:16:57 2009] [error] [client 172.17.6.34]
self.connection.cursor().execute(self.ops.savepoint_create_sql(sid))
[Fri Jan 16 11:16:57 2009] [error] [client 172.17.6.34]
ProgrammingError: current transaction is aborted, commands ignored until
end of transaction block

Has someone a hint how to fix this?

  Thomas

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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



Re: Transactions not working

2009-01-14 Thread Thomas Guettler

You need to test if the data is already in the db first.
There is a handy method:

model_object, created = YourModel.objects.get_or_create(...)

If you still get this errors, you might want to check if
your sequence is in sync:

select max(id) from yourapp_yourmodel;

select * from yourapp_yourmodel_id_seq ;

  Thomas

thomasbecht...@googlemail.com schrieb:
> Hi all,
>
> Problem: I want to use Transaction to save data to a postgresql-db.
> Error: IntegrityError: doppelter Schlüsselwert (double keyvalue)
> verletzt (harm) Unique-Constraint
> ...



-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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



Re: Getting a 'too many values to unpack' error

2009-01-14 Thread Thomas Guettler

yourmodel.objects.filter(a) does not work since a seems to be a queryset.

You need to use .filter(attribute=value) or something like this.

BTW: Why do you do all the select_related() calls?

Michael schrieb:
> Hello,
> Here is my code:
>
> filter = {}
> if request.GET.get('color', '').isdigit():
> filter['color_cat'] = request.GET['color']
> if request.GET.get('origin', '').isdigit():
> filter['collection__origin'] = request.GET['origin']
> styles = Style.objects.select_related().filter(**filter).distinct()
> if request.GET.get('minprice', '').isdigit() :
> if request.GET.get('size', '').isdigit():
> a = Style.objects.filter(Q
> (sandp__size__size_cat=request.GET['size']) & Q
> (sandp__price__name__gte=request.GET['minprice']))
> styles = styles.select_related().filter(a) ### This is the
> line that is giving me the error!!
>
> Whenever I do a search where the user enters a minimum price and
> selects a sizeI get the error:
>
> 'ValueError at /search/ too many values to unpack'
>
> The error comes from the line 'styles = styles.select_related().filter
> (a)'
>   


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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



post_syncdb signal: Called several times

2009-01-14 Thread Thomas Guettler

Hi,

I read the docs for the sync_db signal:
   http://docs.djangoproject.com/en/dev/ref/signals/#post-syncdb

The signal gets fired several times. Since my app has several model classes.

But how can you know that the tabel for a particular model was just created?

Or do you need to write the callback method the way, that it can be called
several times (for example: check if change was already done before
changing something)

  Thomas


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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



Re: Shouldn't get_profile() create the profile object?

2009-01-08 Thread Thomas Guettler

Alvaro Mouriño schrieb:
> I find myself checking for the existence of the profile object for the
> user everytime I call the get_profile function or making sure that it
> gets created with every user.
>
>   
Since a lot of users have this question/problem I added a patch to the
documentation:

http://code.djangoproject.com/ticket/9987

+The method :class:`~django.contrib.auth.models.User.get_profile()`
+does not create the profile, if it does not exist. You need to
+register a handler for the signal
+:attr:`django.db.models.signals.post_save` on the User model, and, in
+the handler, if created=True, create the associated user profile.
+

 Thomas

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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



db_index name clashes with table name

2009-01-06 Thread Thomas Guettler

Hi,

sad,but true, the index name created by a database Field with db_index=True
clashes with a table name.

Is there any way to force a different name for the index as you can with
table names?

Looking at the docs I looks like you can't:

http://docs.djangoproject.com/en/dev/ref/models/fields/#db-index


  Thomas


DB: Postgres 8.2

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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



Re: auth: get_profile(): create if it does not exist.

2008-12-17 Thread Thomas Guettler


> ##
> try:
> m = SomeModel.objects.get(pk=request.user)
> except:
> m = SomeModel()
> ##
>
>   
Attention, catch-all ("except" without an exception class) is evil.
There are a lot of exception
that could happen.

You could use:

try:

except SomeModel.DoesNotExist:
...
 
or

m, created = SomeModel.objects.get_or_create(pk=request.user)

To my original question: Yes, I will use a signal handler to create the
profiles. Thank you
for your answers (Milian Andric).

 Thomas


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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



Re: TimeSpan, Latitude, Longitude field classes for Models

2008-12-17 Thread Thomas Guettler

adrian schrieb:
> Has anyone written these?
>
> TimeSpan for example, is useful because '2 hours' is not a time, it's
> a difference between two times.
> It has its own validation and display needs.
>
>   
I once wrote a TimeDelta Database Field:
http://www.djangosnippets.org/snippets/1060/

You should look at the python documentation of datetime.timedelta, too.

 Thomas

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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



auth: get_profile(): create if it does not exist.

2008-12-17 Thread Thomas Guettler

Hi,

The method user.get_profile() fails, if the user has no profile. During
my custom login I
check if the user has a profile and create it if needed.

But sometimes this fails: A new user gets created, but before his first
login someone else
tries to access the not yet created profile.

Since all fields of my profile model have default values, it could be
created it on the fly.

Since I don't want to run a modified django, I will use my own
get_profile method.

Does some know this problem? How do you solve this?

  Thomas

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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



TransactionMiddleware and SessionMiddleware

2008-12-10 Thread Thomas Guettler

Hi,

I follow: http://docs.djangoproject.com/en/dev/topics/db/transactions/
{{{
The order is quite important. The transaction middleware applies not
only to view functions, but also for all middleware modules that come
after it. So if you use the session middleware after the transaction
middleware, session creation will be part of the transaction.
}}}

# settings.py
MIDDLEWARE_CLASSES = [

'djangotools.middleware.HandleExceptionMiddleware.HandleExceptionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.transaction.TransactionMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.middleware.doc.XViewMiddleware',
]

But the result is not what is excepted if there is an exception:
 1. All DB changes are rolled back by TransactionMiddleware 
(proccess_exception())
 2. Debug-Response is returned. All middleware methods are called:
   SessionMiddleware.process_response() --> commit_unless_managed() --> session 
gets
   saved to DB, since the connection is no longer managed.

Is this a bug or am I missing something?

I use django 1.0.2


  Thomas

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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



cursor already closed

2008-12-10 Thread Thomas Guettler
oo_belegartrequiredgroup"."belegart_id" = 1142  AND
"foo_belegartrequiredgroup"."permission_id" = 26 )
0.000 SELECT "auth_group"."id", "auth_group"."name" FROM "auth_group"
WHERE "auth_group"."id" = 10
0.001 SELECT "auth_permission"."id", "auth_permission"."name",
"auth_permission"."content_type_id", "auth_permission"."codename" FROM
"auth_permission" INNER JOIN "django_content_type" ON
("auth_permission"."content_type_id" = "django_content_type"."id") WHERE
("auth_permission"."codename" = 'view_belegart'  AND
"django_content_type"."app_label" = 'foo' ) ORDER BY
"django_content_type"."app_label" ASC, "auth_permission"."codename" ASC
0.000 SELECT "foo_belegartrequiredgroup"."id",
"foo_belegartrequiredgroup"."belegart_id",
"foo_belegartrequiredgroup"."permission_id",
"foo_belegartrequiredgroup"."group_id" FROM "foo_belegartrequiredgroup"
WHERE ("foo_belegartrequiredgroup"."belegart_id" = 1142  AND
"foo_belegartrequiredgroup"."permission_id" = 64 )
0.001 SELECT "auth_permission"."id", "auth_permission"."name",
"auth_permission"."content_type_id", "auth_permission"."codename" FROM
"auth_permission" INNER JOIN "django_content_type" ON
("auth_permission"."content_type_id" = "django_content_type"."id") WHERE
("auth_permission"."codename" = 'change_belegart'  AND
"django_content_type"."app_label" = 'foo' ) ORDER BY
"django_content_type"."app_label" ASC, "auth_permission"."codename" ASC
0.000 SELECT "foo_belegartrequiredgroup"."id",
"foo_belegartrequiredgroup"."belegart_id",
"foo_belegartrequiredgroup"."permission_id",
"foo_belegartrequiredgroup"."group_id" FROM "foo_belegartrequiredgroup"
WHERE ("foo_belegartrequiredgroup"."belegart_id" = 1142  AND
"foo_belegartrequiredgroup"."permission_id" = 26 )
0.000 SELECT "auth_group"."id", "auth_group"."name" FROM "auth_group"
WHERE "auth_group"."id" = 10
0.000 SELECT "auth_group"."id", "auth_group"."name" FROM "auth_group"
WHERE "auth_group"."id" = 10
0.000 SELECT "foo_index"."id" FROM "foo_index" WHERE "foo_index"."id" =
'ISU'
0.001 SELECT "foo_index"."id" FROM "foo_index" INNER JOIN
"foo_belegart_indexes" ON ("foo_index"."id" =
"foo_belegart_indexes"."index_id") WHERE
"foo_belegart_indexes"."belegart_id" IN (1142, 1082, 1034)
0.000 SELECT "foo_index"."id" FROM "foo_index" WHERE "foo_index"."id" =
'ISU'
0.001 SELECT "foo_index"."id" FROM "foo_index" INNER JOIN
"foo_belegart_indexes" ON ("foo_index"."id" =
"foo_belegart_indexes"."index_id") WHERE
"foo_belegart_indexes"."belegart_id" IN (1142, 1082, 1034)
0.001 SELECT "foo_isu_belegart_contact_klasse"."id",
"foo_isu_belegart_contact_klasse"."belegart_id",
"foo_isu_belegart_contact_klasse"."cls",
"foo_isu_belegart_contact_klasse"."activity" FROM
"foo_isu_belegart_contact_klasse" WHERE
"foo_isu_belegart_contact_klasse"."belegart_id" = 1142
0.000 SELECT "foo_isu_belegart_contact_klasse"."id",
"foo_isu_belegart_contact_klasse"."belegart_id",
"foo_isu_belegart_contact_klasse"."cls",
"foo_isu_belegart_contact_klasse"."activity" FROM
"foo_isu_belegart_contact_klasse" WHERE
"foo_isu_belegart_contact_klasse"."belegart_id" = 1142
0.000 SELECT "foo_isu_belegart_contact_klasse"."id",
"foo_isu_belegart_contact_klasse"."belegart_id",
"foo_isu_belegart_contact_klasse"."cls",
"foo_isu_belegart_contact_klasse"."activity" FROM
"foo_isu_belegart_contact_klasse" WHERE
"foo_isu_belegart_contact_klasse"."belegart_id" = 1082
0.000 SELECT "foo_isu_belegart_contact_klasse"."id",
"foo_isu_belegart_contact_klasse"."belegart_id",
"foo_isu_belegart_contact_klasse"."cls",
"foo_isu_belegart_contact_klasse"."activity" FROM
"foo_isu_belegart_contact_klasse" WHERE
"foo_isu_belegart_contact_klasse"."belegart_id" = 1034
0.000 SELECT "foo_belegart"."id", "foo_belegart"."parent_id",
"foo_belegart"."name", "foo_belegart"."duration", "foo_belegart"."text",
"foo_belegart"."default_gruppe_id", "foo_belegart"."archiv_belegart"
FROM "foo_belegart" WHERE "foo_belegart"."id" = 1142
0.000 SELECT "foo_belegart"."id", "foo_belegart"."parent_id",
"foo_belegart"."name", "foo_belegart"."duration", "foo_belegart"."text",
"foo_belegart"."default_gruppe_id", "foo_belegart"."archiv_belegart"
FROM "foo_belegart" WHERE "foo_belegart"."id" = 1082
0.000 SELECT "foo_belegart"."id", "foo_belegart"."parent_id",
"foo_belegart"."name", "foo_belegart"."duration", "foo_belegart"."text",
"foo_belegart"."default_gruppe_id", "foo_belegart"."archiv_belegart"
FROM "foo_belegart" WHERE "foo_belegart"."id" = 1034

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

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



Re: how to do redirects with django?

2008-12-09 Thread Thomas Guettler

Hi,

def foo(request):

return django.http.HttpResponseRedirect(newlocation)

newlocation can be an URL. I create them with
django.core.urlresolvers.reverse().

  Thomas

nbv4 schrieb:
> If the user goes to /foobar, I want it to redirect him to /foobar-page-
> XX, XX being the last page. I have a this in my urlconf"
>
> (r'^foobar/
> $',
> 'project.main.views.foobar_no_page', ),
> (r'^foobar-page-(?P\d{1,4})/$',
> 'project.main.views.foobar', ),
>
> foobar() in my views in my main function, foobar_no_page() is have set
> as:
>
> def logbook_no_page(request):
>
>   return HttpResponse(location='/foobar-page-55')
>
>
> but that obviously doesn't work. How can I do this?
>
>   


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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



Session based messages without touching DB

2008-12-05 Thread Thomas Guettler

Hi,

I use code based on "session based messages" from:
http://code.djangoproject.com/ticket/4604

What I don't like: There are two database hits, which are not necessary:
Store message in session-pickle
and pop message from session-pickle.

I found this:
   http://www.djangosnippets.org/snippets/1064/
The (flash) message is stored in a cookie.

But I think the snippet is not thread safe. Has anyone a working example?

  Thomas


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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



Re: How to create and send a pdf attachment

2008-12-03 Thread Thomas Guettler

Epinephrine schrieb:
> Does anyone have a code sample that shows how to create a pdf document
> and then, without saving that document to disk, email it as an
> attachment?
>
> I am using the ReportLab PDF library at the platypus level for pdf
> creation.
>
> For emailing, I expect to use Django's EmailMessage class.
>
>   
Hi,

looking at the source:

django/core/mail.py:

def attach(self, filename=None, content=None, mimetype=None):
"""
Attaches a file with the given filename and content. The
filename can
be omitted (useful for multipart/alternative messages) and the
mimetype
is guessed, if not provided.

If the first parameter is a MIMEBase subclass it is inserted
directly
into the resulting message attachments.
"""


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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



Re: Query API: get all users without a group

2008-12-03 Thread Thomas Guettler

Filip Wasilewski schrieb:
> On 2 Gru, 16:45, Thomas Guettler <[EMAIL PROTECTED]> wrote:
>   
>> Hi,
>>
>> I want to get all objects where the corresponding many-to-many field is
>> empty.
>>
>> Example:  get all users without a group
>> 
> [...]
>
> The preferred solution is using the `isnull` filter:
>
> User.objects.filter(groups__isnull=True)
>
> It evaluates to a left join of the `auth_user` table with
> `auth_user_groups` and a simple `where` statement.
>
>   
Thank you! Django ORM is great.

  Thomas

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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



Re: How can I use more than 24 hours in TimeField?

2008-12-02 Thread Thomas Guettler

Hi,

Maybe my TimedeltaField helps you:
http://www.djangosnippets.org/snippets/1060/


K*K schrieb:
> As you know time data type in mysql allow to be used more than 24
> hours, but when there is a more  than 24 hours record in the table
> such as 72:00:00, and then query the table with Django ORM, it will
> report 'ValueError hour must be in 0..23'.
>
> I'm porting a old program that record rum times of the machines to
> Django, so 24 hours is not enough for my new program.
>
> How can I resolve it ?
>
>   


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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



Query API: get all users without a group

2008-12-02 Thread Thomas Guettler

Hi,

I want to get all objects where the corresponding many-to-many field is
empty.

Example:  get all users without a group

My solution:
   User.objects.exclude(groups__in=Group.objects.all())

I think this is not optimal, since Group.objects.all() gets evaluated.
 
Resulting SQL:

SELECT "auth_user"."id", "auth_user"."username",
"auth_user"."first_name", "auth_user"."last_name",
"auth_user"."email", "auth_user"."password", "auth_user"."is_staff",
"auth_user"."is_active", "auth_user"."is_superuser",
"auth_user"."last_login", "auth_user"."date_joined" FROM "auth_user" WHERE
NOT ("auth_user"."id" IN (SELECT U1."user_id" FROM "auth_user" U0
INNER JOIN "auth_user_groups" U1 ON (U0."id" = U1."user_id")
WHERE U1."group_id" IN (9, 10, 11, 8))) LIMIT 21

Any better way to do this?

Should the extra() method be used for this?

  Thomas


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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



Re: Many-to-Many to exists table

2008-12-02 Thread Thomas Guettler

If I understood you problem:

{{{
from django.contrib.auth.models import Group
class Area(models.Model):
groups=models.ManyToManyField(Group)
}}}

This creates a Many-To-May relation to Group.

Copied from brain to keyboard (untested)

HTH,
  Thomas

nucles schrieb:
> Hello Django-People,
>
> we use the embedded functionality of the user authentication in
> Django.
> We use folowing models: "user", "auth_group", "auth_user_group" and
> other embedded models that does not matter in this context.
> We would like to add the additional entity "area" with M-to-M relation
> to the "user_auth_group" entity (please note: "user" has M-to-M
> relation to "auth_group")
>
> How can we do this? The "user_auth_group" will be automatically
> generate from Django, so we can not relate to this entity from any
> other model.
>
> We can of cause create our own user authentication without embedded
> user authentication in Django, but is this the best solution?
> I hope you understand our problem.
>
> Thank you.
> Regard
> Nucles
>
>
> >
>   


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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



Re: Using % with psycopg2

2008-12-02 Thread Thomas Guettler

Siah schrieb:
> Hi,
>
> The following code fails on windows, and works just fine on my unix
> box. To fix the problem in windows, I must replace('%', '%%') so its
> internal string formatting doesn't fail on me. Should I file this bug
> for psycopg2?
>
> from django.db import connection
> cursor=connection.cursor()
> cursor.execute("select '%';")
> print cursor.fetchall()
>
>   
Hi,

I have seen this.
See  http://markmail.org/message/463cildcn777eltr
See http://code.djangoproject.com/ticket/9055

I just saw, that the ticket still needs a testcase. Can you write one?

  Thomas

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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



Re: order by ... nulls [first|last]

2008-11-26 Thread Thomas Guettler

Jarek Zgoda schrieb:
> Wiadomość napisana w dniu 2008-11-26, o godz. 10:20, przez Thomas  
> Guettler:
>
>   
>> I am missing order by nulls [first|last]
>>
>> Either I am blind, or it is not possible.
>> 
>
>
> I think this is database-dependent.
>   
I know, but I would like to force this with django ORM.

something like this:
MyModel.objects.all().order_by('due_date', nulls_last=True)

I don't know if all database backends support this. Postgres does.

  Thomas

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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



order by ... nulls [first|last]

2008-11-26 Thread Thomas Guettler

Hi,

I am missing order by nulls [first|last]

Either I am blind, or it is not possible.

Do other miss this, too?

  Thomas

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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



Re: debug view and list of GET or POST parameters

2008-11-25 Thread Thomas Guettler

Russell Keith-Magee schrieb:
> On Tue, Nov 25, 2008 at 7:21 PM, Thomas Guettler <[EMAIL PROTECTED]> wrote:
>   
>> Hi,
>>
>> If GET or POST contain a list, I only see the last value in the debug view.
>>
>> What do you see on an uncaught excepion with e.g. "?foo=1=2" as
>> query string?
>> 
>
> It depends on how you try to access the values. request.GET and
> request.POST aren't normal dictionaries - they are QueryDicts.
Yes, I know QueryDicts. But why are they are not displayed as lists
in the debug view?

I mean this part:
{{{
Request Information
  GET ...
  POST No Post data
  COOKIES ...
}}}

I have modified the debug view a bit, so I am not sure if this problem
was caused by me.

If I have, time, I will dig deeper and write a patch and upload it to trac.

   Thomas


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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



debug view and list of GET or POST parameters

2008-11-25 Thread Thomas Guettler

Hi,

If GET or POST contain a list, I only see the last value in the debug view.

What do you see on an uncaught excepion with e.g. "?foo=1=2" as
query string?

  Thomas

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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



Re: I18N not working

2008-11-25 Thread Thomas Guettler

The last days I did my first i18n application and befor I read this:
http://docs.djangoproject.com/en/dev/topics/i18n/
{{{
Application message files are a bit complicated to discover -- they need
the LocaleMiddleware.
If you don't use the middleware, only the Django message files and
project message files will be processed.

}}}

I don't know if it is really need. But the documentation says so. Or I
read it to quickly and overlooked

something.

  Thomas

Jarek Zgoda schrieb:
> I know the per-app translations work without this. Mine works equally
> with LANGUAGE_CODE and USE_I18N only on systems with "C" and "pl_PL".  
> There is no need to use LocaleMiddleware if you do not want to change  
> translations (eg. depending on browser settings).
>
>   


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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



Re: I18N not working

2008-11-25 Thread Thomas Guettler

Alex Jonsson schrieb:
> Hey guys,
>
> I have some problems with the translations of my website. Locally, it
> works flawlessly. But as soon as I run the project on my server, it
> won't translate. I've translated the project per app.
Translation per app only works if you have the LocaleMiddleware installed.
Maybe this setting is different on your server?

 Thomas

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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



Re: Change date format in admin

2008-11-11 Thread Thomas Guettler

Alex Rades schrieb:
> Hi,
> Is there a way to do it? Here in europe we really use DD-MM-
>
> Thank you
>
>   
AFAIK you can't change the date format which is used for input fields
in the admin interface.

Sad but true, settings.DATE_FORMAT is even ignored if you use date
objects (datetime.date.today()) in a template.
You need to use the "date" or "time" filter. I think this is redundant.

  Thomas

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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



Re: sorting a list of model instances

2008-11-07 Thread Thomas Guettler

Hi,
> Although I would have to wonder why you're doing it this way, rather
> than using the database to sort them? 
Since in my case it is easier. I need to filter out some item before.
This calculation
needs to be in python code.

  Thomas

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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



sorting a list of model instances

2008-11-07 Thread Thomas Guettler

Hi,

I just discovered, that you can't sort a list of model instances.

This failed with AssertionError:

view_groups=sorted([brg.group for brg in ... ])
change_groups=sorted([...])
if view_groups==change_groups:
...
else:
assert set(view_groups)!=set(change_groups), (view_groups,
change_groups)
 

Is there a reason why this is this way?

   Thomas

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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



Re: App initialized twice? plus, debugging tips.

2008-11-06 Thread Thomas Guettler

project2501 schrieb:
> Hi,
>   I'm new to django and have a couple questions.
>
> I have a __init__.py in my app and try to declare a simple module wide
> variable. I noticed __init__.py is called twice when I run "python
> manage.py runserver". Is this normal?
>   
I remember, that I had a problem like this, too:
   http://www.mail-archive.com/django-users@googlegroups.com/msg39059.html

You can do this to debug it:

# file which gets imported twice
import logging
logging.error('import %s %s' % (__file__, __name__))

To investigate who called this peace of code you can use the traceback
module
and print the stacktrace.

Be sure that you access the module only in one way:
e.g. always "myapp.modules". Not sometimes "myproj.myapp.modules".

 HTH
  Thomas

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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



Re: model inheritance - getting data from child objects

2008-11-06 Thread Thomas Guettler

I have never used model inheritance, but I read the documentation

If all worker classes (cook, waiter, ...) are subclassed from Worker,
something like this should work: Worker.objects.filter(workplace=...)

(Given that workers only work for one workplace)

HTH,
  Thomas

Alistair Marshall schrieb:
> Using the example in the django writing models documentation [1] I
> wish to get a list of all the places, then calculate a value that
> depends on what the type of place it is.
>
> Say in my restraunt I have a function get_workforce() which returns a
> list of all the people that work in the restaraunt. This collects all
> the waiters, cooks and managers that are associated with the
> restraunt.
> Then I have another type of place, a shop which also has a function
> get_workforce() which returns a list of people that work in the shop.
> This collects all the shop_assistants and managers associated with the
> shop.
>
> The function is different depending on the type of subclass but I need
> to be able to get access to it from a list of all the places.
>
> Has anyone come across this before and come up with a solution.
>
> Thanks
> Alistair
>
> [1] http://docs.djangoproject.com/en/dev/topics/db/models/#id6
> >
>   


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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



Re: apache authentication using Django on windows

2008-11-05 Thread Thomas Guettler

Hi,

Have you tried to create an empty file and use the filename as AuthUserFile?

  Thomas

Matt schrieb:
> Hi,
>
> I have Django running on Apache 2.2 on windows.  I am attempting to
> use django authentification to secure an apache folder using this
> configuration:
>
> 
>
> AuthType Basic
> AuthName "mysite.com"
> AuthUserFile /dev/null
> AuthBasicAuthoritative Off
> Require valid-user
> PythonPath "['E:/Software/django'] + sys.path"
> SetEnv DJANGO_SETTINGS_MODULE testproject.settings
> PythonOption DJANGO_SETTINGS_MODULE testproject.settings
> PythonAuthenHandler django.contrib.auth.handlers.modpython
> 
>
> However, it complains that it cannot find /dev/null.  Is there
> something I can use instead of /dev/null for use on windows?
>
> Thanks
>
>   


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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



Re: Newb help request about fields and and subfields

2008-11-05 Thread Thomas Guettler

Hi,

I see two solutions:
 - be strict: Update the table to contain three columns.
   day (0..6), start_hour and end_hour.
--> No need for MultiWidget
 - don't be strict: Leave it as a charfield. I guess this field is
  only read be humans. This gives you more possibilities:
   Mon 15-17. Except in August 15-16.

if you can convert all current charfields to three columns (strict
solution),
I would take the first solution. If you can't since there are already
entries like the one above, choose the second.

BTW, my TimeDeltaField contains a widget which renders as several
input fields. Maybe it helps you:

http://www.djangosnippets.org/snippets/1060/

  Thomas

mondonauta schrieb:
> thanks for the answer... anyway, my problem is that i already
> have a database so i don't really want to change it.
> in this case in particular i have a table called 'teachings'
> (that should be managed by the model i created)
> where all the subjects taught by a professor r stored.
> for each subject (in the teachings table) a single varchar field
> is used to store both a day and a time range to indicate when
> students can go to talk with the professor about that subject.
> so, i think it would be more user friendly to have 3
> choicefields: the first one for the day of the week,
> the second one for the "from time" field and the last one
> for the "to time" field.
>   


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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



cleaned_data of invalid forms

2008-11-05 Thread Thomas Guettler

Hi,

up to now cleaned_data is removed, if the form is invalid.

What is the best way, to get the cleaned data (converted to
python objects) of a form which is invalid?

Example: The form has field for a group. You want to display
the members of the group right to the input widget.

I looked at forms/form.py ... def full_clean(). I could copy
this method an write a utility function which only works
for one field. But that is not a good solution.

Do other people need this too? If yes, I could write a proposal with patch.

 HTH,
   Thomas

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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



Re: Newb help request about fields and and subfields

2008-11-05 Thread Thomas Guettler

mondonauta schrieb:
> hello, sorry i'm newb so that's y i need your help.
> i made a model... and thanks django, it's very simple... but my
> problem
> is that i want 1 specific field from this model to be split in 3
> choiceFields.
>   
Using MultiValueField is not easy. What kind of data do you have?
Why do you want it to split?

Maybe you just need to write a own Widget which sublcasses
from MultiWidget and override the render method?

 HTH
Thomas

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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



Re: strptime() working in python, but not within django?

2008-11-04 Thread Thomas Guettler

Hi,

Maybe some LANG entries in os.environ are different.

Or the datetime module is loaded from a different location.
is datetime.__file__ equal?

  HTH,
Thomas

mpobrien schrieb:
> I'm working on something that involves parsing out a date from a
> string, so i'm using the datetime.strptime() function. I've noticed
> that this works correctly in python, but when i run it within a django
> environment it doesn't seem to work. Example, in python:
>
> ...


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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



Re: align a ModelForm

2008-11-03 Thread Thomas Guettler

limas schrieb:
> Can i align a single long ModelForm into two raws?
> can i use django admin modules for my own purpose by customizing it?
> please give me some suggestions .
>   

Yes, you can do both. Suggestion: Read the documentation.

Suggestion:
http://docs.djangoproject.com/en/dev/ref/contrib/admin/
http://groups.google.com/group/django-users/browse_thread/thread/536e86280059a1f9

 HTH,
  Thomas

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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



Re: 302 status code in django test client

2008-10-30 Thread Thomas Guettler

jeffhg58 schrieb:
> I am having difficulty trying to test out the content of the main
> window because it returns the status code
> of 302. Here is the snippet of my view. So, when I first call the
> search_form the request falls out of the
> if request. GET. Does anyone have an idea on how I can test the
> content of this page?
>
>   

302 is redirect. There is no content.

You hit this line:
>   return HttpResponseRedirect('/resultsdb/newresults')
>   


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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



Re: How to pass a special character in url

2008-10-30 Thread Thomas Guettler

Hi,

you can use django.http.urlencode() to create the part behind the
question mark.
If you want to pass a list in a value you need urlencode(..., True).

 HTH,
   Thomas

Zeal schrieb:
> Hi, All,
>
> I just want to pass a special character by using url to the proper
> view. For example,
>
> "http://127.0.0.1/sampleview/?obj=xxx; , but seems django cannot
> handle such pattern.
>
> Does any one know this, or are there any relevant doc I can learn for
> this.  Your precious suggestion would be highly appreciated!
>
>   


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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



Re: Migrating strings from MySQL latin1 to Postgres UTF-8

2008-10-30 Thread Thomas Guettler

perchance schrieb:
> Anyone know a good way to transform latin 1 foreign characters from
> MySQL into UTF-8 for insertion into Postgres? I feel like I'm missing
> something obvious.
>
>   
You can handle this at python level like this:

byte_string='latin1-bytes'
unicode_string=byte_string.*decode*('latin1')

If you have latin1 and utf8 mixed, you can use this:

# the order of the encoding list is important
encoding_guess_list=['utf8', 'latin1']
def try_unicode(string, errors='strict'):
if isinstance(string, unicode):
return string
for enc in encoding_guess_list:
try:
return string.decode(enc, errors)
except UnicodeError, exc:
continue
raise UnicodeError('Failed to convert %r' % string)

HTH,
  Thomas

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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



Re: Trying to avoid duplicate form posts/database inserts

2008-10-30 Thread Thomas Guettler

Stan Dyck schrieb:
> I'm converting a simple database-backed web form to Django. Each form 
> submit inserts a row into a database.
>
>   

Hi,

you can use yourmodel.objects.get_or_create(...)
To force the uniqueness on database level you should use unique_together.

> To avoid multiple posts inserting duplicate rows I calculate a checksum 
> on selected fields in the form and insert the checksum value into the 
> database along with the form data itself. The checksum field is set in 
> the database schema to be unique so that if an attempt is made to insert 
> a duplicate row, the database will reject the insert.
>   
I think that this is not a good solution. Most databases can check
uniqueness
over several columns.

> My first impulse is that I could override the save method on the form 
> and use it to check the database for a checksum value. If I don't find 
> it, I insert the row along with the checksum. If I find it, I just 
> reject the insert and send the appropriate message to the response.
This might be possible, but I would handle this outside the save method.


  Thomas


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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



generic query builder

2008-10-29 Thread Thomas Guettler

Hi,

has someone written a generic query builder?

The view should take a model class as argument and create
a HTML form for creating a query.

Foreignkey relationships should be followed...
Integer and date fields should be queryable with ranges...
Last: Ordering of the result should be possible, too.

Not an easy task. Has some tried this already?

  Thomas

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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



Re: 500 displayed instead of 404

2008-10-29 Thread Thomas Guettler


> Thanks to all who answered, now I'll go looking for the person who
> messed with the development machine.
>   
Everybody can make mistakes. The root of the problem is (or was)
that you don't see tracebacks if settings.DEBUG=False.

I see them in the apache error log. I use mod_wsgi.

  Thomas

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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



Re: Django full text search best solution

2008-10-29 Thread Thomas Guettler

alain D. schrieb:
> Being inside database transactions is a good reason to use database's
> full text index ... but the sake of simplicity, a full text index
> created by python code inside the models declaration (easily
> maintainable) would be nice ...
>
>
>   
This is inside the model declaration:

class MyModel(models.Model):
...
def save(self, text_update=True):
models.Model.save(self)
if text_update:
text=utils.mymodel_to_text(self)
tsvector=tsearchutils.to_tsvector(text)
cursor=connection.cursor()
cursor.execute(u'''UPDATE myapp_mymodel SET
content=%s::tsvector where id=%s''', [tsvector, self.id])

The column "content" of type tsvector is created by a SQL snippet named
mymodel.sql.

HTH,
  Thomas

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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



Re: looping to create an array of category breadcrumbs

2008-10-29 Thread Thomas Guettler
Hi,

Does this help you?

myslug=...
parents=[]
while myslug:
   cat_crumb=Category.objects.get(slug=myslug) # I guess slug is unique
parents.append(cat_crumb)
myslug=cat_crumb.parent

But be careful, you might get infinite loops if the parent links
to a child. To avoid this you could write an "assert len(parents)<100"
into the loop.
Except you have a really deeply nested categories.

BTW, Why is "parent" a slug field and not a foreign key?

I attached my tree mix in.

coderb schrieb:
> sorry, had not finished this post before accidently submitting it...
>
> for myslug not null
> catcrumb_list = Category.objects.filter(slug=myslug)
> myslug = catcrumb_list.parent
>
> basically, I want to loop through the category model a parent is not
> found, and each pass, store the model tupel in catcrumblist.
>
> I tried catcrumb_list.append, but returns read-only error on 'list'
>
> any help would be apprec-ated.
>
> thank you
>   


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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

# -*- coding: iso-8859-1 -*-
# $Id: tree.py 148 2008-10-15 08:19:10Z tguettler $
# $HeadURL: svn+ssh://svnserver/svn/djangotools/trunk/utils/tree.py $

empty_magic=object()

class Tree(object):
u'''
Model Mix-In

Usage:

class TreeTag(models.Model, tree.Tree):
parent=models.ForeignKey('self', related_name='children', null=True, blank=True)
name=models.CharField(max_length=64)
...

'''
MAX_REC_DEPTH=1000
def __unicode__(self, rec_depth=0):
if not self.parent:
return self.name
if rec_depth>self.MAX_REC_DEPTH:
raise AssertionError('Tree is a loop')
return '%s / %s' % (self.parent.__unicode__(rec_depth+1), self.name)

def parents(self, me_too=False):
iloop=0
parent=self.parent
parents=[]
if me_too:
parents.append(self)
while parent:
iloop+=1
assert iloop<self.MAX_REC_DEPTH, 'Tree is a loop'
parents.append(parent)
parent=parent.parent
return parents

def get_children(self, children=None, me_too=False, rec_depth=0, ids=False):
assert rec_depth0
for child in self.children.all():
if ids:
children.add(child.id)
else:
children.add(child)
child.get_children(children, rec_depth=rec_depth+1)
if me_too:
if ids:
children.add(self.id)
else:
children.add(self)
return children

def test(self):
self.parents() # raises Exception if infinit loop

@classmethod
def str_to_object(cls, object_str, default=empty_magic):
'''
Gibt zu einer Zeichenkette 'Foo / ...'
die entsprechend Objekt (Belegart/Tag) zurück. Falls
die Objekt unbekannt ist, wird None, zurückgegeben.
'''
mylist=object_str.split('/')
mylist.reverse()
kwargs={}
level=0
for name in mylist:
name=name.strip()
assert name
kwargs['%sname' % (level*'parent__' )]=name
level+=1
assert level
kwargs['%sisnull' % (level*'parent__')]=True
try:
obj=cls.objects.get(**kwargs)
except cls.DoesNotExist:
if default==empty_magic:
raise cls.DoesNotExist(unicode(kwargs))
return default
return obj




Re: Django full text search best solution

2008-10-28 Thread Thomas Guettler

alain D. schrieb:
> Hi,
>
> I'm looking at all the available solutions to implement a full text
> index for django models and I found various projects at different
> stages of maturity but none of them seems to have a strong community
> support ... so here is the list along with my comments (and last
> commit time) ... it any of you has some advice or feedback on any of
> those (or can propose an alternative solution), I'll be glad to here
> from you!
>   
Since all external full text indexing (sphinx, lucene) won't be part of
the database transaction,
I choose the full text index of postgres.

I wrote an own to_tsvector method in python, instead of customizing
the to_tsvector method of postgres.

 Thomas



-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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



Re: 500 displayed instead of 404

2008-10-28 Thread Thomas Guettler

Hi,

I guess that you get 500 because there is an unhandled exception. Can
you see
a traceback in your error log?

What happens if you write "return django.http.HttpResponse('OK')"
instead of raise Http404?

 Thomas

janedenone schrieb:
> Hi,
>
> I use the following simple view
>
> def index(request, page_id, current_subpage=1):
>   try:
>   current_page = get_object_or_404(Page, pk=page_id)
>   except:
>   # if anything else goes wrong, display the 404 anway
>   raise Http404
>
> In debug mode, my app returns the detailed 'page not found' page for
> non-existing pages, but as soon as I switch debug to false, the
> 500 template is shown. I can, however, display render and return the
> 404 template manually.
>
> What could possibly go wrong when a Http404 exception is raised, i.e.
> why does Django use the 500 template in this case?
>   


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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



Re: www.djangosnippets.org is down now?

2008-10-23 Thread Thomas Guettler

Gmail schrieb:
> i found lots of snippets to download,but the server always says it is  
> down.
>   
Hi,

two days ago some snippets produced errors. But at least my snippets are
working again.

  Thomas

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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



Re: Python on Windows re-using old .pyc files?

2008-10-21 Thread Thomas Guettler

Ulf Kronman schrieb:
> I'm using Django trunk and I have set the MaxRequestsPerChild 1
> directive in httpd.conf. I'm running on Windows XP (sp3?).
>   
Here a guess:

Apache creates several threads (or worker processes) and after one
request the thread/process gets killed. But the other are still alive and
have the old code loaded.

Maybe you could try mod_wsgi. It is much more flexible.

See "Time to deprecate mod_python":

http://groups.google.com/group/modwsgi/browse_thread/thread/95c5de2b996e2f49/fe4f823a391ad954

HTH,
  Thomas Güttler

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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



Re: missing template for admin

2008-10-20 Thread Thomas Guettler

DanJ schrieb:
> Hi,
>
> I'm new to Django so please pardon my ignorance.
> I've just installed Django 1.0 from SVN. I'm trying to follow the
> tutorial, while at the same time use Apache and mod_python.
>
> When I point my browser to the admin site I get a simple text version,
> as if it missing the template.
> - Are there any logs to check in order to verify if the template was
> not found?
> - What could be causing this error?
>   
Hi,

what does the text contain? Do you see python code? If yes,
the web server does not execute your code.

If you are on unix, go to /var/lib/apache2 and execute 'ls -ltr'
(sort logfiles by date). There should be some error log file. Maybe
this contains some more information.

BTW, mod_wsgi is much better supported and easier to handle than mod_python.

  Thomas Güttler

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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



<    1   2   3   4   >