and
> it needs access to the session from the request object.
>
> You are correct in that what I really want is per thread architectural
> hooks so I can store the request there.
> Django does not provide these hooks (probably on purpose) so I'm
> discouraged in using it.
>
> But, sessio
I looked at my code based on your feedback.
In this particular case, the code that needs the request is doing status
notifications
http://blog.ianbicking.org/web-application-patterns-status-notification.html
and
it needs access to the session from the request object.
You are correct in that what
inking that the django middleware will access the request object
> and create a closure.
> I think I can use a classmethod for the closure so I can access it
> from anywhere.
> This will create a new object for every request -- I'm assuming that
> it will not impact
> performance but I
I seem to need the Django HttpRequest object in functions that are
called by view functions.
I could pass the request, but I'm thinking of trying to create a
closure in middleware so that
I can access the request object (and maybe other objects) from
anywhere.
This seems like it's stretching
Hello, I'have a little problem with this code??
when I'l trying to put :
" def __init__(self, inputUser, *args, **kwargs):"
I have the following error :
__init__() takes at least 2 non-keyword arguments (1 given)
So, I suppose I need to set the inputUser in a specific place, but I
can' figure
Bingo!!!
:D
I follow this:
http://oebfare.com/blog/2008/feb/23/changing-modelchoicefield-queryset/
and now I'm happy with mi desired current user based queryset
Thank you all!
BTW, my form class finally looks like...
---
class SendMessageForm(forms.Form):
recipientUser =
But why don't you put:
recipientUser = ShowValidContactList(currentUser=self.user)
inside the __init__?
- Paulo
2009/8/6 Julián C. Pérez
>
> Thanks for reply, Paulo
> But if I...
> ---
> class SendMessageForm(forms.Form):
>
>recipientUser =
Thanks for reply, Paulo
But if I...
---
class SendMessageForm(forms.Form):
recipientUser = ShowValidContactList(currentUser=self.user,
label=u'Send to')
messageSubject= forms.CharField(label=u'Subject')
messageContent = forms.CharField(label=u'Content',
It doesn't have to be a callable, you can just do something like:
recipientUser = ShowValidContactList(currentUser=self.currentUser)
I never used that kwargs.pop function (I didn't know you could do that),
but I have code like this:
class ExperimentForm(ModelForm):
""" Generate form to
My real problem it that the field should looks like:
---
recipientUser = ShowValidContactList(currentUser=_something_,
label=u'Send to')
---
and if I have a form's init method like...
---
def __init__(self, *args, **kwargs):
self.currentUser = kwargs.pop('currentUser', None)
On Aug 6, 3:34 pm, Julián C. Pérez wrote:
> Hi
> I tried doing that...
> But it does not work
> For example, if I do something like...
> ---
> class SendMessageForm(forms.Form):
> recipientUser = ShowValidContactList(label=u'Send to')
> messageSubject=
Hi
I tried doing that...
But it does not work
For example, if I do something like...
---
class SendMessageForm(forms.Form):
recipientUser = ShowValidContactList(label=u'Send to')
messageSubject= forms.CharField(label=u'Subject')
messageContent = forms.CharField
> ..go back and read the original poster's
> message. Having the user in threadlocals doesn't solve any problem,
> since he's trying to create a form class based on information in the
> request and that only happens at import time, not every time something
> in the file is looked at.
Yes, my
On Thu, 2009-08-06 at 03:33 -0700, krylatij wrote:
> Why do you think so?
It's bad encapsulation practice, for a start. It breaks Python's
namespacing habits.
In this particular case, however, go back and read the original poster's
message. Having the user in threadlocals doesn't solve any
Why do you think so?
--~--~-~--~~~---~--~~
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
On Aug 6, 9:14 am, krylatij <kryla...@gmail.com> wrote:
> You can also use threadlocals middleware (ask google about it =))
> to get current user without request object
No, really, don't. Just don't.
--
DR.
--~--~-~--~~~---~--~~
You received this mes
You can also use threadlocals middleware (ask google about it =))
to get current user without request object
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group,
On Aug 6, 2:24 am, Julián C. Pérez wrote:
> Hi everyone
> I'm in trouble because of a form class
> I have a form class with attributes defined, but with one thing:
> One of the attributes requires the current user, or al least its
> username
>
> The form definition in as shown
Hi everyone
I'm in trouble because of a form class
I have a form class with attributes defined, but with one thing:
One of the attributes requires the current user, or al least its
username
The form definition in as shown below:
---
class SendMessageForm(forms.Form):
recipientUser =
o from a py
> > function that does not have 'request' object.
>
> You could write up something similar to get_language() in
> utils.translation or use threadlocals. I don't know if this is
> actually a good idea.
--~--~-~--~~~---~--~~
You receiv
On 1 kesä, 22:38, Rami <rrr...@gmail.com> wrote:
> I'm trying to access Session's (logged in) user id info from a py
> function that does not have 'request' object.
You could write up something similar to get_language() in
utils.translation or use threadlocals. I don't know if this
On Mon, Jun 1, 2009 at 2:38 PM, Rami <rrr...@gmail.com> wrote:
>
> I'm trying to access Session's (logged in) user id info from a py
> function that does not have 'request' object. I can't find an obvious
> way to access the session or the cookie data NOT through an
>
I'm trying to access Session's (logged in) user id info from a py
function that does not have 'request' object. I can't find an obvious
way to access the session or the cookie data NOT through an
instantiated request (HttpRequest) obj [the same way for example you
can access any Session
On Wed, 2009-03-25 at 05:23 -0700, foxbunny wrote:
> I am trying to write a custom template filter which takes a variable
> which is a model object and grabs fields from a related object based
> on request.session['lang'] parameter. Or it would if I knew how to get
> the `lang` parameter from
I forgot to mention I'm on django-trunk rev. 10163.
Branko
--~--~-~--~~~---~--~~
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
/18914/
line 35, `fieldlang = request.sessions.get` obviously doesn't work
because request object doesn't exist in the scope.
How can I access it?
TIA
Branko
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
"D
>> 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.
>
>
On Mar 19, 1:22 pm, Thomas Guettler <h...@tbz-pariv.de> wrote:
> 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
> f
On Thu, Mar 19, 2009 at 9:22 AM, Thomas Guettler <h...@tbz-pariv.de> wrote:
>
> 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
>
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
Hi Malcolm,
On 20 Jan 2009, at 02:33, Malcolm Tredinnick wrote:
>
> On Tue, 2009-01-20 at 02:07 +, Hans Fangohr wrote:
> [...]
>> However, in the template files, I extend my base.html which makes use
>> of the request object (basically checking whether the request ha
On Tue, 2009-01-20 at 02:07 +, Hans Fangohr wrote:
[...]
> However, in the template files, I extend my base.html which makes use
> of the request object (basically checking whether the request has as
> authenticated used and changing the html depending on this).
>
of the request object (basically checking whether the request has as
authenticated used and changing the html depending on this).
It appears that the request object is not available in registration/
password_change_form.html when called from the view
django.contrib.auth.views.password_change.
Here
Yeah, you want to assign that user_id value in the view, when you're
saving the instance:
mydocument.author_id = request.user.id
mydocument.save()
Are you trying to solve for a case where you want the current *admin*
user to be the author_id for the record? You can also add a save
>
> Hi there,
>
> I'm trying to set up a default value the author field in the model
> above as the current user as the default value.
> Is there any way to access the request object from here?
>
The fact that you say "current user" implies that instances of the mo
No. Request object does not exist when model classes are created.
On Fri, Nov 21, 2008 at 13:47, FT <[EMAIL PROTECTED]> wrote:
>
> class Document(models.Model):
>
>created = models.DateTimeField(
>help_text='Timestamp when the document is created',
> blan
the author field in the model
above as the current user as the default value.
Is there any way to access the request object from here?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
"Django users" grou
nd this is obviously what you want:
>
> def anonymous_only(view):
> # 'view' is the view function to decorate
> # since we decorate views, we know the first parameter
> # is always going to be the current request
> #
> # '_wrapper' is th
that will be used instead
# of 'view'.
def _wrapper(request, *args, **kw):
# here we can access the request object and
# either redirect or call 'view'
if request.user.is_authenticated():
return HttpResponseRedirect('/page_for_logged_in_user')
return view(request, *args, **kw)
Wiadomość napisana w dniu 2008-11-17, o godz. 10:02, przez TH:
> I wanted to redirect a logged in user if he access certain page. For
> example i do not want the user to access registration page if he is
> logged in.
>
> A simple way to do this is:
>
> def register(request):
>if
Hello,
I wanted to redirect a logged in user if he access certain page. For
example i do not want the user to access registration page if he is
logged in.
A simple way to do this is:
def register(request):
if request.user.is_authenticated():
return HttpResponseRedirect('/
On Jul 15, 2008, at 9:55 PM, Nazmi ZORLU wrote:
> Hi,
>
> I wonder if I can access request object in html template or absolute
> page url that currently rendering.
If you're not using generic views, you can pass
"context_instance=RequestContext(request)&quo
Hi,
I wonder if I can access request object in html template or absolute
page url that currently rendering.
Thanks,
Nazmi
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
"Django users" grou
I'm looking for a quick and simple way to create a request object - as
it would be received by a specific view - for some very basic
testing. Additionally, I want this object to have all the added
attributes from the middleware modules e.g. request.user.
I tried this:
(1)
I looked
James,
Thanks, this is great. I never made this connection before. I have
been using threadlocals for a while (to implement a custom manager
with role-based access). Since the start I have been passing a users
role as a kw argument in to the Manager via the shell for testing, and
until
On Mon, May 19, 2008 at 4:10 PM, Tim Chase
<[EMAIL PROTECTED]> wrote:
> It's the last bit that can throw folks...many folks seem to use
> very nice/helpful bits of the framework that abstract the save()
> call so it's never thought-about. Wouldn't adding a parameter to
> save() stymie the admin
>> how do you pass the request object to models?
>
> Same way you pass any argument to any function or method in
> Python: write your function/method to accept the argument, and
> pass it from the code that calls the function/method.
It's the last bit that can throw folks
On May 19, 5:35 pm, "Richard Dahl" <[EMAIL PROTECTED]> wrote:
> http://code.djangoproject.com/wiki/CookBookThreadlocalsAndUser
> -richard
>
Thanks!, it works
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
"Django
On Mon, May 19, 2008 at 3:45 PM, Richard Dahl <[EMAIL PROTECTED]> wrote:
> how do you pass the request object to models?
Same way you pass any argument to any function or method in Python:
write your function/method to accept the argument, and pass it from
the code that calls the functi
how do you pass the request object to models?
-richard
On 5/19/08, James Bennett <[EMAIL PROTECTED]> wrote:
>
>
> On Mon, May 19, 2008 at 3:24 PM, enri57ar <[EMAIL PROTECTED]> wrote:
> > How access to request object within models ?
>
> Pass it as an argument the
On Mon, May 19, 2008 at 3:24 PM, enri57ar <[EMAIL PROTECTED]> wrote:
> How access to request object within models ?
Pass it as an argument the same as any other value. Magical hacks to
try to make it available otherwise are likely to land you in trouble
later on.
--
"Bureaucr
http://code.djangoproject.com/wiki/CookBookThreadlocalsAndUser
-richard
On 5/19/08, enri57ar <[EMAIL PROTECTED]> wrote:
>
>
> How access to request object within models ?
>
>
> from django.contrib.auth.models import User
>
> Class Message(models.Model):
&
How access to request object within models ?
from django.contrib.auth.models import User
Class Message(models.Model):
message = ...
user_id = models.ForeignKey(User)
def save(self):
user_id = request.user.id # doesn't work
super(Mensaje, self).save
roups.com
Para: Django users <django-users@googlegroups.com>
Asunto: Re: Handle on request object from custom tag
Fecha: 10/05/08 06:27
>
>
> That did it -- thanks.
>
> On May 9, 10:41 pm, James Bennett
[EMAIL PROTECTED] wrote:
> On Fri, May 9, 2008 at 10:11 PM, Greg Fuller
[EM
That did it -- thanks.
On May 9, 10:41 pm, "James Bennett" <[EMAIL PROTECTED]> wrote:
> On Fri, May 9, 2008 at 10:11 PM, Greg Fuller <[EMAIL PROTECTED]> wrote:
> > How do I get a handle on the request object from within a custom
> > template tag
On Fri, May 9, 2008 at 10:11 PM, Greg Fuller <[EMAIL PROTECTED]> wrote:
> How do I get a handle on the request object from within a custom
> template tag?
By making the request available to the template as a context variable,
then accessing it the same as any other cont
I searched for solutions/examples with no luck, but this can't be that
hard.
How do I get a handle on the request object from within a custom
template tag?
Thanks --- Greg F
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
On Jan 4, 7:34 am, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Thu, 2008-01-03 at 23:10 +0530, venkata subramanian wrote:
> > Hi,
> > I had a problem recently.
> > To access the request object in all of my templates.
> > The solution I got surprised m
> But, my question was not related to the how part.
>
> Here's a quick rundown of the "why".
>
> Templates aren't triggered by HTTP requests like views are. Instead,
> they're rendered inside views, which *are* triggered by HTTP requests.
> Since the request triggers
On Thu, 2008-01-03 at 23:10 +0530, venkata subramanian wrote:
> Hi,
> I had a problem recently.
> To access the request object in all of my templates.
> The solution I got surprised me. It involved explicitly passing on
> the request object from the views.
>
rendered inside views, which *are* triggered by HTTP requests.
Since the request triggers the view, it makes sense for the view to
receive the request object. Since templates are rendered by views, it
makes sense for templates to receive whatever the view sends them, and
nothing more. This is a design
I understand *how* it is done.
But, my question was not related to the how part.
On Jan 4, 12:17 am, Ariel Calzada <[EMAIL PROTECTED]> wrote:
> venkata subramanian wrote:
> > Hi,
> > I had a problem recently.
> > To access the request object in all of my templat
gt;
> <[EMAIL PROTECTED]> wrote:
> > Hi,
> > I had a problem recently.
> > To access the request object in all of my templates.
> > The solution I got surprised me. It involved explicitly passing on
> > the request object from the views.
> > (Example, to pa
venkata subramanian wrote:
> Hi,
> I had a problem recently.
> To access the request object in all of my templates.
> The solution I got surprised me. It involved explicitly passing on
> the request object from the views.
> (Example, to pass a RequestContext object as
PROTECTED]>
wrote:
> Hi,
> I had a problem recently.
> To access the request object in all of my templates.
> The solution I got surprised me. It involved explicitly passing on
> the request object from the views.
> (Example, to pass a RequestContext object as a context_insta
Security maybe?
Not sure, but if you add django.core.context_processors.request to
your TEMPLATE_CONTEXT_PROCESSORS list in settings.py, you won't have
to explicitly add the request object in every view. You still have to
pass a RequestContext object to the render_to_response method, but you
Hi,
I had a problem recently.
To access the request object in all of my templates.
The solution I got surprised me. It involved explicitly passing on
the request object from the views.
(Example, to pass a RequestContext object as a context_instance
parameter in render_to_response method
Hey Guys
Thanks for your great responses up to now - most interesting. Ive been
reading the documentation and thats been pretty useful (surprise
surprise!), but i have another question...
As the kind of per site skinning falls in line with some of the ideas
of the Django site object, it makes
On Sat, 2007-10-06 at 19:08 +, tim_perrett wrote:
> Thanks for the speedy reply Malcom...
>
> Ive taken a look at loaders.py in the latest trunk... I see what you
> mean; pretty interesting. I could just write my own loader, import any
> classes I needed to use (like the
Thanks for the speedy reply Malcom...
Ive taken a look at loaders.py in the latest trunk... I see what you
mean; pretty interesting. I could just write my own loader, import any
classes I needed to use (like the django.http.HttpRequest so I can use
get_host()) and even use the ORM in the
t() -- which is also
available as the get_host() method on the request object in recent
Django code (that was added in [6166]).
>
> I would then somehow need to change the template path, and this is
> where my understanding drops off I found this post
> http://www.nabble.com/How-to-p
-a-template-based-on-the-request-object--tf4153180.html#a11822505
but am not sure how i would or could go about building a custom
template loader? Also, would there be any scope for checking in the
database what theme a particular host name would recive? I am not new
to web dev, but am new to python
{% if item|in_cart:request %}
--~--~-~--~~~---~--~~
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
art from this bit. I know that I can make a
template tag that has access to the request object (added by the
Context Processors), but am a bit stuck as to how to do this in a
filter. Ideally I would like to do something like:
{% if item|in_cart %}foo{% else %}bar{% endif %}
So, all I really need to
ke to
> pick a template based on the request object. That's easy as long as I
> implement the views using something similar to the utility function
> render_and_response() which knows to add a template folder to the
> template name based on the request object.
>
> However, I'd like to a
Using threadlocals and a custom template loader would probably work,
just put your loader first in settings.py.
http://code.djangoproject.com/wiki/CookBookThreadlocalsAndUser
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the
n
> links he pointed to? They detail how you get the request object accessible
> in your templates, and thus your custom template tag.)
>
> In order to get access to the request object in your custom template tag,
> you must make some code changes elsewhe
I'll try to elaborate what James said. (Did you consult the documentation
links he pointed to? They detail how you get the request object accessible
in your templates, and thus your custom template tag.)
In order to get access to the request object in your custom template tag,
you must make
I don't know if I didn't understand you or if I you didn't don't
understand me :-)
Not sure abou what you are saying, I think I can't use it to make the
template tag work.
The template tag doesn't use a view to render the content, so it
doesn't get the request object as a parameter
On 4/3/07, Grupo Django <[EMAIL PROTECTED]> wrote:
> Inside the custom template tag, I don't get the request object since
> it's not a view.
Look into using RequestContext[1] in your views (generic views all use
it automatically), and enabling the "request" context proces
get the request object since
it's not a view.
I have no idea about how to retrieve the data.
And a secondary question related to this. If I wanted to retrieve a
value by GET within the template tag. Is it possible to access it?
Thank you very much
quick reply.
>
> > What I'm wondering about is that I've seen the pattern repeat itself
> > quite a few times where I have to write a little wrapper doing nothing
> > more than retrieving something from the `request` object.
> > Like
> > * reques
was doing at all.
I'm not really sure what answer you are expecting here. You have to
extract the user information at view processing time -- it can't be done
any earlier because that is the only time you have the accurate request
object. So you need to have views.
Small functions that d
Hi Malcolm,
Thanks for the quick reply.
What I'm wondering about is that I've seen the pattern repeat itself
quite a few times where I have to write a little wrapper doing nothing
more than retrieving something from the `request` object.
Like
* request.user.get_home_url
t;
> I'm wondering how can I eliminate the need for the
> `redirect_to_personalized_watch_list` and use django's `redirect_to`
> generic view? It'll be much easier if I could get `request` object in
> the `urls.py`.
You can't do this directly because of the different scopes the lines of
code are executed in. Any
`request` object in
the `urls.py`.
Thanks,
Alex
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from
Brilliant - thanks, Sam.
Is this in the docs anywhere, I wonder? I've seen a few queries along
these lines.
Might be an FAQ
Q
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to
On Mon, 19 Mar 2007 09:29:08 -0700, quentinsf wrote:
> I need to do something similar. In a form I want to limit the options
> in a ForeignKey's pull-down select field to objects owned by an
> organisation of which the user is a member.
>
> I've been trying to work out where this would fit.
I need to do something similar. In a form I want to limit the options
in a ForeignKey's pull-down select field to objects owned by an
organisation of which the user is a member.
I've been trying to work out where this would fit. Any help much
appreciated.
Is it possible to use a ManyToManyField's limit_choices_to attribute to
limit a user to picking only from related objects that have author =
request.user?
Given that request has no place in the model definition, would it be
necessary to write a custom manipulator?
--
Sam Morris
kahless wrote:
> hi,
> i want to make a simple template loader which loads from directories
> depending on the sub-site the user requests a page from. (or probably
> also from the user session - which theme he has set, etc.)
>
> so i would need to get the current request object
hi,
i want to make a simple template loader which loads from directories
depending on the sub-site the user requests a page from. (or probably
also from the user session - which theme he has set, etc.)
so i would need to get the current request object but haven't found a
solution
On 11/2/06, Merric Mercer <[EMAIL PROTECTED]> wrote:
> That looks like a very good way. Many thanks. For the sake of
> completeness - does that mean my earlier example wouldn't work? Or is
> just not preferred?
It could work provided the code in the 'test' view returns the
appropriate value,
as
Django seems to have many different ways to achieve a particular task.
Cheers
MerMer
James Bennett wrote:
> On 11/2/06, Merric Mercer <[EMAIL PROTECTED]> wrote:
>
>> Assuming I have a generic view. Can I used the "extra_context"
>> parameter to pass a requ
On 11/2/06, Merric Mercer <[EMAIL PROTECTED]> wrote:
> Assuming I have a generic view. Can I used the "extra_context"
> parameter to pass a request object to a function elsewhere or resolve
> request.path directly?
Why not use RequestContext instead of Context, and ena
Assuming I have a generic view. Can I used the "extra_context"
parameter to pass a request object to a function elsewhere or resolve
request.path directly?
Example of what I am trying to do is below:-
from django.http import HttpResponse, HttpRequest
from jmyapp.blog.views i
Hello,
I'm a Java programmer and new to the world of Python and Django.
Because of this, I could be missing something obvious trying to access
the request object from file urls.py in my project. Is it possible?
Where does the request object defined in the views as a parameter come
from?
Thank
couldn't we do something similar to get_active_site() call on the sites table?
that way people who need the 'request' object could just call it and
it wouldn't impact the api of anything else?
On 11/18/05, Adrian Holovaty <[EMAIL PROTECTED]> wrote:
>
> On 11/17/05, plisk <[
On 11/17/05, plisk <[EMAIL PROTECTED]> wrote:
> Seems like its not possible to access request object in hooks like
> pre_save and display methods(those are listed in list_display) ? Is it
> supposed to be like this by design ? If so then hardly its very
> convinient to use in
limodou wrote:
> 2005/11/17, plisk <[EMAIL PROTECTED]>:
> >
> > Hi there.
> >
> > Seems like its not possible to access request object in hooks like
> > pre_save and display methods(those are listed in list_display) ? Is it
> > supposed to be lik
101 - 200 of 203 matches
Mail list logo