Re: Django Tutorial part 2... Admin Site won't work...

2012-06-18 Thread Laurence MacNeill
I'm using 1.4

I finally figured out that if I just create the site manually, everything 
works fine...  I don't know why it wasn't being created when syncdb was 
run...

L.


On Sunday, June 17, 2012 2:17:35 AM UTC-4, Xavier Ordoquy wrote:
>
> Hi,
>
> The site entry is usually created when the syncdb is run.
> What Django version are you using ? If you're using the development 
> version, please remove it and install a stable version.
>
> Regards,
> Xavier Ordoquy,
> Linovia.
>
> Le 16 juin 2012 à 23:16, Laurence MacNeill a écrit :
>
> I'm going through the django tutorial and I'm having difficulties at the 
> beginning of the second part...
>
> It tells me to create the admin site, and browse to 127.0.0.1:8000/adminto 
> log in to the admin site I just created...  But when I do that, I get 
> the python server telling me that the site is not found -- it's not the 
> usual apache web-server 404 error, it's definitely coming from the python 
> server, so I know that's running properly.
>
> Searching through some of the other posts, I came across one responder who 
> asked someone with this same problem to find their site ID in their 
> settings.py file.  Mine says the site ID is 1.  So, armed with that 
> information, I go to the python shell, and type the following:
> >>> from django.contrib.sites.models import Site
> >>> Site.objects.get(id=1)
>
> And I get the following in response:
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "/usr/lib/python2.6/site-packages/django/db/models/manager.py", 
> line 131, in get
> return self.get_query_set().get(*args, **kwargs)
>   File "/usr/lib/python2.6/site-packages/django/db/models/query.py", line 
> 366, in get
> % self.model._meta.object_name)
> DoesNotExist: Site matching query does not exist.
>
> So, it seems that the entire site doesn't exist?  I've followed every step 
> in the tutorial exactly, with no problems so far...  Can anyone help me 
> with this?
>
> Thanks,
> Laurence MacNeill
> Mableton, Georgia, USA
>
>
> -- 
> 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/-/Aq18U3mxM1MJ.
> 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 view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/FA-ss7hNR50J.
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.



Trying to find something in multiple databases... Confused...

2012-06-18 Thread Laurence MacNeill
Ok, I'm a total django noob here, so I am probably doing this wrong...  But 
here goes...

When someone comes to my django app's root (index), I need to verify their 
user-name (which is stored in a Linux environment variable).  Based on 
where (or if) I find their user-name, I want to send them to one of three 
different pages -- if I don't find them in any database, I want to add them 
to a given database, then send them to a page.

So here's what I have in my views.py file:
def index(request)
 current_username = os.environ['REMOTE_USER']

-- 
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/-/89ghQfC_J0IJ.
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: Trying to find something in multiple databases... Confused...

2012-06-18 Thread Laurence MacNeill
well -- I hit the wrong key and posted that before I was finished typing... 

here's what's in my views.py file:
def index(request)
 current_username = os.environ['REMOTE_USER']

This should provide me with their username (yes I do have 'import os' at 
the top of the file)...

Now, after I get their username I want to do something like this (but I'm 
not sure how to write in django -- so I've put ## around the pseudo-code)
 try:
 student = Student.objects.get(student_name=current_username)
 except (#can't find it in Student database, but I don't know what code 
to put here#)
 try:
 instructor = 
Instructor.objects.get(instructor_name=current_username)
 except (#can't find it in Instructor database, but I don't know 
what code to put here#)
   try:
administrator = 
Administrator.objects.get(administrator_name=current_username)
   except (#fail condition - can't find current_username in 
Administrator database, but I don't know what code to put here#)
#because we failed to find it in any database, we 
assume it's a student and add it
student = Student(student_name=current_username)
student.save
 #here's where I'm not sure how to continue -- I want to do something 
like this#
 #if student is defined#
  return render_to_response('ta/student.html', student)
 #else if instructor is defined#
  return render_to_response('ta/instructor.html', instructor)
 #else if administrator is defined#
  return render_to_response('ta/administrator.html', administrator)
#end of my code#

So -- can someone please help me fill in the missing code above?  I've been 
searching for hours, but I just can't seem to hit on the correct 
search-terms to get done what I want here...

Thanks,
Laurence MacNeill
Mableton, Georgia, USA


On Monday, June 18, 2012 3:40:53 AM UTC-4, Laurence MacNeill wrote:
>
> Ok, I'm a total django noob here, so I am probably doing this wrong...  
> But here goes...
>
> When someone comes to my django app's root (index), I need to verify their 
> user-name (which is stored in a Linux environment variable).  Based on 
> where (or if) I find their user-name, I want to send them to one of three 
> different pages -- if I don't find them in any database, I want to add them 
> to a given database, then send them to a page.
>
> So here's what I have in my views.py file:
> def index(request)
>  current_username = os.environ['REMOTE_USER']
>
>

-- 
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/-/rVfs691Nk0AJ.
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.



full_validation fails upon validating an inherited model

2012-06-18 Thread Carsten Reimer

Hallo,

I have a problem running Django's full_validation-method upon an 
instance of an inherited model. Please consider the following two models:


class ParentModel(models.Model):

parent_model_id = models.IntegerField(primary_key=True)
parent_model_attr = models.CharField(max_length=200)


class ChildModel(ParentModel):

child_model_attr = models.CharField(max_length=200)

Creating a ChildModel by using the keyword pk instead of the primary 
key's real attribute name and running full_validation on it before 
saving (after saving this method does not make much sense, I think) 
leads to an error as shown below:


>>> from mytest.models import ChildModel

>>> cm = ChildModel(pk=1,child_model_attr='some 
text',parent_model_attr='Some other text')


>>> cm.full_clean()
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python2.7/dist-packages/django/db/models/base.py", 
line 824, in full_clean

raise ValidationError(errors)
ValidationError: {'parent_model_id': [u'This field cannot be null.']}


Using the primary key's real attribute name works of course (but cannot 
be done in my scenario).


Any ideas how to make using the pk-keyword work without that validation 
error?


Thanks in advance for any hint.


With best regards

Carsten Reimer


--
Carsten Reimer
Web Developer
carsten.rei...@galileo-press.de
Phone +49.228.42150.73

Galileo Press GmbH
Rheinwerkallee 4 - 53227 Bonn - Germany
Phone +49.228.42150.0 (Zentrale) .77 (Fax)
http://www.galileo-press.de/

Managing Directors: Tomas Wehren, Ralf Kaulisch, Rainer Kaltenecker
HRB 8363 Amtsgericht Bonn

--
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: full_validation fails upon validating an inherited model

2012-06-18 Thread Carsten Reimer
in my previous post I named the method in question full_validation. This 
is obviously wrong. It must be full_clean. Sorry for that.


Carsten Reimer schrieb:

Hallo,

I have a problem running Django's full_validation-method upon an 
instance of an inherited model. Please consider the following two models:


class ParentModel(models.Model):

parent_model_id = models.IntegerField(primary_key=True)
parent_model_attr = models.CharField(max_length=200)


class ChildModel(ParentModel):

child_model_attr = models.CharField(max_length=200)

Creating a ChildModel by using the keyword pk instead of the primary 
key's real attribute name and running full_validation on it before 
saving (after saving this method does not make much sense, I think) 
leads to an error as shown below:


 >>> from mytest.models import ChildModel

 >>> cm = ChildModel(pk=1,child_model_attr='some 
text',parent_model_attr='Some other text')


 >>> cm.full_clean()
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python2.7/dist-packages/django/db/models/base.py", line 
824, in full_clean

raise ValidationError(errors)
ValidationError: {'parent_model_id': [u'This field cannot be null.']}


Using the primary key's real attribute name works of course (but cannot 
be done in my scenario).


Any ideas how to make using the pk-keyword work without that validation 
error?


Thanks in advance for any hint.


With best regards

Carsten Reimer





--
Carsten Reimer
Web Developer
carsten.rei...@galileo-press.de
Phone +49.228.42150.73

Galileo Press GmbH
Rheinwerkallee 4 - 53227 Bonn - Germany
Phone +49.228.42150.0 (Zentrale) .77 (Fax)
http://www.galileo-press.de/

Managing Directors: Tomas Wehren, Ralf Kaulisch, Rainer Kaltenecker
HRB 8363 Amtsgericht Bonn

--
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: Various thoughts on authentication, registration and social logins

2012-06-18 Thread Melvyn Sopacua
On 18-6-2012 2:25, Mattias Linnap wrote:

> I would argue that this is as secure as ordinary password reset emails.
> Emailing users their passwords is insecure if they *themselves* chose
> the password - because they often re-use it on multiple sites.
> As long as it is a randomly generated one, it is no different from
> emailing them password reset links.
> Do you agree?

Nope. Emailing passwords is insecure because they guard information not
normally available. If your site stores the user's credit card info,
would you still agree with your own assessment?
Password reset links are more secure not because they don't contain the
password, but because they are time-limited and one-shot, thus requiring
the malicious user to act fast and before the real user does so.
The fact that you do not require them to reset their randomly generated
password makes your method insecure. And the fact that it isn't
time-limited. Even though, mailman does the same thing and even reminds
you monthly, mailman does not claim to be a secure authentication system.

-- 
Melvyn Sopacua

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



SOLVED: Django 1.3 Admin Changelist column alignment

2012-06-18 Thread kooliah
I solved cloning and renaming the templatetag result_list (the rows 
builder) and modifying it.
It checks if the field is a number and set the class attribute  of the 
 tag to "numb", so using the admin css i can change alignment
Obviously i had to override change_list.html too to let it load my 
custom template tag.


It works, but i'm surprising that a so common functionality (everywhere 
numbers are right justify) needs a so complex customization..


I'm sure to have miss something and there is a simpler  way to do it...

If someone has better idea or solution i'm very happy to know

Thanks anyway to all



On 06/17/2012 02:55 PM, kooliah wrote:
I'm trying to change alignment of the number columns in the 
changelist, instead of default left alignment for all, i would like to 
have left for the text and right for the numbers.
Is it possible to do it in the admin.py overriding the default class 
or i have to make some filters and apply to the template?


Overriding i can change the format or the column displayed using a 
callable, so i tryed to rjust the number (converted to string and 
thousand separated) using a function but i think it is trimmed again 
later



Can someone point me in the right direction?

Thanks to all

Kooliah



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



How to call perl script in my django application

2012-06-18 Thread Tanveer Ali Sha
Hello,

how can I call Perl script (EX:hello world) in my django application ?

-- 
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: Trying to find something in multiple databases... Confused...

2012-06-18 Thread Melvyn Sopacua
On 18-6-2012 9:52, Laurence MacNeill wrote:
> well -- I hit the wrong key and posted that before I was finished typing... 
> 
> here's what's in my views.py file:
> def index(request)
>  current_username = os.environ['REMOTE_USER']

And you're sure this works? Try:
 return django.shortcuts.render_to_response(current_username)

here to verify it's coming through. Normally, the authenticated username
would be part of the request dictionary.

> This should provide me with their username (yes I do have 'import os' at 
> the top of the file)...
> 
> Now, after I get their username I want to do something like this (but I'm 
> not sure how to write in django -- so I've put ## around the pseudo-code)
>  try:
>  student = Student.objects.get(student_name=current_username)
>  except (#can't find it in Student database, but I don't know what code 
> to put here#)

It's in tutorial part 3:
https://docs.djangoproject.com/en/1.4/intro/tutorial03/#raising-404

except Student.DoesNotExist:
   student = None

>  #here's where I'm not sure how to continue -- I want to do something 
> like this#
>  #if student is defined#
>   return render_to_response('ta/student.html', student)

Almost correct:
if student is not None :
 # the student.html template will now have a variable named student
 # which is the student object you fetched
 return render_to_response('ta/student.html', student=student)
elif instructor is not None :
 #etc

-- 
Melvyn Sopacua

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



Re: How to call perl script in my django application

2012-06-18 Thread Sergiy Khohlov
Such as in trivial python code . Check python system and os module

2012/6/18 Tanveer Ali Sha :
> Hello,
>
> how can I call Perl script (EX:hello world) in my django application ?
>
> --
> 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: How to call perl script in my django application

2012-06-18 Thread Tanveer Ali Sha
sorry, i dint get that.Please can u give example .??


On Mon, Jun 18, 2012 at 4:36 PM, Sergiy Khohlov  wrote:
> Such as in trivial python code . Check python system and os module
>
> 2012/6/18 Tanveer Ali Sha :
>> Hello,
>>
>> how can I call Perl script (EX:hello world) in my django application 
>> ?
>>
>> --
>> 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.
>

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



Re: How to call perl script in my django application

2012-06-18 Thread Carsten Agger

Den 18-06-2012 13:10, Tanveer Ali Sha skrev:

sorry, i dint get that.Please can u give example .??


  visit this group at http://groups.google.com/group/django-users?hl=en.



There's a discussion of how to do this here:

http://stackoverflow.com/questions/4682088/call-perl-script-from-python

The second answer and the following ones is best.


--
Carsten Agger
Magenta ApS
Åbogade 15
8200 Århus N

Tlf +45 5060 1269
Mob +45 2086 5010
http://www.magenta-aps.dk
carst...@magenta-aps.dk

--
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: Stuck already on step one, django on windows

2012-06-18 Thread Vincent
I had the same problem as you do.

You can try the instructions on this site:
http://djangolife.blogspot.sg/2008/06/part-vi-django.html 

Remember to restart your cmd prompt after you changed the environment 
variables though. I didn't and it took me sometime to figure out that the 
reason the environment variables didn't change was because I did not 
restart my shell/cmd prompt. Hope this helps.

--Vincent

On Monday, June 18, 2012 3:15:53 AM UTC+8, Melvyn Sopacua wrote:
>
> On 14-6-2012 17:25, Daniel Roseman wrote: 
>
> >> I rent space on a server run by hostmonster.com.  Would it be a better 
> >> idea for me to learn how to do all this straight on my server instead 
> of 
> >> windows anyways?  I don't even know how to tell if the django stuff 
> works 
> >> within my hosting environment. 
>
> > 
> > No need for Unix or cygwin. cd works perfectly well in Windows, as does 
> > Django generally. What specific problem are you having? 
>
> The unix/cygwin comment was related to that part specifically. Either 
> way, off-list I received indication that his problem is related to the 
> windows path, and putting that back on the list: 
>
> On 14-6-2012 18:35, Daniel Patriarca wrote: 
> > - I entered  hit enter 
> > 
> > - I got the error that django-admin.py is not recognized as an internal 
> or 
> > external command, operable program or batch file. 
>
> In this case, you need to alter the windows PATH variable. I totally 
> forgot how to do that, something with My Computer and right-clicks. 
> Maybe somebody else can chime in. 
> -- 
> Melvyn Sopacua 
>

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



Re: How to call perl script in my django application

2012-06-18 Thread Sergiy Khohlov
>>> from subprocess import call
>>> call("uname")
Linux
0
>>> call("uname", "-a")


2012/6/18 Carsten Agger :
> Den 18-06-2012 13:10, Tanveer Ali Sha skrev:
>>
>> sorry, i dint get that.Please can u give example .??
>>
>>
>>  visit this group at http://groups.google.com/group/django-users?hl=en.
>>
>
> There's a discussion of how to do this here:
>
> http://stackoverflow.com/questions/4682088/call-perl-script-from-python
>
> The second answer and the following ones is best.
>
>
> --
> Carsten Agger
> Magenta ApS
> Åbogade 15
> 8200 Århus N
>
> Tlf +45 5060 1269
> Mob +45 2086 5010
> http://www.magenta-aps.dk
> carst...@magenta-aps.dk
>
>
> --
> 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: Trying to find something in multiple databases... Confused...

2012-06-18 Thread Daniel Roseman
On Monday, 18 June 2012 08:40:53 UTC+1, Laurence MacNeill wrote:
>
> Ok, I'm a total django noob here, so I am probably doing this wrong...  
> But here goes...
>
> When someone comes to my django app's root (index), I need to verify their 
> user-name (which is stored in a Linux environment variable).  Based on 
> where (or if) I find their user-name, I want to send them to one of three 
> different pages -- if I don't find them in any database, I want to add them 
> to a given database, then send them to a page.
>
> So here's what I have in my views.py file:
> def index(request)
>  current_username = os.environ['REMOTE_USER']
>
>
So Melvyn has answered your question, but a quick note on terminology: what 
you've got there are separate *database tables*, or separate *Django 
models* -- not separate databases. Multiple databases is a whole different 
question, which you really don't want to get into as a newbie (or, indeed, 
at all if possible).
--
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/-/jSuHg6H4amoJ.
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: multiple databases [was]Trying to find something in multiple databases... Confused...

2012-06-18 Thread kenneth gonsalves
On Mon, 2012-06-18 at 05:12 -0700, Daniel Roseman wrote:
> Multiple databases is a whole different 
> question, which you really don't want to get into as a newbie (or,
> indeed, 
> at all if possible). 

could you elaborate on this - I was thinking on getting into multiple
databases and would appreciate your take.
-- 
regards
Kenneth Gonsalves

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



Apache/mod_wsgi documentation problem

2012-06-18 Thread coolgeek
Hello - 

Django newb.  I hope this is the right place to post this.  

I had a problem with the virtualenv section of the Apache/mod_wsgi 
documentation 

https://docs.djangoproject.com/en/1.4/howto/deployment/wsgi/modwsgi/#using-a-virtualenv

Please remove the line:

"To do this, you can add another line to your Apache configuration:" 

and change the following configuration directive to:

"WSGIPythonPath 
/path/to/your/venv/lib/python2.X/site-packages:/path/to/mysite.com"



Thank you.


-- 
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/-/VNDQ7sGh4OwJ.
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: Various thoughts on authentication, registration and social logins

2012-06-18 Thread Ien Cheng
Mattias, 

It may be worth checking out django-allauth. It doesn't use the flow you 
are proposing -- as register-by-email users do need to enter a password -- 
but it has an nicely integrated one-click login via Facebook/Google/etc. 
alternative option for users. I haven't tried, as I like the default flows, 
but I guess you would be able to modify the code to do what you want pretty 
easily. (If you do try it, 
here'sa
 tip on installation.)

--Ien

On Sunday, June 17, 2012 8:25:15 PM UTC-4, Mattias Linnap wrote:
>
> Hi all, 
>
> I'm trying to build a nice authentication flow for a website. 
>
> In my opinion, a good flow would be: 
> 0. There are no usernames, emails are used instead, 
> 1. User signs up by just entering their email address, 
> 2. An account is created for them, and a temporary plaintext password, 
> along with a sign-in link is sent by email (only its hash, not the 
> plaintext password is stored in the database), 
> 3. If they log in for the first time, they are prompted to, but not 
> forced to change their password (this is not emailed), 
> 4. If they forget their password, a new temporary password along with 
> a sign-in link are sent to them by email. 
> 5. There should be as few intermediate "success confirmation" pages as 
> possible, instead redirecting to an useful page, and showing a 
> temporary message on there. 
>
> I would argue that this is as secure as ordinary password reset emails. 
> Emailing users their passwords is insecure if they *themselves* chose 
> the password - because they often re-use it on multiple sites. 
> As long as it is a randomly generated one, it is no different from 
> emailing them password reset links. 
> Do you agree? 
>
> What would you recommend as the approach to building this with least 
> effort, while keeping the rest of django and django.contrib packages 
> working as expected? 
> I've experimented briefly with django-registration, and it seems that 
> the best approach might be writing a new backend for it. 
> Do you have any other suggestions or packages that I should look at first? 
>
> Thanks, 
>
> Mattias 
>

-- 
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/-/292FJQwQYzoJ.
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: multiple databases [was]Trying to find something in multiple databases... Confused...

2012-06-18 Thread Daniel Roseman
On Monday, 18 June 2012 13:16:55 UTC+1, lawgon wrote:
>
> On Mon, 2012-06-18 at 05:12 -0700, Daniel Roseman wrote: 
> > Multiple databases is a whole different 
> > question, which you really don't want to get into as a newbie (or, 
> > indeed, 
> > at all if possible). 
>
> could you elaborate on this - I was thinking on getting into multiple 
> databases and would appreciate your take. 
> -- 
> regards 
> Kenneth Gonsalves 
>
>
Oh, I'm just being my usual crotchety self. There are certain "advanced" 
features of Django - multiple DBs, model subclassing, that sort of thing - 
that I tend to feel we'd be better off without. But I'm almost certainly 
being unfair, there is definitely a use case for multiple DBs: it's when 
people start trying to use it for things like dynamic multitenancy that I 
start to despair.
--
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/-/Hdn_97GiNjAJ.
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: Apache/mod_wsgi documentation problem

2012-06-18 Thread Daniel Roseman
On Monday, 18 June 2012 13:42:46 UTC+1, coolgeek wrote:
>
> Hello - 
>
> Django newb.  I hope this is the right place to post this.  
>
> I had a problem with the virtualenv section of the Apache/mod_wsgi 
> documentation 
>
>
> https://docs.djangoproject.com/en/1.4/howto/deployment/wsgi/modwsgi/#using-a-virtualenv
>
> Please remove the line:
>
> "To do this, you can add another line to your Apache configuration:" 
>
> and change the following configuration directive to:
>
> "WSGIPythonPath 
> /path/to/your/venv/lib/python2.X/site-packages:/path/to/mysite.com"
>
>
>
> Thank you.
>
>
>
If you think the documentation needs changing, you should raise a bug in 
the tracker (http://code.djangoproject.com) or create a fork/pull request 
(https://github.com/django/django).
--
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/-/ZTIfI5goMM0J.
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.



Problem using User.get_profile() in DJANGO

2012-06-18 Thread upmauro
Sorry my english.

In my *models.py*

class Usuario(models.Model):
user = models.ForeignKey(User,primary_key=True)
apelido = models.CharField(max_length=75, blank=True)
class Meta:
db_table = u'usuario'

def create_user_profile(sender, instance, created, **kwargs):
if created:
   profile, created = Usuario.objects.get_or_create(user=instance)

post_save.connect(create_user_profile, sender=User)

In my *views.py*
*
*
@csrf_exempt
def register(request):
user = User.objects.create_user(request.POST['apelido'], 
request.POST['email'], request.POST['pwd'])
user.get_profile().apelido = request.POST['apelido']

*
*
*Error:*
*
*
Exception Value: 
Usuario matching query does not exist

*Line:*.

user.get_profile().apelido = request.POST['apelido'] 

-- 
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/-/c0qZCUUHsGEJ.
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 using User.get_profile() in DJANGO

2012-06-18 Thread Kurtis Mullins
Give this a shot:

user = User.objects.create_user(request.POST['apelido'],
request.POST['email'], request.POST['pwd'])
user.save()
profile = user.get_profile()
profile.apelido = request.POST['apelido']
profile.save()

Also, I recommend using Forms (and better yet, ModelForms with Class-Based
Views) to sanitize and validate your data.

On Mon, Jun 18, 2012 at 9:50 AM, upmauro  wrote:

> Sorry my english.
>
> In my *models.py*
>
> class Usuario(models.Model):
> user = models.ForeignKey(User,primary_key=True)
> apelido = models.CharField(max_length=75, blank=True)
> class Meta:
> db_table = u'usuario'
>
> def create_user_profile(sender, instance, created, **kwargs):
> if created:
>profile, created = Usuario.objects.get_or_create(user=instance)
>
> post_save.connect(create_user_profile, sender=User)
>
> In my *views.py*
> *
> *
> @csrf_exempt
> def register(request):
> user = User.objects.create_user(request.POST['apelido'],
> request.POST['email'], request.POST['pwd'])
> user.get_profile().apelido = request.POST['apelido']
>
> *
> *
> *Error:*
> *
> *
> Exception Value:
> Usuario matching query does not exist
>
> *Line:*.
>
> user.get_profile().apelido = request.POST['apelido']
>
>  --
> 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/-/c0qZCUUHsGEJ.
> 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: multiple databases [was]Trying to find something in multiple databases... Confused...

2012-06-18 Thread Kurtis Mullins
>
> On Mon, Jun 18, 2012 at 9:30 AM, Daniel Roseman 
>  wrote:

There are certain "advanced" features of Django - multiple DBs, model
> subclassing, that sort of thing


I feel there's quite a few problems that would be relatively unsolvable
without model subclassing. At least in any efficient 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.



Authentication

2012-06-18 Thread Harjot Mann
I want to give a username and password to my project in django...can anyone 
tell me what should i do???

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



Re: Django Tutorial part 2... Admin Site won't work...

2012-06-18 Thread Harjot Mann
have you uncomment the lines in the urls.py file???if not uncomment
the 4th,5th and 16th line in urls.py file And then run the server command.
On Mon, Jun 18, 2012 at 1:06 PM, Laurence MacNeill
wrote:

> I'm using 1.4
>
> I finally figured out that if I just create the site manually, everything
> works fine...  I don't know why it wasn't being created when syncdb was
> run...
>
> L.
>
>
>
> On Sunday, June 17, 2012 2:17:35 AM UTC-4, Xavier Ordoquy wrote:
>>
>> Hi,
>>
>> The site entry is usually created when the syncdb is run.
>> What Django version are you using ? If you're using the development
>> version, please remove it and install a stable version.
>>
>> Regards,
>> Xavier Ordoquy,
>> Linovia.
>>
>> Le 16 juin 2012 à 23:16, Laurence MacNeill a écrit :
>>
>> I'm going through the django tutorial and I'm having difficulties at the
>> beginning of the second part...
>>
>> It tells me to create the admin site, and browse to 127.0.0.1:8000/adminto 
>> log in to the admin site I just created...  But when I do that, I get
>> the python server telling me that the site is not found -- it's not the
>> usual apache web-server 404 error, it's definitely coming from the python
>> server, so I know that's running properly.
>>
>> Searching through some of the other posts, I came across one responder
>> who asked someone with this same problem to find their site ID in their
>> settings.py file.  Mine says the site ID is 1.  So, armed with that
>> information, I go to the python shell, and type the following:
>> >>> from django.contrib.sites.models import Site
>> >>> Site.objects.get(id=1)
>>
>> And I get the following in response:
>> Traceback (most recent call last):
>>   File "", line 1, in 
>>   File "/usr/lib/python2.6/site-**packages/django/db/models/**manager.py",
>> line 131, in get
>> return self.get_query_set().get(***args, **kwargs)
>>   File "/usr/lib/python2.6/site-**packages/django/db/models/**query.py",
>> line 366, in get
>> % self.model._meta.object_name)
>> DoesNotExist: Site matching query does not exist.
>>
>> So, it seems that the entire site doesn't exist?  I've followed every
>> step in the tutorial exactly, with no problems so far...  Can anyone help
>> me with this?
>>
>> Thanks,
>> Laurence MacNeill
>> Mableton, Georgia, USA
>>
>>
>> --
>> 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/-/**Aq18U3mxM1MJ
>> .
>> 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/-/FA-ss7hNR50J.
>
> 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: Authentication

2012-06-18 Thread Jonathan Baker
I just implemented Django Registration on an app and found it very easy to
work with: https://bitbucket.org/ubernostrum/django-registration/

On Mon, Jun 18, 2012 at 9:14 AM, Harjot Mann wrote:

> I want to give a username and password to my project in django...can
> anyone tell me what should i do???
>
>  --
> 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/-/_S9334Y7zmcJ.
> 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
Developer
http://jonathandbaker.com

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



Production errors

2012-06-18 Thread Satan Study Django
Hi.

As said in the https://docs.djangoproject.com/en/1.4/howto/error-reporting/
production server with "DEBUG = False" will send "Unhandled exception"
errors to ADMINS and it's great.

But besides it will return http error code 200 and if I'd make some
http check for my service, like nagios check_http to my monitoring
group could watch wrong states I just couldn't make it with only error
code check and I must write some content check and it's not cool.

Could this error code be replaced with 500 or any another?
Could anyone explain why by default it works that way?

Thanks for your attention.

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



Re: django-admin.py startproject mysite

2012-06-18 Thread Seyfullah Tıkıç
I created a file named t.py and wrote what you wrote.
In the first step, I see this :
C:\Python27\MyFiles>t.py a one and a two
Argument 0 is   C:\Python27\MyFiles\t.py


2012/6/18 Dennis Lee Bieber 

> On Sun, 17 Jun 2012 15:54:39 -0700 (PDT), stikic 
> declaimed the following in gmane.comp.python.django.user:
>
> > Hello,
> >
> > I installed django and added it to my PATH in windows. When I run
> > django-admin.py startproject mysite as follows, I get error. How can I
>
> What error?
>
> > solve this?:
> > C:\Python27\MyFiles\mysite>C:\Python27\Lib\site-packages\django\bin
> > \django-admin
> > .py startproject mysite
> > Usage: django-admin.py subcommand [options] [args]
> >
> > Options:
>
> This appears to be the normal command line help given when
> parameters are not found
>
>The cut&paste above doesn't help as one can't determine if the ".py"
> on the next line is a result of an accidental space after django-admin.
>
>The OTHER candidate is that Windows sometimes has trouble passing
> command line arguments or I/O redirection when a program is not directly
> executable but activates an interpreter -- though it appears my system
> handles it okay:
>
> E:\UserData\Wulfraed\MYDOCU~1>type t.py
> import sys
>
> for i,a in enumerate(sys.argv):
>print "Argument %s is\t%s" % (i, a)
>
>
> E:\UserData\Wulfraed\MYDOCU~1>t.py a one and a two
> Argument 0 is   E:\UserData\Wulfraed\MYDOCU~1\t.py
> Argument 1 is   a
> Argument 2 is   one
> Argument 3 is   and
> Argument 4 is   a
> Argument 5 is   two
>
> E:\UserData\Wulfraed\MYDOCU~1>t three or more
> Argument 0 is   E:\UserData\Wulfraed\MYDOCU~1\t.py
> Argument 1 is   three
> Argument 2 is   or
> Argument 3 is   more
>
> E:\UserData\Wulfraed\MYDOCU~1>python t four is what
> python: can't open file 't': [Errno 2] No such file or directory
>
> E:\UserData\Wulfraed\MYDOCU~1>python t.py four is what
> Argument 0 is   t.py
> Argument 1 is   four
> Argument 2 is   is
> Argument 3 is   what
>
> E:\UserData\Wulfraed\MYDOCU~1>
>
>Suggest you try creating a test script (as in the above t.py) and
> execute it in the various versions shown above. Obviously your system is
> finding the Python interpreter, but the arguments are not being found by
> the script (or that .py IS separated by a space and is being seen as the
> first command to the script -- and that is not recognized)
>
>
> --
>Wulfraed Dennis Lee Bieber AF6VN
>wlfr...@ix.netcom.comHTTP://wlfraed.home.netcom.com/
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


-- 
SEYFULLAH TIKIÇ

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



Re: django-admin.py startproject mysite

2012-06-18 Thread Seyfullah Tıkıç
Yes, I restarted my computer.

2012/6/18 şahin mersin 

> Did you restart your computer?
>
> --
> 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.
>



-- 
SEYFULLAH TIKIÇ

-- 
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: multiple databases [was]Trying to find something in multiple databases... Confused...

2012-06-18 Thread Kurtis Mullins
On Mon, Jun 18, 2012 at 1:45 PM, Dennis Lee Bieber wrote:
>
>
> First, is everybody on the same page (terminology)... (Independent
> of Django)
>
>First is: multiple database engines (SQLite3, MySQL, Access/JET,
> etc.). Working across multiple engines is never easy -- one typically
> has to implement the equivalent of "select ... from ... join ..." in
> program code -- that is, fetch records from each engine and merge them
> by hand to produce a result set.
>
>Second is: multiple databases within an engine. Database engines are
> designed to allow for separate databases with independent user access --
> a personnel/payroll database would not be accessible by the parts
> order/tracking system, even when both are stored on the same database
> engine/server -- however, an application /might/ be permitted such an
> odd mix if the user authorization permits access to both databases. For
> SQLite3 and Access/JET, a database is a single file (no particular
> extension for SQLite3, Access used to use .MDB) and an application
> typically opens/connects to just one of these -- but means are available
> to "link" a second into visibility.
>
>Third: a database, as defined in #2, contains multiple relations
> (tables) which may or may not be interconnected by foreign key
> references (in relational database theory, a relation is a single table
> in which the data of each tuple (record) is related to a unique key for
> the tuple; relation does NOT refer to linkages by foreign keys between
> tables).


I believe, by reading the context, it was pretty obvious he meant databases
(definition #2)  being managed under multiple database management systems,
without regards to their specified database engine.

By the way, MySQL is not a database engine -- it is a database management
system. MyISAM and InnoDB would be database engines.

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



Implementing Django Search

2012-06-18 Thread DF
I'm working on my first project and I'm attempting to implement a basic 
search function where users can search for a specific terms.

There are many options available, most a bit too heavy for what I require. 
I found this posting which illustrates how to implement a basic search 
function that sounds ideal: 

http://julienphalip.com/post/2825034077/adding-search-to-a-django-site-in-a-snap#disqus_thread

The problem: the documentation is a bit incomplete, especially for a 
newbie. And I could use some help from those with experience on how to 
implement this.

The first action is to create a file within the project – say search.py – 
with the following code:

import re

from django.db.models import Q

def normalize_query(query_string,
findterms=re.compile(r'"([^"]+)"|(\S+)').findall,
normspace=re.compile(r'\s{2,}').sub):
''' Splits the query string in invidual keywords, getting rid of 
unecessary spaces
and grouping quoted words together.
Example:

>>> normalize_query('  some random  words "with   quotes  " and   
spaces')
['some', 'random', 'words', 'with quotes', 'and', 'spaces']

'''
return [normspace(' ', (t[0] or t[1]).strip()) for t in 
findterms(query_string)] 

def get_query(query_string, search_fields):
''' Returns a query, that is a combination of Q objects. That 
combination
aims to search keywords within a model by testing the given search 
fields.

'''
query = None # Query to search for every search term
terms = normalize_query(query_string)
for term in terms:
or_query = None # Query to search for a given term in each field
for field_name in search_fields:
q = Q(**{"%s__icontains" % field_name: term})
if or_query is None:
or_query = q
else:
or_query = or_query | q
if query is None:
query = or_query
else:
query = query & or_query
return query

Then the next step would be to import this file into the views – import 
search (not sure if the app name should proceed this). Then add this view, 
with the object detail changed to match my model:

def search(request):
query_string = ''
found_entries = None
if ('q' in request.GET) and request.GET['q'].strip():
query_string = request.GET['q']

entry_query = get_query(query_string, ['title', 'body',])

found_entries = 
Entry.objects.filter(entry_query).order_by('-pub_date')

return render_to_response('search/search_results.html',
  { 'query_string': query_string, 'found_entries': 
found_entries },
  context_instance=RequestContext(request))

After this, I'm a bit stumped.

I assume this requires a basic url for the urls.py file, which seems 
straightforward enough. But I'm not sure how to place this within a 
template, what tags to use, etc. I have a search bar form on my main 
template page to which I would like to attach this. But returning the 
search/search_results.html template with the appropriate tags is a bit head 
scratching.

This is a fairly long post but if anyone could provide some insight on 
implementing this search function, it would be much appreciated. Thanks.



-- 
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/-/6jWgePRRzQYJ.
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 using User.get_profile() in DJANGO

2012-06-18 Thread upmauro
Solve, thank you !

On Monday, June 18, 2012 11:29:55 AM UTC-3, Kurtis wrote:
>
> Give this a shot:
>
> user = User.objects.create_user(request.POST['apelido'], 
> request.POST['email'], request.POST['pwd'])
> user.save()
> profile = user.get_profile()
> profile.apelido = request.POST['apelido']
> profile.save()
>
> Also, I recommend using Forms (and better yet, ModelForms with Class-Based 
> Views) to sanitize and validate your data.
>
> On Mon, Jun 18, 2012 at 9:50 AM, upmauro  wrote:
>
>> Sorry my english.
>>
>> In my *models.py*
>>
>> class Usuario(models.Model):
>> user = models.ForeignKey(User,primary_key=True)
>> apelido = models.CharField(max_length=75, blank=True)
>> class Meta:
>> db_table = u'usuario'
>>
>> def create_user_profile(sender, instance, created, **kwargs):
>> if created:
>>profile, created = Usuario.objects.get_or_create(user=instance)
>>
>> post_save.connect(create_user_profile, sender=User)
>>
>> In my *views.py*
>> *
>> *
>> @csrf_exempt
>> def register(request):
>> user = User.objects.create_user(request.POST['apelido'], 
>> request.POST['email'], request.POST['pwd'])
>> user.get_profile().apelido = request.POST['apelido']
>>
>> *
>> *
>> *Error:*
>> *
>> *
>> Exception Value: 
>> Usuario matching query does not exist
>>
>> *Line:*.
>>
>> user.get_profile().apelido = request.POST['apelido'] 
>>
>>  -- 
>> 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/-/c0qZCUUHsGEJ.
>> 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 view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/c79KPGbLxVIJ.
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: Implementing Django Search

2012-06-18 Thread Nikolas Stevenson-Molnar
I've used Haystack with Whoosh: http://haystacksearch.org/. It's
straight-forward, well documented, and mimics the Django ORM. No need to
parse the query yourself or anything like that, just pass the raw input
to Haystack and enjoy delicious search results :)

_Nik

On 6/18/2012 11:23 AM, DF wrote:
> I'm working on my first project and I'm attempting to implement a
> basic search function where users can search for a specific terms.
>
> There are many options available, most a bit too heavy for what I
> require. I found this posting which illustrates how to implement a
> basic search function that sounds ideal: 
>
> http://julienphalip.com/post/2825034077/adding-search-to-a-django-site-in-a-snap#disqus_thread
>
> The problem: the documentation is a bit incomplete, especially for a
> newbie. And I could use some help from those with experience on how to
> implement this.
>
> The first action is to create a file within the project – say
> search.py – with the following code:
>
> import re
>
> from django.db.models import Q
>
> def normalize_query(query_string,
> findterms=re.compile(r'"([^"]+)"|(\S+)').findall,
> normspace=re.compile(r'\s{2,}').sub):
> ''' Splits the query string in invidual keywords, getting rid of
> unecessary spaces
> and grouping quoted words together.
> Example:
> 
> >>> normalize_query('  some random  words "with   quotes  "
> and   spaces')
> ['some', 'random', 'words', 'with quotes', 'and', 'spaces']
> 
> '''
> return [normspace(' ', (t[0] or t[1]).strip()) for t in
> findterms(query_string)] 
>
> def get_query(query_string, search_fields):
> ''' Returns a query, that is a combination of Q objects. That
> combination
> aims to search keywords within a model by testing the given
> search fields.
> 
> '''
> query = None # Query to search for every search term
> terms = normalize_query(query_string)
> for term in terms:
> or_query = None # Query to search for a given term in each field
> for field_name in search_fields:
> q = Q(**{"%s__icontains" % field_name: term})
> if or_query is None:
> or_query = q
> else:
> or_query = or_query | q
> if query is None:
> query = or_query
> else:
> query = query & or_query
> return query
>
> Then the next step would be to import this file into the views –
> import search (not sure if the app name should proceed this). Then add
> this view, with the object detail changed to match my model:
>
> def search(request):
> query_string = ''
> found_entries = None
> if ('q' in request.GET) and request.GET['q'].strip():
> query_string = request.GET['q']
> 
> entry_query = get_query(query_string, ['title', 'body',])
> 
> found_entries =
> Entry.objects.filter(entry_query).order_by('-pub_date')
>
> return render_to_response('search/search_results.html',
>   { 'query_string': query_string,
> 'found_entries': found_entries },
>   context_instance=RequestContext(request))
>
> After this, I'm a bit stumped.
>
> I assume this requires a basic url for the urls.py file, which seems
> straightforward enough. But I'm not sure how to place this within a
> template, what tags to use, etc. I have a search bar form on my main
> template page to which I would like to attach this. But returning the
> search/search_results.html template with the appropriate tags is a bit
> head scratching.
>
> This is a fairly long post but if anyone could provide some insight on
> implementing this search function, it would be much appreciated. Thanks.
>
>
>
> -- 
> 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/-/6jWgePRRzQYJ.
> 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: Implementing Django Search

2012-06-18 Thread DF
Does it provide instructions on connecting it to a search form? Dumb 
question, but sometimes documentation can be lacking.

On Monday, June 18, 2012 2:40:58 PM UTC-4, Nikolas Stevenson-Molnar wrote:
>
> I've used Haystack with Whoosh: http://haystacksearch.org/. It's 
> straight-forward, well documented, and mimics the Django ORM. No need to 
> parse the query yourself or anything like that, just pass the raw input 
> to Haystack and enjoy delicious search results :) 
>
> _Nik 
>
> On 6/18/2012 11:23 AM, DF wrote: 
> > I'm working on my first project and I'm attempting to implement a 
> > basic search function where users can search for a specific terms. 
> > 
> > There are many options available, most a bit too heavy for what I 
> > require. I found this posting which illustrates how to implement a 
> > basic search function that sounds ideal: 
> > 
> > 
> http://julienphalip.com/post/2825034077/adding-search-to-a-django-site-in-a-snap#disqus_thread
>  
> > 
> > The problem: the documentation is a bit incomplete, especially for a 
> > newbie. And I could use some help from those with experience on how to 
> > implement this. 
> > 
> > The first action is to create a file within the project � say 
> > search.py � with the following code: 
> > 
> > import re 
> > 
> > from django.db.models import Q 
> > 
> > def normalize_query(query_string, 
> > findterms=re.compile(r'"([^"]+)"|(\S+)').findall, 
> > normspace=re.compile(r'\s{2,}').sub): 
> > ''' Splits the query string in invidual keywords, getting rid of 
> > unecessary spaces 
> > and grouping quoted words together. 
> > Example: 
> > 
> > >>> normalize_query('  some random  words "with   quotes  " 
> > and   spaces') 
> > ['some', 'random', 'words', 'with quotes', 'and', 'spaces'] 
> > 
> > ''' 
> > return [normspace(' ', (t[0] or t[1]).strip()) for t in 
> > findterms(query_string)] 
> > 
> > def get_query(query_string, search_fields): 
> > ''' Returns a query, that is a combination of Q objects. That 
> > combination 
> > aims to search keywords within a model by testing the given 
> > search fields. 
> > 
> > ''' 
> > query = None # Query to search for every search term 
> > terms = normalize_query(query_string) 
> > for term in terms: 
> > or_query = None # Query to search for a given term in each field 
> > for field_name in search_fields: 
> > q = Q(**{"%s__icontains" % field_name: term}) 
> > if or_query is None: 
> > or_query = q 
> > else: 
> > or_query = or_query | q 
> > if query is None: 
> > query = or_query 
> > else: 
> > query = query & or_query 
> > return query 
> > 
> > Then the next step would be to import this file into the views � 
> > import search (not sure if the app name should proceed this). Then add 
> > this view, with the object detail changed to match my model: 
> > 
> > def search(request): 
> > query_string = '' 
> > found_entries = None 
> > if ('q' in request.GET) and request.GET['q'].strip(): 
> > query_string = request.GET['q'] 
> > 
> > entry_query = get_query(query_string, ['title', 'body',]) 
> > 
> > found_entries = 
> > Entry.objects.filter(entry_query).order_by('-pub_date') 
> > 
> > return render_to_response('search/search_results.html', 
> >   { 'query_string': query_string, 
> > 'found_entries': found_entries }, 
> >   context_instance=RequestContext(request)) 
> > 
> > After this, I'm a bit stumped. 
> > 
> > I assume this requires a basic url for the urls.py file, which seems 
> > straightforward enough. But I'm not sure how to place this within a 
> > template, what tags to use, etc. I have a search bar form on my main 
> > template page to which I would like to attach this. But returning the 
> > search/search_results.html template with the appropriate tags is a bit 
> > head scratching. 
> > 
> > This is a fairly long post but if anyone could provide some insight on 
> > implementing this search function, it would be much appreciated. Thanks. 
> > 
> > 
> > 
> > -- 
> > 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/-/6jWgePRRzQYJ. 
> > 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 view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/

Re: Implementing Django Search

2012-06-18 Thread Nikolas Stevenson-Molnar
There are a number of ways you can use it. Must straight-forward is to
use built-in views with a customized template:
http://django-haystack.readthedocs.org/en/latest/tutorial.html#setting-up-the-views

You can get a bit more advanced by using the various search forms with
your own view:
http://django-haystack.readthedocs.org/en/latest/views_and_forms.html

Or, you can use the basic components (SearchQuerySet) and do everything
else yourself:
http://django-haystack.readthedocs.org/en/latest/searchqueryset_api.html

Even the last case is pretty easy to use. Connecting it to a search form
is as easy as getting the query string from GET or POST data. E.g.:

def my_view(request):
results = SearchQuerySet().filter(content=AutoQuery(results.GET['q']))

_Nik

On 6/18/2012 11:46 AM, DF wrote:
> Does it provide instructions on connecting it to a search form? Dumb
> question, but sometimes documentation can be lacking.
>
> On Monday, June 18, 2012 2:40:58 PM UTC-4, Nikolas Stevenson-Molnar
> wrote:
>
> I've used Haystack with Whoosh: http://haystacksearch.org/. It's
> straight-forward, well documented, and mimics the Django ORM. No
> need to
> parse the query yourself or anything like that, just pass the raw
> input
> to Haystack and enjoy delicious search results :)
>
> _Nik
>
> On 6/18/2012 11:23 AM, DF wrote:
> > I'm working on my first project and I'm attempting to implement a
> > basic search function where users can search for a specific terms.
> >
> > There are many options available, most a bit too heavy for what I
> > require. I found this posting which illustrates how to implement a
> > basic search function that sounds ideal:
> >
> >
> 
> http://julienphalip.com/post/2825034077/adding-search-to-a-django-site-in-a-snap#disqus_thread
> 
> 
>
> >
> > The problem: the documentation is a bit incomplete, especially
> for a
> > newbie. And I could use some help from those with experience on
> how to
> > implement this.
> >
> > The first action is to create a file within the project � say
> > search.py � with the following code:
> >
> > import re
> >
> > from django.db.models import Q
> >
> > def normalize_query(query_string,
> >
> findterms=re.compile(r'"([^"]+)"|(\S+)').findall,
> > normspace=re.compile(r'\s{2,}').sub):
> > ''' Splits the query string in invidual keywords, getting
> rid of
> > unecessary spaces
> > and grouping quoted words together.
> > Example:
> >
> > >>> normalize_query('  some random  words "with   quotes  "
> > and   spaces')
> > ['some', 'random', 'words', 'with quotes', 'and', 'spaces']
> >
> > '''
> > return [normspace(' ', (t[0] or t[1]).strip()) for t in
> > findterms(query_string)]
> >
> > def get_query(query_string, search_fields):
> > ''' Returns a query, that is a combination of Q objects. That
> > combination
> > aims to search keywords within a model by testing the given
> > search fields.
> >
> > '''
> > query = None # Query to search for every search term
> > terms = normalize_query(query_string)
> > for term in terms:
> > or_query = None # Query to search for a given term in
> each field
> > for field_name in search_fields:
> > q = Q(**{"%s__icontains" % field_name: term})
> > if or_query is None:
> > or_query = q
> > else:
> > or_query = or_query | q
> > if query is None:
> > query = or_query
> > else:
> > query = query & or_query
> > return query
> >
> > Then the next step would be to import this file into the views �
> > import search (not sure if the app name should proceed this).
> Then add
> > this view, with the object detail changed to match my model:
> >
> > def search(request):
> > query_string = ''
> > found_entries = None
> > if ('q' in request.GET) and request.GET['q'].strip():
> > query_string = request.GET['q']
> >
> > entry_query = get_query(query_string, ['title', 'body',])
> >
> > found_entries =
> > Entry.objects.filter(entry_query).order_by('-pub_date')
> >
> > return render_to_response('search/search_results.html',
> >   { 'query_string': query_string,
> > 'found_entries': found_entries },
> >   context_instance=RequestContext(request))
> >
> > After this, I'm a bit stumped.
> >
> > I assume this requires a bas

Making fields read-only after first save in admin

2012-06-18 Thread Thomas Weholt
I want to make a few foreignkey-fields read-only in the admin after
the post is saved, ie when the change-form for that item is opened
after the item has been saved the two foreignkeys in question should
not be editable. In my case the user has to chose two foreignkeys when
first adding an entry, but those foreignkeys cannot be changed once
the item has been saved. Is that possible?

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



Wsgi path problem: deploying on a production server

2012-06-18 Thread wgw


I was able to deploy my django app on a new server with this configuration 
option:

WSGIScriptAlias / app1.wsgi

Everything works beautifully (so I have wsgi configured properly), but the 
wsgi script captures all traffic to my server, which I don't want. So I 
tried this: 

WSGIScriptAlias /programs app1.wsgi

And an Apache alias to /programs. 

My app1.wsgi is under ~/public_html/wsgi-bin
My /programs is in fact ~/django/djangotasks2

I thought I was being clever, since my application is unreadable in my home 
directory and my .wsgi file is readable by Apache in the web directory.  

That configuration almost works: my.site.com:8080/programs/ goes to the 
first page of my application. However, when I follow a link from that page 
(admin, or any other), I get a path error: 

File does not exist: /home/wgw/public_html/qtypes, referer: 
http://my.site.com:8080/programs/


(displayed as html page: The requested URL /qtypes/1 was not found on this 
server.)

Ok: it is referring relative to the root of the app1.wsgi file. Logical, 
but not what I want. I want it to refer relative to  ~/django/djangotasks2

I'm assuming I have to tell django that my directory alias is 
/programs/perhaps in the urls.py. 

So instead of 
(r'^admin/', include(admin.site.urls)),

I would have 
(r'^/programs/admin/', include(admin.site.urls)),


I know there is doc about this problem (of changing directory structure for 
the app), but I have lost the reference. 

Any pointers? (and thanks!) 

-- 
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/-/vmcXzx9B3I8J.
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.



blank, null, Oracle, and empty_strings_allowed

2012-06-18 Thread André Pang
Hi all,

The Oracle database backend has the following note about NULLs vs empty 
strings (emphasis  is mine):

Django generally prefers to use the empty string ('') rather than NULL, but 
> Oracle treats both identically. To get around this, the Oracle backend 
> ignores an *explicit null option on fields that have the empty string as 
> a possible value* and generates DDL as if null=True.


However, I've found that the Oracle backend *always *generates NULLs for 
string-like fields (i.e. CharField and friends, such as TextField and 
FilePathField). In other words, it's permitting NULLs for fields where 
null=False and blank=False, which is odds with the documentation.

For a possible fix, I've got a patch in my Django working copy where 
Field.empty_strings_allowed becomes dynamic, based on whether a Field's 
blank option is true. It's pretty basic:

@property
> def empty_strings_allowed_if_blank(self):
> return self.blank
> models.fields.CharField.empty_strings_allowed = 
> empty_strings_allowed_if_blank


Is this a reasonable solution? I apologize if I'm misunderstanding the 
documentation and this isn't a bug.

Thanks,

-- 
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/-/sUMb7pGYhP4J.
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.



Select * from users,country where country.id = users.id in Django using amin.contrib

2012-06-18 Thread django noob
Greetings Django Experts!

Say for example i have the following on my models.py


class Country(models.Model):
name = models.CharField(max_length=50)

def __unicode__(self):
return u'%s %s' % (self.name, self.ID)

class Meta:
verbose_name = 'Countries'

class Users(models.Model):
name = models.CharField(max_length=50)
cUsers = models.ForeignKey(Country)

def __unicode__(self):
return self.name

class Meta:
verbose_name = 'Users on a country'

class GoalsinCountry(models.Model):
gCountry = models.ForeignKey(Country)
name = models.CharField(max_length=50)
descr = models.TextField(blank=True, null=True)

def __unicode__(self):
return self.name
class Meta:
verbose_name = 'Goals Topic'



How would you configure this in GoalsinCountry to return only users in
a particular country and save this to
GoalsinCountry Table?

if i use gCountry = models.ForeignKey(Users)
I would get a list of all users, i am interested in fitering to users
on a particular country??

Please advice

Thank you

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



Oracle: blank, null, and empty_strings_allowed

2012-06-18 Thread André Pang
Hi all,

The Django Oracle documentation has the following to say about NULL and 
empty 
strings
 (emphasis 
mine):

Django generally prefers to use the empty string ('') rather than NULL, but 
> Oracle treats both identically. To get around this, the Oracle backend 
> coerces the null=True option *on fields that have the empty string as a 
> possible value*.


However, I've found that the Oracle schema that Django generates *always 
*allows 
NULLs on all string-like fields (CharField, TextField, FilePathField, etc). 
I'd assume that Django would only generate schemas where NULL is allowed 
for fields where blank=True, and that fields where blank=False would have 
"NOT NULL" included in the Oracle DDL.

It appears that the Oracle backend looks at an undocumented 
"empty_strings_allowed" Field attribute to determine whether to output NOT 
NULL for the DDL. I've got a local patch to override the 
empty_strings_allowed field so that it's dependent on the Field's blank 
attribute, like so:

@property
> def empty_strings_allowed_if_blank(self):
> return self.blank
> models.fields.CharField.empty_strings_allowed = 
> empty_strings_allowed_if_blank 

models.fields.TextField.empty_strings_allowed = 
> empty_strings_allowed_if_blank 

[etc]


This behavior feels like a bug in the Oracle backend that should be fixed, 
but I might be misunderstanding the documentation. I'm also unsure whether 
it's the Field subclasses that should patched or the Oracle backend that's 
in error.

If someone could take a look so that Django 1.5 can have this fixed, that'd 
be great.  Thanks!

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



Re: django-admin.py startproject mysite

2012-06-18 Thread Seyfullah Tıkıç
Any suggestions please?

2012/6/18 Seyfullah Tıkıç 

> Yes, I restarted my computer.
>
>
> 2012/6/18 şahin mersin 
>
>> Did you restart your computer?
>>
>> --
>> 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.
>>
>
>
>
> --
> SEYFULLAH TIKIÇ
>



-- 
SEYFULLAH TIKIÇ

-- 
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 using User.get_profile() in DJANGO

2012-06-18 Thread salai...@gmail.com
Hello !

You must import the user model before using it !


Thks

Le lundi 18 juin 2012 14:29:55 UTC, Kurtis a écrit :
>
> Give this a shot:
>
> user = User.objects.create_user(request.POST['apelido'], 
> request.POST['email'], request.POST['pwd'])
> user.save()
> profile = user.get_profile()
> profile.apelido = request.POST['apelido']
> profile.save()
>
> Also, I recommend using Forms (and better yet, ModelForms with Class-Based 
> Views) to sanitize and validate your data.
>
> On Mon, Jun 18, 2012 at 9:50 AM, upmauro  wrote:
>
>> Sorry my english.
>>
>> In my *models.py*
>>
>> class Usuario(models.Model):
>> user = models.ForeignKey(User,primary_key=True)
>> apelido = models.CharField(max_length=75, blank=True)
>> class Meta:
>> db_table = u'usuario'
>>
>> def create_user_profile(sender, instance, created, **kwargs):
>> if created:
>>profile, created = Usuario.objects.get_or_create(user=instance)
>>
>> post_save.connect(create_user_profile, sender=User)
>>
>> In my *views.py*
>> *
>> *
>> @csrf_exempt
>> def register(request):
>> user = User.objects.create_user(request.POST['apelido'], 
>> request.POST['email'], request.POST['pwd'])
>> user.get_profile().apelido = request.POST['apelido']
>>
>> *
>> *
>> *Error:*
>> *
>> *
>> Exception Value: 
>> Usuario matching query does not exist
>>
>> *Line:*.
>>
>> user.get_profile().apelido = request.POST['apelido'] 
>>
>>  -- 
>> 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/-/c0qZCUUHsGEJ.
>> 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 view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/kKSxcoDE8U4J.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: django-admin.py startproject mysite

2012-06-18 Thread Seyfullah Tıkıç
Thank you for suggestions. What I have done is as follows : The problem
still exists, what can I do next?

C:\Users\syftkc>assoc .py .py=py_auto_file
.py .py=py_auto_file

C:\Users\syftkc>ftype py_auto_file py_auto_file="C:\Python27\python.exe"
"%1" %

py_auto_file py_auto_file="C:\Python27\python.exe" "%1" %*

C:\Users\syftkc>cd C:\Python27\MyFiles

C:\Python27\MyFiles>t.py a s d
Argument 0 is   C:\Python27\MyFiles\t.py

C:\Python27\MyFiles>..\Python.exe t.py a s d
Argument 0 is   t.py
Argument 1 is   a
Argument 2 is   s
Argument 3 is   d

C:\Python27\MyFiles>t.py a s d
Argument 0 is   C:\Python27\MyFiles\t.py


2012/6/18 Dennis Lee Bieber 

> On Mon, 18 Jun 2012 20:35:35 +0300, Seyfullah Tıkıç 
> declaimed the following in gmane.comp.python.django.user:
>
> > I created a file named t.py and wrote what you wrote.
> > In the first step, I see this :
> > C:\Python27\MyFiles>t.py a one and a two
> > Argument 0 is   C:\Python27\MyFiles\t.py
> >
> If that is ALL that you see, then it indicates that on you computer
> configuration, script files that are not natively executable (that is,
> .py invokes python.exe passing the .py name) is NOT passing any other
> arguments.
>
>The fast solution should be to explicitly invoke the Python
> interpreter:
>
> > python t.py arguments...
>
>
>The longer solution gets esoteric... See my example:
>
> E:\UserData\Wulfraed\My Documents>assoc .py
> .py=py_auto_file
>
> E:\UserData\Wulfraed\My Documents>ftype py_auto_file
> py_auto_file="E:\Python25\python.exe" "%1" %*
>
> E:\UserData\Wulfraed\My Documents>
>
>
>Use "assoc" to find out what "file type" .py is considered by the
> OS...
>
>Use "ftype" with that "file type" to see what the execution command
> line becomes.
>
>I suspect what you will find is that your system does NOT have the
> last
>%*
> term on the command. That is what passes the rest of the command line to
> python.
>
>If so, enter
> ftype ="your-python-path-executable" "%1" %*
>
>Then retest with the t.py file and see if the rest of the arguments
> are passed.
> --
>Wulfraed Dennis Lee Bieber AF6VN
>wlfr...@ix.netcom.comHTTP://wlfraed.home.netcom.com/
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


-- 
SEYFULLAH TIKIÇ

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



Custom Tags and Includes, invalid block !

2012-06-18 Thread upmauro
Hello, sorry my english !

I have one question, i create one custom tag and this works fine.

But i have a situation :

*site.html*
*
*
{% include "header.html" %}

Django looks the best framework for web !

{% include "footer.html" %}

If, i use {% load %} in site.html, tag works, but if i {% load %} tag in 
"header.html", when i try use custom tag in site.html raise Invalid block 
tag.

In short, if I load the page included a tag on it is not recognized in the 
current page.

Meant to be?

-- 
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/-/E7i9EQSjhCoJ.
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: Custom Tags and Includes, invalid block !

2012-06-18 Thread Ernesto Guevara
Hi!
Try {% load name_of_custom_tag %} after the extends tag in template.



2012/6/18 upmauro 

> Hello, sorry my english !
>
> I have one question, i create one custom tag and this works fine.
>
> But i have a situation :
>
> *site.html*
> *
> *
> {% include "header.html" %}
>
> Django looks the best framework for web !
>
> {% include "footer.html" %}
>
> If, i use {% load %} in site.html, tag works, but if i {% load %} tag in
> "header.html", when i try use custom tag in site.html raise Invalid block
> tag.
>
> In short, if I load the page included a tag on it is not recognized in the
> current page.
>
> Meant to be?
>
> --
> 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/-/E7i9EQSjhCoJ.
> 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: Oracle: blank, null, and empty_strings_allowed

2012-06-18 Thread Ian


On Monday, June 18, 2012 2:17:26 PM UTC-6, André Pang wrote:
>
> Hi all,
>
> The Django Oracle documentation has the following to say about NULL and 
> empty 
> strings
>  (emphasis 
> mine):
>
> Django generally prefers to use the empty string ('') rather than NULL, 
>> but Oracle treats both identically. To get around this, the Oracle backend 
>> coerces the null=True option *on fields that have the empty string as a 
>> possible value*.
>
>
> However, I've found that the Oracle schema that Django generates *always 
> *allows 
> NULLs on all string-like fields (CharField, TextField, FilePathField, etc).
>

Because those are all "fields that have the empty string as a possible 
value".

 

> I'd assume that Django would only generate schemas where NULL is allowed 
> for fields where blank=True, and that fields where blank=False would have 
> "NOT NULL" included in the Oracle DDL.
>

blank=True is a validation option, not a database option.  A field with 
blank=False can still have the empty string as a possible value, and it can 
be stored like that in any of the other backends; it's just not accepted by 
the admin site.  In this case it's mainly a cross-compatibility issue -- if 
an app stores the empty string on a blank=False field in Postgres, it 
should be able to do that when the backend is Oracle as well.

Cheers,
Ian

-- 
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/-/OQ1fVBapZSoJ.
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: Making fields read-only after first save in admin

2012-06-18 Thread Russell Keith-Magee
On Tue, Jun 19, 2012 at 4:11 AM, Thomas Weholt  wrote:
> I want to make a few foreignkey-fields read-only in the admin after
> the post is saved, ie when the change-form for that item is opened
> after the item has been saved the two foreignkeys in question should
> not be editable. In my case the user has to chose two foreignkeys when
> first adding an entry, but those foreignkeys cannot be changed once
> the item has been saved. Is that possible?

Everything is possible - it's just a matter of how much code you have
to write :-)

In this case, there's no simple option to check to do what you
describe, but I can think of a couple of directions that might be
worth exploring. Roughly in increasing order of preference (i.e., 5 is
probably your best option, followed by 4, and so on):

1) Write a custom extension of ForeignKey that alters the available
choices based on whether the key already has a value.

2) Write a custom Form for the admin that restricts the available
choices, and install that Form in your ModelAdmin. Your form
constructor will need to contain logic something like the following:

if self.instance and self.instance.myfield:
self.fields['myfield'].queryset =
MyObject.objects.filter(pk=self.instance.myfield.pk)

3) Override formfield_for_dbfield() on your ModelAdmin definition to
return a ModelChoiceField with restricted options if the foreign key
exists

4) Override formfield_for_choice_field() on your ModelAdmin definition
to restrict the list of choices.

5) Override get_readonly_fields() to make the foreign key a readonly
field if the foreign key has been defined.

You're going to need to do some experimentation, but hopefully this
has given you some ideas on where to start tinkering.

Yours,
Russ Magee %-)

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



Re: Oracle: blank, null, and empty_strings_allowed

2012-06-18 Thread André Pang
On Jun 18, 2012, at 4:05 PM, Ian wrote:

>> I'd assume that Django would only generate schemas where NULL is allowed for 
>> fields where blank=True, and that fields where blank=False would have "NOT 
>> NULL" included in the Oracle DDL.
> 
> blank=True is a validation option, not a database option.  A field with 
> blank=False can still have the empty string as a possible value, and it can 
> be stored like that in any of the other backends; it's just not accepted by 
> the admin site.

My mistake; I forgot that the blank attribute is an admin validation option 
only.

> In this case it's mainly a cross-compatibility issue -- if an app stores the 
> empty string on a blank=False field in Postgres, it should be able to do that 
> when the backend is Oracle as well.

Gotcha: since Oracle uses NULL to denote empty strings, the Oracle backend 
overrides Field.null to always be True.

What I'd like to do is (1) disallow NULLs, and (2) disallow empty strings.  It 
looks like there's no current way to do this with Oracle since the backend 
overrides null to always be True, and blank is an admin validation thing only.

I'm happy to make my own local subclass of CharField/TextField/etc that has the 
behavior that I'd like; I'm guessing that the Django team don't intend to 
change this behavior.  (It seems that the only way to do this would be to 
change the semantics of null, which seems foolhardy, or add yet another option, 
which would be quite confusing with null and blank already.)

-- 
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 the django.contrib.auth User in my model - database error

2012-06-18 Thread LiuXianghe



Date: Sun, 10 Jun 2012 03:49:36 -0700
From: jonathan.talis...@gmail.com
To: django-users@googlegroups.com
Subject: Re: Using the django.contrib.auth User in my model - database error

I just used an sqlite3 and sqlitemanager which is a sqlite front-end , I am 
guessing it should not be too difficult to drop all tables with a script  too.

On Sunday, June 10, 2012 12:48:46 PM UTC+3, liuxi...@live.cn wrote:how to drop 
all the database tables?



On 6月4日, 下午5时36分, bruno desthuilliers 

wrote:

> On Jun 4, 11:01 am, xTalisman  wrote:

>

> > Solved :

> > I dropped all the database tables (including the contib.auth ones) and ran

> > syncdb, suddenly everything was fine. odd , but is working now .

>

> Well, nice to know it works now, but yes this _is_ odd.



-- 

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/-/EZcFrrEUGyQJ.
 
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.

thank you ,but it's not to the point. All that messed me round is just when i 
syncdb the datebase, the fields I've just added is not actually built in the 
.db file. So I delete the .db file and syncdb again, and it's all done. 
   

-- 
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: Oracle: blank, null, and empty_strings_allowed

2012-06-18 Thread Kurtis Mullins
I've read over this many a time -- never paid much attention because I
don't use Oracle:
https://docs.djangoproject.com/en/dev/ref/models/fields/#null

Anyways, if you don't allow NULL and you don't allow empty strings, what
are you going to put in there when there's nothing?

On Mon, Jun 18, 2012 at 7:59 PM, André Pang  wrote:

> On Jun 18, 2012, at 4:05 PM, Ian wrote:
>
> >> I'd assume that Django would only generate schemas where NULL is
> allowed for fields where blank=True, and that fields where blank=False
> would have "NOT NULL" included in the Oracle DDL.
> >
> > blank=True is a validation option, not a database option.  A field with
> blank=False can still have the empty string as a possible value, and it can
> be stored like that in any of the other backends; it's just not accepted by
> the admin site.
>
> My mistake; I forgot that the blank attribute is an admin validation
> option only.
>
> > In this case it's mainly a cross-compatibility issue -- if an app stores
> the empty string on a blank=False field in Postgres, it should be able to
> do that when the backend is Oracle as well.
>
> Gotcha: since Oracle uses NULL to denote empty strings, the Oracle backend
> overrides Field.null to always be True.
>
> What I'd like to do is (1) disallow NULLs, and (2) disallow empty strings.
>  It looks like there's no current way to do this with Oracle since the
> backend overrides null to always be True, and blank is an admin validation
> thing only.
>
> I'm happy to make my own local subclass of CharField/TextField/etc that
> has the behavior that I'd like; I'm guessing that the Django team don't
> intend to change this behavior.  (It seems that the only way to do this
> would be to change the semantics of null, which seems foolhardy, or add yet
> another option, which would be quite confusing with null and blank already.)
>
> --
> 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: Implementing Django Search

2012-06-18 Thread Daniel Sokolowski
I also found that piece of code when I needed to implement search - it 
was confusing so I ended up with my own approach that was easier to 
understand and simpler at least to me - I pasted an example of live code 
here: http://dpaste.org/KYhUq/


The searching piece of code is in the form_valid() method:

query = (query.filter(name__icontains=bit) | 
query.filter(description__icontains=bit))


This filters the query down on each loop of the word user typed, you 
would adjust that according to your model fields.


Hope that helps.

On 18/06/2012 14:23, DF wrote:

I'm working on my first project and I'm attempting to implement a
basic search function where users can search for a specific terms.

There are many options available, most a bit too heavy for what I
require. I found this posting which illustrates how to implement a
basic search function that sounds ideal:

http://julienphalip.com/post/2825034077/adding-search-to-a-django-site-in-a-snap#disqus_thread

The problem: the documentation is a bit incomplete, especially for a
newbie. And I could use some help from those with experience on how to
implement this.

The first action is to create a file within the project – say
search.py – with the following code:

import re

from django.db.models import Q

def normalize_query(query_string,
findterms=re.compile(r'"([^"]+)"|(\S+)').findall,
normspace=re.compile(r'\s{2,}').sub):
''' Splits the query string in invidual keywords, getting rid of
unecessary spaces
and grouping quoted words together.
Example:
>>> normalize_query('  some random  words "with   quotes  " and   spaces')
['some', 'random', 'words', 'with quotes', 'and', 'spaces']
'''
return [normspace(' ', (t[0] or t[1]).strip()) for t in
findterms(query_string)]

def get_query(query_string, search_fields):
''' Returns a query, that is a combination of Q objects. That
combination
aims to search keywords within a model by testing the given
search fields.
'''
query = None # Query to search for every search term
terms = normalize_query(query_string)
for term in terms:
or_query = None # Query to search for a given term in each field
for field_name in search_fields:
q = Q(**{"%s__icontains" % field_name: term})
if or_query is None:
or_query = q
else:
or_query = or_query | q
if query is None:
query = or_query
else:
query = query & or_query
return query

Then the next step would be to import this file into the views –
import search (not sure if the app name should proceed this). Then add
this view, with the object detail changed to match my model:

def search(request):
query_string = ''
found_entries = None
if ('q' in request.GET) and request.GET['q'].strip():
query_string = request.GET['q']
entry_query = get_query(query_string, ['title', 'body',])
found_entries =
Entry.objects.filter(entry_query).order_by('-pub_date')

return render_to_response('search/search_results.html',
  { 'query_string': query_string,
'found_entries': found_entries },
  context_instance=RequestContext(request))

After this, I'm a bit stumped.

I assume this requires a basic url for the urls.py file, which seems
straightforward enough. But I'm not sure how to place this within a
template, what tags to use, etc. I have a search bar form on my main
template page to which I would like to attach this. But returning the
search/search_results.html template with the appropriate tags is a bit
head scratching.

This is a fairly long post but if anyone could provide some insight on
implementing this search function, it would be much appreciated. Thanks.



--
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/-/6jWgePRRzQYJ.
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.



--
Daniel Sokolowski
Web Engineer
Danols Web Engineering
http://webdesign.danols.com/

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



Re: Wsgi path problem: deploying on a production server

2012-06-18 Thread Daniel Sokolowski
I believe you can accomplish handling specific locations with different 
modules by using the Location and SetHandler directives and using Alias 
for static content.


Notice how I activate the "server-status" module on a sub directory of a 
site, and how I handle static content all from one Apache instance in 
this configuration file: http://dpaste.org/DVp0D/


Hope that helps.

On 18/06/2012 15:48, wgw wrote:


I was able to deploy my django app on a new server with this 
configuration option:


WSGIScriptAlias / app1.wsgi

Everything works beautifully (so I have wsgi configured properly), but 
the wsgi script captures all traffic to my server, which I don't want. 
So I tried this:


WSGIScriptAlias /programs app1.wsgi

And an Apache alias to /programs.

My app1.wsgi is under ~/public_html/wsgi-bin
My /programs is in fact ~/django/djangotasks2

I thought I was being clever, since my application is unreadable in my 
home directory and my .wsgi file is readable by Apache in the web 
directory.


That configuration almost works: my.site.com:8080/programs/ goes to 
the first page of my application. However, when I follow a link from 
that page (admin, or any other), I get a path error:


File does not exist: /home/wgw/public_html/qtypes, 
referer:http://my.site.com:8080/programs/


(displayed as html page: The requested URL /qtypes/1 was not found on 
this server.)


Ok: it is referring relative to the root of the app1.wsgi file. 
Logical, but not what I want. I want it to refer relative to  
~/django/djangotasks2


I'm assuming I have to tell django that my directory alias is 
/programs/perhaps in the urls.py.


So instead of

(r'^admin/', include(admin.site.urls)),

I would have

(r'^/programs/admin/', include(admin.site.urls)),


I know there is doc about this problem (of changing directory 
structure for the app), but I have lost the reference.


Any pointers? (and thanks!)

--
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/-/vmcXzx9B3I8J.

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.



--
Daniel Sokolowski
Web Engineer
Danols Web Engineering
http://webdesign.danols.com/
Office: 613-817-6833
Fax: 613-817-4553
Toll Free: 1-855-5DANOLS
Kingston, ON K7L 1H3, Canada


Notice of Confidentiality:
The information transmitted is intended only for the person or entity to which 
it is addressed and may contain confidential and/or privileged material. Any 
review re-transmission dissemination or other use of or taking of any action in 
reliance upon this information by persons or entities other than the intended 
recipient is prohibited. If you received this in error please contact the 
sender immediately by return electronic transmission and then immediately 
delete this transmission including all attachments without copying distributing 
or disclosing same.


--
Daniel Sokolowski
Web Engineer
Danols Web Engineering
http://webdesign.danols.com/
Office: 613-817-6833
Fax: 613-817-4553
Toll Free: 1-855-5DANOLS
Kingston, ON K7L 1H3, Canada


Notice of Confidentiality:
The information transmitted is intended only for the person or entity to which 
it is addressed and may contain confidential and/or privileged material. Any 
review re-transmission dissemination or other use of or taking of any action in 
reliance upon this information by persons or entities other than the intended 
recipient is prohibited. If you received this in error please contact the 
sender immediately by return electronic transmission and then immediately 
delete this transmission including all attachments without copying distributing 
or disclosing same.

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



Re: django-admin.py startproject mysite

2012-06-18 Thread Seyfullah Tıkıç
Ok, now I did it as you said. It is the same :
C:\Python27\MyFiles>assoc .py=py_auto_file
.py=py_auto_file
C:\Python27\MyFiles>ftype py_auto_file="C:\Python27\python.exe" "%1" %*
py_auto_file="C:\Python27\python.exe" "%1" %*
C:\Python27\MyFiles>t.py a s d
Argument 0 is   C:\Python27\MyFiles\t.py
There is something wrong, but I couldn't understand.

2012/6/19 Dennis Lee Bieber 

> On Tue, 19 Jun 2012 00:23:06 +0300, Seyfullah Tıkıç 
> declaimed the following in gmane.comp.python.django.user:
>
> > Thank you for suggestions. What I have done is as follows : The problem
> > still exists, what can I do next?
> >
> > C:\Users\syftkc>assoc .py .py=py_auto_file
> > .py .py=py_auto_file
> >
> Why the double ".py .py"? It should just be a single term which is
> the extension of the file...
>
> > C:\Users\syftkc>ftype py_auto_file py_auto_file="C:\Python27\python.exe"
> > "%1" %
> >
> > py_auto_file py_auto_file="C:\Python27\python.exe" "%1" %*
> >
> Same here -- it should just be a single occurrence of the type.
> --
>Wulfraed Dennis Lee Bieber AF6VN
>wlfr...@ix.netcom.comHTTP://wlfraed.home.netcom.com/
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


-- 
SEYFULLAH TIKIÇ

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