Re: [django-users] Error when registering a new user - Django 1.5

2013-03-23 Thread Russell Keith-Magee
Variations on this problem report have been made a couple of times

UserCreateForm is a ModelForm. That means the line in your Meta clause for
model=get_user_model() is invoked at the time the module is loaded.
However, there's no guarantee at the time that module is loaded that the
user model has been defined yet -- so you can end up with errors.

There are two options here.

Option 1: We try to define a truly dynamic UserCreateForm that can adapt to
the changing requirements of a User model (and remember, this means
adapting to the REQUIRED_FIELDS as well). This code would be complex and
potentially fragile, since it needs to work with *any* User model, with
*any* collection of required fields.

Option 2: We provide a UserCreateForm that works with the default User
model, and with any AbstractUser descendent that isn't too significantly
modified, and we leave the UserCreateForm for any other User model an an
activity for the developer.

We've chosen Option 2, and documented as such:

https://docs.djangoproject.com/en/1.5/topics/auth/customizing/#custom-users-and-the-built-in-auth-forms

Yours,
Russ Magee %-)

On Sat, Mar 23, 2013 at 12:00 PM, Leonardo S wrote:

> I did it and aparently it worked:
>
> *# forms.py*
> *class UserCreateForm(UserCreationForm):*
> *
> *
> *
> def clean_username(self):
> username = self.cleaned_data["username"]
> try:
> self._meta.model._default_manager.get(username=username)
> except self._meta.model.DoesNotExist:
> return username
> raise
> forms.ValidationError(self.error_messages['duplicate_username'])
> *
> *
> *
> *class Meta:*
> *model = get_user_model()*
> *fields = ('email', 'password1', 'password2', 'first_name',
> 'last_name', 'bio', 'username')*
> *
> *
> From:
> https://groups.google.com/forum/?fromgroups=#!topic/django-users/kOVEy9zYn5c
> Should not it be the UserCreationForm standard?
>
>
> 2013/3/23 Leonardo S 
>
>> Hi,
>>
>> I am getting an error when registering a new user in a Django 1.5 app.
>> It is the postgres' log:
>>
>> *BRT ERROR:  relation "auth_user" does not exist at character 280*
>> *BRT COMMAND:  SELECT "auth_user"."id", "auth_user"."password",
>> "auth_user"."last_login", "auth_user"."is_superuser",
>> "auth_user"."username", "auth_user"."first_name", "auth_user"."last_name",
>> "auth_user"."email", "auth_user"."is_staff", "auth_user"."is_active",
>> "auth_user"."date_joined" FROM "auth_user" WHERE "auth_user"."username" =
>> E'teste'*
>> *
>> *
>> My code is very simple:
>> *
>> *
>> *# models.py*
>> *class User(AbstractUser):*
>> *bio = models.CharField(max_length=255, blank=True, null=True)*
>> *objects = UserManager()*
>>
>> *# forms.py*
>> *class UserCreateForm(UserCreationForm):*
>> *class Meta:*
>> *model = get_user_model()*
>> *fields = ('email', 'password1', 'password2', 'first_name',
>> 'last_name', 'bio', 'username')*
>>
>> *# views.py*
>> *class UserCreateView(CreateView):*
>> *form_class = UserCreateForm*
>> *model = get_user_model()*
>> *
>> *
>> I think that UserCreationForm yet search for auth_user table.
>> A possible solution would be this:
>>
>> *# models.py*
>> *class User(AbstractUser):*
>> *bio = models.CharField(max_length=255, blank=True, null=True)*
>> *objects = UserManager()*
>> *class Meta:*
>> * db_table = u'auth_user'*
>>
>> But i would like to use a correct Django 1.5 approach to register a new
>> user.
>> Can anyone spot the problem?
>>
>> Regards,
>>   Leonardo
>>
>
>  --
> 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?hl=en.
> 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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: TDD with Django/Splinter/plupload queue

2013-03-23 Thread Daniel França
Hi guys,
Thanks for the answers.
I'm gonna have a look in this phantomjs, I think it does what I need.

Best,
Daniel França

On Wed, Mar 20, 2013 at 4:39 PM, Elliot Bradbury wrote:

> PhantomJS is a headless webkit browser that can be programmed to perform
> automated webpage tasks (like maybe select a file for upload). The standard
> API is Javscript but I believe there is a Python port. Maybe that could
> help?
>
> http://phantomjs.org/
>
>
> On Wed, Mar 20, 2013 at 3:34 PM, Bill Freeman  wrote:
>
>> You can always write a stand alone python tool that pretends that it is a
>> browser, does the GET, confirms that the form looks right, gathers the
>> cookies or other CSRF token souces, and does the POST, including attaching
>> the uploaded data parts.  But since this requires dipping into HTTP and
>> HTML further than most people go, it has the potential to be more
>> complicated than what you are testing.  Perhaps someone has already done
>> this and will comment.
>>
>> Of course this doesn't test any browser JavaScript that you are using.
>>
>> Another approach, probably even more complex, is to add to your favorite
>> browser(s) the ability to script the filling of upload fields.
>>
>> There are engines that allow you to script clicking and typing on a
>> desktop, but I have no experience with them, and that sounds fragile to me,
>> since, for example, FireFox auto updates and where things are changes.
>>
>> Bill
>>
>>
>> On Wed, Mar 20, 2013 at 2:19 PM, Daniel França 
>> wrote:
>>
>>> Hi all,
>>> I'm trying to set up tests for a upload using the plupload queue widget:
>>> http://www.plupload.com/
>>> I'm using Splinter for in-browser test, but I couldn't find a way to
>>> make it happen. Splinter has some methods to attach files, but only if it's
>>> a simple file field.
>>> Another way would be click the button to browse the files, and choose
>>> the file... but I don't think it's possible using Splinter (or selenium),
>>> is it?
>>> Or with drag-n-drop of the files.
>>>
>>> Anyone has any suggestion of the best way to automatize theses tests?
>>>
>>> --
>>> Daniel França,
>>> about.me/danielfranca
>>>
>>> --
>>> 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?hl=en.
>>> 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?hl=en.
>> 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?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>



-- 
Daniel França,
about.me/danielfranca

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Python problem

2013-03-23 Thread Mario Gudelj
Looks like you are trying to run terminal commands inside python shell.
Don't go to pyhon shell to run them.
Run them in DOS
On 24 Mar, 2013 9:38 AM, "James"  wrote:

> haha sorry for got to post,
>
> windows 7 running on activepython 2.7.2.5
> (path is under python27)
>
> Microsoft Windows [Version 6.1.7601]
> Copyright (c) 2009 Microsoft Corporation.  All rights reserved.
>
> C:\Users\James>python
> ActivePython 2.7.2.5 (ActiveState Software Inc.) based on
> Python 2.7.2 (default, Jun 24 2011, 12:21:10) [MSC v.1500 32 bit (Intel)]
> on win
> 32
> Type "help", "copyright", "credits" or "license" for more information.
> >>> C:\Users\James\Desktop\test.py runserver
>   File "", line 1
> C:\Users\James\Desktop\test.py runserver
>  ^
> SyntaxError: invalid syntax
> >>> C:\Users\James\Desktop\test.py
>   File "", line 1
> C:\Users\James\Desktop\test.py
>  ^
> SyntaxError: invalid syntax
> >>>
>
> but the test.py file or any other py file is there and the path is correct
> but python fails to recognise it as valid
>
> cheers
>
> On Friday, March 22, 2013 2:32:52 PM UTC+13, James wrote:
>>
>> Hey there,
>>
>> Did first Django app and everything worked find, however my computer
>> crashed and after restoring it each time I try to execute any .py file in
>> command prompt it says syntax error or that the module doesnt exist...
>>
>> Would you know any reasons for this? Python is still installed and
>> everything that was there before the crash is still there.
>>
>> 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?hl=en.
> 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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Python problem

2013-03-23 Thread James
haha sorry for got to post,

windows 7 running on activepython 2.7.2.5 
(path is under python27)

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\James>python
ActivePython 2.7.2.5 (ActiveState Software Inc.) based on
Python 2.7.2 (default, Jun 24 2011, 12:21:10) [MSC v.1500 32 bit (Intel)] 
on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> C:\Users\James\Desktop\test.py runserver
  File "", line 1
C:\Users\James\Desktop\test.py runserver
 ^
SyntaxError: invalid syntax
>>> C:\Users\James\Desktop\test.py
  File "", line 1
C:\Users\James\Desktop\test.py
 ^
SyntaxError: invalid syntax
>>>

but the test.py file or any other py file is there and the path is correct 
but python fails to recognise it as valid 

cheers

On Friday, March 22, 2013 2:32:52 PM UTC+13, James wrote:
>
> Hey there,
>
> Did first Django app and everything worked find, however my computer 
> crashed and after restoring it each time I try to execute any .py file in 
> command prompt it says syntax error or that the module doesnt exist...
>
> Would you know any reasons for this? Python is still installed and 
> everything that was there before the crash is still there.
>
> 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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Python inside Django

2013-03-23 Thread Shawn Milochik
You can completely eliminate Django from your thinking about the
problem. This is a pure Python question.

A Python file being within a Django project changes nothing about how
Python imports code. Either you're importing something on your Python
path or you're doing a relative import. If your import is failing,
then just import it using its full location on the PYTHONPATH.

The only other consideration is if your code isn't anywhere on your
PYTHONPATH, in which case all you need to do is add it. You can add it
to sys.path in your code, but my preference is to use virtualenv for
every project and put my project path in my PYTHONPATH that way.

You can easily do it from the command line manually first just to make
sure it works. Something like:

export PYTHONPATH=$PYTHONPATH:/path/to/my/code

Then run your code and make sure it works. When you have it working,
do something more permanent. I recommend the virtualenv method.

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Create Django web apps with drag and drop interface builder

2013-03-23 Thread timothy crosley
Thanks for the checking the project out and for the advice! I am hoping to 
add more and more documentation over the next few weeks, in addition to 
possibly some screen casts. I will look into how to best support bootstrap 
(and foundation) within the framework, as your right a lot of people are 
using these now.

Thanks again,

Timothy

On Saturday, March 23, 2013 4:17:54 PM UTC-4, אברהם סרור wrote:
>
> This looks nice but the documentation is lacking yet I hope your projects 
> success (also the desktop GUI builder)
>
> If I may make a suggestion, keep in mind that today people use bootstrap 
> (and foundation ), the framework could 
> support that. and also it could make it easy to use jquery
>
>
> On Sat, Mar 23, 2013 at 9:51 PM, timothy crosley 
>  > wrote:
>
>> Hi, 
>>
>> For the last few years I have been working on a WebApplication framework 
>> designed to let you build complex web apps using a drag and drop interface 
>> builder
>> and pure python code. I have just now released it to the public and would 
>> really like feedback and opinions. You can see it here:
>>
>> www.webbot.ws
>>
>>
>> These applications can then run on top of Django or AppEngine.
>> I hope other Django users find it useful!
>>
>> Thanks,
>>
>> Timothy
>>  
>> -- 
>> 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...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com
>> .
>> Visit this group at http://groups.google.com/group/django-users?hl=en.
>> 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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Create Django web apps with drag and drop interface builder

2013-03-23 Thread Avraham Serour
This looks nice but the documentation is lacking yet I hope your projects
success (also the desktop GUI builder)

If I may make a suggestion, keep in mind that today people use bootstrap
(and foundation ), the framework could support
that. and also it could make it easy to use jquery


On Sat, Mar 23, 2013 at 9:51 PM, timothy crosley
wrote:

> Hi,
>
> For the last few years I have been working on a WebApplication framework
> designed to let you build complex web apps using a drag and drop interface
> builder
> and pure python code. I have just now released it to the public and would
> really like feedback and opinions. You can see it here:
>
> www.webbot.ws
>
>
> These applications can then run on top of Django or AppEngine.
> I hope other Django users find it useful!
>
> Thanks,
>
> Timothy
>
> --
> 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?hl=en.
> 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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Create Django web apps with drag and drop interface builder

2013-03-23 Thread timothy crosley
Hi, 

For the last few years I have been working on a WebApplication framework 
designed to let you build complex web apps using a drag and drop interface 
builder
and pure python code. I have just now released it to the public and would 
really like feedback and opinions. You can see it here:

www.webbot.ws


These applications can then run on top of Django or AppEngine.
I hope other Django users find it useful!

Thanks,

Timothy

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: PostgresSQL or MySql with django?

2013-03-23 Thread frocco
I Just downloaded a product called RazorSQL
http://www.razorsql.com

This product has conversion from MySql to Postgresql.

Works great.

On Monday, March 18, 2013 11:30:35 AM UTC-4, frocco wrote:
>
> Hello,
>
> What is the recommended database for django?
>
> I have used MySQL, but am interested in Postgres.
>
> 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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Python inside Django

2013-03-23 Thread Felix Wagner
Hello,

currently I am writing an application that will run a daemon. However I am 
stuck:

What I have so far:

created a project called "ihe", with an app called "devices". Inside 
devices there is "admin.py", "forms.py", "__init__.py", "models.py", 
"urls.py", "views.py".
There are also several directories: "configuration" contains "config.py", 
"__init__.py" and "logging.conf", the "daemons" directory contains the 
daemons that I want
to execute. A standard "managment" directory containing the management 
calls. And lastly a "utilities" direcotry containing "hwcontrol.py" and 
"utils.py".

My issue is that if I want to for instance import hwutils which is pure 
python inside a daemon or a "from devices.models import *" inside a daemon 
or any other file it always complains about an import error:

"Traceback (most recent call last):
  File "database.py", line 14, in 
from devices.models import *
ImportError: No module named devices.models"

"Traceback (most recent call last):
  File "database.py", line 14, in 
from devices.utilities import hwcontrol
"ImportError: No module named devices.utilities"


If I understand correctly this is because of the python path. For instance 
the pythonpath for a daemon:

['/~/software/ihe/devices/daemons', '/usr/lib/portage/pym', 
'/usr/lib64/python27.zip', '/usr/lib64/python2.7', 
'/usr/lib64/python2.7/plat-linux2', '/usr/lib64/python2.7/lib-tk', 
'/usr/lib64/python2.7/lib-old', '/usr/lib64/python2.7/lib-dynload', 
'/usr/lib64/python2.7/site-packages', 
'/usr/lib64/python2.7/site-packages/Orange/orng', 
'/usr/lib64/python2.7/site-packages/PIL', 
'/usr/lib64/python2.7/site-packages/gst-0.10', 
'/usr/lib64/python2.7/site-packages/gtk-2.0', 
'/usr/lib64/python2.7/site-packages/wx-2.8-gtk2-unicode', 
'/usr/lib64/portage/pym']

However I thought that if I put the files inside the django project that 
the imports would then work. What do I have to do to get it working?

Thank you for any help.

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: DB Weirdness

2013-03-23 Thread Tim Cook
Just to complete this issue.
I knew it was a silly mistake.
I had reconfigured my settings.py according to  recommendations from TSD.
BUT! I did not delete the original settings.py file.  So all the
changes I Was making had no effect. Django was using my new
settings/dev.py

--Tim

On Fri, Mar 22, 2013 at 11:07 AM, Tim Cook  wrote:
> Thanks for the reply, Russell.
> Responses inline:
>
> On Fri, Mar 22, 2013 at 10:10 AM, Russell Keith-Magee
>  wrote:
>
>> However, I'm guessing that this *isn't* the name of the database that you've
>> got Django configured to use. If you're following the tutorial (and
>> following the same lessons for your project), you will have invoked "CREATE
>> DATABASE database_name" at some point -- creating a new database, and *that*
>> is the database Django is using.
>>
>
> Certainly.  The tutorial DB is 'polls' and my project DB is 'ccdgen'.
> They both appear on the same server in PGAdminIII  ccdgen.  They also
> both appear on the server (I guess) I setup when I first tried out
> Postgres, named 'mydb'.
>
>> So - I'm guessing the solution here is to point PGAdminIII at the database
>> you created, instead of the default database. Unfortunately, I haven't used
>> PGAdminIII, so I can't give you any practical tips on that front.
>
> I can also see the default postgres DB as well on each of the two servers.
>
> I don't have any valuable data anywhere in the DBs.  Maybe I should
> delete all of my DBs and start over?
>
> Thanks,
> Tim
>
>
>
> --
> 
> 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



-- 

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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: SQL Server Support - Does it Exist

2013-03-23 Thread Liang
Sadly, django doesn't support sql server officially is the only stopper for 
me to adopt django. 

On Friday, 15 July 2011 09:07:23 UTC+8, Russell Keith-Magee wrote:
>
> On Fri, Jul 15, 2011 at 6:03 AM, bruno desthuilliers
>  wrote:
> >
> >
> > On 14 juil, 23:15, Python_Junkie 
> > wrote:
> >> I have searched for the drivers to use the syncdb utility with MS SQL
> >> Server but have been unsuccessful.
> >
> > https://docs.djangoproject.com/en/1.3/ref/databases/
> >
> > Django doesn't support MS SQL.
>
> Django doesn't provide *official* support MSSQL. However, we do have a
> supported backend API, and there are several third-party projects that
> implement MS SQL support [1]. I can't comment on their completeness or
> stability, but the projects exist.
>
> [1] 
> https://docs.djangoproject.com/en/1.3/ref/databases/#using-a-3rd-party-database-backend
>
> Yours,
> Russ Magee %-)
>
>

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Applying admin site foreign key filters when adding new object

2013-03-23 Thread Branko Majic
Hello,

I'm interested what's the proper/best way to restrict foreign keys when
adding a new object through the admin interface.

For example, let's say I have models like this:

class Project(models.Model):
name = models.CharField(max_length = 100)

class Entity(models.Model):
name = models.CharField(max_length = 100)

class Connection(models.Model):
name = models.CharField(max_length = 100)
first = models.ForeignKey(Entity, related_name = "first_set")
second = models.ForeignKey(Entity, related_name = "second_set")

And let's say I have an admin class like this:

class ConnectionAdmin(admin.ModelAdmin):
list_display = ('name', 'first', 'second')
list_filter = ['first__entity__project']

What I need to be able to do is when I select a particular project in
the admin interface, and proceed to then add a new object, get the
filter applied to my foreign key fields.

Right now, what I'm doing is overriding the formfield_for_foreignkey in
the above ConnectionAdmin class to get this behaviour, but the tricky
part was actually getting this project filter information available to
my overridden method. The way I did it was by overriding the
chante_list.html admin template. Inside of it I've done this:

{% extends "admin/change_list.html" %}
{% load i18n admin_static admin_list %}
{% load url from future %}
{% load admin_urls %}

{% block object-tools-items %}

  {# Add the GET parameters from the admin's filter to 'Add entity' 
button #}
  {# so we can perform some filtering on first/second. #}
  
{% blocktrans with cl.opts.verbose_name as name %}Add {{ name 
}}{% endblocktrans %}
  

{% endblock %}

I.e. I'm overriding the link for adding the new object to include get
parameters that are the same as the ones used for filtering in list
view.

So, is this the right way (or did I fail to find the information in the
documentation on this)?

Best regards

P.S.
The actual application code I'm working on can be found at (the above
example is a bit simplified to what I have):

http://hg.majic.rs/conntrackt/

-- 
Branko Majic
Jabber: bra...@majic.rs
Please use only Free formats when sending attachments to me.

Бранко Мајић
Џабер: bra...@majic.rs
Молим вас да додатке шаљете искључиво у слободним форматима.


signature.asc
Description: PGP signature


Re: POSTing JSON to Tastypie from Android

2013-03-23 Thread Pratik Mandrekar
Thanks for the pdb tip Bill!

I tried pdb at the point where the request enters Tastypie (based on 
http://stackoverflow.com/questions/13006901/tastypie-obj-create-method-not-being-called).
 
What I see is that the request.POST and request.raw_post_data are both 
empty. I posted from Android client to a posttestserver and I can see that 
all the headers I set and the request body are set.

However it does say that there are no POST parameters. Here is the logged 
request - http://posttestserver.com/data/2013/03/23/06.42.591241431084. Any 
idea what that means? Note that I had to remove the authorization header to 
post to this server.

Also I'm not sure now where else to start the trace from. Is there another 
place I can pdb trace my HTTP request when it enters the app? Is it 
possible some data gets stripped off the original request somewhere?

Thanks.

Pratik






On Saturday, March 23, 2013 5:50:28 PM UTC+5:30, ke1g wrote:
>
> Still, if you have a break point where the request comes in to the view, 
> you can inspect the POST data to see how it differs from what you expect.  
> That might inform you as to what you might do differently in your 
> JavaScript, whether you need some additional or different encoding or 
> quoting of the data, whether you need to be more explicit about the 
> content-type header (you may have to look at the WSGI request object 
> itself), etc.  Or you may discover that you need to breakpoint at the WSGI 
> application script level to see what you need to see.
>
> Since nobody has jumped in with "I recognize that problem", inspecting 
> your data is probably a good use of your time.  pdb is not hard to use, as 
> long as you are using runserver (and you can almost always arrange to 
> explore a problem under runserver) because there has to be a console for 
> pdb to type on, and on which you can type commands.  The first breakpoint 
> is the only django specific trick.  Put
>
> import pdb; pdb.set_trace()
>
> where you want to stop.  You can use the b command to set additional 
> breakpoints later, but that can be confusing due to threading.  pdb is 
> documented in the library reference for your python version at python.org.  
> Read up on the p, pp, u, d, c, n, s, r, !, and q, commands, probably in 
> that order, and you will find that you usually only use the first 5 of 
> them.  (There are more, for when you want to be a pdb expert.)  And 
> remember to start with a p or pp when you want to see the value of an 
> expression, lest your expression be interpreted as one of the other 
> commands.
>
> Bill
>
> On Sat, Mar 23, 2013 at 5:19 AM, Pratik Mandrekar 
>  > wrote:
>
>> The issue is with setting data in the http post request. I have tried it 
>> with curl and the web client and it works. CSRF is not the issue, requests 
>> work fine without the csrftoken outside of the android client.
>>
>> Pratik
>>
>>
>>
>> On Saturday, March 23, 2013 12:01:21 AM UTC+5:30, ke1g wrote:
>>
>>> Have you tried a breakpoint in the view?  Might it be a CSRF problem?
>>>
>>> On Fri, Mar 22, 2013 at 2:22 PM, Pratik Mandrekar 
>>> wrote:
>>>
 Hello,

 I'm unable to get the POST json to tastypie from an android http client 
 to work.
  
 *I have tried with HttpURLConnection*

 urlConnection = (HttpURLConnection) url.openConnection();


 urlConnection.setDoInput(true);

  urlConnection.setDoOutput(**true**);

  urlConnection.**setRequestProper**ty("Content-**Type", 
 "application/json");

 byte [] encoded = 
 Base64.encode((username+":"+**pa**ssword).getBytes("UTF-8"), 
 Base64.DEFAULT); 

  urlConnection.**setRequestProper**ty("**Authorization", "Basic "+ new 
 String(encoded, "UTF-8"));


 JSONObject jsonObject = new JSONObject();

 jsonObject.put("key1", "value1");

 jsonObject.put("key2", "value2");

   outputStreamWriter = urlConnection.getOutputStream();

  outputStreamWriter.write(**jsonO**bject.toString().**getBytes());

  outputStreamWriter.flush(); 

  


 *And I have tried with Apache HttpClient*

 HttpClient client=new DefaultHttpClient();

 HttpPost post = new HttpPost(url);

 

 post.setHeader("accept", "application/json");

 post.addHeader("Content-Type", "application/json");

 post.addHeader("Authorization", "Basic "+ new String(encoded, 
 "UTF-8"));

  

 ArrayList localArrayList = new ArrayList();

 localArrayList.add(new BasicNameValuePair("json",**json**
 Object.toString()));



  lotlisting.setEntity(new UrlEncodedFormEntity(**localArra**yList));

   String str = EntityUtils.toString(**localDefa**ultHttpClient.**
 execute(**lotlisting).getEntity(**));


 StringEntity se = new StringEntity( jsonObject.toString());  

Re: Im having trouble accessing irc.freenode.net

2013-03-23 Thread Bill Freeman
If you are using FireFox, the Chatzilla add-on is easy to get, probably by
using the tools menu, choosing "Add-ons" and entering "chatzilla" in the
search box on that page.  It's not as fancy as some of the IM tools, but
you can have it anywhere that FireFox runs, and for IRC, it's pretty
trouble free.

On Fri, Mar 22, 2013 at 11:57 PM, hugh Manchu wrote:

> geez Im not sure if I have an IRC Client.. its absense would explain this
>  ... thanks alot Bill will look into this.
> will let you know as soo as I can
> Hugh
>
>
> On Fri, Mar 22, 2013 at 6:40 AM, Bill Freeman  wrote:
>
>> Do you have an IRC client, such as the chatzilla plug in for firefox?
>> Your screenshot is unreadable to me, but if you're just going to
>> irc.freenode.net in your browser, it's not likely to work, since HTTP
>> and IRC are different protocols.
>>
>> On Fri, Mar 22, 2013 at 1:19 AM, Lightning wrote:
>>
>>>  'Where to get help:
>>>
>>> If you’re having trouble going through this tutorial, please post a
>>> message to django-users or 
>>> drop by #django
>>> on irc.freenode.net to chat with other Django users who might be able
>>> to help.'
>>>
>>>
>>> 
>>>
>>> I need help with django related issues, including this one,
>>>
>>> Can someone please help me with this ? Thanks is 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?hl=en.
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>
>>>
>>>
>>
>>  --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "Django users" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/django-users/Tz1-DNtS_g0/unsubscribe?hl=en
>> .
>> To unsubscribe from this group and all its topics, 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?hl=en.
>> 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?hl=en.
> 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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: POSTing JSON to Tastypie from Android

2013-03-23 Thread Bill Freeman
Still, if you have a break point where the request comes in to the view,
you can inspect the POST data to see how it differs from what you expect.
That might inform you as to what you might do differently in your
JavaScript, whether you need some additional or different encoding or
quoting of the data, whether you need to be more explicit about the
content-type header (you may have to look at the WSGI request object
itself), etc.  Or you may discover that you need to breakpoint at the WSGI
application script level to see what you need to see.

Since nobody has jumped in with "I recognize that problem", inspecting your
data is probably a good use of your time.  pdb is not hard to use, as long
as you are using runserver (and you can almost always arrange to explore a
problem under runserver) because there has to be a console for pdb to type
on, and on which you can type commands.  The first breakpoint is the only
django specific trick.  Put

import pdb; pdb.set_trace()

where you want to stop.  You can use the b command to set additional
breakpoints later, but that can be confusing due to threading.  pdb is
documented in the library reference for your python version at python.org.
Read up on the p, pp, u, d, c, n, s, r, !, and q, commands, probably in
that order, and you will find that you usually only use the first 5 of
them.  (There are more, for when you want to be a pdb expert.)  And
remember to start with a p or pp when you want to see the value of an
expression, lest your expression be interpreted as one of the other
commands.

Bill

On Sat, Mar 23, 2013 at 5:19 AM, Pratik Mandrekar  wrote:

> The issue is with setting data in the http post request. I have tried it
> with curl and the web client and it works. CSRF is not the issue, requests
> work fine without the csrftoken outside of the android client.
>
> Pratik
>
>
>
> On Saturday, March 23, 2013 12:01:21 AM UTC+5:30, ke1g wrote:
>
>> Have you tried a breakpoint in the view?  Might it be a CSRF problem?
>>
>> On Fri, Mar 22, 2013 at 2:22 PM, Pratik Mandrekar 
>> wrote:
>>
>>> Hello,
>>>
>>> I'm unable to get the POST json to tastypie from an android http client
>>> to work.
>>>
>>> *I have tried with HttpURLConnection*
>>>
>>> urlConnection = (HttpURLConnection) url.openConnection();
>>>
>>>
>>> urlConnection.setDoInput(true);
>>>
>>> urlConnection.setDoOutput(**true**);
>>>
>>>  urlConnection.**setRequestProper**ty("Content-**Type",
>>> "application/json");
>>>
>>> byte [] encoded = 
>>> Base64.encode((username+":"+**pa**ssword).getBytes("UTF-8"),
>>> Base64.DEFAULT);
>>>
>>> urlConnection.**setRequestProper**ty("**Authorization", "Basic "+ new
>>> String(encoded, "UTF-8"));
>>>
>>>
>>> JSONObject jsonObject = new JSONObject();
>>>
>>> jsonObject.put("key1", "value1");
>>>
>>> jsonObject.put("key2", "value2");
>>>
>>>   outputStreamWriter = urlConnection.getOutputStream();
>>>
>>>  outputStreamWriter.write(**jsonO**bject.toString().**getBytes());
>>>
>>>  outputStreamWriter.flush();
>>>
>>>
>>>
>>>
>>> *And I have tried with Apache HttpClient*
>>>
>>> HttpClient client=new DefaultHttpClient();
>>>
>>> HttpPost post = new HttpPost(url);
>>>
>>>
>>>
>>> post.setHeader("accept", "application/json");
>>>
>>> post.addHeader("Content-Type", "application/json");
>>>
>>> post.addHeader("Authorization", "Basic "+ new String(encoded,
>>> "UTF-8"));
>>>
>>>
>>>
>>> ArrayList localArrayList = new ArrayList();
>>>
>>> localArrayList.add(new BasicNameValuePair("json",**json**
>>> Object.toString()));
>>>
>>>
>>>
>>>  lotlisting.setEntity(new UrlEncodedFormEntity(**localArra**yList));
>>>
>>>  String str = EntityUtils.toString(**localDefa**ultHttpClient.**execute(
>>> **lotlisting).getEntity(**));
>>>
>>>
>>> StringEntity se = new StringEntity( jsonObject.toString());
>>>
>>> se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE,
>>> "application/json"));
>>>
>>>
>>>
>>>  post.setEntity(se);
>>>
>>>
>>>
>>>  HttpResponse response = client.execute(post);
>>>
>>>
>>> I hit the same issue with both of them i.e the POST data as seen as
>>> Querydict in Django, does not have any data. This makes it an invalid json
>>> and it throws a JSON could not be decoded error.
>>>
>>> I have tried playing with all the parameters with little luck. Note that
>>> *get works perfectly*, even with parameters.
>>>
>>> Has anyone been successfully able to post json from an android client to
>>> django/tastypie? If yes, could you please share what worked for you?
>>>
>>> Thanks.
>>>
>>> Pratik
>>>
>>> --
>>> 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...@**googlegroups.com.
>>> To post to this group, send email to django...@googlegroups.com.
>>>
>>> Visit this group at 
>>> 

Re: POSTing JSON to Tastypie from Android

2013-03-23 Thread Pratik Mandrekar
The issue is with setting data in the http post request. I have tried it 
with curl and the web client and it works. CSRF is not the issue, requests 
work fine without the csrftoken outside of the android client.

Pratik



On Saturday, March 23, 2013 12:01:21 AM UTC+5:30, ke1g wrote:
>
> Have you tried a breakpoint in the view?  Might it be a CSRF problem?
>
> On Fri, Mar 22, 2013 at 2:22 PM, Pratik Mandrekar 
>  > wrote:
>
>> Hello,
>>
>> I'm unable to get the POST json to tastypie from an android http client 
>> to work.
>>
>> *I have tried with HttpURLConnection*
>>
>> urlConnection = (HttpURLConnection) url.openConnection();
>>
>>
>> urlConnection.setDoInput(true)**;
>>
>> urlConnection.setDoOutput(**true);
>>
>>  urlConnection.**setRequestProperty("Content-**Type", 
>> "application/json");
>>
>> byte [] encoded = Base64.encode((username+":"+**password).getBytes("UTF-8"), 
>> Base64.DEFAULT); 
>>
>> urlConnection.**setRequestProperty("**Authorization", "Basic "+ new 
>> String(encoded, "UTF-8"));
>>
>>
>> JSONObject jsonObject = new JSONObject();
>>
>> jsonObject.put("key1", "value1");
>>
>> jsonObject.put("key2", "value2");
>>
>>   outputStreamWriter = urlConnection.getOutputStream(**);
>>
>>  outputStreamWriter.write(**jsonObject.toString().**getBytes());
>>
>>  outputStreamWriter.flush(); 
>>
>>  
>>
>>
>> *And I have tried with Apache HttpClient*
>>
>> HttpClient client=new DefaultHttpClient();
>>
>> HttpPost post = new HttpPost(url);
>>
>> 
>>
>> post.setHeader("accept", "application/json");
>>
>> post.addHeader("Content-Type", "application/json");
>>
>> post.addHeader("Authorization"**, "Basic "+ new String(encoded, 
>> "UTF-8"));
>>
>>
>>
>> ArrayList localArrayList = new ArrayList();
>>
>> localArrayList.add(new BasicNameValuePair("json",**
>> jsonObject.toString()));
>>
>>
>>
>>  lotlisting.setEntity(new UrlEncodedFormEntity(**localArrayList));
>>
>>  String str = EntityUtils.toString(**localDefaultHttpClient.**
>> execute(lotlisting).getEntity(**));
>>
>>
>> StringEntity se = new StringEntity( jsonObject.toString());  
>>
>> se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
>>
>> 
>>
>>  post.setEntity(se);
>>
>> 
>>
>>  HttpResponse response = client.execute(post); 
>>
>>
>> I hit the same issue with both of them i.e the POST data as seen as 
>> Querydict in Django, does not have any data. This makes it an invalid json 
>> and it throws a JSON could not be decoded error.
>>
>> I have tried playing with all the parameters with little luck. Note that 
>> *get works perfectly*, even with parameters. 
>>
>> Has anyone been successfully able to post json from an android client to 
>> django/tastypie? If yes, could you please share what worked for you?
>>
>> Thanks.
>>
>> Pratik
>>
>> -- 
>> 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...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com
>> .
>> Visit this group at http://groups.google.com/group/django-users?hl=en.
>> 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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




An alternate cry for help

2013-03-23 Thread Christos Jonathan Hayward
I wrote earlier asking if someone could correct my ignorance to go from
Pinax building blocks to a working site. Since then, I searched Safari, and
found five references to Pinax, at
http://my.safaribooksonline.com/search?q=Pinax . One is a tangent in a
Django book I wrote; three are Python books I didn't write; and one is an
iPhone JavaScript book that includes 'pinax' in a Greek-English lexicon's
URL.

I realized after posting the original post below that although I'm an avid
learner my ignorance of Pinax may be a bit of a challenge to straighten
out. So besides the possibility of educating me to really know how to put
Pinax sites together, could someone preassemble a complete social site that
just needs database setup, a syncdb, and a gunicorn invocation? It would be
nice to have the earlier Pinax Social Project reimplemented using the new
tools, as opposed to the pinax-social-project which is a set of building
blocks to complete a social project. It seems the general approach is to
turn over better and better building blocks to the user, but the
already-working sensible default has its merits, and I'd appreciate those
merits after a day of struggling with old Pinax, new Pinax, borrowed Pinax,
blue Pinax, not getting any responses with good learning resources, and
searching Safari and recognizing that O'Reilly's whole Safari does not
contain as much information about Pinax as the email you are reading, not
enough by half, and that kind of makes my ignorance a less changeable
condition. If I'm ignorant about Django but have the Django documentation
and the Django book, I can reduce my ignorance. Here I don't see how I can
reduce my ignorance, and my thoughts turn to an evaluation that working
Pinax is excellent, not-configured Pinax that you don't know how to improve
is worth very little, and Liferat is mediocre but works, in its own special
way.

*After a day or so of losing at trying to make pinax-social-network 1.0
have the merits of Pinax social-project 0.5 or .7, I'd like to ask how to
cut with the grain instead of against it.*

*The earlier version came as a fully functional site: you could override
and customize if you want, but it came "batteries included", as a room with
well-chosen pegs on the walls, pictures hanging on the hooks, and furniture
as needed. You could replace as much of the room's initial contents as you
wanted, but it came as a furnished room.*

*Pinax-social-network 1.0 is not a furnished room. It has pegs, and the
pegs are about as well-placed as you could ask for, but if you want
pictures on those pegs, it's on you to put pictures on the pegs. And there
is space you can put furniture in the room; the room is left empty so you
can put whatever furniture you want in. And the room comes with elegantly
placed lorem ipsum graffiti on the walls, to motivate you to paint or
wallpaper the walls to meet your taste. It comes "batteries removed."*

*So... what are the resources, and how does one go about, making a social
network here? Do I just take it as a bit of Django putty? I expect I'd do a
lot of reinventing the wheel if I just use Django knowledge. Is there a
tutorial that shows how to make a live site out of one of Pinax's projects?*

*I spent a bit of time reading about Liferat Liferay before remembering how
painful it was even when I knew it well. The problem here may just be that
I am ignorant about Pinax, and ignorance is a changeable condition.*

*So let's say I know something about Python, something about Django and
something about older, fully assembled versions of Pinax, but not how to
take a starter Pinax project and make a finished site out of it. I'm
ignorant on that point. How can I cure my ignorance? What resources are out
there so I can get what was so easily in reach in older versions of Pinax?*

-- 
[image: Christos Jonathan Hayward] 
Christos Jonathan Hayward, an Orthodox Christian author.

*Amazon * • Author
Bio
 • *Email * •
Facebook
 • Fan Page  • Google
Plus
 • LinkedIn  •
*Professional
* • Twitter  •
*Web
* • What's New? 
If you read just *one* of my books, you'll want *The Best of Jonathan's
Corner *.

-- 
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?hl=en.
For more options, visit