Django custom authentication

2013-10-22 Thread Praveen Madhavan
Hello All,

 I am trying custom authentication with django, I wrote a class and 
filled it with the methods authenticate and get_user, I also added this 
authentication to the AUTHENTICATION_BACKENDS in settings.py file.

I have called my custom authenticate method and followed it up with 
login in my view.

Everything seems to work fine, is_authenticated returns true for the 
user after login, but the subsequent requests have request.user as 
anonymous, unable to figure out the reason, require your help


Thanks
Praveen.M

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b2da7920-4154-4315-b4e7-957c869aa727%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Django custom authentication

2013-10-22 Thread François Schiettecatte
Praveen

I would check that cookies are being returned from the browser, the session 
information in stored in them, and did you check that get_user() is returning 
the user corresponding to the ID?

François

On Oct 22, 2013, at 7:53 AM, Praveen Madhavan  wrote:

> Hello All,
> 
>  I am trying custom authentication with django, I wrote a class and 
> filled it with the methods authenticate and get_user, I also added this 
> authentication to the AUTHENTICATION_BACKENDS in settings.py file.
> 
> I have called my custom authenticate method and followed it up with login 
> in my view.
> 
> Everything seems to work fine, is_authenticated returns true for the user 
> after login, but the subsequent requests have request.user as anonymous, 
> unable to figure out the reason, require your help
> 
> 
> Thanks
> Praveen.M
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/b2da7920-4154-4315-b4e7-957c869aa727%40googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/334003D9-F80D-4A9A-BD62-0C7E618BACBC%40gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Django data to Javascript

2013-10-22 Thread drakko
Thanks!!!

This helped a lot. Now it is working as I was hoping :)

drakko

trešdiena, 2013. gada 16. oktobris 16:14:39 UTC+2, ke1g rakstīja:
>
>
> On Wed, Oct 16, 2013 at 3:39 AM, drakko  >wrote:
>
>> ...
>>
>  
>
>> But accessing should_have_found_list in template has no problems. I have 
>> separate JS file that contains functions (event handlers for buttons etc.). 
>> I can't figure out (total newbie in JS :D ) how to access (or pass) 
>> should_have_found_list there. (Sorry I wasn't clear enough in my first post)
>>
>
> Things that the template context knows are available when the template is 
> rendered.  That is, when the template is turned into (in this case) an HTML 
> document (represented as a string).  This happens on the server.
>
> The only thing sent to the browser is that HTML document, notwithstanding 
> that that stuff in that HTML document may cause the browser to load other 
> stuff (like images, javascript files, and CSS files).
>
> But, specifically, the template context is not automatically included in 
> any way.
>
> If you have a template context variables that you wish to reference from 
> the javascript (which runs in the browser, long after template rendering is 
> complete) then you must arrange that the HTML document contain, within a 
> suitable script tag, javascript code that sets a javascript variable to a 
> javascript literal.  For example, if template context variables "count" and 
> "name" have, respectively, values 1 and "Joe", you might write something 
> like this in your template:
>
> 
>var ct = {{ count }},
> nm = "{{ name }}";
> 
>
> Which becomes, in the HTML sent to the bowser:
>
> 
>var ct = 1,
> nm = "Joe";
> 
>
> Now those values are available to the javascript running in the browser as 
> "ct" and "nm".  (You don't have to use different variable names.  I just 
> wanted it to be clear which were template context variables and which were 
> javascript variables).
>
> But note that not all python objects can be sent this way.  You can't, for 
> example, just send a queryset and expect to be able to use its "filter" 
> method from javascript.
>
> You have two choices for sending more complex objects who's ultimate parts 
> are representable as javascript scalars.  If they can be JSON encoded, then 
> that *IS* a javascript object literal.  Or you can iterate through the 
> object (and subobjects) rendering each by hand, including suitable 
> javascript object syntax separators and wrappers, like brackets, braces and 
> commas.
>
> Note, too, that my first code above does not work if the name variable 
> contains a double quote, since:
>
> nm = "Joe "the schmoe" Gogo";
>
> isn't valid javascript.  The json built into modern pythons is willing to 
> encode a string as a suitable javascript object literal, with all necessary 
> escaping and with the quotes built in (even though this isn't legal JSON - 
> formally the top level object must be a javascript array or object).  So if 
> the name template context variable had been created in the view thusly:
>
> ...
> name = json.dumps(obj.name),
> ...
>
> then the following is correct:
>
> 
>var ct = {{ count }},
> nm = {{ name }};
> 
>
> Note that the quotes have been removed.
>
> [It might be useful to have a json dumps template filter.  Perhaps there's 
> one I haven't found.]
>  

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7ccd0e45-d4ec-4340-a6ea-ce88ff86c380%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Django custom authentication

2013-10-22 Thread Tom Evans
On Tue, Oct 22, 2013 at 12:53 PM, Praveen Madhavan
 wrote:
> Hello All,
>
>  I am trying custom authentication with django, I wrote a class and
> filled it with the methods authenticate and get_user, I also added this
> authentication to the AUTHENTICATION_BACKENDS in settings.py file.
>
> I have called my custom authenticate method and followed it up with
> login in my view.

Show us this view. You should not be calling a "custom authenticate
method", you should be using login() and authenticate() from
django.contrib.auth. If you are not, then this explains why on
subsequent views you are not logged in.

>
> Everything seems to work fine, is_authenticated returns true for the
> user after login, but the subsequent requests have request.user as
> anonymous, unable to figure out the reason, require your help

The other cause of login failing is if your browser does not send the
session cookie back to the server. This would happen if you have
configured django to send cookies with a different host than the pages
are served from. Use chrome inspector or firefox or any other tool you
fancy to determine if this is the case.

The easiest way to see is to look at the session cookie sent with the
pre-login page response, and the session cookie sent with the
post-login page response, do they have different ids?

Cheers

Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFHbX1J3Y0qcxen%3D16WoKmVU7bQr0%3DpO0Hjfyq6N-Cwov7McHw%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Django custom authentication

2013-10-22 Thread Praveen Madhavan
Tom 

Thanks for the response, here is my view

def home(request):
if not request.user.is_authenticated():
# I have written my own custom authenticate method that returns an 
user object
user=authenticate(request=request)
if not user:
return HttpResponseRedirect("/accounts")
else:
login(request,user)
return HttpResponse("Logged in Successfully")
else:
return HttpResponse(request.user)



On Tuesday, 22 October 2013 18:30:13 UTC+5:30, Tom Evans wrote:
>
> On Tue, Oct 22, 2013 at 12:53 PM, Praveen Madhavan 
> > wrote: 
> > Hello All, 
> > 
> >  I am trying custom authentication with django, I wrote a class and 
> > filled it with the methods authenticate and get_user, I also added this 
> > authentication to the AUTHENTICATION_BACKENDS in settings.py file. 
> > 
> > I have called my custom authenticate method and followed it up with 
> > login in my view. 
>
> Show us this view. You should not be calling a "custom authenticate 
> method", you should be using login() and authenticate() from 
> django.contrib.auth. If you are not, then this explains why on 
> subsequent views you are not logged in. 
>
> > 
> > Everything seems to work fine, is_authenticated returns true for the 
> > user after login, but the subsequent requests have request.user as 
> > anonymous, unable to figure out the reason, require your help 
>
> The other cause of login failing is if your browser does not send the 
> session cookie back to the server. This would happen if you have 
> configured django to send cookies with a different host than the pages 
> are served from. Use chrome inspector or firefox or any other tool you 
> fancy to determine if this is the case. 
>
> The easiest way to see is to look at the session cookie sent with the 
> pre-login page response, and the session cookie sent with the 
> post-login page response, do they have different ids? 
>
> Cheers 
>
> Tom 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/935a040b-89eb-45cb-9b3e-2e460e64f87f%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: What is the best solution to deploy Django on a Windows server?

2013-10-22 Thread Augusto Destrero
The virtual machine solution already came to my mind, but unfortunately 
it's not practical in this case. I investigated a bit the available 
solutions to have Django running on Windows and I came up with a CherryPy 
based deployment of Django.
I wrote a blog post on my experience with this approach:

http://baxeico.wordpress.com/2013/10/13/django-on-windows/

Please reply here or in the blog if you have comments (I'm particularly 
interested in possible problems arising from my approach).

Thank you very much for your help!

On Friday, October 11, 2013 10:54:38 PM UTC+2, Javier Guerra wrote:
>
> On Fri, Oct 11, 2013 at 2:50 PM, Arnold Krille 
> > 
> wrote: 
> > Create a virtual machine, either with microsofts virtualization or with 
> > virtualbox. Install linux in it, deploy your app as you are used to 
> > do. 
>
>
> while I agree that using Linux is the best solution, Django _does_ run 
> on windows without any problem. 
>
> just don't mess with IIS, Apache+mod_wsgi is a perfectly good 
> platform. (personally, I prefer nginx+uWSGI, but that would need a lot 
> more work to run on windows) 
>
>
> -- 
> Javier 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e07669f0-f8eb-439b-b124-2fc38a5b3c30%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: supervisor

2013-10-22 Thread Diogene Laerce



Are you sure you need one ?
   


Well I need to monitor at least uwsgi to keep the site up. I rely now on 
monit,

it seems ok. Like I asked to Lukas, what do you think of it ?


uWSGI Emperor is way more capable (in terms of monitoring and management
of bad-behaving apps) and easy to manage (just drop files in a directory)
   


Yes I think I saw something like that on my readings but it seemed (on the
moment) way over my humble needs : I've got only 1 application to run.


By the way, if you cannot use distro-included process managers (upstart or
systemd), i find circus a great alternative to suprvisord. I have seen lot
of users happy with 'god' too (it is a ruby app)
   


I tried circus : it's nice but there is no much docs on it and I'm quite 
a newbie

at all this.

And I just realize now that when you said 'god', you didn't mean 'God'.. :)
So I may give a shot later.

Thank you

--
“One original thought is worth a thousand mindless quotings.”
“Le vrai n'est pas plus sûr que le probable.”

  Diogene Laerce

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5266A6A5.9000200%40yahoo.fr.
For more options, visit https://groups.google.com/groups/opt_out.


Re: supervisor

2013-10-22 Thread Diogene Laerce


the trick is to add supervisor command that specifically tells the 
program to NOT daemonize


[program:my_uwsgi]
command = /usr/local/bin/uwsgi -i /path/to/config.ini
autorestart = True
user = your_user

config.ini:
your standard uwsgi config, but NO daemonize=logfile path

that works perfectly

I'm reloading all the time ..


That means that you need to reload for every change in the code 
source, doesn't it ?

There's no over way ?


Exactly, the uwsgi has no idea that you edited .py files, you need to 
reload it. although there is some feature like the django server of 
autoreload, but just to be safe, you should reload the uwsgi processes 
by hand. I think I even saw some plugin for supervisor that does this 
automatically, but I'm not sure...


Hoewer on a different note, you should have your dev code separated 
from production, so you don't change it that often that it would 
bother you to reload it :)


Actually it didn't work for me : all my troubles remained the same.

I found another software in the repositories : monit. It works (well I 
managed to
make it work..) and I can even monitor CPU load with it. But I didn't 
see anyone

use it in a django stack, do you know why ?

Thanks anyway

--
“One original thought is worth a thousand mindless quotings.”
“Le vrai n'est pas plus sûr que le probable.”

  Diogene Laerce

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5266A6C4.6020109%40yahoo.fr.
For more options, visit https://groups.google.com/groups/opt_out.


Django 1.6b4 fails to run tests with runner test.simple trying to import TransRealMixin

2013-10-22 Thread Matthieu Rigal
Hi all,

I know that TransRealMixin already was a problem in the past and I thought 
it was "fixed" in the meaning that it was incorporated in the project. 
(https://github.com/django/django/pull/1147)

I tried to run my actual tests (developed on 1.4.x) on the 1.6b4 and here 
is what comes out when I use the following parameter 

TEST_RUNNER = 'django.test.simple.DjangoTestSuiteRunner'


Traceback (most recent call last):
  File "manage.py", line 15, in 
execute_from_command_line(sys.argv)
  File 
"/Users/mrigal/dev/_virtualenvs/myo_1.6/src/django/django/core/management/__init__.py",
 
line 397, in execute_from_command_line
utility.execute()
  File 
"/Users/mrigal/dev/_virtualenvs/myo_1.6/src/django/django/core/management/__init__.py",
 
line 390, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
  File 
"/Users/mrigal/dev/_virtualenvs/myo_1.6/src/django/django/core/management/commands/test.py",
 
line 50, in run_from_argv
super(Command, self).run_from_argv(argv)
  File 
"/Users/mrigal/dev/_virtualenvs/myo_1.6/src/django/django/core/management/base.py",
 
line 240, in run_from_argv
self.execute(*args, **options.__dict__)
  File 
"/Users/mrigal/dev/_virtualenvs/myo_1.6/src/django/django/core/management/commands/test.py",
 
line 71, in execute
super(Command, self).execute(*args, **options)
  File 
"/Users/mrigal/dev/_virtualenvs/myo_1.6/src/django/django/core/management/base.py",
 
line 283, in execute
output = self.handle(*args, **options)
  File 
"/Users/mrigal/dev/_virtualenvs/myo_1.6/lib/python2.7/site-packages/south/management/commands/test.py",
 
line 8, in handle
super(Command, self).handle(*args, **kwargs)
  File 
"/Users/mrigal/dev/_virtualenvs/myo_1.6/src/django/django/core/management/commands/test.py",
 
line 88, in handle
failures = test_runner.run_tests(test_labels)
  File 
"/Users/mrigal/dev/_virtualenvs/myo_1.6/src/django/django/test/runner.py", 
line 144, in run_tests
suite = self.build_suite(test_labels, extra_tests)
  File 
"/Users/mrigal/dev/_virtualenvs/myo_1.6/src/django/django/test/simple.py", 
line 247, in build_suite
suite.addTest(build_suite(app))
  File 
"/Users/mrigal/dev/_virtualenvs/myo_1.6/src/django/django/test/simple.py", 
line 149, in build_suite
test_module = get_tests(app_module)
  File 
"/Users/mrigal/dev/_virtualenvs/myo_1.6/src/django/django/test/simple.py", 
line 101, in get_tests
test_module = import_module('.'.join(prefix + [TEST_MODULE]))
  File 
"/Users/mrigal/dev/_virtualenvs/myo_1.6/src/django/django/utils/importlib.py", 
line 35, in import_module
__import__(name)
  File 
"/Users/mrigal/dev/_virtualenvs/myo_1.6/src/django/django/contrib/humanize/tests.py",
 
line 22, in 
from i18n import TransRealMixin
ImportError: cannot import name TransRealMixin

Best,
Matthieu

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9db6f8fc-a49a-4250-85ec-1a5e0aca46ff%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: supervisor

2013-10-22 Thread Lukáš Němec

Dne 22. 10. 2013 18:24, Diogene Laerce napsal(a):



the trick is to add supervisor command that specifically tells the
program to NOT daemonize

[program:my_uwsgi]
command = /usr/local/bin/uwsgi -i /path/to/config.ini
autorestart = True
user = your_user

config.ini:
your standard uwsgi config, but NO daemonize=logfile path

that works perfectly

I'm reloading all the time ..


That means that you need to reload for every change in the code
source, doesn't it ?
There's no over way ?



Exactly, the uwsgi has no idea that you edited .py files, you need to
reload it. although there is some feature like the django server of
autoreload, but just to be safe, you should reload the uwsgi processes
by hand. I think I even saw some plugin for supervisor that does this
automatically, but I'm not sure...

Hoewer on a different note, you should have your dev code separated
from production, so you don't change it that often that it would
bother you to reload it :)


Actually it didn't work for me : all my troubles remained the same.

I found another software in the repositories : monit. It works (well I
managed to
make it work..) and I can even monitor CPU load with it. But I didn't
see anyone
use it in a django stack, do you know why ?

Thanks anyway



Never heard of monit... so can't tell you much :)

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5266A78F.5090801%40gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: source code of the Django Tutorial?

2013-10-22 Thread tim
You are mixing versions of the tutorial. Check the URL or the green 
"Documentation version:" in the bottom right. The "dev" versions use 
"Question" while the older versions use "Poll".

On Monday, October 21, 2013 4:13:46 PM UTC-4, Daniel Roseman wrote:
>
> On Monday, 21 October 2013 20:47:51 UTC+1, Yang Yang wrote:
>
>> the tutorial is extremely helpful: 
>> https://docs.djangoproject.com/en/dev/intro/tutorial01/
>>
>> but the code samples there seems to be somehow out of sync with the text, 
>> for example  some parts of the code uses the class "Poll" while some parts 
>> use "Question".
>>
>> is there a complete set of source files showing the complete 6 tutorials?
>>
>> thanks!
>> yang
>>
>
> "question" is a field on the Poll model. There isn't anywhere in the 
> tutorial that uses Question as a model class.
> --
> DR.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c4c34dbf-256d-4604-8c57-b795658d9edb%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: MySQL error when trying to run tests with utf8mb4 charset

2013-10-22 Thread tim
I think you may be barking up the wrong tree, see 
https://code.djangoproject.com/ticket/21196

On Friday, October 18, 2013 7:30:10 PM UTC-4, fle...@fletchowns.net wrote:
>
> Looks like this comes from custom_user.py in django.contrib.auth.tests:
>
> class CustomUser(AbstractBaseUser):
> email = models.EmailField(verbose_name='email address', 
> max_length=255, unique=True)
> is_active = models.BooleanField(default=True)
> is_admin = models.BooleanField(default=False)
> date_of_birth = models.DateField()
>
> I think this should have the same length as AbstractUser, where it does 
> not specify a max_length, so it defaults to 75 in 
> django.db.models.fields.EmailField. Should I submit a pull request for this 
> change?
>
> Thanks!
>
> On Wednesday, October 16, 2013 11:01:45 AM UTC-7, fle...@fletchowns.netwrote:
>>
>> Hello!
>>
>> I tried to run *./manage.py test *for the first time and I got the 
>> following error:
>>
>> *DatabaseError: (1071, 'Specified key was too long; max key length is 
>> 767 bytes')*
>>
>> Looking at the log in MySQL, it appears to be caused by this statement:
>>
>> CREATE TABLE `auth_customuser` (
>> `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
>> `password` varchar(128) NOT NULL,
>> `last_login` datetime NOT NULL,
>> `email` varchar(255) NOT NULL UNIQUE,
>> `is_active` bool NOT NULL,
>> `is_admin` bool NOT NULL,
>> `date_of_birth` date NOT NULL
>> )
>>
>>
>> So the email field of varchar(255) is causing me to go over the 
>> single-column index of 767 bytes in InnoDB when the charset is utf8mb4, 
>> that part I understand.
>>
>> Why is it trying to create this *auth_customuser* table anyways though? 
>> It doesn't exist in my application normally. The *email* field on my *
>> auth_user* table is varchar(75) so no error from that, not sure why it's 
>> a different length there though.
>>
>> To get around the issue temporarily I set the database engine to sqlite, 
>> but I'd like to be able to use MySQL for the tests, since that's what my 
>> application normally uses.
>>
>> Thanks in advance!
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1365ded5-dd5b-4259-ae1b-408ce135e212%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Django 1.6b4 fails to run tests with runner test.simple trying to import TransRealMixin

2013-10-22 Thread Ramiro Morales
Matthieu,

On Tue, Oct 22, 2013 at 1:22 PM, Matthieu Rigal 
wrote:
> Hi all,
>
> I know that TransRealMixin already was a problem in the past and I thought
> it was "fixed"in the meaning that it was incorporated in the project.
> (https://github.com/django/django/pull/1147)
>
> I tried to run my actual tests (developed on 1.4.x) on the 1.6b4 and here
is
> what comes out when I use the following parameter
>
> TEST_RUNNER = 'django.test.simple.DjangoTestSuiteRunner'
>
>
> Traceback (most recent call last):
>   File "manage.py", line 15, in 
> execute_from_command_line(sys.argv)
>   File
>
"/Users/mrigal/dev/_virtualenvs/myo_1.6/src/django/django/core/management/__init__.py",
> line 397, in execute_from_command_line
> utility.execute()
>   File
>
"/Users/mrigal/dev/_virtualenvs/myo_1.6/src/django/django/core/management/__init__.py",
> line 390, in execute
> self.fetch_command(subcommand).run_from_argv(self.argv)
>   File
>
"/Users/mrigal/dev/_virtualenvs/myo_1.6/src/django/django/core/management/commands/test.py",
> line 50, in run_from_argv
> super(Command, self).run_from_argv(argv)
>   File
>
"/Users/mrigal/dev/_virtualenvs/myo_1.6/src/django/django/core/management/base.py",
> line 240, in run_from_argv
> self.execute(*args, **options.__dict__)
>   File
>
"/Users/mrigal/dev/_virtualenvs/myo_1.6/src/django/django/core/management/commands/test.py",
> line 71, in execute
> super(Command, self).execute(*args, **options)
>   File
>
"/Users/mrigal/dev/_virtualenvs/myo_1.6/src/django/django/core/management/base.py",
> line 283, in execute
> output = self.handle(*args, **options)
>   File
>
"/Users/mrigal/dev/_virtualenvs/myo_1.6/lib/python2.7/site-packages/south/management/commands/test.py",
> line 8, in handle
> super(Command, self).handle(*args, **kwargs)
>   File
>
"/Users/mrigal/dev/_virtualenvs/myo_1.6/src/django/django/core/management/commands/test.py",
> line 88, in handle
> failures = test_runner.run_tests(test_labels)
>   File
> "/Users/mrigal/dev/_virtualenvs/myo_1.6/src/django/django/test/runner.py",
> line 144, in run_tests
> suite = self.build_suite(test_labels, extra_tests)
>   File
> "/Users/mrigal/dev/_virtualenvs/myo_1.6/src/django/django/test/simple.py",
> line 247, in build_suite
> suite.addTest(build_suite(app))
>   File
> "/Users/mrigal/dev/_virtualenvs/myo_1.6/src/django/django/test/simple.py",
> line 149, in build_suite
> test_module = get_tests(app_module)
>   File
> "/Users/mrigal/dev/_virtualenvs/myo_1.6/src/django/django/test/simple.py",
> line 101, in get_tests
> test_module = import_module('.'.join(prefix + [TEST_MODULE]))
>   File
>
"/Users/mrigal/dev/_virtualenvs/myo_1.6/src/django/django/utils/importlib.py",
> line 35, in import_module
> __import__(name)
>   File
>
"/Users/mrigal/dev/_virtualenvs/myo_1.6/src/django/django/contrib/humanize/tests.py",
> line 22, in 
> from i18n import TransRealMixin
> ImportError: cannot import name TransRealMixin
>

Could you give us more information about how to reproduce this? i.e. what
tests are you trying to run? etc.

Thanks.

-- 
Ramiro Morales
@ramiromorales

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAO7PdF_L4GeZwmYykk%2BK3vFTWDbv-BH4JjRNQuXFZdT2ZrK2yg%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


HOWTO: Create a ManyToMany Relationship?

2013-10-22 Thread Timothy W. Cook
Can someone point me to where this is explained in the docs (1.6)?

I have a ManyToMany relationship in my models between Author and Paper.

I am processing an XML file to create records for Papers.

I want to check if an Author exists and if not create the record.

This was quite easy for Foreign Key relationships.  But I can't get my head
around how to do this for ManyToMany.  All of my Authors are created
correctly.  But none are automatically selected for the Papers.

Some code:

class AuthorManager(models.Manager):
def create_author(self, name, email, affl):
a = self.create(name=name, email=email, affiliation=affl)
a.save()
return a

class Author(models.Model):
name = models.CharField("Name", max_length=255, db_index=True,
null=True, blank=True, help_text="")
email = models.EmailField("Email", max_length=255, null=True,
blank=True, help_text="")
affiliation = models.CharField("Affiliation", max_length=255,
null=True, blank=True, help_text="")

objects = AuthorManager()

def __str__(self):
return self.name


def import_pubmed_xml(obj, f):
...
p =
Paper.objects.create_paper(ptitle,rid,jid,jyear,jvol,jissue,lang)

#authors
affl = article.xpath("./Affiliation/text()")
if affl: affl = affl[0]
else: affl = 'unknown'
affl = affl.strip()

authorlist = article.xpath("./AuthorList")
for authorentry in authorlist:
for author in authorentry:
lname = author.xpath("./LastName/text()")
if lname:
lname = lname[0]
else:
lname = 'unknown'
fname = author.xpath("./ForeName/text()")
if fname:
fname = fname[0]
else:
fname = 'unknown'
initials = author.xpath("./Initials/text()")
if initials:
initials = initials[0]
else:
initials = ''

a_name = (lname +', '+fname + ' ' +initials).strip()
print(a_name)
email = ''
#need to lookup Author by name then check affiliation. If
not found then create it.
try:
a = Author.objects.get(name=a_name)
p.authors.id = a.id
p.save()
except ObjectDoesNotExist:
a = Author.objects.create_author(a_name, email, affl)
p.authors.id = a.id
p.save()
===

Thanks in Advance,
Tim





-- 
MLHIM VIP Signup: http://goo.gl/22B0U

Timothy Cook, MSc   +55 21 94711995
MLHIM http://www.mlhim.org
Like Us on FB: https://www.facebook.com/mlhim2
Circle us on G+: http://goo.gl/44EV5
Google Scholar: http://goo.gl/MMZ1o
LinkedIn Profile:http://www.linkedin.com/in/timothywaynecook

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2B%3DOU3XyRXaR%2BBt_QsryiXpEv15%2BTCmWYyHzTnOobnVWCS4xiA%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Django 1.6b4 fails to run tests with runner test.simple trying to import TransRealMixin

2013-10-22 Thread Ramiro Morales
On Tue, Oct 22, 2013 at 4:33 PM, Ramiro Morales  wrote:
>
> Could you give us more information about how to reproduce this? i.e. what 
> tests are you trying to run? etc.

Never mind, I've reproduced it and opened ticket [1]12307.

-- 
Ramiro Morales
@ramiromorales

1. https://code.djangoproject.com/ticket/21307

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAO7PdF8ms4sajxk1BkRkeOB%2BybLg-EWbbhduR%3Dg%3DChuNGCbxaw%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: HOWTO: Create a ManyToMany Relationship?

2013-10-22 Thread Pepsodent Cola
I'm a beginner so I can only answer your first question.  The below link 
has helped me with 1:M and N:M relationship experiments.

Can someone point me to where this is explained in the docs (1.6)?


https://docs.djangoproject.com/en/1.6/topics/db/examples/





On Tuesday, October 22, 2013 11:59:14 PM UTC+2, Timothy W. Cook wrote:
>
> Can someone point me to where this is explained in the docs (1.6)?
>
> I have a ManyToMany relationship in my models between Author and Paper.  
>
> I am processing an XML file to create records for Papers.
>
> I want to check if an Author exists and if not create the record. 
>
> This was quite easy for Foreign Key relationships.  But I can't get my 
> head around how to do this for ManyToMany.  All of my Authors are created 
> correctly.  But none are automatically selected for the Papers. 
>
> Some code:
>
> class AuthorManager(models.Manager):
> def create_author(self, name, email, affl):
> a = self.create(name=name, email=email, affiliation=affl)
> a.save()
> return a
>
> class Author(models.Model):
> name = models.CharField("Name", max_length=255, db_index=True, 
> null=True, blank=True, help_text="")
> email = models.EmailField("Email", max_length=255, null=True, 
> blank=True, help_text="")
> affiliation = models.CharField("Affiliation", max_length=255, 
> null=True, blank=True, help_text="")
>
> objects = AuthorManager()
>
> def __str__(self):
> return self.name
>
>
> def import_pubmed_xml(obj, f):
> ...
> p = 
> Paper.objects.create_paper(ptitle,rid,jid,jyear,jvol,jissue,lang)
>
> #authors
> affl = article.xpath("./Affiliation/text()")
> if affl: affl = affl[0]
> else: affl = 'unknown'
> affl = affl.strip()
>
> authorlist = article.xpath("./AuthorList")
> for authorentry in authorlist:
> for author in authorentry:
> lname = author.xpath("./LastName/text()")
> if lname:
> lname = lname[0]
> else:
> lname = 'unknown'
> fname = author.xpath("./ForeName/text()")
> if fname:
> fname = fname[0]
> else:
> fname = 'unknown'
> initials = author.xpath("./Initials/text()")
> if initials:
> initials = initials[0]
> else:
> initials = ''
>
> a_name = (lname +', '+fname + ' ' +initials).strip()
> print(a_name)
> email = ''
> #need to lookup Author by name then check affiliation. If 
> not found then create it.
> try:
> a = Author.objects.get(name=a_name)
> p.authors.id = a.id
> p.save()
> except ObjectDoesNotExist:
> a = Author.objects.create_author(a_name, email, affl)
> p.authors.id = a.id
> p.save()
> ===
>
> Thanks in Advance,
> Tim
>
>
>
>
>
> -- 
> MLHIM VIP Signup: http://goo.gl/22B0U
> 
> Timothy Cook, MSc   +55 21 94711995
> MLHIM http://www.mlhim.org
> Like Us on FB: https://www.facebook.com/mlhim2
> Circle us on G+: http://goo.gl/44EV5
> Google Scholar: http://goo.gl/MMZ1o
> LinkedIn Profile:http://www.linkedin.com/in/timothywaynecook
>  

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ff993a02-baad-4a7d-ad39-529ddafd8861%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Django 1.6b4 fails to run tests with runner test.simple trying to import TransRealMixin

2013-10-22 Thread Ramiro Morales
On Tue, Oct 22, 2013 at 8:26 PM, Ramiro Morales  wrote:
> On Tue, Oct 22, 2013 at 4:33 PM, Ramiro Morales  wrote:
>>
>> Could you give us more information about how to reproduce this? i.e. what 
>> tests are you trying to run? etc.
>
> Never mind, I've reproduced it and opened ticket [1]12307.

This has been fixed in the 1.6.x branch and the fix will be included
in the soon to be tagged 1.6 rc.

Please test it and report back if you find any additional problems.

Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAO7PdF-SRd0zPcmcHA086gzoPdbCos6FhrAGFzcxMJgjz%2Btgig%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


[ANNOUNCE] Django 1.6 release candidate available

2013-10-22 Thread James Bennett
It's almost here!

Tonight we've issued a release candidate for Django 1.6. Information,
including links to downloads and release notes, is available on the Django
project blog:

https://www.djangoproject.com/weblog/2013/oct/22/16c1/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAL13Cg82W91nQKR_PQRBM-76AgpZxWNp6zBRsbUu0fUGJMXyfA%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Auth backends don't work with HttpResponseRedirect and Django 1.4+?

2013-10-22 Thread Praveen Madhavan
Hi,
Can you please exlpain it further. I am facing the same issue. I have 
written a get_user() method in my customauthentication.py. My 
authentication is successful but the subsequent requests show up as 
anonymous user.

Thanks
Praveen.M


On Monday, 21 October 2013 16:28:12 UTC+5:30, HM wrote:
>
> Turns out: the auth backend that worked in 1.3 but not in 1.4+ was missing 
> a get_user()-method. I added it in and that was that.
>
>
> HM
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6415f4cb-2319-4f64-955b-09be2094bf0a%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


variable in django template

2013-10-22 Thread Harjot Mann
I want to initialize a varibale in django template from zero, which I
want to comapre with the some job_no whihc is coming from database. I
am not getting hoe to decalre a variable. Please help me .
-- 
Harjot Kaur Mann
Blog: http://harjotmann.wordpress.com/
Daily Dairy: http://harjotmann.wordpress.com/daily-diary/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAB0GQhBfRf3cK-YZ1R90rNaKWgUunVZ_R_nxynSD8LuXQOGoWQ%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: HOWTO: Create a ManyToMany Relationship?

2013-10-22 Thread Mike Dewhirst

On 23/10/2013 11:51am, Pepsodent Cola wrote:

I'm a beginner so I can only answer your first question.  The below link
has helped me with 1:M and N:M relationship experiments.

Can someone point me to where this is explained in the docs (1.6)?


https://docs.djangoproject.com/en/1.6/topics/db/examples/


https://docs.djangoproject.com/en/1.6/ref/models/fields/#manytomanyfield

Also, a couple of paragraphs below that ...

https://docs.djangoproject.com/en/1.6/ref/models/fields/#django.db.models.ManyToManyField.through

... where it explains that you can have your own table for the m2m 
relationship if you want to store data about the relationship itself.


For this to make sense you need to declare a model class for that table 
with fields for the extra data. Note that this isn't necessary for 
ordinary m2m relationships because Django does it implicitly.


Anyway, if you make an extra table, it needs a FK to each of the other 
tables. Maybe like ...


class AuthorPaper(models.Model):
author = models.ForeignKey('Author')
paper = models.ForeignKey('Paper')
gossip = models.TextField()

Now this being a model in your own code means you can deal with it in 
more or less the same way as all the other models in your views etc.


I haven't read the code below in any detail so this is probably off the 
mark but there is a get_or_create method which might be useful.


https://docs.djangoproject.com/en/1.5/ref/models/querysets/#django.db.models.query.QuerySet.get_or_create

hth

Mike







On Tuesday, October 22, 2013 11:59:14 PM UTC+2, Timothy W. Cook wrote:

Can someone point me to where this is explained in the docs (1.6)?

I have a ManyToMany relationship in my models between Author and Paper.

I am processing an XML file to create records for Papers.

I want to check if an Author exists and if not create the record.

This was quite easy for Foreign Key relationships.  But I can't get
my head around how to do this for ManyToMany.  All of my Authors are
created correctly.  But none are automatically selected for the Papers.

Some code:

class AuthorManager(models.Manager):
 def create_author(self, name, email, affl):
 a = self.create(name=name, email=email, affiliation=affl)
 a.save()
 return a

class Author(models.Model):
 name = models.CharField("Name", max_length=255, db_index=True,
null=True, blank=True, help_text="")
 email = models.EmailField("Email", max_length=255, null=True,
blank=True, help_text="")
 affiliation = models.CharField("Affiliation", max_length=255,
null=True, blank=True, help_text="")

 objects = AuthorManager()

 def __str__(self):
 return self.name 


def import_pubmed_xml(obj, f):
...
 p =
Paper.objects.create_paper(ptitle,rid,jid,jyear,jvol,jissue,lang)

 #authors
 affl = article.xpath("./Affiliation/text()")
 if affl: affl = affl[0]
 else: affl = 'unknown'
 affl = affl.strip()

 authorlist = article.xpath("./AuthorList")
 for authorentry in authorlist:
 for author in authorentry:
 lname = author.xpath("./LastName/text()")
 if lname:
 lname = lname[0]
 else:
 lname = 'unknown'
 fname = author.xpath("./ForeName/text()")
 if fname:
 fname = fname[0]
 else:
 fname = 'unknown'
 initials = author.xpath("./Initials/text()")
 if initials:
 initials = initials[0]
 else:
 initials = ''

 a_name = (lname +', '+fname + ' ' +initials).strip()
 print(a_name)
 email = ''
 #need to lookup Author by name then check
affiliation. If not found then create it.
 try:
 a = Author.objects.get(name=a_name)
p.authors.id  = a.id 
 p.save()
 except ObjectDoesNotExist:
 a = Author.objects.create_author(a_name, email,
affl)
p.authors.id  = a.id 
 p.save()
===

Thanks in Advance,
Tim





--
MLHIM VIP Signup: http://goo.gl/22B0U

Timothy Cook, MSc   +55 21 94711995
MLHIM http://www.mlhim.org
Like Us on FB: https://www.facebook.com/mlhim2

Circle us on G+: http://goo.gl/44EV5
Google Scholar: http://goo.gl/MMZ1o
LinkedIn Pr