Re: passing parameters to a method from a template

2007-02-17 Thread omat * gezgin.com

Thanks for the clarification. I totally agree with your points on good
design. I was just curios...

mat


On Feb 18, 8:33 am, "Russell Keith-Magee" <[EMAIL PROTECTED]>
wrote:
> On 2/18/07, omat * gezgin.com <[EMAIL PROTECTED]> wrote:
>
>
>
> > I couldn't find any reference on passing parameters to a view method
> > from within a template. All I could find are some examples of passing
> > a single parameter to filter functions like:
>
> > {{ pub_date|date:"F j, Y" }}
>
> > Is there a way of doing this?
>
> No, you can't, and that's by design.
>
> Django's template language is not intended to be a full programming
> language. It's intended to be a simple mechanism for getting the logic
> that has been determined in the view to be displayed.  This is for two
> reasons - firstly, to keep the template language simple so that
> designers don't need to learn how to program, and secondly, to
> reinforce good design: View logic should be separate from template
> appearance.
>
> If you have a need to pass arguments to functions in the template, you
> are probably violating the second condition. You either need to put
> this logic into your view (i.e., call the function with the arguments
> in the view, and pass the result in as a context variable), or add a
> method with no arguments that is a version of the function you want,
> but with the arguments preset.
>
> Yours,
> Russ Magee %-)


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

2007-02-17 Thread kbochert



On Feb 17, 11:04 pm, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Sat, 2007-02-17 at 20:51 -0800, kbochert wrote:
> > On a deployed django site, what url does Django use when scanning
> > urls.py when user browses towww.mysite.com ?
>
> > When I access my (non-django) site with
> >  www.mysite.com
> > my host serves up the file that i see as   html/index.html
>
> Only if your webserver is configured to serve up that file in response
> to requests for the root of the URL heirarchy. This isn't a compulsory
> thing.

That is what my host happens to do. Does that give me any clue as to
what urls Django will see?

>
> > If  the polls tutorial is deployed to my host, does the mapping in
> > urls.py work?
>
> > urls.py has a line:
> > (r'^polls/$', 'mysite.polls.views.index'),
> > which i think means that  "www.mysite.com/polls" will get the index
> > page, but "www.mysite.com" will fail
>
> That's correct.
>
>
>
> > Shouldn't urls.py have something like
> >  (r'^index.html$' , 'mysite.polls.views.index' ),
>
> > or perhaps:
> >  (r'^$' , 'mysite.polls.views.index' ),
>
> > or perhaps (in my case)
> >  (r'^html/index.html$' , 'mysite.polls.views.index' ),
>
> > or will this vary with my host??
>
> It will very much vary on a per-host basis. Django code may not be
> responsible for serving all of the URLs for a particular site, for
> example. Somewhere in the web server's configuration (regardless of
> which web server is being used), there will be a setting that says
> "everything under this part of the URL tree gets passed off to that
> Django process over there for processing". Different parts of the URL
> tree may be passed off to different Django instances. So whether Django
> is responsible for serving a response towww.mysite.com/depends on the
> configuration of your site.
>
Do you mean the configuration of my site, or my host's configuration
of the server?

Do I need to talk to my host to find this out, and then have different
url.py
files for development  and deployment?

I.E., how do I design and test a url.py which will work on my host?





--~--~-~--~~~---~--~~
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 and Eclipse Autocomplete NOT WORKING

2007-02-17 Thread Igor Guerrero
Apparently is a random error, I use the svn version, and with one project it
works and with another don't, maybe is a PyDEV bug, but I don't know.

On 2/15/07, Nicolas Steinmetz <[EMAIL PROTECTED]> wrote:
>
>
> Igor Guerrero wrote:
>
> > You must add the app dir and django dir to the PYTHON_PATH env variable
> in
> > the preferrence menu and rescan the PATH.
>
> It worked well with 0.95 version (just need to add django dir to the
> PYTHON
> PATH of Eclipse) but with svn version it looks it does not work any longer
> for me. Any idea about this ?
>
> Nicolas
>
>
> >
>


-- 
:::lxuser 391715:::
http://igordevlog.blogspot.com/

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

2007-02-17 Thread Malcolm Tredinnick

On Sat, 2007-02-17 at 20:51 -0800, kbochert wrote:
> On a deployed django site, what url does Django use when scanning
> urls.py when user browses to www.mysite.com  ?
> 
> 
> When I access my (non-django) site with
>  www.mysite.com
> my host serves up the file that i see as   html/index.html

Only if your webserver is configured to serve up that file in response
to requests for the root of the URL heirarchy. This isn't a compulsory
thing.

> If  the polls tutorial is deployed to my host, does the mapping in
> urls.py work?
> 
> urls.py has a line:
> (r'^polls/$', 'mysite.polls.views.index'),
> which i think means that  "www.mysite.com/polls" will get the index
> page, but "www.mysite.com" will fail

That's correct.

> 
> Shouldn't urls.py have something like
>  (r'^index.html$' , 'mysite.polls.views.index' ),
> 
> or perhaps:
>  (r'^$' , 'mysite.polls.views.index' ),
> 
> or perhaps (in my case)
>  (r'^html/index.html$' , 'mysite.polls.views.index' ),
> 
> or will this vary with my host??

It will very much vary on a per-host basis. Django code may not be
responsible for serving all of the URLs for a particular site, for
example. Somewhere in the web server's configuration (regardless of
which web server is being used), there will be a setting that says
"everything under this part of the URL tree gets passed off to that
Django process over there for processing". Different parts of the URL
tree may be passed off to different Django instances. So whether Django
is responsible for serving a response to www.mysite.com/ depends on the
configuration of your site.

Regards,
Malcolm


> 
> 
> > 
> 


--~--~-~--~~~---~--~~
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: passing parameters to a method from a template

2007-02-17 Thread Russell Keith-Magee

On 2/18/07, omat * gezgin.com <[EMAIL PROTECTED]> wrote:
>
> I couldn't find any reference on passing parameters to a view method
> from within a template. All I could find are some examples of passing
> a single parameter to filter functions like:
>
> {{ pub_date|date:"F j, Y" }}
>
>
> Is there a way of doing this?

No, you can't, and that's by design.

Django's template language is not intended to be a full programming
language. It's intended to be a simple mechanism for getting the logic
that has been determined in the view to be displayed.  This is for two
reasons - firstly, to keep the template language simple so that
designers don't need to learn how to program, and secondly, to
reinforce good design: View logic should be separate from template
appearance.

If you have a need to pass arguments to functions in the template, you
are probably violating the second condition. You either need to put
this logic into your view (i.e., call the function with the arguments
in the view, and pass the result in as a context variable), or add a
method with no arguments that is a version of the function you want,
but with the arguments preset.

Yours,
Russ Magee %-)

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



Deployed url mapping

2007-02-17 Thread kbochert

On a deployed django site, what url does Django use when scanning
urls.py when user browses to www.mysite.com  ?


When I access my (non-django) site with
 www.mysite.com
my host serves up the file that i see as   html/index.html

If  the polls tutorial is deployed to my host, does the mapping in
urls.py work?

urls.py has a line:
(r'^polls/$', 'mysite.polls.views.index'),
which i think means that  "www.mysite.com/polls" will get the index
page, but "www.mysite.com" will fail

Shouldn't urls.py have something like
 (r'^index.html$' , 'mysite.polls.views.index' ),

or perhaps:
 (r'^$' , 'mysite.polls.views.index' ),

or perhaps (in my case)
 (r'^html/index.html$' , 'mysite.polls.views.index' ),

or will this vary with my host??


--~--~-~--~~~---~--~~
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 over modpython

2007-02-17 Thread Scott Paul Robertson
On Sat, Feb 17, 2007 at 04:41:46PM -, akonsu wrote:
> 
> www.prgmr.com seem to have affordable VPS hosting. but i agree, they
> still offer less space and bandwidth than shared hosting.
> 

www.slicehost.com has been treating me very well for VPS hosting.
$20/month for 256 MB RAM, 10 GB disk, 100 GB bandwidth. They even
provide DNS for free.

-- 
Scott Paul Robertson
http://spr.mahonri5.net
GnuPG FingerPrint: 09ab 64b5 edc0 903e 93ce edb9 3bcc f8fb dc5d 7601


pgpe8Ygf5683t.pgp
Description: PGP signature


Re: syncdb on linux problem

2007-02-17 Thread Todd O'Bryan

It could be as simple as a PythonPath problem. Have you tried running
the offending code in the Python shell by using

python manage.py shell

to see if you can figure out what's going wrong?

On Sat, 2007-02-17 at 19:24 -0800, johnny wrote:
> I have moved my folder from Windows to Linux.  It works fine when I
> try "python manage.py syncdb" on windows, exact same project code, in
> linux is not working, when I do "python manage.py syncdb".  This is
> driving me crazy.  I am getting following errors:
> 
> Error: Couldn't install apps, because there were errors in one or more
> models:
> mysite.apps.mail: cannot import name Profile
> 
> Thank you for your help.
> 
> 
> > 


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



syncdb on linux problem

2007-02-17 Thread johnny

I have moved my folder from Windows to Linux.  It works fine when I
try "python manage.py syncdb" on windows, exact same project code, in
linux is not working, when I do "python manage.py syncdb".  This is
driving me crazy.  I am getting following errors:

Error: Couldn't install apps, because there were errors in one or more
models:
mysite.apps.mail: cannot import name Profile

Thank you for your help.


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



Re: "Best" way of using templates

2007-02-17 Thread Lachlan Cannon

Jonathan Ballet wrote:
> I think, we might use the __str__() method, since it seems the
> simplest and cleanest way of doing this (a title is a sort of
> presentation in fact). Or maybe, we will stick with the get_title()
> method (or something like that ...)

Don't forget, either, that you can use a get_title method with a property so it 
looks like a title attribute, if you prefer. Aesthetically I prefer 
{{house.title}} to {{ house.get_title }}.
-- 
Lach
Personal: http://illuminosity.net/


--~--~-~--~~~---~--~~
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: ManyToManyField does not allow empty relations

2007-02-17 Thread Malcolm Tredinnick

On Sun, 2007-02-18 at 01:09 +, akonsu wrote:
> Hello,
> 
> i have set A that has many-to-many relationship with set B
> 
> currently admin interface (at least) forces me to select at least one
> object from B if i add an object to A and the other way around. i do
> not want that. i want to add an object to A which has no related
> objects in B.
> 
> i need to have a model that enables empty relations. is there a way to
> achieve this?

You need to have specified null=True and blank=True on the
ManyToManyField in your model (and you need to have done that before you
created the database, otherwise it will not permit NULL values in that
column). If you do that, it should work fine.

Regards,
Malcolm



--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



ManyToManyField does not allow empty relations

2007-02-17 Thread akonsu

Hello,

i have set A that has many-to-many relationship with set B

currently admin interface (at least) forces me to select at least one
object from B if i add an object to A and the other way around. i do
not want that. i want to add an object to A which has no related
objects in B.

i need to have a model that enables empty relations. is there a way to
achieve this?

thanks
konstantin


--~--~-~--~~~---~--~~
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: newforms select field

2007-02-17 Thread Arnaud Delobelle



On Feb 17, 7:05 pm, "paulh" <[EMAIL PROTECTED]> wrote:
> I feel the following should work:
> class Myform(forms.Form):
> ...publ = forms.ChoiceField(label='Publisher', required=False)
>
> and then in handler I should be able to set the choices dynamically
> by:
>
> def meth(request):
> ...frm=Myform(initial={'publ':((1,2),(2,3),(3,4)))}) #even if the
> brackets are wrong here, they were right in the original
>

That shouldn't work as initial is meant to set the value of a field.

I had the same problem and a peek at the source told me that a
ChoiceField has a 'choices' attribute which is settable so:

form = MyForm(...)
form.fields['publ'].choices = ((1,2),(2,3),(3,4))

will work, but I don't know whether it is the right thing to do (TM).

--
Arnaud


--~--~-~--~~~---~--~~
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: ValueError: Empty module name

2007-02-17 Thread cory

Ah-ha! I think I've found the issue.

The problem was coming from the template context loader I was using.
Or rather, how that was set in the settings.py file. I only had one
template context loader set, and forgot to include a trailing comma so
that it could be processed as a tuple instead of a string. Once I
added that, everything works as it should. Just one of those little
gotchas that you have to look out for.

On Feb 16, 7:10 pm, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Fri, 2007-02-16 at 12:27 -0800, cory wrote:
> > Hello all,
>
> > I keep getting a very strange error in my latest Django project. It
> > repeatedly sends back a ValueError saying 'Empty module name', but in
> > the debug output all of the settings from the settings files are
> > displayed correctly and the settings file that's listed is the correct
> > one.
>
> You may need to provide a little more information for this: where is the
> error coming from? Can you work out what sort of "module name" it is
> expecting?
>
> Your problem may be simple to fix, though...
>
>
>
> > The only thing I can think of is, something isn't right with how
> > mod_python is accessing the project. There are two locations in my
> > httpd.conf file for this project:
>
> > 
> [...]
> > 
>
> > 
> [...]
> > 
>
> "Location" directives in Apache are processed in the order they appear
> in the file. So your first block will catch *all* URLS and the second
> block will never be applied. In this case, you can probably work around
> that by just reversing the order of the Location blocks. In other, more
> complicated cases, you can use LocationMatch (instead of Location) to
> exclude certain match patterns.
>
> Regards,
> Malcolm


--~--~-~--~~~---~--~~
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: newforms select field

2007-02-17 Thread Honza Král
On 2/17/07, paulh <[EMAIL PROTECTED]> wrote:
>
> I feel the following should work:
> class Myform(forms.Form):
> ...publ = forms.ChoiceField(label='Publisher', required=False)
>
> and then in handler I should be able to set the choices dynamically
> by:
>
> def meth(request):
> ...frm=Myform(initial={'publ':((1,2),(2,3),(3,4)))}) #even if the
> brackets are wrong here, they were right in the original

by initial argument, you are meant to pass the initial VALUE (which
choice is currently selected), choices on the other hand are part of
the field's definition...

if you want to setup the choices dynamically, set it in the form's
__init__ (search the list for examples, there were quite a few)
>
> An appropriate variant of the above certainly works for non ordinary
> CharFields.
>
> Any ideas would be appreciated.
>
> Paul Hide
>
>
> >
>


-- 
Honza Kr�l
E-Mail: [EMAIL PROTECTED]
ICQ#:   107471613
Phone:  +420 606 678585

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



newforms select field

2007-02-17 Thread paulh

I feel the following should work:
class Myform(forms.Form):
...publ = forms.ChoiceField(label='Publisher', required=False)

and then in handler I should be able to set the choices dynamically
by:

def meth(request):
...frm=Myform(initial={'publ':((1,2),(2,3),(3,4)))}) #even if the
brackets are wrong here, they were right in the original

An appropriate variant of the above certainly works for non ordinary
CharFields.

Any ideas would be appreciated.

Paul Hide


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



passing parameters to a method from a template

2007-02-17 Thread omat * gezgin.com

I couldn't find any reference on passing parameters to a view method
from within a template. All I could find are some examples of passing
a single parameter to filter functions like:

{{ pub_date|date:"F j, Y" }}


Is there a way of doing this?


--~--~-~--~~~---~--~~
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 over modpython

2007-02-17 Thread akonsu

www.prgmr.com seem to have affordable VPS hosting. but i agree, they
still offer less space and bandwidth than shared hosting.

konstantin

On Feb 17, 8:03 am, [EMAIL PROTECTED] wrote:
> Yes, most of the hostings have fastCGI, but not flup.
> I know the best is to have VPS hosting, but they are very expensive,
> and I think I can manage with a shared hosting.
> I think Blouehost looks good.
>
> On 17 feb, 11:32, "ashwoods" <[EMAIL PROTECTED]> wrote:
>
>
>
> > i've been checking out hosts for myself, and the already 
> > mentionedwww.webfaction.comseemsto be very good.
> > i haven't chosen yet, but their team seems to be very friendly and I
> > have had some _weird_ requests myself and they were very helpfull.
>
> > but most hosting do have fastCGI, and that works.
>
> > On Feb 16, 8:32 pm, [EMAIL PROTECTED] wrote:
>
> > > Maybe this is a stupid question.
> > > I have been looking for a hosting which supports modpython to run
> > > django.
> > > One of them (bluehost) told me that they support it through CGI. I
> > > suppose that this is all right and django would run without any
> > > problem isn't it?
> > > I just want t be sure before buying.
>
> > > Thank you.- Hide quoted text -
>
> - Show quoted text -


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Free Pc To Phone Calling

2007-02-17 Thread coolguy17111987

Now you can call anywhere in world for free
...hurry up...Its Globe 7..
you are paid to watch free videos(of your choice)...
Now its no. 1 VOIP service in the worldClick on the link
below...download the software, register for free and start calling
What are you waiting for now
Call any phone anywhere Free! - Globe 7
http://surl.in/HLGB7268591UXYDPMK-google


Weather Report Toolbar
Hi all..Now you can get the weather report of your area
instantly...Just Install the toolbar and get the weather report on
it..Instant report..Go for it...What is you waiting for...
Download the toolbar only 400Kb, Install it..and thats it...
Download Weather Toolbar - Instant weather reports, forecasts, and
radar images anytime for FREE! - http://surl.in/HLWTD268591UXYDPMK-google


Hey i know u wanna chat now...go for it...free chatting and
dating...try it...
Search Profiles - FREE! Intimate Dating. Start Chatting within seconds
- http://surl.in/HLMAT268591UXYDPMK-google

Free ! Free ! Free !
Unlimited iPod Music, Movies, TV Shows Downloads. No Monthly or Per
Downloads Fees! - http://surl.in/HLMID268591UXYDPMK-google

Earn money online!!
Webmasters - Earn Money from your Website. Get Paid Daily! -
http://surl.in/HLAXR268591UXYDPMK-google

Send free Sms Anywhere free from your mobile...just try it...I have
been using it for a month now...
Send SMS to any mobile anywhere in world Free! - 
http://surl.in/PCMCACL268591UXYDPMK

Download COOL Free Screensavers & Wallpapers - 
http://surl.in/PCOISCR268591UXYDPMK


--~--~-~--~~~---~--~~
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: Custom model initializers - getting logged in user in django models

2007-02-17 Thread kahless

altough i'm not sure if thread locals are that clean .. i guess it's a
better way ..
thanks .. i was searching for something like that .. i wonder why i
haven't found that site :(
it seems there are tons more documentation in the wiki as i've
thought ;)

cu,
  herbert

On Feb 17, 3:22 pm, "Honza Král" <[EMAIL PROTECTED]> wrote:
> This doesn't seem very clean to me...
>
> I also need to have logged-in user available in my models, so I have
> written a custom middleware that stores the user in thread_locals:
>
> import threading
> _thread_locals = threading.local()
>
> def get_current_user():
> return getattr( _thread_locals, 'user', None )
>
> class RequestMiddleware( object ):
>
> def process_request( self, request ):
>
> _thread_locals.user = request.user
>
> then, I can use get_current_user() anywhere in my application and it
> will provide me with the current user, for some fields I even have
> something like:
>
>   user = models.ForeignKey( User, default=get_current_user )
>
> I cannot take credit for this, I found it on
>
> http://code.djangoproject.com/wiki/CookBookThreadlocalsAndUser
>
> On 2/17/07, kahless <[EMAIL PROTECTED]> wrote:
>
>
>
>
>
> > hi,
>
> > i am creating a very simple board and wanted to add a method to my
> > models which would check if there are any new posts in a thread /
> > forum for a given user.. for this to work .. i obviously need the
> > currently logged in user in my models ..
>
> > but i didn't want to iterate through all my models in my view, since i
> > used the django.views.generic.list_detail.object_list which does the
> > paging and everything for me ..
>
> > so i thought the easiest way would be to allow adding of custom
> > initializers.. which would be called once a model was created by
> > django.db.models.query.QuerySet .. so i played around a little until
> > it worked for me:http://yourhell.com/~kahless/query_initializers_patch.diff
>
> > the usage is quite simple:
> > class MyModelInitializer(object):
> >   def __init__(self, request):
> > self.request = request
>
> >   def init_model(self, model):
> > model.do_init( self, self.request.user )
>
> > (my models would have a 'do_init' method which takes the user and
> > stores it internally)
>
> > the object_list would then get a queryset argument in my view like:
> > queryset =
> > Post.objects.filter( . ).add_initializer( MyModelInitializer( request ) 
> > )
>
> > and my templates could simply call {% if thread.hasNewPosts %} ...
>
> > so .. is this a clean solution ? or can this be done differently ?
> > and .. would there any chance this patch could find it's way into
> > django or does it break any main design philosophy ?
>
> > - i'm very new to python and django alike .. so there might be an
> > obvious other solution.
>
> > thanks & cu,
> >   Herbert Poul
>
> --
> Honza Kr?l
> E-Mail: [EMAIL PROTECTED]
> ICQ#:   107471613
> Phone:  +420 606 678585


--~--~-~--~~~---~--~~
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: error pages ?

2007-02-17 Thread Honza Král
On 2/17/07, akonsu <[EMAIL PROTECTED]> wrote:
>
> hello,
>
> the tutorial on djangoproject.com explains how to set up views
> generating error pages for responses such as 404 or 500. is there a
> way to use mod_python functionality and make apache serve its own
> error pages? in case when it is running under mod_python of course. or
> is it against django design goals?

django tries to handle all its errors on its own. Only if there is
some error in django itself does the error get propagated to
mod_python...

>
> thanks
> konstantin
>
>
> >
>


-- 
Honza Kr�l
E-Mail: [EMAIL PROTECTED]
ICQ#:   107471613
Phone:  +420 606 678585

--~--~-~--~~~---~--~~
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: Help about saving two linked instances...

2007-02-17 Thread Honza Král
Hi Giuseppe,

On 2/17/07, Giuseppe Franchi <[EMAIL PROTECTED]> wrote:
>
> Hello everyone!
> I've approached Django and Python from a few time and i love them
> both.
> As i am newbie i have a noobish question. My problem is: i have to
> store a Resource object splitted in two tables as following:
>
> class Resource(models.Model):
>
>   title = models.CharField(maxlength=100)
>   creator = models.CharField(maxlength=50)
>   ...blah blah
>
> class Resource_systeminfo(models.Model):
>
>   resource_ID = models.ForeignKey(Resource)
>   owner = models.ForeignKey(User)
>   date_birth = models.DateField()
>
>
> (that represent who added the resource in the db, and when)
> All the info in the Resource table are filled in by a user. As a user
> insert a new resource, i wish to create in automatic a
> Resource_systeminfo instance linked to the first, but i have no idea
> about how to do that...
> Actually my view is
>
> @login_required
> def resource_edit_insert(request, id=None):
> ResourceForm = form_for_model(Resource)
> if id is not None:
> pass
> #...i still have to implement resource modification :)
> else:
> if request.POST:
> form = ResourceForm(request.POST)
> if form.is_valid():
> form.save()
> '''Here starts my problem. I tried to use a form_for_model (great
> tool) but obviously i have also to insert the foreign key to the
> Resource object... and i absolutely dunno how to do it!'''

you can do
mod = form.save( commit=False )
# now edit any fields of mod you wish
mod.save() # manually call the save

> ResourceSystemForm =
> form_for_model(Resource_systeminfo)
> data = {'owner': request.user, 'date_birth':
> datetime.date.today()}
> systemform = ResourceSystemForm(data)
> systemform.save()
> return HttpResponseRedirect('/mainpage/')
> else:
> context = {'form': form, 'error_message': "Please
> correct errors below."}
> else:
> context = {'form': ResourceForm()}
> return render_to_response(
> 'catalog/resource_edit_insert.html',
> context,
> context_instance=RequestContext(request)
> )
>
>
> If someone knows how it could be done... A note: I would prefer not to
> join the two tables, keep it as very last solution!
>
> Cheers and sorry for my terrible english.
>
>
> >
>


-- 
Honza Kr�l
E-Mail: [EMAIL PROTECTED]
ICQ#:   107471613
Phone:  +420 606 678585

--~--~-~--~~~---~--~~
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: Custom model initializers - getting logged in user in django models

2007-02-17 Thread Honza Král
This doesn't seem very clean to me...

I also need to have logged-in user available in my models, so I have
written a custom middleware that stores the user in thread_locals:

import threading
_thread_locals = threading.local()

def get_current_user():
return getattr( _thread_locals, 'user', None )

class RequestMiddleware( object ):

def process_request( self, request ):

_thread_locals.user = request.user

then, I can use get_current_user() anywhere in my application and it
will provide me with the current user, for some fields I even have
something like:

  user = models.ForeignKey( User, default=get_current_user )

I cannot take credit for this, I found it on

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

On 2/17/07, kahless <[EMAIL PROTECTED]> wrote:
>
> hi,
>
> i am creating a very simple board and wanted to add a method to my
> models which would check if there are any new posts in a thread /
> forum for a given user.. for this to work .. i obviously need the
> currently logged in user in my models ..
>
> but i didn't want to iterate through all my models in my view, since i
> used the django.views.generic.list_detail.object_list which does the
> paging and everything for me ..
>
> so i thought the easiest way would be to allow adding of custom
> initializers.. which would be called once a model was created by
> django.db.models.query.QuerySet .. so i played around a little until
> it worked for me: http://yourhell.com/~kahless/query_initializers_patch.diff
>
> the usage is quite simple:
> class MyModelInitializer(object):
>   def __init__(self, request):
> self.request = request
>
>   def init_model(self, model):
> model.do_init( self, self.request.user )
>
> (my models would have a 'do_init' method which takes the user and
> stores it internally)
>
> the object_list would then get a queryset argument in my view like:
> queryset =
> Post.objects.filter( . ).add_initializer( MyModelInitializer( request ) )
>
> and my templates could simply call {% if thread.hasNewPosts %} ...
>
> so .. is this a clean solution ? or can this be done differently ?
> and .. would there any chance this patch could find it's way into
> django or does it break any main design philosophy ?
>
> - i'm very new to python and django alike .. so there might be an
> obvious other solution.
>
> thanks & cu,
>   Herbert Poul
>
>
> >
>


-- 
Honza Kr�l
E-Mail: [EMAIL PROTECTED]
ICQ#:   107471613
Phone:  +420 606 678585

--~--~-~--~~~---~--~~
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: rendering dynamic fields in newforms

2007-02-17 Thread Honza Král
for rendering you should use BoundField...

I use something like this...
for s in :
name = 'stay_' + str( s.id )
bf = BoundField( self, self.fields[name], name )
output.append( u'%s' % bf )


On 2/17/07, Rubic <[EMAIL PROTECTED]> wrote:
>
> Hi, I'm the 985th person to attempt dynamic fields
> in newforms.  ;-)
>
> Actually I've been able to do lots of dynamic stuff
> in newforms.  It's rendering the forms in templates
> that sometimes confuses me.  For example, given
> the following code to build a form based on an
> arbitrary number of medications:
> --
> from django import newforms as forms
> from django.template import Context, Template
>
> class MedForm(forms.Form):
> def __init__(self, *args, **kwargs):
> super(MedForm, self).__init__(*args, **kwargs)
> self.med_list = []
> for i in range(1, 4):  # arbitrary number
> k = 'med_%d' % i
> self.fields[k] = forms.CharField(required=False, label=k)
> self.med_list.append(self.fields[k])
>
> t = Template("""{% for med in form.med_list %}
>   {{ med.label }}: {{ med }}
> {% endfor %}""")
>
> print t.render(Context({'form':MedForm({})}))
> --
> Produces the following output:
>
>   med_1: 
>   med_2: 
>   med_3: 
>
> Obviously, what I want is something more like this:
>
>   med_1: 
>   med_2: 
>   med_3: 
>
> So how do I get there?  I could do something like
> this in line 11:
>
>   bf = BoundField(self, self.fields[k], k)
>   self.med_list.append(bf.as_widget(self.fields[k].widget))
>
> But I'd lose all the field information.  Basically, I'm
> looking for the magic BoundField.as_widget() rendering
> formula.  I've put the above code here for easier viewing:
>
>   http://dpaste.com/hold/5764/
>
> --
> Jeff Bauer
> Rubicon, Inc.
>
>
> >
>


-- 
Honza Kr�l
E-Mail: [EMAIL PROTECTED]
ICQ#:   107471613
Phone:  +420 606 678585

--~--~-~--~~~---~--~~
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 over modpython

2007-02-17 Thread aribao

Yes, most of the hostings have fastCGI, but not flup.
I know the best is to have VPS hosting, but they are very expensive,
and I think I can manage with a shared hosting.
I think Blouehost looks good.

On 17 feb, 11:32, "ashwoods" <[EMAIL PROTECTED]> wrote:
> i've been checking out hosts for myself, and the already 
> mentionedwww.webfaction.comseems to be very good.
> i haven't chosen yet, but their team seems to be very friendly and I
> have had some _weird_ requests myself and they were very helpfull.
>
> but most hosting do have fastCGI, and that works.
>
> On Feb 16, 8:32 pm, [EMAIL PROTECTED] wrote:
>
> > Maybe this is a stupid question.
> > I have been looking for a hosting which supports modpython to run
> > django.
> > One of them (bluehost) told me that they support it through CGI. I
> > suppose that this is all right and django would run without any
> > problem isn't it?
> > I just want t be sure before buying.
>
> > Thank you.


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Custom model initializers - getting logged in user in django models

2007-02-17 Thread kahless

hi,

i am creating a very simple board and wanted to add a method to my
models which would check if there are any new posts in a thread /
forum for a given user.. for this to work .. i obviously need the
currently logged in user in my models ..

but i didn't want to iterate through all my models in my view, since i
used the django.views.generic.list_detail.object_list which does the
paging and everything for me ..

so i thought the easiest way would be to allow adding of custom
initializers.. which would be called once a model was created by
django.db.models.query.QuerySet .. so i played around a little until
it worked for me: http://yourhell.com/~kahless/query_initializers_patch.diff

the usage is quite simple:
class MyModelInitializer(object):
  def __init__(self, request):
self.request = request

  def init_model(self, model):
model.do_init( self, self.request.user )

(my models would have a 'do_init' method which takes the user and
stores it internally)

the object_list would then get a queryset argument in my view like:
queryset =
Post.objects.filter( . ).add_initializer( MyModelInitializer( request ) )

and my templates could simply call {% if thread.hasNewPosts %} ...

so .. is this a clean solution ? or can this be done differently ?
and .. would there any chance this patch could find it's way into
django or does it break any main design philosophy ?

- i'm very new to python and django alike .. so there might be an
obvious other solution.

thanks & cu,
  Herbert Poul


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Reuse inclusion template tag in admin textarea?

2007-02-17 Thread Dirk Eschler

Hi,

i'm using the following template tag in my application:

@register.inclusion_tag('gallery/flv.html')
def flv(movie, width=320, height=160):
"""
"""
fl = FlashMovie()
return {
'flv_player': fl.get_flvplayer(),
'movie': '%s/%s' % (fl.get_upload_url(), movie),
'width': int(width),
'height': int(height),
}

In the templates i simply write {% flv "foo.flv" 320 160 %} to get the 
appropriate html for the movie.

Is it possible to reuse the inclusion tag in a admin textarea?

Say i write this into a admin textarea:
Here's my cool movie: {% flv "foo.flv" 320 160 %} ...

And in the model's save() method the template tag is replaced with the 
appropriate piece of html (from gallery/flv.html), which is then saved in the 
db. Can this be done, or should i better parse the content myself?

Best Regards.

-- 
Dirk Eschler 
http://www.krusader.org

--~--~-~--~~~---~--~~
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: HTTP_REFERER

2007-02-17 Thread [EMAIL PROTECTED]


Pythoni napisał(a):
> I would like to use HTTP_REFERER in my Django project to find out from
> where users came to my website. So, my first page is INDEX.HTML that
> uses
> def Index(request) procedure.
> In this def Index(request) I use
> request.META['REMOTE_ADDR']
> but I found out that Referer does not work.
> HTTP_REFERER  is empty.
> Is HTTP_REFERER value transfered between different domains?
> Thank you for help
> L.

It works for me on the dev server and mod_python. Note that
HTTP_REFERER doesn't always have a value. Also browser settings may
affect it (may not send the referer in the header )


--~--~-~--~~~---~--~~
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: Help about saving two linked instances...

2007-02-17 Thread Pythoni


I think you need some relations.
You can have  a look at http://www.djangoproject.com/documentation/models/

 and choose the best model for your problem
L.


--~--~-~--~~~---~--~~
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 over modpython

2007-02-17 Thread ashwoods

i've been checking out hosts for myself, and the already mentioned
www.webfaction.com seems to be very good.
i haven't chosen yet, but their team seems to be very friendly and I
have had some _weird_ requests myself and they were very helpfull.

but most hosting do have fastCGI, and that works.

On Feb 16, 8:32 pm, [EMAIL PROTECTED] wrote:
> Maybe this is a stupid question.
> I have been looking for a hosting which supports modpython to run
> django.
> One of them (bluehost) told me that they support it through CGI. I
> suppose that this is all right and django would run without any
> problem isn't it?
> I just want t be sure before buying.
>
> Thank you.


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Help about saving two linked instances...

2007-02-17 Thread Giuseppe Franchi

Hello everyone!
I've approached Django and Python from a few time and i love them
both.
As i am newbie i have a noobish question. My problem is: i have to
store a Resource object splitted in two tables as following:

class Resource(models.Model):

  title = models.CharField(maxlength=100)
  creator = models.CharField(maxlength=50)
  ...blah blah

class Resource_systeminfo(models.Model):

  resource_ID = models.ForeignKey(Resource)
  owner = models.ForeignKey(User)
  date_birth = models.DateField()


(that represent who added the resource in the db, and when)
All the info in the Resource table are filled in by a user. As a user
insert a new resource, i wish to create in automatic a
Resource_systeminfo instance linked to the first, but i have no idea
about how to do that...
Actually my view is

@login_required
def resource_edit_insert(request, id=None):
ResourceForm = form_for_model(Resource)
if id is not None:
pass
#...i still have to implement resource modification :)
else:
if request.POST:
form = ResourceForm(request.POST)
if form.is_valid():
form.save()
'''Here starts my problem. I tried to use a form_for_model (great
tool) but obviously i have also to insert the foreign key to the
Resource object... and i absolutely dunno how to do it!'''
ResourceSystemForm =
form_for_model(Resource_systeminfo)
data = {'owner': request.user, 'date_birth':
datetime.date.today()}
systemform = ResourceSystemForm(data)
systemform.save()
return HttpResponseRedirect('/mainpage/')
else:
context = {'form': form, 'error_message': "Please
correct errors below."}
else:
context = {'form': ResourceForm()}
return render_to_response(
'catalog/resource_edit_insert.html',
context,
context_instance=RequestContext(request)
)


If someone knows how it could be done... A note: I would prefer not to
join the two tables, keep it as very last solution!

Cheers and sorry for my terrible english.


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



HTTP_REFERER

2007-02-17 Thread Pythoni

I would like to use HTTP_REFERER in my Django project to find out from
where users came to my website. So, my first page is INDEX.HTML that
uses
def Index(request) procedure.
In this def Index(request) I use
request.META['REMOTE_ADDR']
but I found out that Referer does not work.
HTTP_REFERER  is empty.
Is HTTP_REFERER value transfered between different domains?
Thank you for help
L.


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---