redirect after login
Hi, I have the below line in my login code which decides the redirect screen on successful login redirect_to = request.REQUEST.get('next') However redirect_to is always evaluating to None even though the parameter 'next' is part of the url. Any idea what i might be doing wrong? Thanks in advance. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: redirect after login
On Tue, 2010-12-07 at 02:31 -0800, vamsy krishna wrote: > redirect_to = request.REQUEST.get('next') how about redirect_to = request.GET? -- regards Kenneth Gonsalves -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Django CSRF 1.2
I have a PERL test script for DJANGO connection test. It works on Django 1.1 admin login page, but doesn't work on 1.2. The request contains: Forbidden (403) CSRF verification failed. Request aborted. Here is the perl script: $response = $ua->get("$url/admin/"); my @lines = grep /id='csrfmiddlewaretoken'/,$response->content; $lines[0] =~ /id='csrfmiddlewaretoken' name='csrfmiddlewaretoken' value='([a-f0-9]+)'/; $csrfid=$1; my $req = HTTP::Request->new(POST => "$url/admin/", [csrfmiddlewaretoken=>$csrfid]); $req->header('Referer', "$url/admin/"); $ua->cookie_jar->add_cookie_header($req); $response = $ua->request($req); What's wrong? Have I forgot something? 1. Read the csrf hidden input 2. Keep cookies 3. Set csrf input to POST 4. Set cookie to headers 5. Set refer page (beacuse of HTTPS conection) 6. Make a POST request Where can I find similar python script to test login page? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: redirect after login
request.GET returns an empty dict On Dec 7, 3:35 pm, Kenneth Gonsalves wrote: > On Tue, 2010-12-07 at 02:31 -0800, vamsy krishna wrote: > > redirect_to = request.REQUEST.get('next') > > how about > redirect_to = request.GET? > -- > regards > Kenneth Gonsalves -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Query about GenericTabularInline
Hi I have set up a Generic inline (using generic.GenericTabularInline). It behaves differently (and from my application's point of view, wrongly) from the standard admin.TabularInline in two ways: 1. It doesn't have the plus icon next to foreign key fields that allows users to add new foreign objects directly from this view. 2. In settings.py I set TEMPLATE_STRING_IF_INVALID = 'PROGRAMMING ERROR! INVALID TEMPLATE STRING.' Unfortunately, this string then appears on the left of each entry in my GenericTabularInline. Have other people experienced this? If so, should I log this as a bug or am I doing something wrong or making a wrong assumption about how it should work? Thanks. Regards Nathan -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Authentication
Eeek, that looks pretty hacky, I wouldn't do that. I can think of a couple of options: Write some middleware that runs before the authentication middleware, and updates REMOTE_USER. or On your dev site only, specify that the RemoteUserMiddleware use a header rather than the REMOTE_USER environment variable (see the docs you were originally looking at), and use a browser extension to inject that header into your requests. Cheers Tom On Mon, Dec 6, 2010 at 10:04 PM, Mike Hull wrote: > Thanks Tom, > Out of interest, is there a good way of testing this. I want to work > on my site until I push it to the server, is there someway I can use > the > development server, but get it to set REMOTE_USER for testing > purposes? > > I tried the following: > > urls.py: > p = ( > > (r'^/?$', studentsite.views.viewIndex), > (r'view_tutorial_sheet/(\d+)/$', > studentsite.views.viewTutorialSheet), > (r'view_question/(\d+)/$', studentsite.views.viewQuestion), > > (r'upload_submission/$', studentsite.views.uploadSubmission), > (r'view_submission_details/(\d+)/$', > studentsite.views.viewSubmissionDetails), > > ) > > > > def decorateFunction(f): > > def newFunc(request, *args,**kwargs): > request.META['REMOTE_USER'] = "mytestuser" > return f(request, *args,**kwargs) > return newFunc > > p = tuple ( [ (url,decorateFunction(f)) for (url,f) in p] ) > > > host = socket.gethostname() > if host == 'ubuntu-temp': > p = p + ( > (r'^site_media/sphinx/(?P.*)$', 'django.views.static.serve', > {'document_root': '/home/michael/hw/infandango/src/labs/frontend/ > infandango-fe/static/sphinx/'}), > (r'^site_media/simplebutcool/(?P.*)$', > 'django.views.static.serve', {'document_root': '/home/michael/hw/ > infandango/src/labs/frontend/infandango-fe/static/simplebutcool/'}), > ) > > > urlpatterns = patterns('',*p) > > > in order to try and decorate each function so that I would manually > add the header to the request, but it doesn't seem to be working > If I look at the user object, it always seens to give an > AnnoymousUser. > > Any suggestions would be greatly appreciated! > > Thanks > > > Mike > > > On Dec 6, 4:00 pm, Tom Evans wrote: >> On Mon, Dec 6, 2010 at 3:10 PM, Mike Hull wrote: >> > Hi, >> > We are setting up a website using django and Cosign for >> > authentification, but I am not getting my head around django plays >> > withs apache user authentification, so I wonder if someone can shed >> > some light on how the pieces are supposed to fit together! >> >> > As I understand it; when Cosign is set-up, it sets a variable which >> > can be used in django: request.META["REMOTE_USER"] >> > What I dont understand is how does this fit in with the >> > auth.middleware. I read: >> >http://docs.djangoproject.com/en/dev/howto/auth-remote-user/ >> > what I understand is that if I enable auth.middleware, >> > then this will set the User variable in the context processor, which I >> > can then use in templates. >> > But how would I access this variable in a python view function, would >> > I do something like: >> >> > user = User.objects.get(id=request.META["REMOTE_USER"]) >> >> > to generate particular content for that user?? Or is there a simpler >> > solution? >> >> > Many thanks >> >> > Mike >> >> If you set up authentication as detailed in that article, then the >> current user is available as request.user, just as it is for all other >> auth backends. >> >> Cheers >> >> Tom > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
WEB service using Restify
THANKS FOR NOTIFICATION I am trying to do webservice with RESTfull web service but i dint create models my view file looks like this from django.http import * import urllib def current_datetime(request): word = request.GET['word'] message=urllib.urlopen('http://m.broov.com/wap/di/sub?word='+word+'&type=00submit=Submit',) return HttpResponse(message) My url looks like this (r'^wap/di/sub/',current_datetime ), i want to restify my view but all examples are showing oly models .py now i need help to do that THANKS -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: redirect after login
Did you get the next parameter in the login template and append it to form action, If that is not done then once the form is submitted the next param would be lost. On Dec 7, 5:45 am, vamsy krishna wrote: > request.GET returns an empty dict > > On Dec 7, 3:35 pm, Kenneth Gonsalves wrote: > > > On Tue, 2010-12-07 at 02:31 -0800, vamsy krishna wrote: > > > redirect_to = request.REQUEST.get('next') > > > how about > > redirect_to = request.GET? > > -- > > regards > > Kenneth Gonsalves -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Django CSRF 1.2
I'm sorry, the error was in my PERL code: $req->content("csrfmiddlewaretoken=$csrfid"); is the correct POST request setting. On Dec 7, 11:40 am, gentlestone wrote: > I have a PERL test script for DJANGO connection test. It works on > Django 1.1 admin login page, but doesn't work on 1.2. The request > contains: > > Forbidden (403) > CSRF verification failed. Request aborted. > > > Here is the perl script: > $response = $ua->get("$url/admin/"); > my @lines = grep /id='csrfmiddlewaretoken'/,$response->content; > $lines[0] =~ /id='csrfmiddlewaretoken' name='csrfmiddlewaretoken' > value='([a-f0-9]+)'/; > $csrfid=$1; > my $req = HTTP::Request->new(POST => "$url/admin/", > [csrfmiddlewaretoken=>$csrfid]); > $req->header('Referer', "$url/admin/"); > $ua->cookie_jar->add_cookie_header($req); > $response = $ua->request($req); > > What's wrong? Have I forgot something? > 1. Read the csrf hidden input > 2. Keep cookies > 3. Set csrf input to POST > 4. Set cookie to headers > 5. Set refer page (beacuse of HTTPS conection) > 6. Make a POST request > > Where can I find similar python script to test login page? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Suppressing validation
Hi all, How would I suppress validation on a django.forms control instance? Eg, I have: link = forms.CharField(widget=forms.TextInput(attrs={'size':'70'})) or link = forms.URLField() How would I stop Django from enforcing that the field must be populated with data? I think that this is what's causing my form not to save. -- Regards, Sithembewena Lloyd Dube -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Suppressing validation
On Tue, Dec 7, 2010 at 2:32 PM, Sithembewena Lloyd Dube wrote: > Hi all, > > How would I suppress validation on a django.forms control instance? Eg, I > have: > > link = forms.CharField(widget=forms.TextInput(attrs={'size':'70'})) > > or > > link = forms.URLField() > > How would I stop Django from enforcing that the field must be populated with > data? I think that this is what's causing my form not to save. > > -- > Regards, > Sithembewena Lloyd Dube > http://docs.djangoproject.com/en/1.2/ref/forms/fields/#required Cheers Tom -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Suppressing validation
Neat Tom, thanks! Lloyd On Tue, Dec 7, 2010 at 4:35 PM, Tom Evans wrote: > On Tue, Dec 7, 2010 at 2:32 PM, Sithembewena Lloyd Dube > wrote: > > Hi all, > > > > How would I suppress validation on a django.forms control instance? Eg, I > > have: > > > > link = forms.CharField(widget=forms.TextInput(attrs={'size':'70'})) > > > > or > > > > link = forms.URLField() > > > > How would I stop Django from enforcing that the field must be populated > with > > data? I think that this is what's causing my form not to save. > > > > -- > > Regards, > > Sithembewena Lloyd Dube > > > > http://docs.djangoproject.com/en/1.2/ref/forms/fields/#required > > Cheers > > Tom > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com > . > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- Regards, Sithembewena Lloyd Dube -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: WEB service using Restify
On Tue, Dec 7, 2010 at 1:50 PM, sami nathan wrote: > THANKS FOR NOTIFICATION > > I am trying to do webservice with RESTfull web service but i dint create > models > > my view file looks like this > from django.http import * > import urllib > > def current_datetime(request): > word = request.GET['word'] > > message=urllib.urlopen('http://m.broov.com/wap/di/sub?word='+word+'&type=00submit=Submit',) > return HttpResponse(message) > > My url looks like this (r'^wap/di/sub/',current_datetime ), > i want to restify my view but all examples are showing oly models .py > now i need help to do that > THANKS > I can't understand what you are trying to do. You have a view called current_datetime, which then queries a WML service that seems to look up words in a dictionary (ie nothing to do with dates or times), and you then say you want to 'restify my view'.. What precisely is it that you want to 'restify' about this view? Do you want POST requests to the service URL to create new entries in this dictionary, DELETE requests to remove words? Typically REST examples only show interaction with models, because REST is usually used to provide state-less web services for accessing collections of objects. You aren't doing any of that.. Cheers Tom -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Django forms - List of radio buttons and list of checkboxes?
Hi how to change this checkbox code to django form? Are you involved in any of the following? (check all that apply): Website Design Web Server Administration Electronic Commerce Web Marketing/ Advertising Web-related Education And how to make similar in django form to this: Poor 1 2 3 4 5 Excellent I was looking for a simple example but I couldnt find I found widget but I am not sure is the django form code: howreach = forms.ChoiceField(choices=boxes_choices, label='Are you involved in any of the following? (check all that apply):', widget=forms.CheckboxInput) is the same like the first checkbox code above? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Post URL characters problem
Hi, if you have ... when the form is submitted, django complains about this : Request Method: POST Request URL:http://mysite/blabla/topic/reply/114-test%20?/ Django Version: 1.3 pre-alpha SVN-13865 Exception Type: RuntimeError Exception Value: You called this URL via POST, but the URL doesn't end in a slash and you have APPEND_SLASH set. REQUEST_URI '/blabla/topic/reply/114-test%20?/' PATH_INFO u'/blabla/topic/reply/114-test ' PATH_TRANSLATED '/my.wsgi/blabla/topic/reply/114-test ' can anyone tell if this is a bug of django ? thanx. Keats. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Post URL characters problem
On Tue, Dec 7, 2010 at 3:26 PM, Keats wrote: > Hi, > if you have > id="addReplyForm" name="addReplyForm"> > ... > > > when the form is submitted, django complains about this : > Request Method: POST > Request URL: http://mysite/blabla/topic/reply/114-test%20?/ > Django Version: 1.3 pre-alpha SVN-13865 > Exception Type: RuntimeError > Exception Value: > > You called this URL via POST, but the URL doesn't end in a slash and > you have APPEND_SLASH set. > > REQUEST_URI '/blabla/topic/reply/114-test%20?/' > PATH_INFO u'/blabla/topic/reply/114-test ' > PATH_TRANSLATED '/my.wsgi/blabla/topic/reply/114-test ' > > can anyone tell if this is a bug of django ? > > thanx. > Keats. > Why do you think it is a bug? The URL doesn't match one in your urlconf, but would with an appended slash, which is missing from the URL (the '/' in your URL is part of the query string). Since this is a POST request, it cannot redirect without losing data, so it is a runtime error. Cheers Tom -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: admin view
To fire off an action (method) after an object is saved, you want to listen for its signal. Check out http://docs.djangoproject.com/en/dev/topics/signals/ On Mon, Dec 6, 2010 at 11:28 PM, commonzenpython wrote: > hey guys, im trying to get a script to run, like a view after a user > in the admin interface checks a box and saves the object, is there any > way of accomplishing this without having to rewrite the add_view, and > edit_view ? > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com > . > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: General question about NOT EXISTS...
> > How does that look when you are building an object list in the Q( )... > style format? Where I am hung up is finding syntax examples of how to > do the functional equivalent of a sql where not exists clause. > > Is there a way to do this without using .extra() and using just normal > django? > > Look here: http://docs.djangoproject.com/en/dev/topics/db/queries/#complex-lookups-with-q-objects Basically, you specify the keywords just as you would in regular field lookups, and you can use &, |, and ~ to AND, OR, or COMPLEMENT (negate) your results. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Post URL characters problem
the urlpattern is : ^'/blabla/topic/(?P\d+)-(?P.*)/$ and i think it's a bug because if you see request URL there is a slash and if it was an urlconf problem django would have reply url not found. i think the problem is linked to the fact that the test topic ends with "?" and for some reason django is bothered by it... maybe because "?..."are usually processed has get variables... thanx Keats. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Post URL characters problem
As I explained in my original email, the URL in your example _DOES NOT_ end in a slash. It has a query string that ends with a slash which is _NOT_ the same thing. Sorry to shout, but I explained it quite clearly before :/ Cheers Tom On Tue, Dec 7, 2010 at 3:50 PM, Keats wrote: > the urlpattern is : > ^'/blabla/topic/(?P\d+)-(?P.*)/$ > > and i think it's a bug because if you see request URL there is a > slash > and if it was an urlconf problem django would have reply url not > found. > i think the problem is linked to the fact that the test topic ends > with "?" and for some reason django is bothered by it... > maybe because "?..."are usually processed has get variables... > > thanx > Keats. > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Django in production on Windows
I'm not the windows guru I used to be. Converted my household to Ubuntu Linux and have been pretty happy since. The kids miss some flash games, I don't miss the virus issue. www.cygwin.com is one possible windows avenue that might work. When I was hanging on to windows because I had to support it, I used cygwin religiously. I found a lot about cygwin to be frustrating, but it was better than being w/out unix/linux all-together. Unless you absolutely positively must remain a Windows/Microsoft supporter, I recommend grabbing an old decommissioned box and slap Linux on it. It's gotten a lot easier with the latest distributions. I use Ubuntu for most, but Cent-os might be just what you need, and I've heard good things about Mint, but haven't gone there. If you can live without the Xwindows/GUI almost *any* machine will work and perform just fine. W/Google and apt-get command line, you should be able to get a box up and running inside of a couple of hours. I can imagine Linux is frightening, but it doesn't need to be. For me it's like a big box of toys, you might have to do a fair amount of reading, but there's a lot of good documentation and Google can be your friend. I prefer googling linux issues over Microsoft Technet issues. Tech-net can be such a royal PITA. Ctrl-R for reverse command line search was a godsend to me, why Microsoft has never implemented something, so useful, is beyond me. F5-F6, I forget which key brings up the annoying scroll box for command history... What were they thinking? Argh, soo far off topic, my apologies. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
sum() of Model field or DB field
hi I want to use mysql Query : Select sum(field_name) FROM table_name WHERE some condition. Is it possible without using raw queries in Django ? if yes, please help. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: sum() of Model field or DB field
You want to use an aggregation function: http://docs.djangoproject.com/en/dev/ref/models/querysets/#aggregation-functions On Tue, Dec 7, 2010 at 11:14 AM, Jagdeep Singh Malhi < singh.malh...@gmail.com> wrote: > hi > > I want to use mysql Query : > Select sum(field_name) FROM table_name WHERE some condition. > > Is it possible without using raw queries in Django ? > if yes, please help. > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com > . > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: sum() of Model field or DB field
for raw sql queries: http://docs.djangoproject.com/en/dev/topics/db/sql/ On Dec 7, 7:14 pm, Jagdeep Singh Malhi wrote: > hi > > I want to use mysql Query : > Select sum(field_name) FROM table_name WHERE some condition. > > Is it possible without using raw queries in Django ? > if yes, please help. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
returning type and value
Hi all, I have this in my model.py def recipe_cost(self): total = IngredientInfo.objects.filter(recipe = self.id).aggregate(Sum('total')).values() return total Then in my admin.py I call that to display the cost. class RecipeAdmin(admin.ModelAdmin): list_display = ('title','recipe_cost') I can see the cost but it's being returned like this: [Decimal('500.00')] But obviously I'd just want the value 500. What should I change? Thanks -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
How to use django-command-extentions dumpscript?
Hi all, I'm trying out django-command-extensions I want to use the dumpscript command but I don't understand what I'm supposed to do to set it up. How to use django-command-extentions dumpscript? Thanks -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: makemessages failing to extract all strings from Javascript
I'm still struggling with the javascript translation problem, so it seems like I'm forced to pull it out of the project I'm working on. If anybody has any input I'm still interested. -Lau On Nov 24, 3:39 am, Lau wrote: > I'm having some trouble with makemessages failing while parsing my > javascript files. I'm running it with domain set todjangojsand it's > successfully finding all my javascript files but keeps halting during > the parsing. > > I did a bit of debugging in the makemessages command (Django version > 1.2.1 and trunk) and found that when running indjangojsmode it > pythonizes the javascript files with pythonize_re.sub('\n#', src), but > then runs the xgettext shell command with language "Perl". Why is > this? > > The javascript code it's bailing out on is stuff like this: > > message.css("margin-left", -1*message.width()/2); > $(".action", form).val(id ? "change" : "create"); > > The outcome is a bit random, for some javascript functions the parser > just skips the function, which also skips the gettext calls in it, and > at other times it just breaks out of the whole file with no further > processing. So I'm not entirely sure what the makemessages command is > supposed to be doing ("converting" the javascript to python and > running xgettext on it as if it were perl?). > > Any clarification on this would be great, thanks! > > -Lau -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: returning type and value
On Tue, Dec 7, 2010 at 5:29 PM, mongoose wrote: > Hi all, > > I have this in my model.py > def recipe_cost(self): > > total = IngredientInfo.objects.filter(recipe = > self.id).aggregate(Sum('total')).values() > > return total > > Then in my admin.py I call that to display the cost. > class RecipeAdmin(admin.ModelAdmin): > list_display = ('title','recipe_cost') > > I can see the cost but it's being returned like this: > [Decimal('500.00')] > > But obviously I'd just want the value 500. What should I change? > > Thanks > What you are calling total isn't the total, its a ValuesQuerySet. You want to extract the value from there, and convert it into whatever format you want. Eg: def recipe_cost(self): qs = IngredientInfo.objects.filter( recipe=self.id).aggregate(Sum('total')).values() return unicode(qs[0]) Cheers Tom -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Alphabetic filtering of Django Admin drop down menu
Hi All In one of tables that we access through the Admin menu we have around 50,000 objects which return string o/p as the return value, but the problem is that it takes too long for them to load ( more than few minutes) in a drop down I have also gone through the raw_id_fields but it doesn't fit our requirement Is there a way that we can have alphabetic pagination in the drop down menu of Admin Thanks in advance Subramanyam -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Alphabetic filtering of Django Admin drop down menu
If you can't use raw_id_fields i guess you should write that view and use javascript to search inside the view. Can you use a auto complete approach instead a drop down menu? If you can, my suggestion is to use a jquery plugin to do the hard work: http://docs.jquery.com/Plugins/autocomplete -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: django auth for existing cgi
Copying things from request.META to the env parameter of Popen allows me to get the cgi off the ground. Now I have the problem that the cgi is generating a cookie and content type, which django returns to the browser as page content. Is there a way to pass it back transparently? Or, failing that, can someone point a newbie to an appropriate method to parse the header so it can be used to create a HttpResponse? On Mon, Dec 6, 2010 at 7:06 PM, Wayne Smith wrote: > > > On Mon, Dec 6, 2010 at 4:42 PM, bc wrote: >> >> Is there any simple way to use django authentication/authorization to >> control access to an existing (not django) cgi? >> >> I could use subprocess.Popen to invoke the cgi after checking >> authorization, but the environment needs to be set up to look like a >> cgi call (setting QUERY_STRING, etc.). Is there a better way? >> > > I don't know if you could do some special trick with an HttpRequest or some > kind of redirect from one view to hit the cgi script with the automatically > created (HttpRequest) data. I'm guessing the answer is no or more trouble > than it would be worth, but that's just a guess. > > I would say you really have two options. > > 1. Implement the script in Python, and bring it in under Django. > > 2. Craft your own Http Request header with Python's libraries and point it > to the cgi script. > >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Django users" group. >> To post to this group, send email to django-us...@googlegroups.com. >> To unsubscribe from this group, send email to >> django-users+unsubscr...@googlegroups.com. >> For more options, visit this group at >> http://groups.google.com/group/django-users?hl=en. >> > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Migrating to class-based views and django.core.urlresolvers.reverse
Moved from django-developers: On 7 December 2010 20:15, Sean Brant wrote: > Again this topic is now in django-user land. > > I do this in views.py if want the decorator on all methods (get|post). > > myview = login_required(MyView.as_view()) > > > > On Dec 7, 2010, at 1:10 PM, Daniel Swarbrick > wrote: > >> That is indeed in the docs, and I have seen that. What eludes me is >> how to use decorators more complex than login_required() from within >> urls.py. >> >> For example, this works fine: >> >> from django.contrib.auth.decorators import user_passes_test >> from django.utils.decorators import method_decorator >> from django.views.generic import TemplateView, View >> >> class IndexView(TemplateView): >> template_name = 'index.html' >> >> �...@method_decorator(user_passes_test(lambda u: u.is_superuser)) >> def dispatch(self, *args, **kwargs): >> return super(IndexView, self).dispatch(*args, **kwargs) >> >> But how would one avoid having to override the dispatch() method on >> many classes, and put the user_passes_test() decorator in the urls.py >> definition? Or for that matter, the permission_required() decorator? One option is to make a base class that has the right method decorated and then subclass it. This is what the docs show. Another is to decorate the function returned by as_view(). >> >> As a side note, could a mixin be used to setup permission_required, >> login_required etc, and user-defined class-based views be derived from >> multiple parent classes? Yes. Some decorators make sense as Mixins, others don't - it's a matter of judgement. IMHO, login_required doesn't make much sense as a Mixin. >> >> Sorry if this has meandered into django-users land... maybe some >> advanced CBV examples in the docs? Here's a view from my project: @view_decorator(never_cache) @view_decorator(csrf_exempt) @view_decorator(domain_required(login=True)) class FileCollectionView(JSONMixin, PersonMixin, SingleObjectMixin, View): # lots of secret code :) pass This uses view_decorator() function I wrote[1], which is a shortcut for overriding ``as_view`` method (I prefer to override that instead of ``dispatch``). Maybe you'll find it helpful. [1]: https://github.com/lqc/django/blob/0eb2de3c156d8e6d1c31f46e0734af0ff06f93c4/django/utils/decorators.py#L46 -- Łukasz Rekucki -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Feature Flipper
I'm working on an (open source) project that wants to move to continuous deployment and could do with "feature flipper" functionality similar to that discussed at http://www.alandelevie.com/tag/feature-flippers/ We'd envisage it being a separate application that we'd release as open source. Does anyone know of something similar around, or in development? Toby Champion, Seattle, WA -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Is this a good practice, or is it just plain stupid?
Hi everyone, I hope that this group is the good one for this kind of questions. So today, I decided to write a tiny django app (in less than 5 minutes actually) that helps me add views arguments to templates contexts automatically. For eg. def latest_tagged_objects(request, obj, limit, tag): """ Displays the 'limit' latest objects 'obj' tagged with 'tag' """ # Retrieve these objects #create a context that will include the args passed to this view along with #other variables context = dict( obj=obj, limit=limit, tag=tag, #Other variables here ) I do this often. i.e. add views arguments to my context, so I wanted to write a middleware and a context processor that will do it for me. I wrote this: https://github.com/initpy/django-viewctx With this app I can omit 'obj', 'limit', and 'tag' in the previous dict and have them available in my template as: {{view.kwargs.obj}}, {{view.kwargs.limit}} and {{view.kwargs.tag}} It was so simple that I'm still wondering if it is a good practice or just stupid. Thanks for your help and suggestions! -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: doing validation in admin form
On 12/06/2010 04:18 PM, Wayne Smith wrote: > Then yes, in the clean() method of your Galeria form, you could check the > number of fotos present and then raise a ValidationError if it is too many, > along with a custom message for the user. > > Is that what you wish to do? > hi I think the "clean" method wont solve the problem because at the time it is called, the inlines from galeria have not been saved yet... This is what happen when I submit a form with a galeria and two fotografias. the methods are called in this order: 1. Galeria.clean - don't know the fotografias yet! 2. GaleriaAdmin.save_model (before calling super.save_model) 3. Galeria.save ( before calling super.save) 4. galeria presave signal 5. galeria presave signal 6. galeria postsave signal 7. galeria postsave signal 8. Galeria.save ( after calling super.save) 9. GaleriaAdmin.save_model (after calling super.save_model) 10. Fotografia.save - first foto - only now the fotos are saved... 11. Fotografia.save - second foto So it seems if someone wants to execute some code after all the form has been processed, he has to do that somewhere else. [ Maybe in the form submit view? ] Anyway if I want to perform a validation there, it is to late. Maybe the only solution would be to do that in the GaleriaAdmin.save_model, and have to see the request parameters to know how many new files have been uploaded... signature.asc Description: OpenPGP digital signature
Re: Django in production on Windows
On 8 December 2010 02:50, shmengie <1st...@gmail.com> wrote: > www.cygwin.com is one possible windows avenue that might work. When I > was hanging on to windows because I had to support it, I used cygwin > religiously. I found a lot about cygwin to be frustrating, but it was > better than being w/out unix/linux all-together. That isn't really going to help. The issue isn't *nix compatibility, but connecting Django with IIS. FastCGI is the official way to go; the other ISAPI modules are the next best thing. I work with both platforms, and I've lost count the number of times I've typed 'ls' into a Windows command prompt and have it error out :) Luckily it works in PowerShell, which is one of the things that Windows does that's better than *nix. > Unless you absolutely positively must remain a Windows/Microsoft > supporter, I recommend grabbing an old decommissioned box and slap > Linux on it. It's gotten a lot easier with the latest distributions. > I use Ubuntu for most, but Cent-os might be just what you need, and > I've heard good things about Mint, but haven't gone there. If you can > live without the Xwindows/GUI almost *any* machine will work and > perform just fine. W/Google and apt-get command line, you should be > able to get a box up and running inside of a couple of hours. It doesn't work like that in corporate environments. You can't just set up a box and connect it to the network - the IT admins will scream at you (at the very least). They need to be properly assessed, configured, and most importantly maintained - an improperly maintained/configured *nix box isn't secure either. And as OP doesn't have any *nix admins, it isn't going to happen unless they hire or outsource. > I can imagine Linux is frightening, but it doesn't need to be. For me > it's like a big box of toys, you might have to do a fair amount of > reading, but there's a lot of good documentation and Google can be > your friend. I prefer googling linux issues over Microsoft Technet > issues. Tech-net can be such a royal PITA. It isn't utopia on the Linux side either - with the slight variations between every Linux distro, often solutions you find don't exactly work because of some annoying difference (versions, config paths, location of files, default packages etc.). > Argh, soo far off topic, my apologies. So back to on to the topic - Is the issue that FastCGI isn't up to scratch in terms of performance, or is it not working at all? > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: admin view
thanks for your reply, iv been reading the documentation, and wrote the code, but theres one thing im having trouble with, i included the signal connection in my models.py, and passed the model that was there to the handler function so that it can be tied to that specific model, like so class foo(models.Model): #model code here def handler(sender=foo, **kwargs): #code to be executed when model foo saved post_save.connect(handler) now, in the code to be executed i instantiate a class that imports the model foo, but django wont import it -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
handling generated files
Hi, How do I use Django's FileField with autogenerated files? That is, these files aren't uploaded by a user, but rather are created on the fly. I've looked at ContentFile, but this class doesn't seem to have a way to attach a file name (the name is also computed at run-time based on some criteria). Do I need to write my own implementation of File for this or am I missing an existing class? Thanks Dmitry -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Feature Flipper
On Wed, Dec 8, 2010 at 3:15 AM, Toby Champion wrote: > I'm working on an (open source) project that wants to move to > continuous deployment and could do with "feature flipper" > functionality similar to that discussed at > http://www.alandelevie.com/tag/feature-flippers/ > We'd envisage it being a separate application that we'd release as > open source. Does anyone know of something similar around, or in > development? > I am not sure whether anything similar already exists, but i dont think it would be tough to implement. One of the approaches would be to store the features in a table - the features can be associated with functions or in the function(as mentioned in the same ruby code there, in this case-the view) check the value of this feature and have the flow based on this. (So, if you notice, its basically a lookup) -V http://twitter.com/venkasub -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Django in production on Windows
Eeek. Just had a poke around with getting Django running on IIS. Making it work with FastCGI will need a bit of work; doesn't work out of the box and isn't well documented as most of the focus has been on PHP. It does seem to work ok with PyISAPIe. I'd probably install Apache and use that instead though, either replacing IIS, or using IIS as a reverse proxy to Apache. On 8 December 2010 11:07, Sam Lai wrote: > On 8 December 2010 02:50, shmengie <1st...@gmail.com> wrote: >> www.cygwin.com is one possible windows avenue that might work. When I >> was hanging on to windows because I had to support it, I used cygwin >> religiously. I found a lot about cygwin to be frustrating, but it was >> better than being w/out unix/linux all-together. > > That isn't really going to help. The issue isn't *nix compatibility, > but connecting Django with IIS. FastCGI is the official way to go; the > other ISAPI modules are the next best thing. > > I work with both platforms, and I've lost count the number of times > I've typed 'ls' into a Windows command prompt and have it error out :) > Luckily it works in PowerShell, which is one of the things that > Windows does that's better than *nix. > >> Unless you absolutely positively must remain a Windows/Microsoft >> supporter, I recommend grabbing an old decommissioned box and slap >> Linux on it. It's gotten a lot easier with the latest distributions. >> I use Ubuntu for most, but Cent-os might be just what you need, and >> I've heard good things about Mint, but haven't gone there. If you can >> live without the Xwindows/GUI almost *any* machine will work and >> perform just fine. W/Google and apt-get command line, you should be >> able to get a box up and running inside of a couple of hours. > > It doesn't work like that in corporate environments. You can't just > set up a box and connect it to the network - the IT admins will scream > at you (at the very least). They need to be properly assessed, > configured, and most importantly maintained - an improperly > maintained/configured *nix box isn't secure either. And as OP doesn't > have any *nix admins, it isn't going to happen unless they hire or > outsource. > >> I can imagine Linux is frightening, but it doesn't need to be. For me >> it's like a big box of toys, you might have to do a fair amount of >> reading, but there's a lot of good documentation and Google can be >> your friend. I prefer googling linux issues over Microsoft Technet >> issues. Tech-net can be such a royal PITA. > > It isn't utopia on the Linux side either - with the slight variations > between every Linux distro, often solutions you find don't exactly > work because of some annoying difference (versions, config paths, > location of files, default packages etc.). > >> Argh, soo far off topic, my apologies. > > So back to on to the topic - > > Is the issue that FastCGI isn't up to scratch in terms of performance, > or is it not working at all? > >> -- >> You received this message because you are subscribed to the Google Groups >> "Django users" group. >> To post to this group, send email to django-us...@googlegroups.com. >> To unsubscribe from this group, send email to >> django-users+unsubscr...@googlegroups.com. >> For more options, visit this group at >> http://groups.google.com/group/django-users?hl=en. >> >> > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: sum() of Model field or DB field
On Dec 7, 10:16 pm, Wayne Smith wrote: > You want to use an aggregation > function:http://docs.djangoproject.com/en/dev/ref/models/querysets/#aggregatio... > Thanks, Problem solve. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Django based issue tracker
The button on the first page of http://www.django-projector.org/ says "Sing up for the demo project". Makes a refreshing change from the usual getting started red-tape ;) On Dec 7, 6:59 am, zodman wrote: > django-projector > > > > On Wed, Nov 10, 2010 at 2:05 PM, Toby Champion > wrote: > > I don't know of a Django-based issue tracker that's in active > > development, but I'd suggest you first try using a web-based, hosted > > tool. If your project is simple enough, something > > likehttp://www.unfuddle.com/ > > might meet your needs. Accounts are free for very small projects, and > > include a SVN or Git repository. Otherwise Trac, which is of course > > used for tracking issues in Dango itself athttp://code.djangoproject.com/, > > so at least you know there's knowledge in the community. It's written > > in Python, too, so if you enjoy working in Python even without Django, > > you're onto a winner. > > > On Nov 10, 12:12 am, Joakim Hove wrote: > >> Hello, > > >> I am setting up a bug/issue tracker - the project is quite small and I > >> do not have complex needs. As I enjoy working with Django I was > >> looking for a Django based solution. Can someone reccomend a Django > >> based issue tracker? > > >> In case I fail finding something based on Django I think I will use > >> Trac which seems quite nice. > > >> Joakim > > > -- > > You received this message because you are subscribed to the Google Groups > > "Django users" group. > > To post to this group, send email to django-us...@googlegroups.com. > > To unsubscribe from this group, send email to > > django-users+unsubscr...@googlegroups.com. > > For more options, visit this group > > athttp://groups.google.com/group/django-users?hl=en. > > -- > Andres Vargaswww.zodman.com.mx -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.