Re: De-serialization of ManyToManyField

2012-03-28 Thread sk
Hi,

I finally worked out where the problem was!

I am posting the answer in case that someone else has a similar issue
and stumbles upon this.

So I have reverted to the original model, as defined in the first
email here. The problem was with my definition of the natural keys, my
function was not retruning a tuple.

The solution was to add a comma to the return value of the natural_key
methods:

---
from django.db import models
class TestManager(models.Manager):
def get_by_natural_key(self, name):
return self.get(name=name,)


class Test(models.Model):
name = models.CharField(max_length = 100, unique = True)
date = models.DateField()


def __unicode__(self):
return self.name


def natural_key(self):
return (self.name,)


class InstanceManager(models.Manager):
def get_by_natural_key(self, name):
return self.get(name=name,)


class Instance(models.Model):
name = models.CharField(max_length = 100, unique = True)
test = models.ManyToManyField(Test)
date = models.DateField()


def __unicode__(self):
return self.name


def natural_key(self):
return (self.name,)

I realise this is a pretty basic Python 'gotcha' and one I would hope
I would normally spot! In this case I was just not sure where the
problem was.

I hope this helps someone else with the same problem, at some point!

regards
Stephen

On Mar 27, 11:02 am, sk <6b656...@gmail.com> wrote:
> Hi,
>
> So a brief update. I changed the way I was building this model and
> explicitly created a 'joining' table and added a through clause to the
> ManyToManyField definition as well as allowing null values. This meant
> I was able to populate the joining table using YAML after building the
> test/instance tables using the natural keys for each of 'test' and
> 'instance'.
>
> However when I view the table in the admin interface there is no
> multiple selector for 'test' when I edit the instance in the admin
> interface. I have added the joining table to the list of admin tables
> (if this makes a difference).
>
> Can anyone explain to me whether this is another error on my part, or
> if it is expected that if you explicitly define a joining table then
> Django suppresses the management of the relationship outside of the
> joining table itself?
>
> Obviously if it were possible to use the built in manytomany
> management and be able to import the YAML defining this that I
> included in the initial question that would be favourable.
>
> For context this is a simplified example of a reasonably large
> database that I am trying to port to a Django model so manually
> building the contents of the joining table is not a reasonable
> solution. I can generate the YAML, or similar, fairly trivially and so
> it is best for me to build the fixtures to get the initial DB set up
> and import them after the initial syndb.
>
> Any guidance on this would be much appreciated - I am really enjoying
> the elegance of Django but little issues caused by my (lack of)
> understanding are definitely holding me up!
>
> Regards
> Stephen
>
> On Mar 26, 12:01 pm, sk <6b656...@gmail.com> wrote:
>
>
>
> > Hi,
>
> > I have searched high and low to an answer to this, but have been
> > unable too turn anything up. Apologies if I have overlooked an answer
> > or explanation elsewhere.
>
> > I have set up a very simple model as follows:
> > ---
> > from django.db import models
> > class TestManager(models.Manager):
> >     def get_by_natural_key(self, name):
> >         return self.get(name=name,)
>
> > class Test(models.Model):
> >     name = models.CharField(max_length = 100, unique = True)
> >     date = models.DateField()
>
> >     def __unicode__(self):
> >         return self.name
>
> >     def natural_key(self):
> >         return (self.name)
>
> > class InstanceManager(models.Manager):
> >     def get_by_natural_key(self, name):
> >         return self.get(name=name,)
>
> > class Instance(models.Model):
> >     name = models.CharField(max_length = 100, unique = True)
> >     test = models.ManyToManyField(Test)
> >     date = models.DateField()
>
> >     def __unicode__(self):
> >         return self.name
>
> >     def natural_key(self):
> >         return (self.name)
> > ---
>
> > looking at the admin interface I am able to add a couple of
> > 'tests' (test 1 and test 2). I am then able to add an instance which
> > is linked to both test 1 and test 2. If I dump the data to YAML format
> > then I get the following (for the two tables in question):
>
> > ---
> > - fields: {date: 2012-03-26, name: test 1}
> >   model: TempDB.test
> >   pk: 1
> > - fields: {date: 2012-03-26, name: test 2}
> >   model: TempDB.test
> >   pk: 2
> > - fields:
> >    

Re: TestCase Client.login() fails

2012-03-28 Thread Reinout van Rees

On 28-03-12 08:05, jondbaker wrote:


def test_login(self):
user = User.objects.create_user('test', 't...@test.com', 't3stp@s$')
response = self.client.login(username=user.username, password=user.password)
self.assertTrue(response)

After creating the user, I can verify that user.is_active is in fact
True, but unfortunately response returns False. Both
'django.contrib.auth.middleware.AuthenticationMiddleware' and
'django.contrib.auth' are declared in settings.py.

Any thoughts?


Yes: You have to call user.save() after creating it. Otherwise the user 
object exists, but it isn't saved to the database yet. And 
"self.client.login()" queries the database, not user objects local to 
the test.



Creating model objects in tests and testing them afterwards is something 
that needs a bit of care. I've made several mistakes with them already 
:-) Look at [1] for an example error.



Reinout

[1]: 
http://reinout.vanrees.org/weblog/2011/11/18/django_unicodedecodeerror.html


--
Reinout van Reeshttp://reinout.vanrees.org/
rein...@vanrees.org http://www.nelen-schuurmans.nl/
"If you're not sure what to do, make something. -- Paul Graham"

--
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: Looking for a developer who knows Django well

2012-03-28 Thread MSSONI
I am extremely sorry. This is a startup in Pune, India. We are looking
for a Django developer in Pune itself. We are willing to pay 15-22k
rupees per month. If anybody is interested please contact me on
00919922455685.

Regards,
Mayuresh S Soni

On Mar 27, 5:53 pm, Daniel Roseman  wrote:
> On Tuesday, 27 March 2012 12:34:46 UTC+1, MSSONI wrote:
>
> > I have just started a company. The company is yet to be registered. We
> > have launched our productwww.instashare.me. Our alpha has just
> > launched. We are looking for passionate developers. Our salary will
> > range from 15-25k depending on the developers abilities.
>
> Seems legit... No location, salary absurdly low even though it's not clear
> what currency we're talking about, no contact details. Yes, this must be a
> real startup.
> --
> DR.

-- 
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: TestCase Client.login() fails

2012-03-28 Thread jondbaker
Problem solved. I forgot that .create_user will create and return a hashed 
password, which obviously won't work if said returned object password 
property is entered into the password field of the login form.

On Wednesday, March 28, 2012 12:05:49 AM UTC-6, jondbaker wrote:
>
> I'm trying to write a unit test that will verify that the login form 
> authenticates a user. Whenever I run 'manage.py test' the runner fails with 
> this message:
> *AssertionError: False is not True*
>
> *tests.py*
> from django.test import TestCase
> from django.test.client import Client
> from django.contrib.auth.models import User
>
> class TestAccountLogin(TestCase):
> def setUp(self):
> self.client = Client()
>
> def test_login(self):
> user = User.objects.create_user('test', 't...@test.com', 
> 't3stp@s$')
> response = self.client.login(username=user.username, 
> password=user.password)
> self.assertTrue(response)
>
> After creating the user, I can verify that user.is_active is in fact True, 
> but unfortunately response returns False. Both 
> 'django.contrib.auth.middleware.AuthenticationMiddleware' and 
> 'django.contrib.auth' are declared in settings.py.
>
> Any thoughts?
>

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



DjangoCon Europe Early Bird registration

2012-03-28 Thread Daniele Procida
Just a reminder - you only have a couple of days left to register at the Early 
Bird rate.



Also, I challenge you to find cooler accommodation in Zürich than I have:



Daniele

-- 
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: IE9+Django,Don't respond or Socket error!!!

2012-03-28 Thread Andre Terra
On Mon, Mar 26, 2012 at 11:31 PM, br  wrote:

> 2) If you want to use the runserver that comes with django:
> - to run runserver, use "manage.py runserver 0.0.0.0:8000" instead of
> the default (which goes to localhost or 127.0.0.1) , and then figure
> out your computer's IP address in your intranet (ivarious ways to do
> this, i use "ipconfig" from command line and pick the one that
> probably starts with 192.168).  Then when you want to access your app,
> do it at http://:8000
>


To make things easier, create a free host redirect on no-ip.org[1] and name
it something like 'mydjangoserver.no-ip.org', then install the No-IP
service for automatically updating the redirect to match your current IP
(on a defined interval, which I usually set for 30 mins). This way you can
always point to http://mydjangoserver.no-ip.org regardless of which network
you're currently on. Helps if you're on the go often, or if you've got a
dynamic IP (my original problem back when I started using it).


Cheers,
AT

[1] http://no-ip.org/

-- 
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: TestCase Client.login() fails

2012-03-28 Thread Alexey Kinyov
Hello, Jonathan!

I think issue is in the fragment 'password=user.password' in the line:

>         response = self.client.login(username=user.username,
> password=user.password)

'user.password' - is not plain text password, it's encrypted and it's
not equal 't3stp@s$' !

Alexey rudyryk
///

On Wed, Mar 28, 2012 at 10:05 AM, jondbaker
 wrote:
> I'm trying to write a unit test that will verify that the login form
> authenticates a user. Whenever I run 'manage.py test' the runner fails with
> this message:
> AssertionError: False is not True
>
> tests.py
> from django.test import TestCase
> from django.test.client import Client
> from django.contrib.auth.models import User
>
> class TestAccountLogin(TestCase):
>     def setUp(self):
>         self.client = Client()
>
>     def test_login(self):
>         user = User.objects.create_user('test', 't...@test.com', 't3stp@s$')
>         response = self.client.login(username=user.username,
> password=user.password)
>         self.assertTrue(response)
>
> After creating the user, I can verify that user.is_active is in fact True,
> but unfortunately response returns False. Both
> 'django.contrib.auth.middleware.AuthenticationMiddleware' and
> 'django.contrib.auth' are declared in settings.py.
>
> Any thoughts?
>
> --
> 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/-/5zI85qKS4acJ.
> 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: TestCase Client.login() fails

2012-03-28 Thread Alexey Kinyov
Hello, Reinout!

> Yes: You have to call user.save() after creating it. Otherwise the user
> object exists, but it isn't saved to the database yet.

That' wrong.

Documentation says:

create_user(username, email=None, password=None)

Creates, saves and returns a User.

https://docs.djangoproject.com/en/1.4/topics/auth/#django.contrib.auth.models.UserManager.create_user

I think the problem is that 'user.password' is hashed value but
login() method receives raw plain text password, as I answered above.

Alexey
///

On Wed, Mar 28, 2012 at 12:27 PM, Reinout van Rees  wrote:
> On 28-03-12 08:05, jondbaker wrote:
>
>> def test_login(self):
>>    user = User.objects.create_user('test', 't...@test.com', 't3stp@s$')
>>    response = self.client.login(username=user.username,
>> password=user.password)
>>    self.assertTrue(response)
>>
>> After creating the user, I can verify that user.is_active is in fact
>> True, but unfortunately response returns False. Both
>> 'django.contrib.auth.middleware.AuthenticationMiddleware' and
>> 'django.contrib.auth' are declared in settings.py.
>>
>> Any thoughts?
>
>
> Yes: You have to call user.save() after creating it. Otherwise the user
> object exists, but it isn't saved to the database yet. And
> "self.client.login()" queries the database, not user objects local to the
> test.
>
>
> Creating model objects in tests and testing them afterwards is something
> that needs a bit of care. I've made several mistakes with them already :-)
> Look at [1] for an example error.
>
>
> Reinout
>
> [1]:
> http://reinout.vanrees.org/weblog/2011/11/18/django_unicodedecodeerror.html
>
> --
> Reinout van Rees                    http://reinout.vanrees.org/
> rein...@vanrees.org             http://www.nelen-schuurmans.nl/
> "If you're not sure what to do, make something. -- Paul Graham"
>
>
> --
> 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: TestCase Client.login() fails

2012-03-28 Thread Reinout van Rees

On 28-03-12 11:17, Alexey Kinyov wrote:

Yes: You have to call user.save() after creating it. Otherwise the user
>  object exists, but it isn't saved to the database yet.

That' wrong.

Documentation says:

 create_user(username, email=None, password=None)

 Creates, saves and returns a User.


You're right, I was wrong :-)  I overlooked that create_user is a 
special call and thought it was just a generic create statement.



Reinout

--
Reinout van Reeshttp://reinout.vanrees.org/
rein...@vanrees.org http://www.nelen-schuurmans.nl/
"If you're not sure what to do, make something. -- Paul Graham"

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



BitNami Django Stack with Django 1.4.0

2012-03-28 Thread victoria
Hi,

I just wanted to let you know that BitNami installers, virtual
machines and AMIs for Django 1.4.0 are already available.

http://bitnami.org/stack/djangostack

I hope you enjoy it and I'd love to hear ther comments and suggestions
that you may have.

Cheers,

Victoria.

-- 
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: Looking for a developer who knows Django well

2012-03-28 Thread kenneth gonsalves
On Tue, 2012-03-27 at 05:53 -0700, Daniel Roseman wrote:
> On Tuesday, 27 March 2012 12:34:46 UTC+1, MSSONI wrote:
> >
> > I have just started a company. The company is yet to be registered.
> We 
> > have launched our product www.instashare.me. Our alpha has just 
> > launched. We are looking for passionate developers. Our salary will 
> > range from 15-25k depending on the developers abilities.
> 
> 
> Seems legit... No location, salary absurdly low even though it's not
> clear 
> what currency we're talking about, no contact details. Yes, this must
> be a 
> real startup. 

looks like India - here we quote salaries by the month ;-)
-- 
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.



Bug in BaseForm?

2012-03-28 Thread Marcin
Consider the following stack trace (all relevant code is shown in the stack 
trace):

In [3]: f.clean()
---
AttributeErrorTraceback (most recent call last)
C:\Users\Marcin\Documents\oneclickcos\lib\site-packages\django\core\management\commands\shell.pyc
 
in ()
> 1 f.clean()

C:\Users\Marcin\Documents\oneclickcos\oneclickcos\mainapp\incorporate_helpers.pyc
 
in clean(self)
569 This checks the relations between fields, ensures 
consistent state, and exports bits about the state of the form that can be 
used in subsequent
validations
570 """
--> 571 cleaned_data = super(IncorporateForm, self).clean()
572 #logger.debug('IncorporationForm.cleaned_data: ' + 
str(cleaned_data))

573 try:

C:\Users\Marcin\Documents\oneclickcos\oneclickcos\mainapp\incorporate_helpers.pyc
 
in clean(self)
402
403 def clean(self):
--> 404 cleaned_data = super(CreateForm, self).clean()
405 # trying to use an empty pk can result in a ValueError. 
Easier to expunge.

406 if cleaned_data.get('pk', None) == '': del 
cleaned_data['pk']

C:\Users\Marcin\Documents\oneclickcos\lib\site-packages\django\forms\forms.pyc 
in clean(self)
315 association with the field named '__all__'.
316 """
--> 317 return self.cleaned_data
318
319 def has_changed(self):

AttributeError: 'IncorporateForm' object has no attribute 'cleaned_data'

As you can see, my code conforms to the examples 
at 
https://docs.djangoproject.com/en/1.4/ref/forms/validation/#cleaning-and-validating-fields-that-depend-on-each-other.

However, the error comes from BaseForm's clean method, which expects a 
cleaned_data property or attribute to exist. What gives? Is this a bug in 
django?

-- 
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/-/_yqLTmCFK4MJ.
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: Bug in BaseForm?

2012-03-28 Thread Marcin Tustin
It has been pointed out to me that this error does not occur if one calls
is_valid().

On Wed, Mar 28, 2012 at 14:57, Marcin  wrote:

> Consider the following stack trace (all relevant code is shown in the
> stack trace):
>
> In [3]: f.clean()
> ---
> AttributeErrorTraceback (most recent call last)
> C:\Users\Marcin\Documents\oneclickcos\lib\site-packages\django\core\management\commands\shell.pyc
> in ()
> > 1 f.clean()
>
> C:\Users\Marcin\Documents\oneclickcos\oneclickcos\mainapp\incorporate_helpers.pyc
> in clean(self)
> 569 This checks the relations between fields, ensures
> consistent state, and exports bits about the state of the form that can be
> used in subsequent
> validations
> 570 """
> --> 571 cleaned_data = super(IncorporateForm, self).clean()
> 572 #logger.debug('IncorporationForm.cleaned_data: ' +
> str(cleaned_data))
>
> 573 try:
>
> C:\Users\Marcin\Documents\oneclickcos\oneclickcos\mainapp\incorporate_helpers.pyc
> in clean(self)
> 402
> 403 def clean(self):
> --> 404 cleaned_data = super(CreateForm, self).clean()
> 405 # trying to use an empty pk can result in a ValueError.
> Easier to expunge.
>
> 406 if cleaned_data.get('pk', None) == '': del
> cleaned_data['pk']
>
> C:\Users\Marcin\Documents\oneclickcos\lib\site-packages\django\forms\forms.pyc
> in clean(self)
> 315 association with the field named '__all__'.
> 316 """
> --> 317 return self.cleaned_data
> 318
> 319 def has_changed(self):
>
> AttributeError: 'IncorporateForm' object has no attribute 'cleaned_data'
>
> As you can see, my code conforms to the examples at
> https://docs.djangoproject.com/en/1.4/ref/forms/validation/#cleaning-and-validating-fields-that-depend-on-each-other
> .
>
> However, the error comes from BaseForm's clean method, which expects a
> cleaned_data property or attribute to exist. What gives? Is this a bug in
> django?
>
> --
> 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/-/_yqLTmCFK4MJ.
> 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.
>



-- 
Marcin Tustin
Tel: 07773 787 105

-- 
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: Bug in BaseForm?

2012-03-28 Thread Xavier Ordoquy
Hi,

Have you called is_valid() on the form before that ?

Regards,
Xavier Ordoquy,
Linovia.

Le 28 mars 2012 à 15:57, Marcin a écrit :

> Consider the following stack trace (all relevant code is shown in the stack 
> trace):
> 
> In [3]: f.clean()
> ---
> AttributeErrorTraceback (most recent call last)
> C:\Users\Marcin\Documents\oneclickcos\lib\site-packages\django\core\management\commands\shell.pyc
>  in ()
> > 1 f.clean()
> 
> C:\Users\Marcin\Documents\oneclickcos\oneclickcos\mainapp\incorporate_helpers.pyc
>  in clean(self)
> 569 This checks the relations between fields, ensures consistent 
> state, and exports bits about the state of the form that can be used in 
> subsequent
> validations
> 570 """
> --> 571 cleaned_data = super(IncorporateForm, self).clean()
> 572 #logger.debug('IncorporationForm.cleaned_data: ' + 
> str(cleaned_data))
> 
> 573 try:
> 
> C:\Users\Marcin\Documents\oneclickcos\oneclickcos\mainapp\incorporate_helpers.pyc
>  in clean(self)
> 402
> 403 def clean(self):
> --> 404 cleaned_data = super(CreateForm, self).clean()
> 405 # trying to use an empty pk can result in a ValueError. 
> Easier to expunge.
> 
> 406 if cleaned_data.get('pk', None) == '': del cleaned_data['pk']
> 
> C:\Users\Marcin\Documents\oneclickcos\lib\site-packages\django\forms\forms.pyc
>  in clean(self)
> 315 association with the field named '__all__'.
> 316 """
> --> 317 return self.cleaned_data
> 318
> 319 def has_changed(self):
> 
> AttributeError: 'IncorporateForm' object has no attribute 'cleaned_data'
> 
> As you can see, my code conforms to the examples at 
> https://docs.djangoproject.com/en/1.4/ref/forms/validation/#cleaning-and-validating-fields-that-depend-on-each-other.
> 
> However, the error comes from BaseForm's clean method, which expects a 
> cleaned_data property or attribute to exist. What gives? Is this a bug in 
> django?
> 
> -- 
> 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/-/_yqLTmCFK4MJ.
> 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: Bug in BaseForm?

2012-03-28 Thread Marcin Tustin
Ah, no I hadn't, which is the problem here. Thanks for your help!

On Wed, Mar 28, 2012 at 15:51, Xavier Ordoquy  wrote:

> Hi,
>
> Have you called is_valid() on the form before that ?
>
> Regards,
> Xavier Ordoquy,
> Linovia.
>
> Le 28 mars 2012 à 15:57, Marcin a écrit :
>
> Consider the following stack trace (all relevant code is shown in the
> stack trace):
>
> In [3]: f.clean()
> ---
> AttributeErrorTraceback (most recent call last)
> C:\Users\Marcin\Documents\oneclickcos\lib\site-packages\django\core\management\commands\shell.pyc
> in ()
> > 1 f.clean()
>
> C:\Users\Marcin\Documents\oneclickcos\oneclickcos\mainapp\incorporate_helpers.pyc
> in clean(self)
> 569 This checks the relations between fields, ensures
> consistent state, and exports bits about the state of the form that can be
> used in subsequent
> validations
> 570 """
> --> 571 cleaned_data = super(IncorporateForm, self).clean()
> 572 #logger.debug('IncorporationForm.cleaned_data: ' +
> str(cleaned_data))
>
> 573 try:
>
> C:\Users\Marcin\Documents\oneclickcos\oneclickcos\mainapp\incorporate_helpers.pyc
> in clean(self)
> 402
> 403 def clean(self):
> --> 404 cleaned_data = super(CreateForm, self).clean()
> 405 # trying to use an empty pk can result in a ValueError.
> Easier to expunge.
>
> 406 if cleaned_data.get('pk', None) == '': del
> cleaned_data['pk']
>
> C:\Users\Marcin\Documents\oneclickcos\lib\site-packages\django\forms\forms.pyc
> in clean(self)
> 315 association with the field named '__all__'.
> 316 """
> --> 317 return self.cleaned_data
> 318
> 319 def has_changed(self):
>
> AttributeError: 'IncorporateForm' object has no attribute 'cleaned_data'
>
> As you can see, my code conforms to the examples at
> https://docs.djangoproject.com/en/1.4/ref/forms/validation/#cleaning-and-validating-fields-that-depend-on-each-other
> .
>
> However, the error comes from BaseForm's clean method, which expects a
> cleaned_data property or attribute to exist. What gives? Is this a bug in
> django?
>
> --
> 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/-/_yqLTmCFK4MJ.
> 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.
>



-- 
Marcin Tustin
Tel: 07773 787 105

-- 
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: Need help creating model.

2012-03-28 Thread Psamathos
I would create a many-to-many relationship between Student and Class 
through a custom intermediate model called Grade. You can then add a date 
field to Grade and any other extra fields you want.

Read up on m2m relationships here: 
https://docs.djangoproject.com/en/dev/topics/db/models/#many-to-many-relationships

Basically, you want to add a field to Student like

classes = models.ManyToManyField(Class, through='Grade')

Then add a new model like this:

class Grade(models.Model):
student = models.ForeignKey(Student)
class = models.ForeignKey(Class)
grade = models.IntegerField()
date = models.DateField(auto_now_add=True)


-Psamathos


On Tuesday, 27 March 2012 21:18:12 UTC-4, Zach wrote:
>
> I have the following in my Student model. I am wanting to track the 
> date of each point given to each student. The idea would be so that I 
> could see not only how many points each student has, but also see the 
> date each point was given. In the future I want to see the trend of 
> each students' points.   How should I go about this? Should I use a 
> Foreign Key in another class. I am new to this so thanks for reading. 
>
>
> class Student(models.Model): 
>
>   CLASS_CHOICES = ( 
> (u'Yoga','Yoga'), 
> (u'Spanish', 'Spanish'), 
> (u'French', 'French'), 
> (u'Dance', 'Dance'), 
>   ) 
>
>   name = models.CharField(max_length=30) 
>   points = models.IntegerField(max_length=4) 
>   classname = models.CharField("Class Name",max_length=20, choices = 
> CLASS_CHOICES) 
>
>
On Tuesday, 27 March 2012 21:18:12 UTC-4, Zach wrote:
>
> I have the following in my Student model. I am wanting to track the 
> date of each point given to each student. The idea would be so that I 
> could see not only how many points each student has, but also see the 
> date each point was given. In the future I want to see the trend of 
> each students' points.   How should I go about this? Should I use a 
> Foreign Key in another class. I am new to this so thanks for reading. 
>
>
> class Student(models.Model): 
>
>   CLASS_CHOICES = ( 
> (u'Yoga','Yoga'), 
> (u'Spanish', 'Spanish'), 
> (u'French', 'French'), 
> (u'Dance', 'Dance'), 
>   ) 
>
>   name = models.CharField(max_length=30) 
>   points = models.IntegerField(max_length=4) 
>   classname = models.CharField("Class Name",max_length=20, choices = 
> CLASS_CHOICES) 
>
>

-- 
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/-/GJahRfAOpuoJ.
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: TestCase Client.login() fails

2012-03-28 Thread jondbaker
Thanks for all the responses. I actually solved the problem about 15 
minutes after posting this question and indicated so in the first reply. 
Perhaps that reply did not go out in time? Anyway, thanks for the help!

On Wednesday, March 28, 2012 1:28:56 AM UTC-6, rudyryk wrote:
>
> Hello, Jonathan!
>
> I think issue is in the fragment 'password=user.password' in the line:
>
> > response = self.client.login(username=user.username,
> > password=user.password)
>
> 'user.password' - is not plain text password, it's encrypted and it's
> not equal 't3stp@s$' !
>
> Alexey rudyryk
> ///
>
> On Wed, Mar 28, 2012 at 10:05 AM, jondbaker
>  wrote:
> > I'm trying to write a unit test that will verify that the login form
> > authenticates a user. Whenever I run 'manage.py test' the runner fails 
> with
> > this message:
> > AssertionError: False is not True
> >
> > tests.py
> > from django.test import TestCase
> > from django.test.client import Client
> > from django.contrib.auth.models import User
> >
> > class TestAccountLogin(TestCase):
> > def setUp(self):
> > self.client = Client()
> >
> > def test_login(self):
> > user = User.objects.create_user('test', 't...@test.com', 
> 't3stp@s$')
> > response = self.client.login(username=user.username,
> > password=user.password)
> > self.assertTrue(response)
> >
> > After creating the user, I can verify that user.is_active is in fact 
> True,
> > but unfortunately response returns False. Both
> > 'django.contrib.auth.middleware.AuthenticationMiddleware' and
> > 'django.contrib.auth' are declared in settings.py.
> >
> > Any thoughts?
> >
> > --
> > 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/-/5zI85qKS4acJ.
> > 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/-/-urgiz-8OQwJ.
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.



comparing custom template tag within if tag

2012-03-28 Thread Nikhil Verma
Hi all

i have a custom template tag that takes some argument and calculates the
result.
I want to compare that value obtained from that custom tag with another
variable.

Custom template tag
{% price_for_pax service pax '' %}

variable :

{{service.price}}

What i want is {% if service.price == price_for_pax service pax ' ' %}
   do something
 {% endif %}

When i look for the result it does not show anything
Can i compare like this ? If not what can be the solution ?

Thanks in advance



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

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



Re: Sending data to the server

2012-03-28 Thread drk
It works if you apply the filer 'escapejs'.

Thanks anyway.

On 26 Mar, 16:29, drk  wrote:
> Just to rephrase it, I'm setting the data through a variable in a django
> template, maybe that's not the best way to do it, I guess.
>
> Segunda-feira, 26 de Março de 2012 16h23min15s UTC+1, drk escreveu:
>
>
>
>
>
>
>
>
>
> > Yea, that was it.
> > Also changing the url to just '/logout'
>
> > Thanks!
>
> > I'm having other problem now, the data that is getting sent to the
> > javascript code from the server is json data, but the quote symbol " is
> > returned as "
> > and so I get an error when trying to parse it.
>
> > Segunda-feira, 26 de Março de 2012 08h16min49s UTC+1, jim escreveu:
>
> >> Do you have CSRF protection enabled?
>
> >>https://docs.djangoproject.com/en/dev/ref/contrib/csrf/
>
> >> It will 403 POST requests unless they have the right token.
>
> >> Jim
>
> >> On Sun, Mar 25, 2012 at 11:24 PM, drk  wrote:
> >> > Hi, so I have a application that works offline (with localStorage),
> >> > and now I'm trying to get it to work in a server.
>
> >> > I'm having a problem sending the data to server, I'm using jquery:
>
> >> > $.ajax({
>
> >> >    type: 'POST',
> >> >    url: 'http://mysite.aa/logout/',
> >> >    data: JSON.stringify( stuff ),
> >> >    contentType: 'text/plain; charset=utf-8',
> >> >    complete: function() { console.log('complete'); }
> >> > });
>
> >> > and I get a 403 error.
>
> >> > In chrome's console:
>
> >> > POSThttp://mysite.aa/logout/403 (FORBIDDEN)
> >> > XHR finished loading: "http://myserver.aa/logout/";
>
> >> > In server:
> >> > [25/Mar/2012 17:20:43] "POST /logout/ HTTP/1.1" 403 2282
>
> >> > Any ideas?
>
> >> > --
> >> > 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: Http404 and process_exception

2012-03-28 Thread Justin Holmes
Russell,

Thanks for the reply.

Two reasons:

1) Up until now, I hadn't encountered a 404 that had triggered this
particular process_exception.  It hadn't occurred to me that since
get_object_or_404 actually raises the Http404 exception that the behavior
was going to be different than, say, a try block whose exception clause
returned HttpResponseNotFound.

2) Once I had encountered this phenomenon, a quick google search led me to
this page from the book:

http://www.djangobook.com/en/beta/chapter16/

which seemed, at least for a moment, to verify my previous experience.

I think though that I simply hadn't raised Http404 since implementing this
middleware.  It makes perfect sense that it behaves the way it does.



On Tue, Mar 27, 2012 at 11:29 PM, Russell Keith-Magee <
russ...@keith-magee.com> wrote:

>
> On 28/03/2012, at 6:31 AM, Justin Holmes wrote:
>
> > Heretofore, I had always believed that Http404 did not cause Middleware
> process_exception() to be run.  Am I right in this thinking?
> >
> > I have a get_object_or_404 that, when the object in question isn't
> found, is running process_exception.
>
> Http404 is an exception, so yes, it should cause process_exception() to be
> run.
>
> The test suite for middleware processing might be (slightly) illuminating
> here; it's a bit long winded and gnarly, but it enumerates and validates
> the full path for every possible combination of middleware and response
> type.
>
> Look at regression_tests/middleware_exceptions;
> test_process_exception_middleware_not_found is the test for your specific
> case.
>
> Out of interest -- can you put your finger on why you heretofore thought
> Http404 didn't hit exception middleware? I've done a quick poke through the
> history of the middleware handling code, and I can't see any obvious reason
> why this would have changed (even inadvertently).
>
> 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.
>
>


-- 
Justin Holmes

Head Instructor, SlashRoot Collective
SlashRoot: Coffee House and Tech Dojo
60 Main Street
New Paltz, NY 12561
845.633.8330

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



Hosting tutorials

2012-03-28 Thread Jak
Hello All,

I am new to programming, and I have spent the year learning HTML, CSS,
Python, and now Django. I can build a basic dynamic site on the
development server, but I have no idea how to share this site with the
world. The Django deployment section in the Django book is difficult
to understand. What do I need to know before I can begin hosting my
projects. Do I need to know apache? I'm not even entirely sure how
servers work. I read the w3schools sever tutorial, but it only
describes what a server is, not how or what you need to host your
site. Does anyone know of any good tutorials for beginners?

Thanks

Programming noob

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



django.contrib.auth.views.login no response

2012-03-28 Thread jondbaker
I'm trying to build a login form by following the instructions on this page 
https://docs.djangoproject.com/en/dev/topics/auth/#django.contrib.auth.views.login.
 
The form is rendered in the template with a username and password field, 
but the hidden "next" field has no value, the form does not return error 
messages and there's no response on submit. Here is my code:

*urls.py*
urlpatterns = patterns('',
url(r'^accounts/login/$', 'django.contrib.auth.views.login', {
'template_name': 'accounts/login.html'
}
)

*templates/accounts/login.html*
{% extends 'base.html' %}
{% load url from future %}

{% block content %}

{% if form.errors %}
Your username and password didn't match. Please try again.
{% endif %}


{% csrf_token %}

{{ form.username.label_tag }}
{{ form.username }}


{{ form.password.label_tag }}
{{ form.password }}





{% endblock %}

-- 
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/-/g3sCK82eI0gJ.
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: Hosting tutorials

2012-03-28 Thread NENAD CIKIC
Hi,
i am also new to django. I have put alive my first django project on
linode VPS.
First I have created on my development machine the virtual box with
last ubuntu. Then I have put alive the django project following
instruction on
https://code.djangoproject.com/wiki/DjangoAndNginx
i.e. I have used nginx as it seemed from newgroup posting easier to
install for newbies.
After I have done it on vbox I have bought linode account and repeated
the sequence there.

All in all, in two days I have put the project alive. Probably not all
is done as it should be, but it is live.

The most time I have spent is on how to share the folder between vbox
and windows host. The not documented hint (at least i did not find
anywhere) is that the root user of ubuntu shall be part of vboxusers
group, so I have created the group with
groupadd vboxusers
and added the user to the group
sudo usermod -a -G vboxusers cikic
After that I could use the vbox additions; i.e. I could map one folder
for data exchanging.

hth
Nenad

On 28 ožu, 16:03, Jak  wrote:
> Hello All,
>
> I am new to programming, and I have spent the year learning HTML, CSS,
> Python, and now Django. I can build a basic dynamic site on the
> development server, but I have no idea how to share this site with the
> world. The Django deployment section in the Django book is difficult
> to understand. What do I need to know before I can begin hosting my
> projects. Do I need to know apache? I'm not even entirely sure how
> servers work. I read the w3schools sever tutorial, but it only
> describes what a server is, not how or what you need to host your
> site. Does anyone know of any good tutorials for beginners?
>
> Thanks
>
> Programming noob

-- 
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: Hosting tutorials

2012-03-28 Thread yati sagade
Hi
I you just want to share your apps with the world, you do not need to pay
for a complete server setup. I have been using OpenShift(
https://openshift.redhat.com/app/) for long now, and it's quite easy to get
up and running. Others are[not tried, but heard are great] Heroku(
http://www.heroku.com/), Google AppEngine(https://appengine.google.com/).
I've actually used GAE for Python, but using Django and it's ORM is a bit
tricky here, but nonetheless doable. Another one with great reviews is
CloudFoundry by VMWare (http://www.cloudfoundry.com/).

Cheers!

-- 
Yati Sagade 

Twitter: @yati_itay 

Organizing member of TEDx EasternMetropolitanBypass
http://www.ted.com/tedx/events/4933
https://www.facebook.com/pages/TEDx-EasternMetropolitanBypass/337763226244869

-- 
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 With Tweepy

2012-03-28 Thread Konstantinos Pachnis
Hi,

You could use celery (http://celeryproject.org/) and create a task (with
your code) to run periodically.

Oh, one more thing. I don't really understand why you don't use the
Django API for your queries.

Cheers,
Konstantinos

> coded kid 
> March 27, 2012 10:59
> Hi guys, I’m confused on how to make this work. I want to stream
> user’s tweets in my django app using tweepy. I’ve written the
> streaming code but the problem I’m facing is: should I paste the code
> in views.py and input- return
> render_to_response('tweet.html',context_instance=RequestContext(request))
> after writing the code. Just like this:
>
>
> Q= sys.argv[1:]
>
> db=MySQLdb.connect("localhost","","","Juzme")
>
> auth=tweepy.OAuthHandler(consumer_key, consumer_secret)
> auth.set_access_token(access_token, access_token_secret)
>
> cur=db.cursor()
>
> class CustomStreamListener(tweepy.StreamListener):
> def on_status(self, status):
> try:
> print "%s\t%s\t%s\t%s" % (status.text,
> status.author.screen_name,
> status.created_at,
> status.source,)
> cur.execute("INSERT INTO tweets VALUES (%s, %s, %s, %s)",
> (status.text,
>
> status.author.screen_name,
>
> status.created_at,
>
> status.source))
> except Exception, e:
> print >> sys.stderr, 'Encountered Exception:', e
> pass
> def on_error(self, status_code):
> print >> sys.stderr, 'Encountered error with status code:',
> status_code
> return True
> def on_timeout(self):
> print >> sys.stderr, 'Timeout...'
> return True
> streaming_api=tweepy.streaming.Stream(auth, CustomStreamListener(),
> timeout=60)
> print >> sys.stderr, 'Filtering the public timeline for "%s"' % ('
> '.join(sys.argv[1:]),)
> streaming_api.filter(follow=[], track=Q)
> return
> render_to_response('tweet.html',context_instance=RequestContext(request))
>
> If I can do it like this, won’t there be any code in template? Or
> what’s the best way I can carry out this operation. I hope you get my
> point? Thanks!
>

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

<>

IntegrityError at /register/ auth_user.username may not be NULL

2012-03-28 Thread laurence Turpin
I'm getting the following error with my registration  section of my
program.

IntegrityError at /register/
auth_user.username may not be NULL

I am using django 1.3.1 and python 2.7.2 and I'm using sqlite3 as the
database.
I am a newbie and I'm learning Djanogo from the book "Learning website
development with Django"

The registration form is displayed ok  and I'm able to fill it out and
it is when I click register that the problem occurs.

///

My views.py  looks like the following and register_page is the
relevant function here:

///

from django.http import Http404
from django.contrib.auth.models import User
from django.shortcuts import render_to_response
from django.http import HttpResponseRedirect
from django.contrib.auth import logout
from django.template import RequestContext
from bookmarks.bookmarksapp.forms import RegistrationForm


def main_page(request):
return render_to_response(
'main_page.html', RequestContext(request)
)

def user_page(request, username):
try:
user = User.objects.get(username=username)
except:
raise Http404('Requested user not found')

bookmarks = user.bookmark_set.all()
variables = RequestContext(request, {
'username': username,
'bookmarks': bookmarks
})
return render_to_response('user_page.html', variables)

def logout_page(request):
logout(request)
return HttpResponseRedirect('/')

def register_page(request):
if request.method =='POST':
form = RegistrationForm(request.POST)
if form.is_valid():
form.user = User.objects.create_user(
username = form.cleaned_data['username'],
password = form.cleaned_data['password1'],
email = form.cleaned_data['email']
)
return HttpResponseRedirect('/register/success/')
else:
form = RegistrationForm()
variables = RequestContext(request, {
   'form': form
})
return render_to_response(
   'registration/register.html',
   variables
)

///

My forms.py  is the following:

///

from django import forms
import re
from django.contrib.auth.models import User
from django.core.exceptions import ObjectDoesNotExist

class RegistrationForm(forms.Form):
username = forms.CharField(label="Username", max_length=30)
email = forms.EmailField(label='Email')
password1 = forms.CharField(
label='Password',
widget=forms.PasswordInput()
)
password2 = forms.CharField(
label='Password',
widget=forms.PasswordInput()
)

def clean_password2(self):
if 'password1' in self.cleaned_data:
password1 = self.cleaned_data['password1']
password2 = self.cleaned_data['password2']
if password1 == password2:
return password2
raise forms.ValidationError('Passwords do not match.')

def clean_username(self):
username = self.cleaned_data['username']
if not re.search(r'^\w+$', username):
raise forms.ValidationError('Username can only contain
alphanumeric characters and underscores')
try:
User.objects.get(username=username)
except ObjectDoesNotExist:
return username
raise forms.ValidationError('Username already taken. ')

///

my register.html looks like the following:

///

{% extends "base.html" %}
{% block title %}User Registration{% endblock %}
{% block head %}User Registration{% endblock %}
{% block content %}
{% csrf_token %}
{{ form.as_p }}


{% endblock %}

///

I hope somebody has an idea of what the problem is all I know is it's
something to do with the database.

The exception location is:
C:\Python27\lib\site-packages\django\db\b

Re: IntegrityError at /register/ auth_user.username may not be NULL

2012-03-28 Thread Daniel Roseman
On Wednesday, 28 March 2012 20:31:09 UTC+1, laurence Turpin wrote:
>
> I'm getting the following error with my registration  section of my 
> program. 
>
> IntegrityError at /register/ 
> auth_user.username may not be NULL 
>
> I am using django 1.3.1 and python 2.7.2 and I'm using sqlite3 as the 
> database. 
> I am a newbie and I'm learning Djanogo from the book "Learning website 
> development with Django" 
>
> The registration form is displayed ok  and I'm able to fill it out and 
> it is when I click register that the problem occurs. 
>
> ///
>  
>
>
> My views.py  looks like the following and register_page is the 
> relevant function here: 
>
> 
>
 

> def clean_username(self): 
> username = self.cleaned_data['username'] 
> if not re.search(r'^\w+$', username): 
> raise forms.ValidationError('Username can only contain 
> alphanumeric characters and underscores') 
> try: 
> User.objects.get(username=username) 
> except ObjectDoesNotExist: 
> return username 
> raise forms.ValidationError('Username already taken. ') 
>
 
Looks like you have an indentation problem in clean_username - the lines 
under the first "raise forms.ValidationError" should be one level to the 
left, otherwise they will never be reached and the method will never return 
the cleaned value for username.
--
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/-/sXr3JbbnrqcJ.
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: IntegrityError at /register/ auth_user.username may not be NULL

2012-03-28 Thread laurence Turpin


On Mar 28, 9:38 pm, Daniel Roseman  wrote:
> On Wednesday, 28 March 2012 20:31:09 UTC+1, laurence Turpin wrote:
>
> > I'm getting the following error with my registration  section of my
> > program.
>
> > IntegrityError at /register/
> > auth_user.username may not be NULL
>
> > I am using django 1.3.1 and python 2.7.2 and I'm using sqlite3 as the
> > database.
> > I am a newbie and I'm learning Djanogo from the book "Learning website
> > development with Django"
>
> > The registration form is displayed ok  and I'm able to fill it out and
> > it is when I click register that the problem occurs.
>
> > /// 
> > /// 
> > /
>
> > My views.py  looks like the following and register_page is the
> > relevant function here:
>
> > 
>
> >     def clean_username(self):
> >         username = self.cleaned_data['username']
> >         if not re.search(r'^\w+$', username):
> >             raise forms.ValidationError('Username can only contain
> > alphanumeric characters and underscores')
> >             try:
> >                 User.objects.get(username=username)
> >             except ObjectDoesNotExist:
> >                 return username
> >             raise forms.ValidationError('Username already taken. ')
>
> Looks like you have an indentation problem in clean_username - the lines
> under the first "raise forms.ValidationError" should be one level to the
> left, otherwise they will never be reached and the method will never return
> the cleaned value for username.
> --
> DR.

Thank you Danial you are absolutely right. I tried what you said and
it works fine now.

-- 
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 With Tweepy

2012-03-28 Thread Python_Junkie
Interesting question.

I would have to think about your larger question, but the smaller issue, is 
that you need to close the crsr and you need to commit, 

I would think that you would not want to make commit automatic, so that 
your code has a chance to do some error checking and perhaps roll back.



On Tuesday, March 27, 2012 3:59:28 AM UTC-4, coded kid wrote:
>
> Hi guys, I’m confused on how to make this work. I want to stream 
> user’s tweets in my django app using tweepy. I’ve written the 
> streaming code but the problem I’m facing is: should I paste the code 
> in views.py and input- return 
> render_to_response('tweet.html',context_instance=RequestContext(request)) 
> after writing the code. Just like this: 
>
>
> Q= sys.argv[1:] 
>
> db=MySQLdb.connect("localhost","","","Juzme") 
>
> auth=tweepy.OAuthHandler(consumer_key, consumer_secret) 
> auth.set_access_token(access_token, access_token_secret) 
>
> cur=db.cursor() 
>
> class CustomStreamListener(tweepy.StreamListener): 
> def on_status(self, status): 
> try: 
> print "%s\t%s\t%s\t%s" % (status.text, 
>   status.author.screen_name, 
>   status.created_at, 
>   status.source,) 
> cur.execute("INSERT INTO tweets VALUES (%s, %s, %s, %s)", 
> (status.text, 
>   
> status.author.screen_name, 
>   
> status.created_at, 
>   
> status.source)) 
> except Exception, e: 
> print >> sys.stderr, 'Encountered Exception:', e 
> pass 
> def on_error(self, status_code): 
> print >> sys.stderr, 'Encountered error with status code:', 
> status_code 
> return True 
> def on_timeout(self): 
> print >> sys.stderr, 'Timeout...' 
> return True 
> streaming_api=tweepy.streaming.Stream(auth, CustomStreamListener(), 
> timeout=60) 
> print >> sys.stderr, 'Filtering the public timeline for "%s"' % (' 
> '.join(sys.argv[1:]),) 
> streaming_api.filter(follow=[], track=Q) 
> return 
> render_to_response('tweet.html',context_instance=RequestContext(request)) 
>
> If I can do it like this, won’t there be any code in template? Or 
> what’s the best way I can carry out this operation. I hope you get my 
> point? 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/-/ayxpyVfTYB4J.
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.



Tweepy Not Displaying

2012-03-28 Thread coded kid
Hi guys, I want to display user’s timeline in my django app but it’s
not working. It only display a white blank page! I’m using Tweepy.
Below are my codes:

Views.py

import tweepy

def tweetstream(request):
consumer_key=""
consumer_secret="XXX"
access_token="XXX"
access_token_secret=""
auth=tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api=tweepy.API(auth)
status=api.user_timeline()
for status in status:
if status:
status.__getstate__()
return render_to_response('tweet.html',
context_instance=RequestContext(request))

Template:
{% extends "base.html" %}

 {% block content %}

 {% for status in status %}
   {% if status %}
{{ status.author.screen_name}} {{status.text}}
{{status.source}}

{% endif %}
 {% endfor %}


{% endblock %}

What I’m I missing? How can I make it return user’s timeline?

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



strange problem deleting objects

2012-03-28 Thread Marc Aymerich
Hi!,
I've overrided the save() method of one of my ModelForms and I'm
performing a delete of some related objects depending on some form
fields values. The thing is I'm getting differents behaviours
dependening on how the deletion is performed, consider:

1) self.instance.delete()
2) MyModel.objects.get(pk=self.instance.pk).delete()

I'm listening the post_delete of self.instance class, in there I
create a "dependency graph" of their related objects. The problem is
that at some point I'm retriveing self.instance like:
MyRelatedModel.self_instance_related_name and with the first (1)
delete method I can still access to self.instance but with the second
(2) delete method i'm getting a DoesNotExist.

Why it's different?

Thanks!
-- 
Marc

-- 
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 With Tweepy

2012-03-28 Thread coded kid
Thanks guys!  @Pachnis How do you mean by Django API queries? 

On Tuesday, 27 March 2012 08:59:28 UTC+1, coded kid wrote:
>
> Hi guys, I’m confused on how to make this work. I want to stream 
> user’s tweets in my django app using tweepy. I’ve written the 
> streaming code but the problem I’m facing is: should I paste the code 
> in views.py and input- return 
> render_to_response('tweet.html',context_instance=RequestContext(request)) 
> after writing the code. Just like this: 
>
>
> Q= sys.argv[1:] 
>
> db=MySQLdb.connect("localhost","","","Juzme") 
>
> auth=tweepy.OAuthHandler(consumer_key, consumer_secret) 
> auth.set_access_token(access_token, access_token_secret) 
>
> cur=db.cursor() 
>
> class CustomStreamListener(tweepy.StreamListener): 
> def on_status(self, status): 
> try: 
> print "%s\t%s\t%s\t%s" % (status.text, 
>   status.author.screen_name, 
>   status.created_at, 
>   status.source,) 
> cur.execute("INSERT INTO tweets VALUES (%s, %s, %s, %s)", 
> (status.text, 
>   
> status.author.screen_name, 
>   
> status.created_at, 
>   
> status.source)) 
> except Exception, e: 
> print >> sys.stderr, 'Encountered Exception:', e 
> pass 
> def on_error(self, status_code): 
> print >> sys.stderr, 'Encountered error with status code:', 
> status_code 
> return True 
> def on_timeout(self): 
> print >> sys.stderr, 'Timeout...' 
> return True 
> streaming_api=tweepy.streaming.Stream(auth, CustomStreamListener(), 
> timeout=60) 
> print >> sys.stderr, 'Filtering the public timeline for "%s"' % (' 
> '.join(sys.argv[1:]),) 
> streaming_api.filter(follow=[], track=Q) 
> return 
> render_to_response('tweet.html',context_instance=RequestContext(request)) 
>
> If I can do it like this, won’t there be any code in template? Or 
> what’s the best way I can carry out this operation. I hope you get my 
> point? 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/-/eTmXh1EiYNwJ.
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: Http404 and process_exception

2012-03-28 Thread Russell Keith-Magee

On 29/03/2012, at 12:10 AM, Justin Holmes wrote:

> Russell,
> 
> Thanks for the reply.
> 
> Two reasons:  
> 
> 1) Up until now, I hadn't encountered a 404 that had triggered this 
> particular process_exception.  It hadn't occurred to me that since 
> get_object_or_404 actually raises the Http404 exception that the behavior was 
> going to be different than, say, a try block whose exception clause returned 
> HttpResponseNotFound.
> 
> 2) Once I had encountered this phenomenon, a quick google search led me to 
> this page from the book:
> 
> http://www.djangobook.com/en/beta/chapter16/
> 
> which seemed, at least for a moment, to verify my previous experience.

Yes - that does seem to suggest 404's don't trigger exception middleware. 
However, I've checked the code back to the magic-removal merge (in 2005) [1], 
and I can't see any evidence that 404's have ever been a special case. 

[1] 
https://code.djangoproject.com/browser/django/trunk/django/core/handlers/base.py?rev=2809#L73

The only change to this area that I can see is to make sure that the response 
raised by the exception middleware is in recent times has been a modification 
that means that if the exception middleware returns a response, that response 
goes through the response middleware; back in the days of magic-removal, it 
would be returned verbatim.

> I think though that I simply hadn't raised Http404 since implementing this 
> middleware.  It makes perfect sense that it behaves the way it does.

Yes and no; yes, in that it's an exception; no, in that it's an interesting 
inconsistency that 404s are (or can be) handled as exceptions, but no other 
status code is handled as an exception.

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.



Auth app in separate database

2012-03-28 Thread Chris
Has anyone been successful in putting the auth application in a
separate database so that users can be shared with different django
projects?

When I try to put the auth application in a different database I get
an error with syncdb:

django.db.utils.DatabaseError: relation "auth_permission" does not
exist
LINE 1: ...ntent_type_id", "auth_permission"."codename" FROM
"auth_perm...

-- 
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: Tweepy Not Displaying

2012-03-28 Thread creecode
Hello coded kid,

On Wednesday, March 28, 2012 3:56:12 PM UTC-7, coded kid wrote:
 
>
> Template: 
>
 

>  {% for status in status %}
>

That bit looks like it might cause trouble.  You are assigning status to 
status.  Normally you'd want something like...

{% for status in statuses %}

or

{% for status in status_list %}

or

{% item in status %}

Use whatever variable names you want as long as you're not clobbering 
variables that are needed while looping.

Toodle-loo
creecode

-- 
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/-/3Kf6U0WIrMUJ.
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.



Cant get spatialite and pysqlite working

2012-03-28 Thread Jak
We have a Django aplication which depends on Spatialite and Pysqlite.
It works well for testing under Ubuntu, but when we try to install it
on the server, we are getting the following error after installing
PySqlite. We did set it up with define=OMIT_SQLITE_LOAD_EXTENSION
commented out:
django.core.exceptions.ImproperlyConfigured: The pysqlite library does
not support C extension loading. Both SQLite and pysqlite must be
configured to allow the loading of extensions to use SpatiaLite.

What could be causing this?

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



Re: Django With Tweepy

2012-03-28 Thread Python_Junkie
I believe he means using the Object Relational Model  ORM, which is an API 
abstraction for several frameworks.

Whether you use sql or the ORM (you can learn more about the ORM on the 
django project tutorial) only clouds the issue that you are trying to answer

SQL is SQL whether you make an abstraction layer or not

On Wednesday, March 28, 2012 7:07:22 PM UTC-4, coded kid wrote:
>
> Thanks guys!  @Pachnis How do you mean by Django API queries? 
>
> On Tuesday, 27 March 2012 08:59:28 UTC+1, coded kid wrote:
>>
>> Hi guys, I’m confused on how to make this work. I want to stream 
>> user’s tweets in my django app using tweepy. I’ve written the 
>> streaming code but the problem I’m facing is: should I paste the code 
>> in views.py and input- return 
>> render_to_response('tweet.html',context_instance=RequestContext(request)) 
>> after writing the code. Just like this: 
>>
>>
>> Q= sys.argv[1:] 
>>
>> db=MySQLdb.connect("localhost","","","Juzme") 
>>
>> auth=tweepy.OAuthHandler(consumer_key, consumer_secret) 
>> auth.set_access_token(access_token, access_token_secret) 
>>
>> cur=db.cursor() 
>>
>> class CustomStreamListener(tweepy.StreamListener): 
>> def on_status(self, status): 
>> try: 
>> print "%s\t%s\t%s\t%s" % (status.text, 
>>   status.author.screen_name, 
>>   status.created_at, 
>>   status.source,) 
>> cur.execute("INSERT INTO tweets VALUES (%s, %s, %s, %s)", 
>> (status.text, 
>>   
>> status.author.screen_name, 
>>   
>> status.created_at, 
>>   
>> status.source)) 
>> except Exception, e: 
>> print >> sys.stderr, 'Encountered Exception:', e 
>> pass 
>> def on_error(self, status_code): 
>> print >> sys.stderr, 'Encountered error with status code:', 
>> status_code 
>> return True 
>> def on_timeout(self): 
>> print >> sys.stderr, 'Timeout...' 
>> return True 
>> streaming_api=tweepy.streaming.Stream(auth, CustomStreamListener(), 
>> timeout=60) 
>> print >> sys.stderr, 'Filtering the public timeline for "%s"' % (' 
>> '.join(sys.argv[1:]),) 
>> streaming_api.filter(follow=[], track=Q) 
>> return 
>> render_to_response('tweet.html',context_instance=RequestContext(request)) 
>>
>> If I can do it like this, won’t there be any code in template? Or 
>> what’s the best way I can carry out this operation. I hope you get my 
>> point? 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/-/M4lYq8eObEQJ.
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.



svm python

2012-03-28 Thread dummyman dummyman
Hi,

I am looking for svm classifier implementation in python. My input is a set
of feature vectors of the form
[Feature1,Feature2,[Feature3],Feature4] =>This is for a user

so the input is basically a multidimensional list in python

I have a set of users . So we have of multidimensional lists.
Output should be confusion matrix or a statistical analysis

Which is the best implementation of svm python module which suits these
needs ?

-- 
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: Auth app in separate database

2012-03-28 Thread Amit
While running syncdb command django uses default database to create
tables.
You can do one thing, first create default database using syncdb then
copy auth related tables to another database.
Then define router for auth. You can get more ref form django
documentatiion.

Regards,
Amit

On Mar 29, 4:08 am, Chris  wrote:
> Has anyone been successful in putting the auth application in a
> separate database so that users can be shared with different django
> projects?
>
> When I try to put the auth application in a different database I get
> an error with syncdb:
>
> django.db.utils.DatabaseError: relation "auth_permission" does not
> exist
> LINE 1: ...ntent_type_id", "auth_permission"."codename" FROM
> "auth_perm...

-- 
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 Foreign Key without admin interface

2012-03-28 Thread Sandeep kaur
On Fri, Mar 9, 2012 at 4:31 AM, Ramiro Morales  wrote:
> On Thu, Mar 8, 2012 at 4:44 PM, Sandeep kaur  wrote:
>>                        job_no_id = client.job_no
>>                        ...
>> Am I wrong somewhere?  How should I do this?  Please help!!
>
> Yes, that client variable appears magically. Please paste working code,
> an abridged version but working code.
>
Sorry for very late reply. See my code at :

https://github.com/sandeepmadaan/TCC11_12_1/tree/master/TCC


-- 
Sandeep Kaur
E-Mail: mkaurkha...@gmail.com
Blog: sandymadaan.wordpress.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.