Re: Help with django-paypal anyone?

2012-03-21 Thread Jonathan Baker
You'll need to enable the CSRF middleware, adjust your view and make use of
the {% csrf_token %} template tag in your template. Details can be found
here: https://docs.djangoproject.com/en/dev/ref/contrib/csrf/

On Wed, Mar 21, 2012 at 11:35 PM, Stanwin Siow wrote:

> Hello,
>
> I was following this tutorial on django-paypal from this link:
> http://od-eon.com/blogs/nai/django-paypal-step-step-integration/?c=619
>
> i managed to get the paypal button working but when i click return to home
> page i get a CSRF token not found.
>
> Please advise on how i should continue?
>
> I would appreciate any help rendered.
>
> Thank you.
>
> Best Regards,
>
> Stanwin Siow
>
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>



-- 
Jonathan D. Baker
Web Developer
http://jonathandbaker.com
303.257.4144

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



Help with django-paypal anyone?

2012-03-21 Thread Stanwin Siow
Hello,

I was following this tutorial on django-paypal from this link:  
http://od-eon.com/blogs/nai/django-paypal-step-step-integration/?c=619

i managed to get the paypal button working but when i click return to home page 
i get a CSRF token not found.

Please advise on how i should continue?

I would appreciate any help rendered. 

Thank you.

Best Regards,

Stanwin Siow



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



Re: find django template developers

2012-03-21 Thread Carlos Daniel Ruvalcaba Valenzuela
There is also djangopeople.me where you can directly find people and it is free.

I'm not affiliated to them in any way but I have had jobs before from
people cold calling me after finding me in djangopeople.

Regards,
Carlos Ruvalcaba

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



Re: find django template developers

2012-03-21 Thread Sithembewena Lloyd Dube
Hi Brian,

What kind of work do you want done?

PM me if you like.

On Tue, Mar 20, 2012 at 6:23 PM, brian wrote:

> What are the resources to find django template developers?
>
> I've posted my project to:
> https://www.elance.com
> http://www.getacoder.com
> https://www.odesk.com
> https://www.freelancer.com
>
> I've read on the forums about http://djangogigs.com/ but they seem
> over priced and doesn't seem to have a lot of activity.  I've also
> read about http://www.donanza.com/jobs/django but that just seems like
> a screen scraper.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


-- 
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-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: redirect page/view after login in 'django-registration'

2012-03-21 Thread Ahmad Abd Arrahman
edite this line in your settings.py or add it if not there

#Login redirects to
LOGIN_REDIRECT_URL = '/accounts/profile'

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



Is there a place for new Django specialized hosting?

2012-03-21 Thread Martin Tiršel

Hello,

I am playing with an idea to create a hosting service specialized for  
Django. I would be glad if you can provide some feedback if you would use  
such service (or why not) and what monthly fee would you pay for this.


This would be based on virtual servers without root access (only  
unprivileged shell access) with web based administration:


* create so many webs you want (or resources allows)
* separated webserver for media files/static content
* virtualenv support, multiple python versions
* SVN/Git
* testing/production environment (clone production data to testing  
environment [app, media, database] -> export project from svn/git -> apply  
migrations -> test -> apply to production)

* one click trac installation
* integrated web based editor for some quick changes/fixes  
(http://ace.ajax.org/)

* backup/restore
* some tools that makes life easier like one click project initialization  
inside svn/git and prepared settings (so you don't need to create project,  
add it to repository and rewrite common settings), ...

* basic support for Django
* easy SSL certificate installation
* and many others :)

There could be two programs, for example 1GB RAM, 2 vCPU's, 30 GB HDD or  
2GB RAM, 3 vCPU's, 50GB HDD


My goal is to provide an environment for developers with multiple projects  
that wants virtual server but don't want/know to install/configure such  
virtual server. Or is there already a service like this?


Thanks,
Martin

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



Re: Having all objects defined in Models.py editable in one admin page

2012-03-21 Thread Sithembewena Lloyd Dube
Thanks Andre! That idea did cross our minds, but the scope and certainly
the budget of this project do not allow for building of a "from scratch"
admin site with custom views. I can only implement Django's default admin
site and create views/ a front end only for the actual app. logic.

On Wed, Mar 21, 2012 at 8:12 PM, Andre Terra  wrote:

> Try writing your own views rather than expanding the Admin. It's well
> worth it in the long run!
>
>
> Cheers,
> AT
>
> On Wed, Mar 21, 2012 at 1:50 PM, Sithembewena Lloyd Dube <
> zebr...@gmail.com> wrote:
>
>> Hi guys,
>>
>> I am building a learning application for a client. The problem we are
>> experiencing is that of inlines. We have multiple related objects and the
>> client wants to be able to edit all objects from one CRUD. Unfortunately,
>> there seems to be no solution for multiple inlines in a Django admin.
>> application. Is there a sensible way to address this problem?
>>
>> --
>> 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-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>



-- 
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-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: using forloop.counter to access data

2012-03-21 Thread Andre Terra
You could always try writing a custom template tag or filter as someone
else suggested earlier in the thread before resorting to JavaScript.

Cheers,
AT
On Mar 21, 2012 5:41 PM, "Larry Martell"  wrote:

> On Wed, Mar 21, 2012 at 12:52 PM, James  wrote:
> >
> >
> > On Wednesday, March 21, 2012 10:41:08 AM UTC-4, Larry@gmail.comwrote:
> >>
> >> On Wed, Mar 21, 2012 at 7:53 AM, James <> wrote:
> >> >
> >> >
> >> > On Wednesday, March 21, 2012 8:47:23 AM UTC-4, larry@gmail.com
> >> > wrote:
> >> >>
> >> >> This is probably a stupid newbie question 
> >> >>
> >> >> I want to access a column of data in a row using forloop.counter, but
> >> >> I cannot get it to work.
> >> >>
> >> >> In my test code, if I display {{ forloop.counter }} I get 2
> >> >> If I display {{ headers.0.2 }} I get ToolType
> >> >> But if I display {{ headers.0.forloop.counter }} I get nothing
> >> >>
> >> >> What is the proper syntax for this?
> >> >
> >> >
> >> > the forloop.counter and friends will simply give you information about
> >> > the
> >> > iteration, it won't give you any information about the data in the
> >> > queryset
> >>
> >> Yes, I realize that. I am using it withing a loop to try an access a
> >> specific item of data. The code I showed was just an example from one
> >> iteration of the loop.
> >>
> >> > (I'm assuming this is what you mean when you say column).
> >> >
> >> > Here are the
> >> >
> >> > docs
> https://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs#for
> >> >
> >> >  If you want to access the column of data, assuming it's referenced
> from
> >> > a
> >> > model, just the attribute of that model. If you passed in a list to
> the
> >> > template, you just use the django "dot" look-up syntax.
> >>
> >> Perhaps my question wasn't clear. I have a list called headers. From
> >> within a for loop I want the n'th item from the first row. In the loop
> >> I am trying to access {{ headers.0.forloop.counter }} but I get no
> >> value from that. But if I hard code the number (as a test), e.g.:  {{
> >> headers.0.2 }} then I do get the value.
> >
> >  With regards to your reply:
> >
> >
> >>  Yes, I realize that. I am using it withing a loop to try an access a
> >> specific item of data. The code I showed was just an example from one
> >> iteration of the loop.
> >
> >
> > You can't use forloop and friends in the manner you attempting to use it.
> > It's The reason is, headers.0 has no attribute named "forloop"
> >
> > The best that you could do here, in this situation, is to create a custom
> > filter and pass it forloop.counter as variable like so:
> > {{ headers.0|forloop.counter }} You will of course have to write that
> filter
> > out first, register it, and install it in the template.
> >
> > I'm still not sure if this is the right approach. Why not just iterate
> over
> > the list itself, if you want to print the nth item within the list?
>
> That would be really inefficient, as the table can have thousands of
> rows, with 30 columns each. I'd have to iterate through the header row
> for each column in each row to get the value to put into the href.
>
> > Or,
> > structure the list/queryset from the view such that you don't have to do
> > such acrobatics.
> >
> >>  But if I hard code the number (as a test), e.g.:  {{
> >> headers.0.2 }} then I do get the value.
> >
> >
> > This works because headers.0 has an attribute that works by way of the
> > django dot look up. See Tom Evan's post regarding this.
> >
> > It seems to me that you have a list of lists (and not a single list). In
> > which case, you can just iterate over the first list and iterate over the
> > second list. If you need some control flow, just use the standard if /
> else
> > conditions. But, maybe I'm missing something?
>
> Yes, I think you are. I have 2 header rows, and thousands of data
> rows. For each column in each data row I have to construct a href. One
> of the parameters in the href comes from the first header row. The
> header rows get processed first, then the data rows (to build the
> table). So by the time I am processing the data I don't have the
> header any more. I should probably just do this in javascript.
>
> > Even easier would be to use django's introspect feature and create models
> > based on the tables in the DB, query the DB using the models and create
> > querysets. Then you can access and display the data in a more
> > coherent manner.
> >
> > see the docs here for
> > introspection:
> https://docs.djangoproject.com/en/dev/howto/legacy-databases/?from=olddocs
>
>
> That already is the case. I am trying to add functionality to an existing
> app.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this 

Re: redirect page/view after login in 'django-registration'

2012-03-21 Thread Mario Gudelj
You do this in your settings file. Not sure of the exact sintax but it's
something like login="yoururl".

On 22/03/2012 10:45 AM, "H.T. Wei"  wrote:

> Hey,
>
> I used 'django-registration' for user registration. Is there anyone know
> how configure to redirect the page/view I want after login?
> Thanks in advance.
>
> --
> " stay hungry, stay foolish"
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



redirect page/view after login in 'django-registration'

2012-03-21 Thread H.T. Wei
Hey,

I used 'django-registration' for user registration. Is there anyone know
how configure to redirect the page/view I want after login?
Thanks in advance.

-- 
" stay hungry, stay foolish"

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



twitter timeline

2012-03-21 Thread Randa Hisham
hey
iam going to make an app that read the timeline of a user from twitter what
django package do you recommend?

-- 
Randa Hesham
Software Developer

Twitter:@ro0oraa 
FaceBook:Randa Hisham 

ٍ

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



Re: Preventing JOIN while checking if a self referencing FK is null

2012-03-21 Thread Andre Terra
Sorry. In the process of changing model names to fit my own installation
and test the code, I also managed to invert the relation.

Pay no attention to the man behind the curtains!

Cheers,
AT
On Mar 21, 2012 6:42 PM, "diafygi"  wrote:

> I cannot confirm that behavior. Can others verify?
>
> I'm using Django 1.3 and I get:
> >>> print Blog.objects.filter(editor=None).values('id').query
> SELECT `myapp_blog`.`id` FROM `myapp_blog` LEFT OUTER JOIN
> `myapp_user` ON (`myapp_blog`.`editor_id` = `myapp_user`.`id`) WHERE
> `myapp_user`.`id` IS NULL
>
> -Daniel
>
> On Mar 21, 2:07 pm, Andre Terra  wrote:
> > On Wed, Mar 21, 2012 at 5:41 AM, diafygi  wrote:
> > > >>> Blog.objects.filter(editor=None)
> >
> > >>> print Blog.objects.filter(editor=None).values('id').query
> >
> > SELECT "myapp_blog"."id" FROM "myapp_blog" WHERE "myappblog"."editor_id"
> IS
> > NULL
> >
> > Cheers,
> > AT
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Preventing JOIN while checking if a self referencing FK is null

2012-03-21 Thread diafygi
I cannot confirm that behavior. Can others verify?

I'm using Django 1.3 and I get:
>>> print Blog.objects.filter(editor=None).values('id').query
SELECT `myapp_blog`.`id` FROM `myapp_blog` LEFT OUTER JOIN
`myapp_user` ON (`myapp_blog`.`editor_id` = `myapp_user`.`id`) WHERE
`myapp_user`.`id` IS NULL

-Daniel

On Mar 21, 2:07 pm, Andre Terra  wrote:
> On Wed, Mar 21, 2012 at 5:41 AM, diafygi  wrote:
> > >>> Blog.objects.filter(editor=None)
>
> >>> print Blog.objects.filter(editor=None).values('id').query
>
> SELECT "myapp_blog"."id" FROM "myapp_blog" WHERE "myappblog"."editor_id" IS
> NULL
>
> Cheers,
> AT

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



login() within form clean or outside ?

2012-03-21 Thread Nolhian
Hello,

I have a sign in form and a lost password form.
Currently in my clean method in the sign in form I got :

user = authenticate(username=self.cleaned_data['login'],
password=self.cleaned_data['password'])

In my view, when my form is valid I need to log the user in so I use
login() but it requires a user object. I have 2 ideas but I don't know
which one is safe or safer :

1) put self.user instead of user in the clean method and then in the
view do login(request, myform.user). => don't know if this is safe to
add variables with self in a form.

2) put login() directly in the form clean method instead of the view.
=> seems a little strange to write it there.

I have question with my lost password form since I need to set a new
password which also requires a user object and then use send_mail().

How would you do it ?

Thanks in advance,
Nolhian

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



Re: using forloop.counter to access data

2012-03-21 Thread Larry Martell
On Wed, Mar 21, 2012 at 12:52 PM, James  wrote:
>
>
> On Wednesday, March 21, 2012 10:41:08 AM UTC-4, larry@gmail.com wrote:
>>
>> On Wed, Mar 21, 2012 at 7:53 AM, James <> wrote:
>> >
>> >
>> > On Wednesday, March 21, 2012 8:47:23 AM UTC-4, larry@gmail.com
>> > wrote:
>> >>
>> >> This is probably a stupid newbie question 
>> >>
>> >> I want to access a column of data in a row using forloop.counter, but
>> >> I cannot get it to work.
>> >>
>> >> In my test code, if I display {{ forloop.counter }} I get 2
>> >> If I display {{ headers.0.2 }} I get ToolType
>> >> But if I display {{ headers.0.forloop.counter }} I get nothing
>> >>
>> >> What is the proper syntax for this?
>> >
>> >
>> > the forloop.counter and friends will simply give you information about
>> > the
>> > iteration, it won't give you any information about the data in the
>> > queryset
>>
>> Yes, I realize that. I am using it withing a loop to try an access a
>> specific item of data. The code I showed was just an example from one
>> iteration of the loop.
>>
>> > (I'm assuming this is what you mean when you say column).
>> >
>> > Here are the
>> >
>> > docs https://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs#for
>> >
>> >  If you want to access the column of data, assuming it's referenced from
>> > a
>> > model, just the attribute of that model. If you passed in a list to the
>> > template, you just use the django "dot" look-up syntax.
>>
>> Perhaps my question wasn't clear. I have a list called headers. From
>> within a for loop I want the n'th item from the first row. In the loop
>> I am trying to access {{ headers.0.forloop.counter }} but I get no
>> value from that. But if I hard code the number (as a test), e.g.:  {{
>> headers.0.2 }} then I do get the value.
>
>  With regards to your reply:
>
>
>>  Yes, I realize that. I am using it withing a loop to try an access a
>> specific item of data. The code I showed was just an example from one
>> iteration of the loop.
>
>
> You can't use forloop and friends in the manner you attempting to use it.
> It's The reason is, headers.0 has no attribute named "forloop"
>
> The best that you could do here, in this situation, is to create a custom
> filter and pass it forloop.counter as variable like so:
> {{ headers.0|forloop.counter }} You will of course have to write that filter
> out first, register it, and install it in the template.
>
> I'm still not sure if this is the right approach. Why not just iterate over
> the list itself, if you want to print the nth item within the list?

That would be really inefficient, as the table can have thousands of
rows, with 30 columns each. I'd have to iterate through the header row
for each column in each row to get the value to put into the href.

> Or,
> structure the list/queryset from the view such that you don't have to do
> such acrobatics.
>
>>  But if I hard code the number (as a test), e.g.:  {{
>> headers.0.2 }} then I do get the value.
>
>
> This works because headers.0 has an attribute that works by way of the
> django dot look up. See Tom Evan's post regarding this.
>
> It seems to me that you have a list of lists (and not a single list). In
> which case, you can just iterate over the first list and iterate over the
> second list. If you need some control flow, just use the standard if / else
> conditions. But, maybe I'm missing something?

Yes, I think you are. I have 2 header rows, and thousands of data
rows. For each column in each data row I have to construct a href. One
of the parameters in the href comes from the first header row. The
header rows get processed first, then the data rows (to build the
table). So by the time I am processing the data I don't have the
header any more. I should probably just do this in javascript.

> Even easier would be to use django's introspect feature and create models
> based on the tables in the DB, query the DB using the models and create
> querysets. Then you can access and display the data in a more
> coherent manner.
>
> see the docs here for
> introspection: https://docs.djangoproject.com/en/dev/howto/legacy-databases/?from=olddocs


That already is the case. I am trying to add functionality to an existing app.

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



Re: usage of url template tag

2012-03-21 Thread Larry Martell
On Wed, Mar 21, 2012 at 2:06 PM, Daniel Roseman  wrote:
> On Wednesday, 21 March 2012 03:01:23 UTC-7, larry@gmail.com wrote:
>>
>>
>> I'm very new to django. The rest of the URL comes from the index
>> function in views.py. I wasn't sure if it violated the DRY principle
>> to hardcode it.
>
>
> Fine, but you can't reverse a URL that does not exist. If you tried to
> access "/report/faloom/EventLog/" in your browser, you would get a 404
> because you have no URLconf that matches it. So there's no point in
> outputting that URL in your template.

That's not true. My urlpatterns has:

(r'^report/(\w+)/(\w+)/$', motor.core.reports.views.view)

so /report/faloom/EventLog/ get routed to the view function in
motor/core/report/views.py, which renters the 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-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Session resets - help me find the bug.

2012-03-21 Thread Daniel Roseman
On Wednesday, 21 March 2012 11:12:09 UTC-7, Daniel Sokolowski wrote:
>
> Hi All, 
>
> I have the following code: http://dpaste.com/719654/ for a session 
> based cart implementation I've created. I run into an odd bug/issue 
> that I can't figure out, when I create or retrieve the Cart instance 
> from session by hooking into __new__ class method my session gets 
> wiped or corruped I think, for example I get logged out of admin 
> howefver the cart contents seem to stick. Also the session key stays 
> the same as I have tested for that. But if I create the cart by 
> calling the Cart.get_cart(...) method all works as expected. 
>
> Any thoughts? I might have a bug somewhere else, and so second hand of 
> eyes helps. 
>
> Please note if you are using __new__ or get_cart uncomment either line 
> 78-79



Argh. I can't read that code at all. If you're posting code for feedback, 
please remove commented-out lines.

You shouldn't be overriding __new__ at all. There's almost never a reason 
to do this. Use __init__ instead.
--
DR.

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



Re: usage of url template tag

2012-03-21 Thread Daniel Roseman
On Wednesday, 21 March 2012 03:01:23 UTC-7, larry@gmail.com wrote:
>
>
> I'm very new to django. The rest of the URL comes from the index
> function in views.py. I wasn't sure if it violated the DRY principle
> to hardcode it.
>

Fine, but you can't reverse a URL that does not exist. If you tried to 
access "/report/faloom/EventLog/" in your browser, you would get a 404 
because you have no URLconf that matches it. So there's no point in 
outputting that URL in your template.
--
DR.

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



startup query slows Django on Red Hat Enterprise Server 6.0

2012-03-21 Thread Jerry Stratton
We are in the process of moving a Django 1.3.1 project from a Mac OS X 10.5 
server to a Red Hat Enterprise Server 6.0 VM. For most things, the new 
server is about 2 times faster than the old one.

For Django queries, the new server is much slower. A single objects.get 
that should take less than a second takes over two seconds. I've tracked it 
down to this line in one of my models.py:

defaultHost = Host.objects.get(name='www.sandiego.edu').id

That line is not part of any model; it is run whenever Django is started up 
for use in one of my fields:

server = models.ForeignKey(Host, default=defaultHost)

That is the only place defaultHost is used. If I change the defaultHost 
line to:

defaultHost = None

model.objects.get requests drop from 2-4 seconds to less than half a 
second. The change makes no difference on the current (Mac OS X) server.

Any idea what could be causing this or how I can find out? On the front 
end, things that take a second or two to display now take a minute, two 
minutes, or more.

This is the test script I'm using:

#!/usr/bin/python
import datetime
import sys, os

baseDir = '/projects'
sys.path.append(baseDir)
project_name = 'usdpages'
os.environ['DJANGO_SETTINGS_MODULE'] = '%s.settings' % project_name

from usdpages.pages.models import Page

start = datetime.datetime.now()

Page.objects.get(slug='vector-apps')

end = datetime.datetime.now()

print 'Duration:', end - start

With startup query:

$ ./test
Duration: 0:00:02.252040
$ ./test
Duration: 0:00:02.298540
$ ./test
Duration: 0:00:01.851589

Without startup query:

$ ./test
Duration: 0:00:00.140946
$ ./test
Duration: 0:00:00.142173
$ ./test
Duration: 0:00:00.140059

I also tested it with the 1.4c2 release candidate, and it is slow 
regardless of that defaultHost line; it takes 1.8-2.4 seconds for that one 
Page query with a defaultHost=None, and 2.9 seconds consistently with 
defaultHost set to a query result.

One odd thing: in the method _cursor in the class DatabaseWrapper 
in /usr/lib/python2.6/site-packages/django/db/backends/mysql/base.py if I 
change:

if not self._valid_connection():

to:

if True or not self._valid_connection():

the query time drops to the .14 second range as well. (In 1.4c2 it drops to 
.77-.81 seconds.)


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



Re: Caching and model import question

2012-03-21 Thread Jeff Heard
Well, I was wrong... how *should* this work?  I tried a signal handler
to reload modules whenever someone added or deleted a model, but that
only seems to matter if a particular module that loads "models" hasn't
been loaded yet.

On Wed, Mar 21, 2012 at 12:59 PM, Jeff Heard
 wrote:
> Thanks.  I don't think that *in principle* creating new models on the
> fly is a bad thing, although maybe some will argue with me.  There's
> another Django app that allows you to do this within the admin
> interface, and I've considered using it.  I dislike the idea of having
> to make assumptions about the backend that will be running, though,
> and assuming that my users will be using mod_wsgi, FastCGI, or
> gunicorn is anaethema to the idea of making a portable app.  I *think*
> I have it figured, out, although my implementation still feels
> "hackish" to me.  I suppose another couple of iterations on it may
> make sense.
>
> On Wed, Mar 21, 2012 at 12:52 PM, Tom Evans  wrote:
>> On Wed, Mar 21, 2012 at 4:19 PM, Jeff Heard  
>> wrote:
>>> Question 1: Would this work with views, or for that matter, anything
>>> else in Django, assuming you're using a WSGI server like gunicorn?
>>> http://code.activestate.com/recipes/578078/  Specifically, will it
>>> cache across HTTP requests, or not?
>>>
>>
>> Probably, but that is the worst place to cache in a web framework, as
>> it is a cache per process. That is 'ok' if you use a single process,
>> multi thread serving model on a single server, but useless/wasteful if
>> you run a multi-process serving model or serve from multiple servers.
>>
>> It is much better to use caches at a higher level, eg memcached, which
>> is distributed and can be shared easily amongst any model.
>>
>>> I guess the one thing I don't understand well in Django is when
>>> modules are re-loaded.  I know it's different in a "full-fledged"
>>> setup vs. the test server, but is there a rule one can follow? Is it
>>> different on WSGI vs. FastCGI?
>>>
>>
>> Never automatically. mod_wsgi will reload your app if you touch
>> (change the mtime) the app.wsgi file. mod_fastcgi will reload your app
>> when you restart the process.
>>
>>> And finally, if I delete a module from sys.modules, does that
>>> effectively delete it from the cache or is there something else I need
>>> to do to make sure it's reloaded the next time someone makes a
>>> request?  I would assume that deleting the module from sys.modules
>>> would only delete it from one worker process.  Is there an accepted
>>> way to get a module to reload across all processes?
>>>
>>> What I'm trying to do is allow a user to create models on the fly by
>>> uploading data.  One answer is just to have a post_save signal call
>>> supervisorctl and restart the webservices, but that seems nonportable
>>> and rather broken.  There's got to be a better way.
>>>
>>
>> Eurgh. Now I don't want to help you! These links will help:
>>
>> http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode#Reloading_In_Daemon_Mode
>> http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode#Restarting_Daemon_Processes
>>
>> 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-users@googlegroups.com.
>> To unsubscribe from this group, send email to 
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at 
>> http://groups.google.com/group/django-users?hl=en.
>>

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



Re: using forloop.counter to access data

2012-03-21 Thread James


On Wednesday, March 21, 2012 10:41:08 AM UTC-4, larry@gmail.com wrote:
>
> On Wed, Mar 21, 2012 at 7:53 AM, James <> wrote:
> >
> >
> > On Wednesday, March 21, 2012 8:47:23 AM UTC-4, Larry@gmail.comwrote:
> >>
> >> This is probably a stupid newbie question 
> >>
> >> I want to access a column of data in a row using forloop.counter, but
> >> I cannot get it to work.
> >>
> >> In my test code, if I display {{ forloop.counter }} I get 2
> >> If I display {{ headers.0.2 }} I get ToolType
> >> But if I display {{ headers.0.forloop.counter }} I get nothing
> >>
> >> What is the proper syntax for this?
> >
> >
> > the forloop.counter and friends will simply give you information about 
> the
> > iteration, it won't give you any information about the data in the 
> queryset
>
> Yes, I realize that. I am using it withing a loop to try an access a
> specific item of data. The code I showed was just an example from one
> iteration of the loop.
>
> > (I'm assuming this is what you mean when you say column).
> >
> > Here are the
> > docs 
> https://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs#for
> >
> >  If you want to access the column of data, assuming it's referenced from 
> a
> > model, just the attribute of that model. If you passed in a list to the
> > template, you just use the django "dot" look-up syntax.
>
> Perhaps my question wasn't clear. I have a list called headers. From
> within a for loop I want the n'th item from the first row. In the loop
> I am trying to access {{ headers.0.forloop.counter }} but I get no
> value from that. But if I hard code the number (as a test), e.g.:  {{
> headers.0.2 }} then I do get the value.
>
 With regards to your reply:


 Yes, I realize that. I am using it withing a loop to try an access a
> specific item of data. The code I showed was just an example from one
> iteration of the loop.


You can't use forloop and friends in the manner you attempting to use it. 
It's The reason is, headers.0 has no attribute named "forloop"

The best that you could do here, in this situation, is to create a custom 
filter and pass it forloop.counter as variable like so:
{{ headers.0|forloop.counter }} You will of course have to write that 
filter out first, register it, and install it in the template.

I'm still not sure if this is the right approach. Why not just iterate over 
the list itself, if you want to print the nth item within the list? Or, 
structure the list/queryset from the view such that you don't have to do 
such acrobatics.

 But if I hard code the number (as a test), e.g.:  {{
> headers.0.2 }} then I do get the value. 


This works because headers.0 has an attribute that works by way of the 
django dot look up. See Tom Evan's post regarding this.

It seems to me that you have a list of lists (and not a single list). In 
which case, you can just iterate over the first list and iterate over the 
second list. If you need some control flow, just use the standard if / else 
conditions. But, maybe I'm missing something?

Even easier would be to use django's introspect feature and create models 
based on the tables in the DB, query the DB using the models and create 
querysets. Then you can access and display the data in a more 
coherent manner.

see the docs here for introspection: 
https://docs.djangoproject.com/en/dev/howto/legacy-databases/?from=olddocs


 

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



Re: [bump] Preventing JOIN while checking if a self referencing FK is null

2012-03-21 Thread Andre Terra
Because django offers a nice ORM that makes it easy to do most queries,
especially one-liners like this one.

And refactoring raw SQL is a royal PITA.


Cheers,
AT

On Wed, Mar 21, 2012 at 3:14 PM, Python_Junkie <
software.buy.des...@gmail.com> wrote:

> Use straight sql.
>
> There are always potentially limitations with an abstraction such as the
> ORM.
>
> Why try to fit a square peg into a round whole.
>
>
> On Wednesday, March 21, 2012 4:41:32 AM UTC-4, diafygi wrote:
>>
>> There is an old thread that didn't end in a resolution about
>> preventing joins in a filter(foreign_key=None) scenario.
>>
>> http://groups.google.com/**group/django-users/browse_**
>> thread/thread/61ee2fb22deae326
>>
>> I'd like to bring it up again and ask if there is now a way to prevent
>> joins from a query.
>>
>> An example:
>> class Blog(model.Models):
>>editor = models.ForeignKey(User, null=True)
>>
>> # find all the blogs with no editors
>> >>> Blog.objects.filter(editor=**None)
>> DEBUG:django.db.backends:(0.**039) SELECT `myapp_blog`.`id` FROM
>> `myapp_blog` LEFT OUTER JOIN `myapp_user` ON (`myapp_blog`.`editor_id`
>> = `myapp_user`.`id`) WHERE `myapp_user`.`id` IS NULL;
>>
>> # Is there a way to do this query?
>> >>> Blog.objects.filter(editor=**None)
>> DEBUG:django.db.backends:(0.**039) SELECT `myapp_blog`.`id` FROM
>> `myapp_blog` WHERE `myapp_blog`.`editor_id` IS NULL;
>>
>> Thanks!
>> Daniel
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/NfvXnYxnHBkJ.
>
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: Problem with Django starting up

2012-03-21 Thread Andre Terra
What I recommend is that you install pip and virtualenv, create a folder
(say, C:\virtual\) where you will place different python "environments" per
virtualenv, then create a folder (say, C:\projects) where you will create
different django projects.

This way you can always use virtualenv to "activate" different environments
and not need to install libraries system-wide.


Basically (blue commands are to be typed in the command prompt):
01. Go to http://pypi.python.org/pypi/pip#downloads
02. Download the archive, extract the contents to a given folder (you might
need 7-zip[1]).
03. Open the command prompt (Winkey+R, type in "cmd" with no quotes)
04. cd into the folder created by the extracted archive in step 02
05. python setup.py install
06. Make sure you have C:\Python27\Scripts in your PATH.
06.1. Do this by typing set PATH=C:\Python27\Scripts;%PATH% in the command
prompt
07. pip install virtualenv
08. mkdir c:\virtual && mkdir c:\projects
09. cd c:\virtual
10. virtualenv --no-site-packages myfirstenvironment (you can name this
after your project if you want to)
11. cd myfirstenvironment

*12. Activate your environment:
C:\virtual\myfirstenvironment\Scripts\activate.bat*

If you want the development version of Django:
13.A. pip install git+https://github.com/django/django.git#egg=django

If you want a stable release:
13.B. pip install django

14. Whenever you need to install a package, just do the same as in step #12
but type the package name instead of django. Don't forget to activate your
environment whenever you open a command prompt window and BEFORE you start
working on your project!


I think that about sums it up. Using this on linux is of course easier. I
hope I didn't miss any steps, but I'm sure others will correct me if I
forgot anything.


Cheers,
AT


[1] http://www.7-zip.org/download.html


On Wed, Mar 21, 2012 at 3:48 AM, Jani Tiainen  wrote:

> 21.3.2012 7:50, Samuel Muiruri kirjoitti:
>
>  I can't get the first part to work
>>
>>
> I assume that you have python installed to c:\python27\
>
> You need to add c:\python27\scripts to your path.
>
> Or alternatively:
>
> c:\python27\scripts\django-**admin.py startproject mysite
>
> --
>
> Jani Tiainen
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to django-users+unsubscribe@**
> 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-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Session resets - help me find the bug.

2012-03-21 Thread Daniel Sokolowski
Hi All,

I have the following code: http://dpaste.com/719654/ for a session
based cart implementation I've created. I run into an odd bug/issue
that I can't figure out, when I create or retrieve the Cart instance
from session by hooking into __new__ class method my session gets
wiped or corruped I think, for example I get logged out of admin
howefver the cart contents seem to stick. Also the session key stays
the same as I have tested for that. But if I create the cart by
calling the Cart.get_cart(...) method all works as expected.

Any thoughts? I might have a bug somewhere else, and so second hand of
eyes helps.

Please note if you are using __new__ or get_cart uncomment either line
78-79

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



Re: [bump] Preventing JOIN while checking if a self referencing FK is null

2012-03-21 Thread Python_Junkie
Use straight sql.

There are always potentially limitations with an abstraction such as the 
ORM.

Why try to fit a square peg into a round whole.

On Wednesday, March 21, 2012 4:41:32 AM UTC-4, diafygi wrote:
>
> There is an old thread that didn't end in a resolution about 
> preventing joins in a filter(foreign_key=None) scenario. 
>
>
> http://groups.google.com/group/django-users/browse_thread/thread/61ee2fb22deae326
>  
>
> I'd like to bring it up again and ask if there is now a way to prevent 
> joins from a query. 
>
> An example: 
> class Blog(model.Models): 
>editor = models.ForeignKey(User, null=True) 
>
> # find all the blogs with no editors 
> >>> Blog.objects.filter(editor=None) 
> DEBUG:django.db.backends:(0.039) SELECT `myapp_blog`.`id` FROM 
> `myapp_blog` LEFT OUTER JOIN `myapp_user` ON (`myapp_blog`.`editor_id` 
> = `myapp_user`.`id`) WHERE `myapp_user`.`id` IS NULL; 
>
> # Is there a way to do this query? 
> >>> Blog.objects.filter(editor=None) 
> DEBUG:django.db.backends:(0.039) SELECT `myapp_blog`.`id` FROM 
> `myapp_blog` WHERE `myapp_blog`.`editor_id` IS NULL; 
>
> Thanks! 
> Daniel

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



Re: Having all objects defined in Models.py editable in one admin page

2012-03-21 Thread Andre Terra
Try writing your own views rather than expanding the Admin. It's well worth
it in the long run!


Cheers,
AT

On Wed, Mar 21, 2012 at 1:50 PM, Sithembewena Lloyd Dube
wrote:

> Hi guys,
>
> I am building a learning application for a client. The problem we are
> experiencing is that of inlines. We have multiple related objects and the
> client wants to be able to edit all objects from one CRUD. Unfortunately,
> there seems to be no solution for multiple inlines in a Django admin.
> application. Is there a sensible way to address this problem?
> --
> 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-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: where did I install Django

2012-03-21 Thread Andre Terra
How to have a sane python setup:

1. use pip and virtualenv[1]
2. ???
3. PROFIT!

Cheers,
AT

[1]
http://www.saltycrane.com/blog/2009/05/notes-using-pip-and-virtualenv-django/




On Tue, Mar 20, 2012 at 8:30 PM, jdw  wrote:

> got it!  This one worked.  Thanks.
>
> On Tuesday, March 20, 2012 3:52:05 PM UTC-7, Furbee wrote:
>>
>> From an answer on stackoverflow.com (http://stackoverflow.com/**
>> questions/122327/how-do-i-**find-the-location-of-my-**
>> python-site-packages-directory
>> **):
>>
>> Enter python shell by executing python binary:
>>
>> from distutils.sysconfig import get_python_lib
>>
>>
>> print(get_python_lib())
>>
>>
>> It usually resides in a folder named site-packages or dist-packages
>> somewhere in the Python directory. In Windows it is different than in Unix.
>>
>> When all else fails, you can run a find command on Unix, or a do an
>> advanced search in Windows.
>>
>> On Tue, Mar 20, 2012 at 3:30 PM, jdw 
>> 
>> > wrote:
>>
>>> Newbie alert...
>>>
>>> I installed Django and finished the first tutorial.  On the second one,
>>> I could not log in to the website because  I didn't set a superuser.
>>> Ultimately, I figured out my problem, but I realized I have no idea where I
>>> installed Django.  Is there an easy way to find out where the code lives?
>>>
>>> I realized I had no idea when the tutorial suggested running this:
>>>
>>> python /path/to/django/contrib/auth/c**reate_superuser.py
>>>
>>>
>>>
>>>  --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To view this discussion on the web visit https://groups.google.com/d/**
>>> msg/django-users/-/**9FZCBitFicMJ
>>> .
>>> To post to this group, send email to django-users@googlegroups.com.
>>> To unsubscribe from this group, send email to django-users+unsubscribe@*
>>> *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 view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/bHhVJmu5AJEJ.
>
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: [bump] Preventing JOIN while checking if a self referencing FK is null

2012-03-21 Thread Andre Terra
On Wed, Mar 21, 2012 at 5:41 AM, diafygi  wrote:

> >>> Blog.objects.filter(editor=None)
>


>>> print Blog.objects.filter(editor=None).values('id').query
SELECT "myapp_blog"."id" FROM "myapp_blog" WHERE "myappblog"."editor_id" IS
NULL


Cheers,
AT

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



Re: TemplateSyntaxError: 'if' statement improperly formatted

2012-03-21 Thread Lee Sparks
Its also important to use {% endifequal %} So...went passing to HTML 
templates

{% ifequal rowvalue "Blue" %}
Its Blue 
{% endifequal %}

L.

On Sunday, 3 January 2010 17:34:22 UTC, Biju Varghese wrote:
>
> hi
>If you want to compare the value you have to use ifequal or
> ifnotequal tag in template language. if you use "if"
> this will check only weather  the variable is empty or not
>

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



Re: Caching and model import question

2012-03-21 Thread Jeff Heard
Thanks.  I don't think that *in principle* creating new models on the
fly is a bad thing, although maybe some will argue with me.  There's
another Django app that allows you to do this within the admin
interface, and I've considered using it.  I dislike the idea of having
to make assumptions about the backend that will be running, though,
and assuming that my users will be using mod_wsgi, FastCGI, or
gunicorn is anaethema to the idea of making a portable app.  I *think*
I have it figured, out, although my implementation still feels
"hackish" to me.  I suppose another couple of iterations on it may
make sense.

On Wed, Mar 21, 2012 at 12:52 PM, Tom Evans  wrote:
> On Wed, Mar 21, 2012 at 4:19 PM, Jeff Heard  
> wrote:
>> Question 1: Would this work with views, or for that matter, anything
>> else in Django, assuming you're using a WSGI server like gunicorn?
>> http://code.activestate.com/recipes/578078/  Specifically, will it
>> cache across HTTP requests, or not?
>>
>
> Probably, but that is the worst place to cache in a web framework, as
> it is a cache per process. That is 'ok' if you use a single process,
> multi thread serving model on a single server, but useless/wasteful if
> you run a multi-process serving model or serve from multiple servers.
>
> It is much better to use caches at a higher level, eg memcached, which
> is distributed and can be shared easily amongst any model.
>
>> I guess the one thing I don't understand well in Django is when
>> modules are re-loaded.  I know it's different in a "full-fledged"
>> setup vs. the test server, but is there a rule one can follow? Is it
>> different on WSGI vs. FastCGI?
>>
>
> Never automatically. mod_wsgi will reload your app if you touch
> (change the mtime) the app.wsgi file. mod_fastcgi will reload your app
> when you restart the process.
>
>> And finally, if I delete a module from sys.modules, does that
>> effectively delete it from the cache or is there something else I need
>> to do to make sure it's reloaded the next time someone makes a
>> request?  I would assume that deleting the module from sys.modules
>> would only delete it from one worker process.  Is there an accepted
>> way to get a module to reload across all processes?
>>
>> What I'm trying to do is allow a user to create models on the fly by
>> uploading data.  One answer is just to have a post_save signal call
>> supervisorctl and restart the webservices, but that seems nonportable
>> and rather broken.  There's got to be a better way.
>>
>
> Eurgh. Now I don't want to help you! These links will help:
>
> http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode#Reloading_In_Daemon_Mode
> http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode#Restarting_Daemon_Processes
>
> 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-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: Caching and model import question

2012-03-21 Thread Tom Evans
On Wed, Mar 21, 2012 at 4:19 PM, Jeff Heard  wrote:
> Question 1: Would this work with views, or for that matter, anything
> else in Django, assuming you're using a WSGI server like gunicorn?
> http://code.activestate.com/recipes/578078/  Specifically, will it
> cache across HTTP requests, or not?
>

Probably, but that is the worst place to cache in a web framework, as
it is a cache per process. That is 'ok' if you use a single process,
multi thread serving model on a single server, but useless/wasteful if
you run a multi-process serving model or serve from multiple servers.

It is much better to use caches at a higher level, eg memcached, which
is distributed and can be shared easily amongst any model.

> I guess the one thing I don't understand well in Django is when
> modules are re-loaded.  I know it's different in a "full-fledged"
> setup vs. the test server, but is there a rule one can follow? Is it
> different on WSGI vs. FastCGI?
>

Never automatically. mod_wsgi will reload your app if you touch
(change the mtime) the app.wsgi file. mod_fastcgi will reload your app
when you restart the process.

> And finally, if I delete a module from sys.modules, does that
> effectively delete it from the cache or is there something else I need
> to do to make sure it's reloaded the next time someone makes a
> request?  I would assume that deleting the module from sys.modules
> would only delete it from one worker process.  Is there an accepted
> way to get a module to reload across all processes?
>
> What I'm trying to do is allow a user to create models on the fly by
> uploading data.  One answer is just to have a post_save signal call
> supervisorctl and restart the webservices, but that seems nonportable
> and rather broken.  There's got to be a better way.
>

Eurgh. Now I don't want to help you! These links will help:

http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode#Reloading_In_Daemon_Mode
http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode#Restarting_Daemon_Processes

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-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Having all objects defined in Models.py editable in one admin page

2012-03-21 Thread Sithembewena Lloyd Dube
Hi guys,

I am building a learning application for a client. The problem we are
experiencing is that of inlines. We have multiple related objects and the
client wants to be able to edit all objects from one CRUD. Unfortunately,
there seems to be no solution for multiple inlines in a Django admin.
application. Is there a sensible way to address this problem?
-- 
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-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Caching and model import question

2012-03-21 Thread Jeff Heard
Question 1: Would this work with views, or for that matter, anything
else in Django, assuming you're using a WSGI server like gunicorn?
http://code.activestate.com/recipes/578078/  Specifically, will it
cache across HTTP requests, or not?

I guess the one thing I don't understand well in Django is when
modules are re-loaded.  I know it's different in a "full-fledged"
setup vs. the test server, but is there a rule one can follow? Is it
different on WSGI vs. FastCGI?

And finally, if I delete a module from sys.modules, does that
effectively delete it from the cache or is there something else I need
to do to make sure it's reloaded the next time someone makes a
request?  I would assume that deleting the module from sys.modules
would only delete it from one worker process.  Is there an accepted
way to get a module to reload across all processes?

What I'm trying to do is allow a user to create models on the fly by
uploading data.  One answer is just to have a post_save signal call
supervisorctl and restart the webservices, but that seems nonportable
and rather broken.  There's got to be a better way.

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



Re: Preventing JOIN while checking if a self referencing FK is null

2012-03-21 Thread diafygi
>>> Blog.objects.filter(editor_id=None)
FieldError: Cannot resolve keyword 'editor_id' into field.

This was actually an offered answer in the previous thread, but the id
version of the field still raises a field error.

Daniel

On Mar 21, 9:47 am, Javier Guerra Giraldez  wrote:
> try:
>
> > Blog.objects.filter(editor_id=None)
>
> --
> Javier

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



Re: database router raises TypeError: expecting router class instance as first argument

2012-03-21 Thread Chris Ghormley

Thanks Tom. I was too busy to think clearly yesterday so when I tested with 
quotes I didn't include the path to my routers module.

In my experience the Django docs are good, just a little DRY - they only 
point out the obvious *once*.

Chris

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



Re: using forloop.counter to access data

2012-03-21 Thread Tom Evans
On Wed, Mar 21, 2012 at 2:58 PM, Larry Martell  wrote:
> OK, but is there some reason {{ headers.0.forloop.counter } does not
> work when forloop.counter has a value of 2, yet {{ headers.0.2 }}
> does work?

Django never does variable interpolation when resolving dot separated variables.

What django does do when it resolves dot separated variables is well documented:

https://docs.djangoproject.com/en/1.3/topics/templates/#variables

So outputting 'headers.0.forloop.counter' first finds the 'headers'
variable, and gets the 0th entry. In fact, first of all it tries

  headers.get('0')

IE, a dictionary lookup. This fails, so it tries

  getattr(headers, '0')

IE, an attribute lookup. This fails, so it tries

  headers.0() *

IE, a method call. This fails, so it tries

  headers[0]

IE, a list index lookup.

Having got 'headers.0' resolved, it would then step on to the next
part of the lookup - 'forloop'.

I think if you trace through yourself what it will do to lookup
forloop as a dictionary entry of headers[0], an attribute of
headers[0], a method call of headers[0] or a list index lookup of
headers[0], you will see that obviously all of these would fail. If
you replace forloop.counter with the raw value '2' and repeat the
process, you'll see why that works as well.

Cheers

Tom

* It doesn't actually do this, I haven't checked the code, but it
probably does something like this:

  val = headers.get('0')
  if not val:
val = getattr(headers, '0')
if callable(val):
  return val()
  if not val:
val = headers[0]
  return val

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



Re: using forloop.counter to access data

2012-03-21 Thread Larry Martell
On Wed, Mar 21, 2012 at 8:32 AM, Tom Evans  wrote:
> On Wed, Mar 21, 2012 at 12:47 PM, Larry Martell  
> wrote:
>> This is probably a stupid newbie question 
>>
>> I want to access a column of data in a row using forloop.counter, but
>> I cannot get it to work.
>>
>> In my test code, if I display {{ forloop.counter }} I get 2
>> If I display {{ headers.0.2 }} I get ToolType
>> But if I display {{ headers.0.forloop.counter }} I get nothing
>>
>> What is the proper syntax for this?
>>
>
> The preferred solution is to structure your data better in your view
> so that writing the template to render the data is straightforward.

This is a very large existing app, and I am new at this job. That have
a table of data and they want me to make some of the data in the table
into links that take them to a more detailed view of the data. The
functionality to provide this more detailed view of the data already
exist in the app. So I am just trying to construct the href. As I
iterate through the table data, I need info from the header to build
the href.

>
> The pragmatic solution is to use a custom filter to access your
> current data structures:
>
> http://stackoverflow.com/questions/2024660/django-sort-dict-in-template

OK, but is there some reason {{ headers.0.forloop.counter } does not
work when forloop.counter has a value of 2, yet {{ headers.0.2 }}
does work?

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



Re: using forloop.counter to access data

2012-03-21 Thread Larry Martell
On Wed, Mar 21, 2012 at 7:53 AM, James  wrote:
>
>
> On Wednesday, March 21, 2012 8:47:23 AM UTC-4, larry@gmail.com wrote:
>>
>> This is probably a stupid newbie question 
>>
>> I want to access a column of data in a row using forloop.counter, but
>> I cannot get it to work.
>>
>> In my test code, if I display {{ forloop.counter }} I get 2
>> If I display {{ headers.0.2 }} I get ToolType
>> But if I display {{ headers.0.forloop.counter }} I get nothing
>>
>> What is the proper syntax for this?
>
>
> the forloop.counter and friends will simply give you information about the
> iteration, it won't give you any information about the data in the queryset

Yes, I realize that. I am using it withing a loop to try an access a
specific item of data. The code I showed was just an example from one
iteration of the loop.

> (I'm assuming this is what you mean when you say column).
>
> Here are the
> docs https://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs#for
>
>  If you want to access the column of data, assuming it's referenced from a
> model, just the attribute of that model. If you passed in a list to the
> template, you just use the django "dot" look-up syntax.

Perhaps my question wasn't clear. I have a list called headers. From
within a for loop I want the n'th item from the first row. In the loop
I am trying to access {{ headers.0.forloop.counter }} but I get no
value from that. But if I hard code the number (as a test), e.g.:  {{
headers.0.2 }} then I do get the value.

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



Re: using forloop.counter to access data

2012-03-21 Thread Tom Evans
On Wed, Mar 21, 2012 at 12:47 PM, Larry Martell  wrote:
> This is probably a stupid newbie question 
>
> I want to access a column of data in a row using forloop.counter, but
> I cannot get it to work.
>
> In my test code, if I display {{ forloop.counter }} I get 2
> If I display {{ headers.0.2 }} I get ToolType
> But if I display {{ headers.0.forloop.counter }} I get nothing
>
> What is the proper syntax for this?
>

The preferred solution is to structure your data better in your view
so that writing the template to render the data is straightforward.

The pragmatic solution is to use a custom filter to access your
current data structures:

http://stackoverflow.com/questions/2024660/django-sort-dict-in-template

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-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



SiteProfileNotAvailable

2012-03-21 Thread lumati
Hi all.
When I develop the custom user with profile, there is an error.
I do like 
http://www.b-list.org/weblog/2006/jun/06/django-tips-extending-user-model/
create the app: account
in account/models.py
#
from django.db import models
from django.contrib.auth.models import User
from django.db.models.signals import post_save

class UserProfile(models.Model):
user = models.ForeignKey(User, unique=True)
url = models.URLField("Website", blank=True)
company = models.CharField(max_length=50, blank=True)

def create_user_profile(sender, instance, created, **kwargs):
if created:
UserProfile.objects.create(user=instance)

post_save.connect(create_user_profile, sender=User)

in the settings.py
#
AUTH_PROFILE_MODULE = "account.UserProfile"

and i also do the syndb, and there indeed account_userprofile table in
database.

but when I run this code:
from django.contrib.auth.models import User
users = User.objects.all()
user = users[0]
user.get_profile()

where will be error like this:
Traceback (most recent call last):
  File "", line 1, in 
  File "E:\python25\lib\site-packages\django\contrib\auth\models.py",
line 380, in get_profile
raise SiteProfileNotAvailable('Unable to load the profile '
SiteProfileNotAvailable: Unable to load the profile model, check
AUTH_PROFILE_MODULE in your project settings

and i think the models.get_model function throw the exception.
Anyone can help me? 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-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Problem with tuncated Admin pages in apache + mod_fcgid

2012-03-21 Thread Another Django Newbie


On Wednesday, March 21, 2012 10:29:48 AM UTC, Jani Tiainen wrote:
>
> Like this:
>
> 'default': {
>'ENGINE': '...',
>'OPTIONS': {
>   'threaded': True
>}
> }
>

Thanks again Jani, switching my question to the modwsgi group 

Regards, ADN
 

>
>

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



Re: using forloop.counter to access data

2012-03-21 Thread James


On Wednesday, March 21, 2012 8:47:23 AM UTC-4, larry@gmail.com wrote:
>
> This is probably a stupid newbie question 
>
> I want to access a column of data in a row using forloop.counter, but
> I cannot get it to work.
>
> In my test code, if I display {{ forloop.counter }} I get 2
> If I display {{ headers.0.2 }} I get ToolType
> But if I display {{ headers.0.forloop.counter }} I get nothing
>
> What is the proper syntax for this?
>

the forloop.counter and friends will simply give you information about the 
iteration, it won't give you any information about the data in the queryset 
(I'm assuming this is what you mean when you say column).

Here are the docs 
https://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs#for

 If you want to access the column of data, assuming it's referenced from a 
model, just the attribute of that model. If you passed in a list to the 
template, you just use the django "dot" look-up syntax.

Docs here: https://docs.djangoproject.com/en/dev/ref/templates/api/#render

So, let's say your list looks like a = [1,2,3,4] and in your context it 
looks like c ={'a':a}

if you want to reference the second "column" (index really) you would just 
do {{ a.1 }}, this will render the number "2".

You would use forloop.counter for something like, let's say we passed in 
hundreds of such lists. And, for whatever reason, once we reach the 100th 
iteration, we want the loop to end.

Then we would do this:

{% for list in list_of_lists %}
  {{ list.1 }}
{% if forloop.counter == 100 %}
{% endfor %}
{% endif %}
{% if forloop. last %} 
{% endfor %}
{% endif %} 

The last if / endif is not necessary, but I wanted to show some control 
flow using the forloop context. In fact, I wouldn't do this at all at the 
template level. I would instead limit the queryset to 100 when creating the 
queryset and pass that in and then just iterate over it like any other 
queryset, but I think you see what I mean.

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



Re: [bump] Preventing JOIN while checking if a self referencing FK is null

2012-03-21 Thread Javier Guerra Giraldez
try:

> Blog.objects.filter(editor_id=None)



-- 
Javier

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



using forloop.counter to access data

2012-03-21 Thread Larry Martell
This is probably a stupid newbie question 

I want to access a column of data in a row using forloop.counter, but
I cannot get it to work.

In my test code, if I display {{ forloop.counter }} I get 2
If I display {{ headers.0.2 }} I get ToolType
But if I display {{ headers.0.forloop.counter }} I get nothing

What is the proper syntax for 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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Looking for paid advice on (NoSQL) Hadoop / MongoDB / Dynamo

2012-03-21 Thread Cal Leeming [Simplicity Media Ltd]
Hi all,

Currently looking at getting some expert advice relating to NoSQL solutions
such as Hadoop, MongoDB, Dynamo and others.

The kind of advice we're looking for is an 'overall' perspective and
general discussion, rather than a step by step guide.

Can pay market rates for up to 8 hours worth of 'training' - and this can
be done either remotely via Skype or on-site at our UK offices.

As part of this, the consultant must be able to demonstrate significant
knowledge in this area, as well as actual experience in large real life
deployments.

Looking to have this signed off by end of the week, and for the session to
take place next week.

Feel free to send replies directly to me on
cal.leem...@simplicitymedialtd.co.uk - or reply to the thread if you'd
prefer your details to be public.

Cheers

Cal

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



Re: This field is required error if enctype="multipart/form-data" is not set

2012-03-21 Thread Sachin Gupta
Ok, got it 

Thanks 
Sachin

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



issues with dejango-ckeditor

2012-03-21 Thread Sagiedd
Hello,

I am trying to use the django-ckeditor in my models / forms.
However, the RichTextField or CKEditorWidget seem to work like regular
text field. This happens both on the admin site and in my own forms.

I followed the installation guide as explained here :
https://github.com/shaunsephton/django-ckeditor

I feel like there is some step I did wrong or something else I forgot
to install, because there are no error message.

Thanks for helping.

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



Re: usage of url template tag

2012-03-21 Thread Tim Ney
Have you read the Django book section on advanced urlconfs, there is a very
good discussion on how to put together customs urls. There are also good
examples
as well. The Django book is online all you have to do is google for it.

On Wed, Mar 21, 2012 at 6:01 AM, Larry Martell wrote:

> On Tue, Mar 20, 2012 at 11:04 PM, Daniel Roseman 
> wrote:
> > On Tuesday, 20 March 2012 15:27:27 UTC-7, larry@gmail.com wrote:
> >>
> >> I'm trying to generate a URL that looks something like this:
> >>
> >>
> >>
> /report/faloom/EventLog/?message=EventSearchString_ids=13_1=Tool_2=Time_3=Module_4=Message_preview=Generate+Report
> >>
> >> I have the values for the arguments (message, tool_ids, etc)  available
> to
> >> me.
> >>
> >> My urlconf has:
> >>
> >> (r'^report/$', motor.ui.views.index)
> >>
> >> If I put this in my template:
> >>
> >> {% url motor.ui.views.index %}
> >>
> >> I get:
> >>
> >> /report/
> >>
> >> What do I use as arguments with the url tag to get the URL I want?
> >> I've tried many, many different things, but no matter what, I get a
> >> NoReverseMatch exception.
> >
> >
> > This question makes no sense at all. Your URL is just "/report/". You can
> > add the  GET parameters manually, since they aren't matched in a URLconf,
> > but where is the 'faloom/EventLog' bit supposed to be coming from? There
> is
> > no URL that matches that.
>
> I'm very new to django. The rest of the URL comes from the index
> function in views.py. I wasn't sure if it violated the DRY principle
> to hardcode 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-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: database router raises TypeError: expecting router class instance as first argument

2012-03-21 Thread Tom Evans
On Wed, Mar 21, 2012 at 2:55 AM, Chris Ghormley
 wrote:
> I'm having trouble with database routers in a Django 1.3.1 project.
> I'm by no means a Django or Python expert, but I've been using Django
> for a few years now. When I enable any kind of router in my project,
> it throws a TypeError like the following:
>
> "unbound method db_for_read() must be called with DBRouter instance as
> first argument (got ModelBase instance instead)"
>
> I've tried a few different examples based on the Django documentation,
> but it seems like I am missing something basic here.
>
> Does anybody have an idea what I've done wrong? Please let me know if
> you need more information.
>
> Here's some background:
>
> The new database is used by a new app with a model in the app's
> models.py. Using the shell I've proved that the database and model are
> OK.
>
> The routers.py is in the new app. The settings file imports the router
> class, and includes the following line:
>
> DATABASE_ROUTERS = [ DBRouter, ]
>

https://docs.djangoproject.com/en/1.3/topics/db/multi-db/#topics-db-multi-db-routing

"""
Then, in your settings file, add the following (substituting path.to.
with the actual python path to the module where you define the
routers):

DATABASE_ROUTERS = ['path.to.MyAppRouter', 'path.to.MasterSlaveRouter']
"""

DATABASE_ROUTERS is supposed to be a list of strings, each string
denoting the python path and class name of a DB router class. You are
setting it to a list of klasses.

Django will take care of instantiating instances of the DB router
classes as needed.

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-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: This field is required error if enctype="multipart/form-data" is not set

2012-03-21 Thread Tom Evans
On Tue, Mar 20, 2012 at 8:24 PM, Sachin Gupta  wrote:
> In a file upload form if the enctype attribute is not set then, django
> throws the error
>
> This field is required
>
> In case null=True and blank = True is set for the file field then nothing
> happens at all. Shouldn't it be such that django should throw some other
> error since we are sending a File object and the enctype attribute is not
> sent. Django should be expecting a file backend and instead of throwing form
> error it should so some other kind of error.
>

In a file upload form, if the enctype is not 'multipart/form-data',
then the browser will not upload the file, ergo there is no file
object.

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-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Problem with tuncated Admin pages in apache + mod_fcgid

2012-03-21 Thread Jani Tiainen

Like this:

'default': {
  'ENGINE': '...',
  'OPTIONS': {
 'threaded': True
  }
}

21.3.2012 11:05, Another Django Newbie kirjoitti:



On Wednesday, March 21, 2012 7:18:16 AM UTC, Jani Tiainen wrote:

20.3.2012 16:45, Another Django Newbie kirjoitti:
 >
 >
 > On Tuesday, March 20, 2012 10:28:49 AM UTC, Another Django Newbie
wrote:
 >
 >
 >
 > On Tuesday, March 20, 2012 10:01:36 AM UTC, Tom Evans wrote:
 >
 > On Mon, Mar 19, 2012 at 5:24 PM, Jani Tiainen 
 > wrote:
 > > Hi,
 > >
 > > Since we use same setup except one part: we use mod_wsgi
 > instead of
 > > mod_fcgi.
 > >
 > > (Since wsgi is considered to be defacto protocol). Could you
 > try to use it?
 > >
 >
 > WSGI is the de-facto for hosting python in web servers. If you
 > aren't
 > running just python, it's nice to use the same hosting mechanism for
 > all your apps, and fastcgi is a supported mechanism.
 >
 > OP: You mention using mod_fcgid, but you do not give us any idea of
 > how you are using mod_fcgid. Configuration and error logs
 > please. FYI,
 > we run django quite happily under mod_fastcgi.
 >
 > Cheers
 >
 > Tom
 >
 >
 >
 > Hi Tom, Jani,
 >
 > Currently struggling to compile mod_wsgi, or more specifically a
 > shared library version of python - something to do with mismatched
 > 32/64 bit libraries I think.
 >
 > Here's an extract from httpd.conf.
 >
 > RewriteEngine On
 > RewriteRule ^.*/cfServer/(.*)$ /cgi-bin/django.cgi/$1 [PT]
 > 
 > Options ExecCGI
 > AddHandler fcgid-script .cgi
 > # AddHandler cgi-script .cgi
 > Require all granted
 > 
 >
 > and the relevant django.cgi
 >
 > #!/usr/local/bin/python
 > from FcgiWsgiAdapter import list_environment, serve_wsgi
 >
 > import os, sys
 > os.environ['DJANGO_SETTINGS_MODULE'] = 'cfServer.settings'
 > os.environ['ORACLE_HOME'] = '/oracle/11gStdEd'
 >
 > from django.core.handlers.wsgi import WSGIHandler
 >
 > # use this to test that fastcgi works and to inspect the environment
 > # serve_wsgi(list_environment)
 > # use this to serve django
 > serve_wsgi(WSGIHandler())
 >
 > The "FcgiWsgiAdapter" referred to came from djangosnippets.org

 > >.
 >
 > As to error logs, as I mentioned in the original post I don't see
 > anything added to any logs when this happens and there is only a
 > warning about the ssl library when apache is restarted.
 >
 > Regards, ADN
 >
 >
 >
 > *So I swapped to using WSGI with this apache config *
 >
 > WSGIScriptAlias /
/home/user/python/djcode/cfServer/apache/django.wsgi
 > WSGIDaemonProcess site-1 threads=30
 > WSGIProcessGroup site-1
 >
 > 
 > AllowOverride None
 > Options None
 > Require all granted
 > 
 >
 > and this django.wsgi
 >
 > import os, sys
 > sys.path.append('/home/user/python/djcode')
 > os.environ['DJANGO_SETTINGS_MODULE'] = 'cfServer.settings'
 > os.environ['ORACLE_HOME'] = '/oracle/11gStdEd'
 > os.environ['PYTHON_EGG_CACHE'] = '/var/www/.python-eggs'
 >
 > import django.core.handlers.wsgi
 >
 > application = django.core.handlers.wsgi.WSGIHandler()
 >
 > and I get segmentation faults (debug level tracing from apache
error log)
 >
 > [Tue Mar 20 14:16:28.126341 2012] [core:notice] [pid 17487:tid
 > 47401308446624] AH00051: child pid 17490 exit signal Segmentation
fault
 > (11), possible coredump in /tmp/apache2-gdb-dump
 > [Tue Mar 20 14:16:28.126385 2012] [:info] [pid 17487:tid
47401308446624]
 > mod_wsgi (pid=17490): Process 'site-2' has died, deregister and
restart it.
 > [Tue Mar 20 14:16:28.126394 2012] [:info] [pid 17487:tid
47401308446624]
 > mod_wsgi (pid=17490): Process 'site-2' has been deregistered and
will no
 > longer be monitored.
 > [Tue Mar 20 14:16:28.126826 2012] [:info] [pid 17846:tid
47401308446624]
 > mod_wsgi (pid=17846): Starting process 'site-2' with uid=48,
gid=48 and
 > threads=25.
 > [Tue Mar 20 14:16:28.127268 2012] [:info] [pid 17846:tid
47401308446624]
 > mod_wsgi (pid=17846): Initializing Python.
 >
 > Back trace on core file ...
 >
 > Core was generated by `/usr/local/apache2/bin/httpd -k start'.
 > Program terminated with signal 11, Segmentation fault.
 > #0 0x0036422cb2e6 in poll () from /lib64/libc.so.6
 > (gdb) bt
 > #0 0x0036422cb2e6 in poll () from /lib64/libc.so.6
 > #1 0x2b1c7a05dd79 in apr_poll (aprset=0x7fff13f01e40, num=1,
 > nsds=0x7fff13f01e94, timeout=0) at poll/unix/poll.c:120
 > #2 0x2b1c7d5166d3 in 

Re: usage of url template tag

2012-03-21 Thread Larry Martell
On Tue, Mar 20, 2012 at 11:04 PM, Daniel Roseman  wrote:
> On Tuesday, 20 March 2012 15:27:27 UTC-7, larry@gmail.com wrote:
>>
>> I'm trying to generate a URL that looks something like this:
>>
>>
>> /report/faloom/EventLog/?message=EventSearchString_ids=13_1=Tool_2=Time_3=Module_4=Message_preview=Generate+Report
>>
>> I have the values for the arguments (message, tool_ids, etc)  available to
>> me.
>>
>> My urlconf has:
>>
>> (r'^report/$', motor.ui.views.index)
>>
>> If I put this in my template:
>>
>> {% url motor.ui.views.index %}
>>
>> I get:
>>
>> /report/
>>
>> What do I use as arguments with the url tag to get the URL I want?
>> I've tried many, many different things, but no matter what, I get a
>> NoReverseMatch exception.
>
>
> This question makes no sense at all. Your URL is just "/report/". You can
> add the  GET parameters manually, since they aren't matched in a URLconf,
> but where is the 'faloom/EventLog' bit supposed to be coming from? There is
> no URL that matches that.

I'm very new to django. The rest of the URL comes from the index
function in views.py. I wasn't sure if it violated the DRY principle
to hardcode 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-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Problem with tuncated Admin pages in apache + mod_fcgid

2012-03-21 Thread Another Django Newbie


On Wednesday, March 21, 2012 7:18:16 AM UTC, Jani Tiainen wrote:
>
> 20.3.2012 16:45, Another Django Newbie kirjoitti:
> >
> >
> > On Tuesday, March 20, 2012 10:28:49 AM UTC, Another Django Newbie wrote:
> >
> >
> >
> > On Tuesday, March 20, 2012 10:01:36 AM UTC, Tom Evans wrote:
> >
> > On Mon, Mar 19, 2012 at 5:24 PM, Jani Tiainen 
> > wrote:
> >  > Hi,
> >  >
> >  > Since we use same setup except one part: we use mod_wsgi
> > instead of
> >  > mod_fcgi.
> >  >
> >  > (Since wsgi is considered to be defacto protocol). Could you
> > try to use it?
> >  >
> >
> > WSGI is the de-facto for hosting python in web servers. If you
> > aren't
> > running just python, it's nice to use the same hosting mechanism 
> for
> > all your apps, and fastcgi is a supported mechanism.
> >
> > OP: You mention using mod_fcgid, but you do not give us any idea 
> of
> > how you are using mod_fcgid. Configuration and error logs
> > please. FYI,
> > we run django quite happily under mod_fastcgi.
> >
> > Cheers
> >
> > Tom
> >
> >
> >
> > Hi Tom, Jani,
> >
> > Currently struggling to compile mod_wsgi, or more specifically a
> > shared library version of python - something to do with mismatched
> > 32/64 bit libraries I think.
> >
> > Here's an extract from httpd.conf.
> >
> > RewriteEngine On
> > RewriteRule ^.*/cfServer/(.*)$ /cgi-bin/django.cgi/$1 [PT]
> > 
> > Options ExecCGI
> > AddHandler fcgid-script .cgi
> > # AddHandler cgi-script .cgi
> > Require all granted
> > 
> >
> > and the relevant django.cgi
> >
> > #!/usr/local/bin/python
> > from FcgiWsgiAdapter import list_environment, serve_wsgi
> >
> > import os, sys
> > os.environ['DJANGO_SETTINGS_MODULE'] = 'cfServer.settings'
> > os.environ['ORACLE_HOME'] = '/oracle/11gStdEd'
> >
> > from django.core.handlers.wsgi import WSGIHandler
> >
> > # use this to test that fastcgi works and to inspect the environment
> > # serve_wsgi(list_environment)
> > # use this to serve django
> > serve_wsgi(WSGIHandler())
> >
> > The "FcgiWsgiAdapter" referred to came from djangosnippets.org
> > .
> >
> > As to error logs, as I mentioned in the original post I don't see
> > anything added to any logs when this happens and there is only a
> > warning about the ssl library when apache is restarted.
> >
> > Regards, ADN
> >
> >
> >
> > *So I swapped to using WSGI with this apache config *
> >
> > WSGIScriptAlias / /home/user/python/djcode/cfServer/apache/django.wsgi
> > WSGIDaemonProcess site-1 threads=30
> > WSGIProcessGroup site-1
> >
> > 
> > AllowOverride None
> > Options None
> > Require all granted
> > 
> >
> > and this django.wsgi
> >
> > import os, sys
> > sys.path.append('/home/user/python/djcode')
> > os.environ['DJANGO_SETTINGS_MODULE'] = 'cfServer.settings'
> > os.environ['ORACLE_HOME'] = '/oracle/11gStdEd'
> > os.environ['PYTHON_EGG_CACHE'] = '/var/www/.python-eggs'
> >
> > import django.core.handlers.wsgi
> >
> > application = django.core.handlers.wsgi.WSGIHandler()
> >
> > and I get segmentation faults (debug level tracing from apache error log)
> >
> > [Tue Mar 20 14:16:28.126341 2012] [core:notice] [pid 17487:tid
> > 47401308446624] AH00051: child pid 17490 exit signal Segmentation fault
> > (11), possible coredump in /tmp/apache2-gdb-dump
> > [Tue Mar 20 14:16:28.126385 2012] [:info] [pid 17487:tid 47401308446624]
> > mod_wsgi (pid=17490): Process 'site-2' has died, deregister and restart 
> it.
> > [Tue Mar 20 14:16:28.126394 2012] [:info] [pid 17487:tid 47401308446624]
> > mod_wsgi (pid=17490): Process 'site-2' has been deregistered and will no
> > longer be monitored.
> > [Tue Mar 20 14:16:28.126826 2012] [:info] [pid 17846:tid 47401308446624]
> > mod_wsgi (pid=17846): Starting process 'site-2' with uid=48, gid=48 and
> > threads=25.
> > [Tue Mar 20 14:16:28.127268 2012] [:info] [pid 17846:tid 47401308446624]
> > mod_wsgi (pid=17846): Initializing Python.
> >
> > Back trace on core file ...
> >
> > Core was generated by `/usr/local/apache2/bin/httpd -k start'.
> > Program terminated with signal 11, Segmentation fault.
> > #0 0x0036422cb2e6 in poll () from /lib64/libc.so.6
> > (gdb) bt
> > #0 0x0036422cb2e6 in poll () from /lib64/libc.so.6
> > #1 0x2b1c7a05dd79 in apr_poll (aprset=0x7fff13f01e40, num=1,
> > nsds=0x7fff13f01e94, timeout=0) at poll/unix/poll.c:120
> > #2 0x2b1c7d5166d3 in wsgi_daemon_main (p=0x1257a138, 
> daemon=0x12696218)
> > at mod_wsgi.c:11330
> > #3 0x2b1c7d51851f in wsgi_start_process (p=0x1257a138,
> > daemon=0x12696218)
> > at mod_wsgi.c:11969
> > #4 0x2b1c7d518f50 in wsgi_start_daemons (pconf=0x1257a138,
> > ptemp=, plog=,
> > s=) at mod_wsgi.c:12181
> > #5 wsgi_hook_init (pconf=0x1257a138, 

[bump] Preventing JOIN while checking if a self referencing FK is null

2012-03-21 Thread diafygi
There is an old thread that didn't end in a resolution about
preventing joins in a filter(foreign_key=None) scenario.

http://groups.google.com/group/django-users/browse_thread/thread/61ee2fb22deae326

I'd like to bring it up again and ask if there is now a way to prevent
joins from a query.

An example:
class Blog(model.Models):
   editor = models.ForeignKey(User, null=True)

# find all the blogs with no editors
>>> Blog.objects.filter(editor=None)
DEBUG:django.db.backends:(0.039) SELECT `myapp_blog`.`id` FROM
`myapp_blog` LEFT OUTER JOIN `myapp_user` ON (`myapp_blog`.`editor_id`
= `myapp_user`.`id`) WHERE `myapp_user`.`id` IS NULL;

# Is there a way to do this query?
>>> Blog.objects.filter(editor=None)
DEBUG:django.db.backends:(0.039) SELECT `myapp_blog`.`id` FROM
`myapp_blog` WHERE `myapp_blog`.`editor_id` IS NULL;

Thanks!
Daniel

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



Re: Basic Random Number Generation

2012-03-21 Thread Jani Tiainen

So you initialize randomnumber library everytime with your custom seed:

def random_generator(x):
random.seed(x) # Set seed to fixed value
return random.randint(10, 99)

But as you already know, that has nothing to do with randomness. You 
return always the same number so you may use much more

lightweight solutions to calculate your 6 digit numbers.

21.3.2012 10:20, Nikhil Verma kirjoitti:

Hi Jani

The def random_generator(n): here n parameter is any number which i will
get from my request in a function.
Now when i will get the number let say 101 i will pass this 101 in my
random_generator(n) so it becomes random_generator(101) .

Now in return it should give me 6-digit number. If the 101 comes again
in that function it will generate the same random number.

I read about random.seed but how can i relate that in my case.

Thanks  for help.



On Wed, Mar 21, 2012 at 1:01 PM, Jani Tiainen > wrote:

21.3.2012 9:19, Nikhil Verma kirjoitti:

Hi All

I want to generate a fix 6-digit random number from a function.

eg :-

  def random_generator(n):
   # do domething great
   return '6-digit random number'

 output examples
 >>>random_number(6) # n is the input number that i will get
from my request
 >>>987657

 >>>random_number(100)
 >>>987647

 >>>random_number(6) # if the same input comes again it would
generate a
same random number
 >>>987657

If the same input cannot be generated any other way to do this part

Any help would be appreciated.


It seems that you're initializing pseudorandom generator with same
seed number. So yes, sequence of generated numbers will be same.

so doing something like this:

from random import choice # Initializes from current time.

def random_digits():
return [choice('0123456789') for i in range(7)]

or if you need it:

from random import randint # Initializes from current time.

def random_int():
return randit(10, 99)


Note that pseudorandom generator is only initialized first time
import happens. After that you can set it manually using
random.seed([x]) function.

--

Jani Tiainen

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




--
Regards
Nikhil Verma
+91-958-273-3156

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


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



Re: Basic Random Number Generation

2012-03-21 Thread Nikhil Verma
Hi Jani

The def random_generator(n): here n parameter is any number which i will
get from my request in a function.
Now when i will get the number let say 101 i will pass this 101 in my
random_generator(n) so it becomes random_generator(101) .

Now in return it should give me 6-digit number. If the 101 comes again in
that function it will generate the same random number.

I read about random.seed but how can i relate that in my case.

Thanks  for help.



On Wed, Mar 21, 2012 at 1:01 PM, Jani Tiainen  wrote:

> 21.3.2012 9:19, Nikhil Verma kirjoitti:
>
>  Hi All
>>
>> I want to generate a fix 6-digit random number from a function.
>>
>> eg :-
>>
>>  def random_generator(n):
>>   # do domething great
>>   return '6-digit random number'
>>
>> output examples
>>  >>>random_number(6) # n is the input number that i will get from my
>> request
>>  >>>987657
>>
>>  >>>random_number(100)
>>  >>>987647
>>
>>  >>>random_number(6) # if the same input comes again it would generate a
>> same random number
>>  >>>987657
>>
>> If the same input cannot be generated any other way to do this part
>>
>> Any help would be appreciated.
>>
>>
> It seems that you're initializing pseudorandom generator with same seed
> number. So yes, sequence of generated numbers will be same.
>
> so doing something like this:
>
> from random import choice # Initializes from current time.
>
> def random_digits():
>return [choice('0123456789') for i in range(7)]
>
> or if you need it:
>
> from random import randint # Initializes from current time.
>
> def random_int():
>return randit(10, 99)
>
>
> Note that pseudorandom generator is only initialized first time import
> happens. After that you can set it manually using
> random.seed([x]) function.
>
> --
>
> Jani Tiainen
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to django-users+unsubscribe@**
> googlegroups.com .
> For more options, visit this group at http://groups.google.com/**
> group/django-users?hl=en
> .
>
>


-- 
Regards
Nikhil Verma
+91-958-273-3156

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



Re: Basic Random Number Generation

2012-03-21 Thread Jani Tiainen

21.3.2012 9:19, Nikhil Verma kirjoitti:

Hi All

I want to generate a fix 6-digit random number from a function.

eg :-

  def random_generator(n):
   # do domething great
   return '6-digit random number'

 output examples
 >>>random_number(6) # n is the input number that i will get from my request
 >>>987657

 >>>random_number(100)
 >>>987647

 >>>random_number(6) # if the same input comes again it would generate a
same random number
 >>>987657

If the same input cannot be generated any other way to do this part

Any help would be appreciated.



It seems that you're initializing pseudorandom generator with same seed 
number. So yes, sequence of generated numbers will be same.


so doing something like this:

from random import choice # Initializes from current time.

def random_digits():
return [choice('0123456789') for i in range(7)]

or if you need it:

from random import randint # Initializes from current time.

def random_int():
return randit(10, 99)


Note that pseudorandom generator is only initialized first time import 
happens. After that you can set it manually using

random.seed([x]) function.

--

Jani Tiainen

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



Basic Random Number Generation

2012-03-21 Thread Nikhil Verma
Hi All

I want to generate a fix 6-digit random number from a function.

eg :-

 def random_generator(n):
  # do domething great
  return '6-digit random number'

output examples
>>>random_number(6) # n is the input number that i will get from my request
>>>987657

>>>random_number(100)
>>>987647

>>>random_number(6) # if the same input comes again it would generate a
same random number
>>>987657

If the same input cannot be generated any other way to do this part

Any help would be appreciated.


-- 
Regards
Nikhil Verma
+91-958-273-3156

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



Re: Problem with tuncated Admin pages in apache + mod_fcgid

2012-03-21 Thread Jani Tiainen

20.3.2012 16:45, Another Django Newbie kirjoitti:



On Tuesday, March 20, 2012 10:28:49 AM UTC, Another Django Newbie wrote:



On Tuesday, March 20, 2012 10:01:36 AM UTC, Tom Evans wrote:

On Mon, Mar 19, 2012 at 5:24 PM, Jani Tiainen 
wrote:
 > Hi,
 >
 > Since we use same setup except one part: we use mod_wsgi
instead of
 > mod_fcgi.
 >
 > (Since wsgi is considered to be defacto protocol). Could you
try to use it?
 >

WSGI is the de-facto for hosting python in web servers. If you
aren't
running just python, it's nice to use the same hosting mechanism for
all your apps, and fastcgi is a supported mechanism.

OP: You mention using mod_fcgid, but you do not give us any idea of
how you are using mod_fcgid. Configuration and error logs
please. FYI,
we run django quite happily under mod_fastcgi.

Cheers

Tom



Hi Tom, Jani,

Currently struggling to compile mod_wsgi, or more specifically a
shared library version of python - something to do with mismatched
32/64 bit libraries I think.

Here's an extract from httpd.conf.

RewriteEngine On
RewriteRule ^.*/cfServer/(.*)$ /cgi-bin/django.cgi/$1 [PT]

Options ExecCGI
AddHandler fcgid-script .cgi
# AddHandler cgi-script .cgi
Require all granted


and the relevant django.cgi

#!/usr/local/bin/python
from FcgiWsgiAdapter import list_environment, serve_wsgi

import os, sys
os.environ['DJANGO_SETTINGS_MODULE'] = 'cfServer.settings'
os.environ['ORACLE_HOME'] = '/oracle/11gStdEd'

from django.core.handlers.wsgi import WSGIHandler

# use this to test that fastcgi works and to inspect the environment
# serve_wsgi(list_environment)
# use this to serve django
serve_wsgi(WSGIHandler())

The "FcgiWsgiAdapter" referred to came from djangosnippets.org
.

As to error logs, as I mentioned in the original post I don't see
anything added to any logs when this happens and there is only a
warning about the ssl library when apache is restarted.

Regards, ADN



*So I swapped to using WSGI with this apache config *

WSGIScriptAlias / /home/user/python/djcode/cfServer/apache/django.wsgi
WSGIDaemonProcess site-1 threads=30
WSGIProcessGroup site-1


AllowOverride None
Options None
Require all granted


and this django.wsgi

import os, sys
sys.path.append('/home/user/python/djcode')
os.environ['DJANGO_SETTINGS_MODULE'] = 'cfServer.settings'
os.environ['ORACLE_HOME'] = '/oracle/11gStdEd'
os.environ['PYTHON_EGG_CACHE'] = '/var/www/.python-eggs'

import django.core.handlers.wsgi

application = django.core.handlers.wsgi.WSGIHandler()

and I get segmentation faults (debug level tracing from apache error log)

[Tue Mar 20 14:16:28.126341 2012] [core:notice] [pid 17487:tid
47401308446624] AH00051: child pid 17490 exit signal Segmentation fault
(11), possible coredump in /tmp/apache2-gdb-dump
[Tue Mar 20 14:16:28.126385 2012] [:info] [pid 17487:tid 47401308446624]
mod_wsgi (pid=17490): Process 'site-2' has died, deregister and restart it.
[Tue Mar 20 14:16:28.126394 2012] [:info] [pid 17487:tid 47401308446624]
mod_wsgi (pid=17490): Process 'site-2' has been deregistered and will no
longer be monitored.
[Tue Mar 20 14:16:28.126826 2012] [:info] [pid 17846:tid 47401308446624]
mod_wsgi (pid=17846): Starting process 'site-2' with uid=48, gid=48 and
threads=25.
[Tue Mar 20 14:16:28.127268 2012] [:info] [pid 17846:tid 47401308446624]
mod_wsgi (pid=17846): Initializing Python.

Back trace on core file ...

Core was generated by `/usr/local/apache2/bin/httpd -k start'.
Program terminated with signal 11, Segmentation fault.
#0 0x0036422cb2e6 in poll () from /lib64/libc.so.6
(gdb) bt
#0 0x0036422cb2e6 in poll () from /lib64/libc.so.6
#1 0x2b1c7a05dd79 in apr_poll (aprset=0x7fff13f01e40, num=1,
nsds=0x7fff13f01e94, timeout=0) at poll/unix/poll.c:120
#2 0x2b1c7d5166d3 in wsgi_daemon_main (p=0x1257a138, daemon=0x12696218)
at mod_wsgi.c:11330
#3 0x2b1c7d51851f in wsgi_start_process (p=0x1257a138,
daemon=0x12696218)
at mod_wsgi.c:11969
#4 0x2b1c7d518f50 in wsgi_start_daemons (pconf=0x1257a138,
ptemp=, plog=,
s=) at mod_wsgi.c:12181
#5 wsgi_hook_init (pconf=0x1257a138, ptemp=,
plog=, s=) at mod_wsgi.c:13755
#6 0x00444c2c in ap_run_post_config (pconf=0x1257a138,
plog=0x125df538, ptemp=0x125a5348, s=0x125a3508) at config.c:101
#7 0x00428734 in main (argc=3, argv=0x7fff13f02498) at main.c:765



Using WSGI briefly solved the original problem, in that I could see the
complete admin page that was previously truncated but now nothing works
- I get internal server error for all pages on the server.



https://docs.djangoproject.com/en/1.3/ref/databases/#threaded-option

Maybe you need to do that

--

Jani Tiainen

--
You received this message 

Re: Problem with Django starting up

2012-03-21 Thread Jani Tiainen

21.3.2012 7:50, Samuel Muiruri kirjoitti:

I can't get the first part to work



I assume that you have python installed to c:\python27\

You need to add c:\python27\scripts to your path.

Or alternatively:

c:\python27\scripts\django-admin.py startproject mysite

--

Jani Tiainen

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



Migrating wrapped function-based generic view to class-based generic view

2012-03-21 Thread saxon75
Hi all,

I have a site built on Django 1.2 that makes use of wrapped generic
views, and I'm wondering what the right way to migrate them to the new
class-based views in 1.3 is.  Here's an example:

urlpatterns = patterns('',
 (r'^(?P\S+)/$', views.node_section_all),
)

def node_section_all(request, sect):
  try:
object = Node.objects.filter(section__keyword=sect, published=True)
[0]
  except:
return render_to_response('doesntexist.html', {'identifier':
'node'}, context_instance=RequestContext(request))
  if object == None:
return render_to_response('doesntexist.html', {'identifier':
'node'}, context_instance=RequestContext(request))
  if Section.objects.get(keyword=sect).sort_reverse:
sort_order = 'created'
  else:
sort_order = '-created'
  return list_detail.object_list(
  request,
  queryset = Node.objects.filter(section__keyword=sect,
published=True).order_by(sort_order),
  template_name = 'node/section_list.html',
  allow_empty = True,
  paginate_by = 10,
  )

This is a fairly straightforward wrapper.  Check to see if the Section
contains any Nodes, and if so, display a list of all of the Nodes in
the Section.  If not, display an error page.

I tried just changing the "return list_detail.object_list(" line to
"return ListView.as_view(" and then removing the "request" and
"allow_empty" arguments, but I end up with an AttributeError:
'function' object has no attribute 'status_code'

So, what's the right way to migrate this sort of wrapper? Should I
subclass ListView and try to put the wrapper functionality in there?
How would that work?

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