Re: UnicodeDecodeError: 'ascii' codec can't decode byte 0xe0 in position 0: ordinal not in range(128)

2011-03-02 Thread Daniel Roseman
On Thursday, March 3, 2011 6:48:21 AM UTC, Vladimir wrote:
>
> Good morning! 
> In me first exercise project with Django I met an error message: 
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xe0 in position 
> 0: ordinal not in range(128). Admin pages are built without css. 
> Then I changed all .py-files entering 
> # -*- coding: utf-8 -*- 
> into the first row and recreated database: 
> ALTER DATABASE `djangodb` DEFAULT CHARACTER SET utf-8 COLLATE 
> utf8_unicode_ci 
> I also tryed COLLATE utf8_swedish_ci. Then I recreated tables with 
> manage.py syncdb. 
> No effect. Is this a typical problem of Django beginners? 
> I need only russian and english languages in my projects endeed.


You haven't posted any code, so it's impossible to help you. The error 
message will have included a traceback, which you should post here, along 
with the relevant model or view.

In my experience, though, this error is usually caused by returning 
non-unicode strings from the __unicode__ method of a model.
--
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.



AW: UnicodeDecodeError: 'ascii' codec can't decode byte 0xe0 in position 0: ordinal not in range(128)

2011-03-02 Thread Szabo, Patrick (LNG-VIE)
Good morning !

Unfortunately i cant help you with your problem because i have the same problem 
here ;)
I can however answer youre question if this is a common problem for django 
beginners.
I don't think it's common for django beginners, i'd rather say it's common for 
python beginners - like me ;)

Kind regards


. . . . . . . . . . . . . . . . . . . . . . . . . .
Patrick Szabo
 XSLT Developer 
LexisNexis
Marxergasse 25, 1030 Wien

mailto:patrick.sz...@lexisnexis.at
Tel.: +43 (1) 534 52 - 1573 
Fax: +43 (1) 534 52 - 146 


-Ursprüngliche Nachricht-

Von: django-users@googlegroups.com [mailto:django-users@googlegroups.com] Im 
Auftrag von Vladimir
Gesendet: Donnerstag, 03. März 2011 07:48
An: Django users
Betreff: UnicodeDecodeError: 'ascii' codec can't decode byte 0xe0 in position 
0: ordinal not in range(128)

Good morning!
In me first exercise project with Django I met an error message:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe0 in position
0: ordinal not in range(128). Admin pages are built without css.
Then I changed all .py-files entering
# -*- coding: utf-8 -*-
into the first row and recreated database:
ALTER DATABASE `djangodb` DEFAULT CHARACTER SET utf-8 COLLATE
utf8_unicode_ci
I also tryed COLLATE utf8_swedish_ci. Then I recreated tables with
manage.py syncdb.
No effect. Is this a typical problem of Django beginners?
I need only russian and english languages in my projects endeed.

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



UnicodeDecodeError: 'ascii' codec can't decode byte 0xe0 in position 0: ordinal not in range(128)

2011-03-02 Thread Vladimir
Good morning!
In me first exercise project with Django I met an error message:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe0 in position
0: ordinal not in range(128). Admin pages are built without css.
Then I changed all .py-files entering
# -*- coding: utf-8 -*-
into the first row and recreated database:
ALTER DATABASE `djangodb` DEFAULT CHARACTER SET utf-8 COLLATE
utf8_unicode_ci
I also tryed COLLATE utf8_swedish_ci. Then I recreated tables with
manage.py syncdb.
No effect. Is this a typical problem of Django beginners?
I need only russian and english languages in my projects endeed.

-- 
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: urls.py usage

2011-03-02 Thread Vladimir
Thank you very much!!! It works!
I followed "Python Web Development with Django. J.Forcier, P.Bissex,
W.Chun" (I used russian edition). They instruct readers to include
registration statement in model.py:
Chapter 2 (my reverse translation from russian into English): Open
file mysite/blog/models.py, add admin application import statement and
then add in the end of file your model registration statement.
from django.db import models
from django.contrib import admin
class BlogPost(models.Model):
title = models.CarField(max_length=150)
body=models.TextField()
timestamp=models.DateTimeField()
admin.site.register(BlogPost)

Later they develop this model: Add to your file mysite/blog/models.py
a new class BlogPostAdmin and add this name to registration method
call:
class BlogPostAdmin(admin.ModelAdmin):
list_display = ('title', 'timestamp')
admin.site.register(BlogPost, BlogPostAdmin)

In other projects they instruct us similarly. No admin.py files!

-- 
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: sites framework + gunicorn

2011-03-02 Thread Shawn Milochik
What do you mean by 'gunicorn instance' here?

> The idea is that in each gunicorn instance I set the
> DJANGO_SETTINGS_MODULE to a different settings.py file, and hopefully
> get the corrrect result.

In any case, I highly recommend you just use supervisord[1] for this
and put the path to the settings files in your supervisor config.

Here's an example of what your supervisord config might look like:

[program:my_site_1]
command=/home/username/projects/awesome_site/manage.py run_gunicorn
127.0.0.1:8000 --settings=projects.site1_settings


[program:my_site_2]
command=/home/username/projects/awesome_site/manage.py run_gunicorn
127.0.0.1:8100 --settings=projects.site2_settings


1: http://supervisord.org/


Shawn

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



sites framework + gunicorn

2011-03-02 Thread ronny
Hi,

I'm trying to run multiples sites using the sites-framework, and
gunicorn.

I'm using the same project, same databases, only I try to use
different settings.py files with different names.

The idea is that in each gunicorn instance I set the
DJANGO_SETTINGS_MODULE to a different settings.py file, and hopefully
get the corrrect result.

Unforutunately, it doesn't seem to matter what I set
DJANGO_SETTINGS_MODULE to, no matter what it always points to
settings.py


Now I've run gunicorn using manage.py and explicitly pointing to the
settings.py file I want, and maybe that's the solution I will end up
using, but I'd like to be able to set things using gunicorn
configuration files.

So my question is this, does anyone have an idea what my problem is,
and what the solution is?

Thanks

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



Re: Using Django to white-label sites for multiple clients

2011-03-02 Thread Shawn Milochik
One option would be to just change the value of MEDIA_ROOT in
settings.py. Or, if you're using 1.3 beta or above, STATIC_ROOT.

You could do this by having multiple settings files -- one main one
with anything that's common across all clients and one settings file
for each client which imports the main file and overrides the stuff
you care about.

Shawn

-- 
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: Converting to UTF8

2011-03-02 Thread Tim Sawyer

On 02/03/11 21:50, Javier Guerra Giraldez wrote:

On Wed, Mar 2, 2011 at 4:21 PM, Tim Sawyer  wrote:

However, my web page now gets Harry Størksen instead.

looks like part of your stack is still interpreting utf-8 data as latin1

check that
1: the field
2: the table
3: the database
4: the client connection
5: the webapp
6: the template
7: the html headers
8: the browser
all know that the data is utf-8

Fixed it, thanks.

There were two problems.

1) I hadn't actually created the database using utf8 encoding it was 
still latin1 (oops!)

2) I needed to edit the .sql file after running iconv so it had

SET client_encoding = 'UTF-8';

instead of

SET client_encoding = 'LATIN1';

Cheers,

Tim.

--
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: oAuth 2.0

2011-03-02 Thread Mick
In the README for python-oauth2 (https://github.com/simplegeo/python-oauth2) 
there is a good example in the "Logging into Django w/ Twitter" section.




_Mick
On Wednesday, March 2, 2011 at 2:36 PM, Олег Корсак wrote: 
> hello. Is there any tutorial/example about oAuth 2.0 built into Django
> and through python-oauth2-1.2.1 ? 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.



oAuth 2.0

2011-03-02 Thread Олег Корсак
hello. Is there any tutorial/example about oAuth 2.0 built into Django
and through python-oauth2-1.2.1 ? thanks



signature.asc
Description: OpenPGP digital signature


Re: Converting to UTF8

2011-03-02 Thread Javier Guerra Giraldez
On Wed, Mar 2, 2011 at 4:21 PM, Tim Sawyer  wrote:
> However, my web page now gets Harry Størksen instead.

looks like part of your stack is still interpreting utf-8 data as latin1

check that
1: the field
2: the table
3: the database
4: the client connection
5: the webapp
6: the template
7: the html headers
8: the browser
all know that the data is utf-8


-- 
Javier

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



Re: newbie going through basic tutorial

2011-03-02 Thread Alex Hall
Well, looks like things are suddenly working. I started over, and
changed two things: I removed the path from the database file name and
I gave it an extension of .db. The file appeared in the same place as
before, so my path was right, but the .db extension seems to have made
something quite happy as things are now working quite nicely.

On 3/2/11, Alex Hall  wrote:
> On 3/2/11, Kenneth Gonsalves  wrote:
>> On Tue, 2011-03-01 at 23:14 -0500, Alex Hall wrote:
>>> I get a very long traceback, ending with sqlite3.OperationalError:
>>> unable to open database file.
>>
>> looks like a permissions problem. Does the webserver have permissions to
>> write to the parent directory of the sqllite file?
> Sorry, but how would I tell? I am on Windows7x64, Python2.7.
>>
>> btw, it is good practice to paste the traceback at the bottom of your
>> mail (yes it is long, but people here are experts at reading and
>> diagnosing from them)
> Okay, here it is:
> Traceback (most recent call last):
>   File "manage.py", line 11, in 
> execute_manager(settings)
>   File "c:\python27\lib\site-packages\django\core\management\__init__.py",
> line 438, in execute_manager
> utility.execute()
>   File "c:\python27\lib\site-packages\django\core\management\__init__.py",
> line 379, in execute
> self.fetch_command(subcommand).run_from_argv(self.argv)
>   File "c:\python27\lib\site-packages\django\core\management\base.py",
> line 191, in run_from_argv
> self.execute(*args, **options.__dict__)
>   File "c:\python27\lib\site-packages\django\core\management\base.py",
> line 220, in execute
> output = self.handle(*args, **options)
>   File "c:\python27\lib\site-packages\django\core\management\base.py",
> line 286, in handle
> app_output = self.handle_app(app, **options)
>   File
> "c:\python27\lib\site-packages\django\core\management\commands\sql.py",
> line 19, in handle_app
> return u'\n'.join(sql_create(app, self.style,
> connections[options.get('database',
> DEFAULT_DB_ALIAS)])).encode('utf-8')
>   File "c:\python27\lib\site-packages\django\core\management\sql.py",
> line 26, in sql_create
> tables = connection.introspection.table_names()
>   File "c:\python27\lib\site-packages\django\db\backends\__init__.py",
> line 504, in table_names
> cursor = self.connection.cursor()
>   File "c:\python27\lib\site-packages\django\db\backends\__init__.py",
> line 75, in cursor
> cursor = self._cursor()
>   File "c:\python27\lib\site-packages\django\db\backends\sqlite3\base.py",
> line 174, in _cursor
> self.connection = Database.connect(**kwargs)
> sqlite3.OperationalError: unable to open database file
>
>> --
>> regards
>> KG
>> http://lawgon.livejournal.com
>> Coimbatore LUG rox
>> http://ilugcbe.techstud.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.
>>
>>
>
>
> --
> Have a great day,
> Alex (msg sent from GMail website)
> mehg...@gmail.com; http://www.facebook.com/mehgcap
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap

-- 
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: Pinax static files in windows7 virtualenv

2011-03-02 Thread mongoose
are you getting an errors, maybe 404 erros when the request is being
made for the media files?

On Feb 25, 1:07 pm, Kopch  wrote:
> Hi all! I'm noob in django. I've installed Pinax project in windows
> virtualenv, after i've made static files collect with build_media.
> Everything were collected in the site_media\static. But pinax project
> doesn't see them anyway. ADMIN_MEDIA_PREFIX is '/site_media/static/
> admin' and all files are there.
> In Ubuntu everything works fine, but i need to work in windows. Please
> help me somebody and sorry for my English.

-- 
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: Custom User Profiles + Signals

2011-03-02 Thread Jeremiah
So continuing with this...  I got the print-outs to work (I still need
to try Stefano's suggestion)...  I register a new user (duh6) via my
register page and in the output for the dev server, I see:
in myproject.cc.models: for user , pr
ofile  already exists
in cc.models: for user ,
profile  already exists

So, it seems like the user has a profile.  But, if I fire-up a shell
via manage.py and do the following:
>>> from django.contrib.auth.models import User
>>> import cc.models
in cc.models
in cc.models: connected profile_handler to post_save signal
>>> u = User.objects.get(username__exact="duh6")
>>> u

>>> u.email
u'd...@duh6.com'
>>> u.userprofile
Traceback (most recent call last):
  File "", line 1, in 
  File "c:\python27\lib\site-packages\django\db\models\fields
\related.py", line
226, in __get__
rel_obj = self.related.model._base_manager.using(db).get(**params)
  File "c:\python27\lib\site-packages\django\db\models\query.py", line
347, in g
et
% self.model._meta.object_name)
DoesNotExist: UserProfile matching query does not exist.
>>> u.get_profile()
Traceback (most recent call last):
  File "", line 1, in 
  File "c:\python27\lib\site-packages\django\contrib\auth\models.py",
line 373,
in get_profile
self._profile_cache =
model._default_manager.using(self._state.db).get(user_
_id__exact=self.id)
  File "c:\python27\lib\site-packages\django\db\models\query.py", line
347, in g
et
% self.model._meta.object_name)
DoesNotExist: UserProfile matching query does not exist.
>>>

Am I trying to access the profile incorrectly?  Not getting something?
All of the above? :)

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



Converting to UTF8

2011-03-02 Thread Tim Sawyer

Hi,

I have a postgres database that is LATIN1.  It contains extended 
characters, for example Harry Størksen.


I dumped this out to a file:

pg_dump -U dbuser db > db.sql

and then ran iconv

iconv --from-code latin1 --to-code utf-8 db.sql > db-utf8.sql

and then imported into a database which has utf8 encoding

db_utf8=> \i db-utf8.sql

If I query this data inside the psql prompt, it works:

db_utf8=> select name from app_table where slug = 'harry-strksen';
  name
-
 Harry Størksen

However, my web page now gets Harry Størksen instead.

Switching back to the LATIN1 database, all is fine.

Does anyone have any clues as to why this doesn't work and what I can do 
to fix it?


Cheers,

Tim.

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



Query Builder & temporary tables

2011-03-02 Thread Pascal Germroth
Hi,

using the PostgreSQL backend I have a complex query
  q = Model.objects.filter(…)
that selects some objects using multiple joins and some geoDjango magic.

Then there are some other simpler queries like
  q2 = OtherModel.filter(foreign__in = q.query)
  q3 = YetAnotherModel.filter(foreign__in = q.query)

I don't actually evaluate q but it's only input for the others. Now
evaluating q2 and q3 of course leads to basically executing q two times,
as a subquery.

So I would like to do a `CREATE TEMPORARY TABLE temp_q AS ` and use this table for q2 and q3, something like:

  new_q = Model.objects.raw('SELECT * FROM temp_q')
  q2 = OtherModel.filter(foreign__in = new_q.query)
  q3 = YetAnotherModel.filter(foreign__in = new_q.query)

My question: what is the nice way to do this? I would fall back to
string manipulation 'CREATE…AS ' + str(q.query) and using a cursor to
run this, but this feels hacky.

Of course q might still return a lot of objects, so creating a list of
primary keys in python and passing that as a parameter is no good either.



Cheers,
-- 
Pascal Germroth

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



Putting content_type on a different class for a generic relation?

2011-03-02 Thread Jim D
I've got two models. Here's what I'm trying to do:

class InterestSet(models.Model, MailChimpAPIMixin):
name = models.CharField(help_text="The interest grouping to add.
Grouping names must be unique.", max_length=128, unique=True)
content_type = models.ForeignKey(ContentType, blank=True,
null=True)

class InterestGroup(models.Model, MailChimpAPIMixin):
name = models.CharField(max_length=128, unique=True)
interest_grouping = models.ForeignKey(InterestGrouping)
object_id = models.PositiveIntegerField(blank=True, null=True)
content_object =
generic.GenericForeignKey('interest_set__content_type', 'object_id')


Basically, I want to define a content type for an Interest Set on the
"parent" model. Then, for each Interest Group, I want the object id to
always refer to the content type set on Interest Set. You can see by
the first argument to GenericForeignKey() how I wish it worked.

Alas it does not. Plan B is just to move the content_type field back
to Interest Grouping and deal (or possibly just custom code my
relationships without relying on GenericForeignKey). It's a shame
because it duplicates data unnecessarily and creates an opportunity
for a relationship to be created that violates a business rule for
this application (which is that all Interest Groups in an Interest Set
must be related to the same content type).

I'm just wondering if either a) I'm missing an obvious way to
accomplish this or b) this has come up before or been discussed
somewhere. I might explore the possibility of patching the source code
to enable this behavior of that sounds at all desirable.

Let me know your thoughts. 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.



curious about model classes

2011-03-02 Thread Alex Hall
Hi all,
Still working through that tutorial. I am just curious: why are none
of the class variables called self.var, but rather just var? For
example:
import models
class Poll(models.Model):
 question=models.CharField(max_length=200)

Should that not be
self.question=...
instead? Otherwise, saying something like:
poll=Poll()
poll.question="question?"
should not work; question is not told to be part of the class by way
of self. This may stray from django and into pure python territory, so
sorry if it gets off-topic. I have never seen a class that does not
tie its variables to itself with self or some other keyword. Come to
think of it, there is no __init__ method. I know that it is not
necessary to have one, but I figured I would have seen one to get
things set up.

-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap

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



htaccess/rewrite engine/default page

2011-03-02 Thread Tim Johnson
I am using Python 2.6.6 on mint 10. I just installed django from
synaptic. This is not a django-specific question, but I am hopeful
that the answer will be helpful to other noobs.

Given that I have the following python script installed on my
machine:
myFooLoader.py

And I point my browser to
http://localhost/cgi-bin/path/to/foo/myFooLoader.py
to execute myFooLoader.py

Now I want configure for a default page so I can point my browser to
just
http://localhost/cgi-bin/path/to/foo
and execute myFooLoader.py - I.E. 'myFooLoader.py' is recognized as
the default page.

This entails using an .htaccess file in the same directory as the
script with 'rewriteengine on' (I don't need to use mod_python) at
this time.

I could use some examples on how to set up .htaccess to enable this.
I haven't used .htaccess since apache 1.~
URLs to relevant discussions are welcome.

thanks
-- 
Tim 
tim at johnsons-web.com or akwebsoft.com
http://www.akwebsoft.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.



Using Django to white-label sites for multiple clients

2011-03-02 Thread Greg Pelly
I'm looking to "white label" a site built using Django.

For those unfamiliar with white-labeling, we would like my site (call it
"Amazing Site") to be able to be customized by sponsors A and B. Customer A
provides us with their header, footer, css, and we can do *basic*
re-branding, in order to present the site as "A Amazing Site" (or B's
Amazing Site).

I have considered rolling my own by changing the base template. So instead
of
  {% extends "base.html" %}
I would pass in a variable from the view:
  {% extends site-base-template %}

Have others tried this? Are there existing strategies? Perhaps a django app
that takes care of this?

Thanks,
Greg

-- 
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: Custom User Profiles + Signals

2011-03-02 Thread bruno desthuilliers
On 2 mar, 19:31, Jeremiah  wrote:

(snip)
>> Given the above statement, I assume the "models.py" file you're
>> talking about is not the one where you define your UserProfile class.
(snip)

> It is the same models.py file with the UserProfile class.  Is this the
> incorrect way to set this up?  I have a feeling I'm completely missing
> something.

If it's in the same module (=> .py file), then you don't have to
reference it as "cc.models.UserProfile" - "UserProfile" is enough.

IOW:

def profile_handler(sender, **kwargs):
""" Signal handler to deal with a save on the User model """
try:
sender.userprofile
except UserProfile.DoesNotExist:
profile = UserProfile(user=sender)
profile.save()


> I have it registered under INSTALLED_APPS using the name of the
> project

Don't. It's not necessary, and may break if for any reason you either
rename your project or try to reuse the same app in another project.
Also and FWIW, there are (complicated) issues with modules / packages
qualified names and the way django import models at startup, that may
end up with your module being imported twice under two different
names.

The only potential problem with removing the "project" namespace from
your settings.INSTALLED_APPS *and* imports is that you'll have to add
both the project's parent dir and the project's dir in your sys.path
(in the .wsgi file) when deploying using mod_wsgi.

>
> > FWIW, you can insert print statements (poor man logging) in your
> > models.py file to make sure it's imported and check if the signal
> > handler is executed:
>
> > # wherever/models.py
> > from django.db.models.signals import post_save
>
> > print "in %s" % __name__
>
> > def profile_handler(sender, **kwargs):
> >     """ Signal handler to deal with a save on the User model """
> >     try:
> >         p = sender.userprofile
> >         print "in %s : for user %s, profile %s already exists" %
> > (__name__, sender, p)
> >     except cc.models.UserProfile.DoesNotExist:
> >         profile = cc.models.UserProfile(user=sender)
> >         profile.save()
> >         print "in %s : for user %s, created profile %s " % (__name__,
> > sender, p)
> >     except Exception, e:
> >         print "in %s : for user %s, got unexpected exception %s" %
> > (__name__, sender, e)
> >         raise
>
> > print "in %s : connecting profile_handler to post_save signal" %
> > __name__
> > post_save.connect(profile_handler, sender=User)
> > print "in %s : connected profile_handler to post_save signal" %
> > __name__
>
> Thanks!  I didn't know you could do that - I thought it would be
> gobbled up as invalid output by the http server so I hadn't tried.

It's invalid when running django behind a front-end webserver like
Apache but works fine with the builtin dev server.

The RightThingToDo(tm) is of course to use Python's logging package,
but it's a bit more involved.

> > While we're at it, the pythonic convention for indentations is 4-
> > spaces, no tabs
>
> Thank you for this as well!  I'm both new to Django and Python -
> learning as I go.

comp.lang.py is a very newbie-friendly place (well, it's a very
friendly place, period), with quite a few gurus hanging around. I
strongly suggest you post your "pure-python" questions there. I
learned quite a few thangs lurking there ;)

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



form.is_valid() changes a ModelForm's associated instance now?

2011-03-02 Thread Jumpfroggy
I discovered the recent changes to the "is_valid()" model form method
in 1.2, and I'd love to hear thoughts on the rationale behind this
change.

I have this kind of code:

item = Item.objects.get(id=1)
print 'item.value: %s' % item.value
form = ItemModelForm(request.POST, instance=item)
old_item = item
if form.is_valid():
print 'old_item.value: %s' % old_item.value
print "form.cleaned_data['value']: %s" %
form.cleaned_data['value']
new_item = form.save(commit=False)
print 'new_item.value: %s' % new_item.value

And I'd expect this output:

item.value: old_value
old_item.value: old_value
form.cleaned_data['value']: new_value
new_item.value: new_value

But instead I get this:

item.value: old_value
old_item.value: new_value
form.cleaned_data['value']: new_value
new_item.value: new_value

It seems like the "is_valid()" function not only checks for validation
errors and creates the "form.cleaned_data" members, it also modifies
the instance of the model attached to this form.  I just looked over
the docs, and I can now see that this is implied but not really
explicitly referenced here:

http://docs.djangoproject.com/en/1.2/topics/forms/modelforms/

The first time you call is_valid() or access the errors attribute
of a ModelForm has always triggered form validation, but as of Django
1.2, it will also trigger model validation. This has the side-effect
of cleaning the model you pass to the ModelForm constructor. For
instance, calling is_valid() on your form will convert any date fields
on your model to actual date objects.

The problem is not that the instance is being "cleaned".  It's that
the instance is being modified, then cleaned.  It would help if the
docs specified this as well, so we know what the side effects of
"is_valid()" really are.

Also, doesn't this make this code obsolete?

item = form.save()

And:

item = form.save(commit=False)
item.save()

We could instead just do this:

form = ItemModelForm(request.POST, instance=item)
if form.is_valid():
item.save()

(assuming that we're modifying an existing instance, and not creating
a new one)

Since the original "item" is modified, I could just save that as well,
right?  Is that what we truly want to happen?  Seems like the
modification of the original instance in this case is an unintentional
side effect of needing to clean the model for validation.  It seems
like it would be better if is_valid() created a copy of the instance,
and then modified & cleaned that copy instead of the original.
Otherwise it seems tricky to have a validation method secretly
modifying seemingly unrelated data.

I just want to wrap my head around these new changes, and maybe
understand the rationale behind them.  Thanks!

PS. The solution to my specific problem above is to do this:

item = Item.objects.get(id=1)
print 'item.value: %s' % item.value
form = ItemModelForm(request.POST, instance=item)
# NOTE: This fixes the problem:
old_item = copy.deepcopy(item)
if form.is_valid():
print 'old_item.value: %s' % old_item.value
print "form.cleaned_data['value']: %s" %
form.cleaned_data['value']
new_item = form.save(commit=False)
print 'new_item.value: %s' % new_item.value

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



Re: Custom User Profiles + Signals

2011-03-02 Thread Jeremiah
I appreciate all of your feedback!  My comments inserted within the
message below:


> What does cc.models.UserProfile looks like ?
class UserProfile(models.Model):
user = models.OneToOneField(User)
thing = models.CharField(max_length=200)

def __unicode__(self):
return unicode(self.user)


> This should be :
>
>   ... except cc.models.UserProfile.DoesNotExist:
>
> As a general rule:
> * NEVER use a bare except clause unless you reraise the SAME exception
> in the except block.
> * always catch the most specific exception type.

Noted!  Thank you for your guidelines.


> Given the above statement, I assume the "models.py" file you're
> talking about is not the one where you define your UserProfile class.
> If yes - you may have legitimate reasons to split this between
> different apps -, are you sure the models.py file where you set up
> this signal handler is correctly registered and imported ? (hint: is
> the app containing this models.py in your settings.INSTALLED_APPS ?)
It is the same models.py file with the UserProfile class.  Is this the
incorrect way to set this up?  I have a feeling I'm completely missing
something.

I have it registered under INSTALLED_APPS using the name of the
project I created with startproject (myproject for the sake of
example) and the name of the app via startapp:
...,
'myproject.cc',
...,


> FWIW, you can insert print statements (poor man logging) in your
> models.py file to make sure it's imported and check if the signal
> handler is executed:
>
> # wherever/models.py
> from django.db.models.signals import post_save
>
> print "in %s" % __name__
>
> def profile_handler(sender, **kwargs):
>     """ Signal handler to deal with a save on the User model """
>     try:
>         p = sender.userprofile
>         print "in %s : for user %s, profile %s already exists" %
> (__name__, sender, p)
>     except cc.models.UserProfile.DoesNotExist:
>         profile = cc.models.UserProfile(user=sender)
>         profile.save()
>         print "in %s : for user %s, created profile %s " % (__name__,
> sender, p)
>     except Exception, e:
>         print "in %s : for user %s, got unexpected exception %s" %
> (__name__, sender, e)
>         raise
>
> print "in %s : connecting profile_handler to post_save signal" %
> __name__
> post_save.connect(profile_handler, sender=User)
> print "in %s : connected profile_handler to post_save signal" %
> __name__

Thanks!  I didn't know you could do that - I thought it would be
gobbled up as invalid output by the http server so I hadn't tried.

> While we're at it, the pythonic convention for indentations is 4-
> spaces, no tabs
Thank you for this as well!  I'm both new to Django and Python -
learning as I go.

-- 
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: Custom User Profiles + Signals

2011-03-02 Thread Wandering Weezard
I'll give that a shot.  Thank you for your feedback. Still learning a lot as
I go.

On Tue, Mar 1, 2011 at 8:07 PM, Stefano  wrote:

> why you don't create the profile only if needed ?
>
> class UserProfile(models.Model):
>user = models.ForeignKey(User, unique=True)
>
> User.profile = property(lambda u:
> UserProfile.objects.get_or_create(user=u)[0])
>
> 2011/3/2 Jeremiah :
> > Hi All,
> >
> > I'm going through the help document (http://docs.djangoproject.com/en/
> > 1.2/topics/auth/#storing-additional-information-about-users) and I'm
> > starting to figure out how signals work.  What I'm having problems
> > with is getting my signal to trigger (or at least figuring out if the
> > signal is actually triggering?)
> >
> > So, if I do the following from the shell (as spawned by manage.py):
>  import cc.models
>  from django.contrib.auth.models import User
>  u = User.objects.get(username__exact="duh3")
>  try:
> > ... u.userprofile
> > ... except:
> > ... profile = cc.models.UserProfile()
> > ... profile.user = u
> > ... profile.thing = "Test"
> > ... profile.save()
> > ...
> > 
>  u.userprofile.user
> > 
>  u.userprofile.thing
> > u'Test'
> >
> > I can get the profile to work.  So, then I add the following lines to
> > my "models.py" file:
> > from django.db.models.signals import post_save
> > ...
> > def profile_handler(sender, **kwargs):
> >""" Signal handler to deal with a save on the User model """
> >try:
> >sender.userprofile
> >except:
> >profile = cc.models.UserProfile()
> >profile.user = sender
> >profile.save()
> >
> > post_save.connect(profile_handler, sender=User)
> >
> > But, what i can't tell is if anything is happening.  If I create a new
> > user and then try userinstance.userprofile, I get the expected
> > exception.
> >
> > Could someone please point me at my issue?
> >
> > Thanks,
> > Jeremiah
> >
> > --
> > 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: What apps or snippets to use for Facebook and Twitter registration, login and posting?

2011-03-02 Thread Jason Culverhouse
On Mar 2, 2011, at 8:28 AM, Rodrigo Cea wrote:

> I am developing a site that I want to link with Facebook and Twitter. 
> 
> So as to not reinvent the wheel, I'm looking for apps or snippets that can 
> help with this, specifically:
> 
> 1) allow users to register and login with their Facebook and/or Twitter 
> accounts.
> 
> 2) Have these accounts be linked to the local one (crossposting to their FB 
> and Twitter account, pulling in their posts on FB and TW, etc.)
> 

Pointing you here, since davidmarble does a nice rollup of the of options in a 
github readme 

From:
https://github.com/davidmarble/Django-Socialauth

Important note
This is a fork to rollup other forks of this app and try to get it running with 
the most recent facebook/twitter/linkedin APIs. It is completely untested. Just 
thought I'd share the work while it's in-progress. It's supposed to allow 
logging in via Facebook, Yahoo, Gmail, Twitter and Openid.

It's sad that Rails has such a complete solution with omniauth -- Django has 
nothing to compare! I'm hoping we all rally around one of these projects to 
create our own omniauth. I'm not sure this is the best code base to start from. 
I'm also exploring the following:

• https://github.com/pennersr/django-allauth
• https://github.com/flashingpumpkin/django-socialregistration (note 
the forks)
• https://github.com/kmike/django-registration-facebook-backend
• https://github.com/zbowling/python-oauth2 (good fork of simplegeo's)
• https://github.com/tschellenbach/Django-facebook.

Jason

-- 
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: Query involving manytomany relationship

2011-03-02 Thread gontran
I will answer to myself (after having been trying for over an hour, I
found the answer a couple of minutes after posting my question)

products =
Product.objects.filter(productlicence__client=client).distinct()

-- 
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: Query involving manytomany relationship

2011-03-02 Thread gontran
Sorry for the question,
but I've been trying for over an hour and just when I post this
message, I find the answer!!

Here is it:
products =
Product.objects.filter(productlicence__client=client).distinct()

Hope that it will be useful

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



Query involving manytomany relationship

2011-03-02 Thread gontran
Hello everybody

this is maybe simple but I can't succeed in making a query.
here is my model:

class Client(models.Model):
user= models.OneToOneField(User)
product_licence= models.ManyToManyField('ProductLicence',
blank=True, null=True)

class ProductLicence(models.Model):
product= models.ForeignKey('Produit')

class Product(models.Model):
code= models.CharField(max_length=15)
name   = models.CharField(max_length=50)

In my model, clients may buy licences for different products.
I'm trying to get in one query all products for which a given client
owns a licence.

Is it possible to do it or should I make 2 queries?

Thanks in advance

regards,

Gontran

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



What apps or snippets to use for Facebook and Twitter registration, login and posting?

2011-03-02 Thread Rodrigo Cea
I am developing a site that I want to link with Facebook and Twitter. 

So as to not reinvent the wheel, I'm looking for apps or snippets that can 
help with this, specifically:

1) allow users to register and login with their Facebook and/or Twitter 
accounts.

2) Have these accounts be linked to the local one (crossposting to their FB 
and Twitter account, pulling in their posts on FB and TW, etc.)

Thanks,

Rodrigo

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



Regarding fieldsets in django

2011-03-02 Thread Suchindra Chandrahas
Hi All,
  I am a django newbie and I have a pretty small question
here

  I need to register a customized admin view, so I edited
/admin.py file and added the customized fieldsets, which is
working perfectly fine

  However, I need to design a form with nested fieldsets
something like below:

general

field1
field2
field3

details
  section1

  field4
  field5
  field6

 section2

 field7
 field8
 field9


I tried the following fieldset in my admin.py:

fieldset1 = (
('general', {
'fields': ('f1', 'f2', 'f3', 'f4')
})
)

fieldset2 = (
(section1, {
'fields': ('f1', 'f2', 'f3', 'f4')
})
)

fieldset3 = (
(section2, {
'fields': ('f1', 'f2', 'f3', 'f4')
})
)

fieldsets = (fieldset1, fieldset2, fieldset3)


With the above design, I am getting something like below:

general

field1
field2
field3

section1
 field1
 field2
 field3

section2
 field1
 field2
 field3

However, this is not what I wanted

My question is how to design a nested fieldset using django?

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



InterfaceError: Connection already closed -- is this a regression?

2011-03-02 Thread onelson
I recently switched a project from mysql to postgres and started to
see httpd throwing intermittent 500 errors.

mod_wsgi (pid=26467): Exception occurred processing WSGI script '/
htdocs/django.wsgi'.
 Traceback (most recent call last):
   File "./lib/python2.6/site-packages/django/core/handlers/
wsgi.py", line 275, in __call__
 signals.request_finished.send(sender=self.__class__)
   File "./lib/python2.6/site-packages/django/dispatch/
dispatcher.py", line 172, in send
 response = receiver(signal=self, sender=sender, **named)
   File "./lib/python2.6/site-packages/django/db/__init__.py",
line 84, in close_connection
 conn.close()
   File "./lib/python2.6/site-packages/django/db/backends/
__init__.py", line 79, in close
 self.connection.close()
InterfaceError: connection already closed

I'm seeing this maybe every 20-30th page request.

Looking at the issues on trac, I see a handful of tickets that share
this error, however I don't see anything common between them (or my
own situation) beyond using psycopg2.
http://code.djangoproject.com/search?q=InterfaceError+connection+already+closed&noquickjump=1&ticket=on
Most of the tickets are *old*. Years old. Either this is something pg
users are familiar with and just know how to deal with, or this is a
bug (or both?)

Thoughts please!

-- 
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: python mysqldb installation problem

2011-03-02 Thread zhou vika
Thanks for solution.
I have also encounter similar problem before. I have found the name for
socket file appeared in exception content is different from which MySQL
server using, but don't know how where to indicate the socket file name.

/etc/mysql/my.cnf

2011/3/2 draix 

> Hey Pulkit,
>
> I've had this error a couple of times too. Check the location of your
> MySQL socket, maybe it's different to '/var/run/mysqld/mysqld.sock'.
> You can do it checking /etc/mysql/my.cnf. After that, just update
> DATABASE_HOST in settings.py and add the path to the new socket.
>
> PS: you can also use "python manage.py dbshell" to test your DB
> access.
>
> Cheers,
> Martin
>
> On 28 feb, 16:19, Pulkit Mehrotra  wrote:
> > OS: Ubuntu 10.04
> > I am learning web developing with Django.I downloaded and installed
> > python-mysql but i couldn't connect.I think problem is database
> > settings.
> > Here is the process:
> >
> > django-admin.py startproject mysite #creating a project and a mysite
> > folder
> >
> > files in 'mysite' folder:
> > /__init__.py
> > /urls.py
> > /manage.py
> > /views.py
> > /settings.py
> >
> > Then i edited the 'settings.py' file.There are alse database settings
> > in it.
> >
> > Here are the settings:
> >
> > DATABASE_ENGINE = 'mysql'
> > DATABASE_NAME = 'mydb'
> > DATABASE_USER = 'me'
> > DATABASE_PASSWORD = 'pwd'
> > DATABASE_HOST = ''
> > DATABASE_PORT = ''
> >
> > then i write the codes below with terminal:
> >
> > python manage.py shell
> >
> > from django.db import connection
> > cursor=connection.cursor()
> >
> > Then the error occurs as:
> >
> > Traceback (most recent call last):
> > File "", line 1, in 
> > File "/usr/lib/python2.5/site-packages/django/db/backends/mysql/
> > base.py", line 99, in cursor
> > self.connection = Database.connect(**kwargs)
> > File "/var/lib/python-support/python2.5/MySQLdb/__init__.py", line 74,
> > in Connect
> > return Connection(*args, **kwargs)
> > File "/var/lib/python-support/python2.5/MySQLdb/connections.py", line
> > 170, in __init__
> > super(Connection, self).__init__(*args, **kwargs2)
> > OperationalError: (2002, "Can't connect to local MySQL server through
> > socket '/var/run/mysqld/mysqld.sock' (2)")
> >
> > It looks like that error occurs from DATABASE_HOST but i don't think
> > so because when using MySQL DATABASE_HOST may be left blank
>
> --
> 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: mysql MySQL-python and libmysqlclient.so.16 hell

2011-03-02 Thread Tom Evans
On Wed, Mar 2, 2011 at 3:01 PM, vanderkerkoff  wrote:
> Thanks Graham
>
> I went for the first option and added the path to my mysql libraries
> to /etc/ld.so.conf
>
> Never had to do that before though, and I've installed this type of
> system many many times.  This one is newer ubuntu and newer mysql
> though, must be a change in that.
>
> Thanks again
>
> Matt
>
>

This has been true for many years; if you install libraries to
locations outside of your OS's LD_LIBRARY_PATH, you're responsible for
ensuring that the linker/rtld has enough information to use it. man
rtld/ld.so/ld

In fact, whilst installing MySQL 5.5 from source, the following
message is emitted (obviously, the location is different):

Libraries have been installed in:
   /usr/local/lib/mysql

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
 during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
 during linking
   - use the `-Wl,-rpath -Wl,LIBDIR' linker flag

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.


Cheers

Tom

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



Re: Django ORM query modelling question

2011-03-02 Thread Carsten Fuchs

Hi Jirka,

Am 01.03.2011 21:44, schrieb Jirka Vejrazka:

   this does not seem to me like something you would be able to do
using SQL (or Django ORM) only. I would guess that you'll have to
write a bit of Python code that will walk through the entries and
detect those that are different from "previous"


Many thanks for your reply and for pointing this out!

For better performance, I had hoped that there is a way to eliminate the 
unwanted rows in the database instead of Python code, but doing the 
filtering for "changes" now in Python code in fact solved the problem 
quite nicely.  :-)


Best regards,
Carsten




smime.p7s
Description: S/MIME Cryptographic Signature


Re: How to pre-cache model data?

2011-03-02 Thread Alex Robbins
If you need to run tasks outside the request/response cycle, then you
should be using celery.

http://celeryproject.org/

Celery includes something called periodic tasks.
http://ask.github.com/celery/userguide/periodic-tasks.html

You just need to make a task that updates the value in cache, and then
set it to run with a schedule=timedelta(minutes=3) (or schedule=60*3).

Hope that helps!
Alex

On Mar 1, 9:10 am, Helgi Borg  wrote:
> I need my Django app to poll data in DB regularly  (say once every 3
> minutes) and cache the data. I have some queries that take up to 20
> sec. The users must never wait this long for response from my app.
> What is the must natural way to go about this in Django?
>
> I know that I can use memcache, but that way the users will once in
> while have to wait a long time while the cache is being refreshed.
>
> Best regards,
> Helgi Borg

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



weird permissions issue

2011-03-02 Thread Eric Abrahamsen
I'm using the emencia newsletter, and things are essentially fine,
except that I've run into a very strange permissions issue in the admin
backend. I have my regular user login, and the superuser. I've given my
regular user all permissions for all newsletter models, and yet some of
the inter-modal relations are not showing up.

The MailingList model has a ManyToMany relationship to Contact, yet when
I'm logged in as my regular user and look at a MailingList instance, the
two windows for selecting Contacts from the contact list are blank. Same
for all the relationship fields on all the models: whether ForeignKey or
ManyToMany, none of them display the choices for creating a
relationship. I just tried using the admin javascript green "plus sign"
to both create an instance of a related model and put it into the list.
The creation comes off okay, and I see the new Contact (in this case)
appear in the list, but when I save the MailingList model, it tells me:
"Select a valid choice. 594 is not one of the available choices." 594 is
the id of the Contact instance I just created.

This only happens on my production system, not my development system.
Both are running django 1.2.3, and version 0.2 of the emencia
newsletter. What can have gotten screwed up here? I added the newsletter
app much later, is there a possibility this is a database-level issue?

Any pointers towards further debugging would be much welcome…

Thanks,
Eric

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



.htaccess + Django issues

2011-03-02 Thread Sithembewena Lloyd Dube
Hi all,

Pardon me if this is the wrong list for the issue I have.

I have a .htaccess file containing the following lines:

AddType text/x-component .htc
RewriteEngine On
RewriteBase /

RewriteCond %{QUERY_STRING} .
RewriteRule ^(.*)\.php(.*)$ http://www.mydomain/forum/? [R=301,L]
RewriteRule ^forum/(.*)$ /forum/$1 [R=301,L]
RewriteRule ^blog/(.*)$ /blog/$1 [R=301,L]

I then have the following URLs:

 · 
http://www.mydomain/forum/calendar.php?c=1&week=1301788800

· 
http://www.mydomain/forum/strategy-and-coaching/coaching-analysis/

· 
http://www.mydomain/blog/joining-coaching-sessions/

The first two URLs are 301 redirected as expected, but the last one is not.
What could I be getting wrong here?
-- 
Regards,
Sithembewena Lloyd Dube

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



Re: newbie going through basic tutorial

2011-03-02 Thread Alex Hall
On 3/2/11, Kenneth Gonsalves  wrote:
> On Tue, 2011-03-01 at 23:14 -0500, Alex Hall wrote:
>> I get a very long traceback, ending with sqlite3.OperationalError:
>> unable to open database file.
>
> looks like a permissions problem. Does the webserver have permissions to
> write to the parent directory of the sqllite file?
Sorry, but how would I tell? I am on Windows7x64, Python2.7.
>
> btw, it is good practice to paste the traceback at the bottom of your
> mail (yes it is long, but people here are experts at reading and
> diagnosing from them)
Okay, here it is:
Traceback (most recent call last):
  File "manage.py", line 11, in 
execute_manager(settings)
  File "c:\python27\lib\site-packages\django\core\management\__init__.py",
line 438, in execute_manager
utility.execute()
  File "c:\python27\lib\site-packages\django\core\management\__init__.py",
line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
  File "c:\python27\lib\site-packages\django\core\management\base.py",
line 191, in run_from_argv
self.execute(*args, **options.__dict__)
  File "c:\python27\lib\site-packages\django\core\management\base.py",
line 220, in execute
output = self.handle(*args, **options)
  File "c:\python27\lib\site-packages\django\core\management\base.py",
line 286, in handle
app_output = self.handle_app(app, **options)
  File "c:\python27\lib\site-packages\django\core\management\commands\sql.py",
line 19, in handle_app
return u'\n'.join(sql_create(app, self.style,
connections[options.get('database',
DEFAULT_DB_ALIAS)])).encode('utf-8')
  File "c:\python27\lib\site-packages\django\core\management\sql.py",
line 26, in sql_create
tables = connection.introspection.table_names()
  File "c:\python27\lib\site-packages\django\db\backends\__init__.py",
line 504, in table_names
cursor = self.connection.cursor()
  File "c:\python27\lib\site-packages\django\db\backends\__init__.py",
line 75, in cursor
cursor = self._cursor()
  File "c:\python27\lib\site-packages\django\db\backends\sqlite3\base.py",
line 174, in _cursor
self.connection = Database.connect(**kwargs)
sqlite3.OperationalError: unable to open database file

> --
> regards
> KG
> http://lawgon.livejournal.com
> Coimbatore LUG rox
> http://ilugcbe.techstud.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.
>
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap

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



extend TimeFormat

2011-03-02 Thread marco ghidinelli
hello,

i've a problem extending the TimeFormat class (used by "time" template
filter).

basically, i need a new method: 

def F(self):
if self.date.minute == 0:
return self.G()
return u'%s:%s' % (self.G(), self.i())

very similar to the original one except for a G() instead of a g().

the (too) easy path is to modify the dateformat.py, but i don't want
to modify the django installation for many obvious reasons.

i want to extend the dateformat class, and i tryed to put this

-
from django.utils.dateformat import TimeFormat

class TimeFormat(TimeFormat):
"extends with one method"

def F(self):
if self.date.minute == 0:
return self.G()
return u'%s:%s' % (self.G(), self.i())
---

in many places inside my project tree (settings.py, views.py, __init__.py ) 
but in vain.

where should i put it?


regards, 
marco.

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



Creating one model row from another model save method

2011-03-02 Thread Kirill Gorin
Hi community

I have two models in two apps,
first named newsItem

from django.db import models
from datetime import datetime

class newsItem(models.Model):
pubDate = models.DateTimeField('date
published',default=datetime.now())
author = models.CharField(max_length=20, default="author")
title = models.CharField(max_length=200)
text = models.TextField()
snippet = models.TextField(blank=True)
tags = models.ManyToManyField('newsTag', through='TagsToNews')
needsGallery = models.BooleanField()

def __unicode__(self):
return self.title

def save(self, *args, **kwargs):
if len(unicode.strip(self.snippet)) == 0:
self.snippet = ""
super(newsItem, self).save(*args, **kwargs)

and second one in another app called subGallery, which is related to
newsItem via foreign key
from django.db import models
from news.models import newsItem, newsTag

class subGallery(models.Model):
pubDate = models.DateTimeField('date published')
title = models.CharField(max_length=200)
text = models.TextField(blank=True)
tags = models.ManyToManyField(newsTag, through='TagsToGalleries')
newsItem = models.ForeignKey('news.newsItem')

def __unicode__(self):
return self.title

class Meta:
verbose_name_plural = "Galleries"

What I want to do is to create new subGallery whenever newsItem with
"needGallery" field set to true gets created or saved, so I altered
save method of newsItem like this:

def save(self, *args, **kwargs):
if len(unicode.strip(self.snippet)) == 0:
self.snippet = ""
super(newsItem, self).save(*args, **kwargs)

if self.needsGallery:
if not(len(self.subGallery_set.all())):
gallery = subGallery(title = self.title,
pubDate=self.pubDate)
gallery.save()

but when I am creating newsItem through admin page it says: 'newsItem'
object has no attribute 'subGallery_set'
What am I doing wrong?

-- 
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: Custom User Profiles + Signals

2011-03-02 Thread bruno desthuilliers
On 2 mar, 00:50, Jeremiah  wrote:
> Hi All,
>
> So, if I do the following from the shell (as spawned by manage.py):
> >>> import cc.models

What does cc.models.UserProfile looks like ?

> >>> from django.contrib.auth.models import User
> >>> u = User.objects.get(username__exact="duh3")
> >>> try:
>
> ...     u.userprofile
> ... except:

This should be :

  ... except cc.models.UserProfile.DoesNotExist:


As a general rule:
* NEVER use a bare except clause unless you reraise the SAME exception
in the except block.
* always catch the most specific exception type.


> ...     profile = cc.models.UserProfile()
> ...     profile.user = u
> ...     profile.thing = "Test"
> ...     profile.save()
> ...

(snip)

> I can get the profile to work.  So, then I add the following lines to
> my "models.py" file:
> from django.db.models.signals import post_save
> ...
> def profile_handler(sender, **kwargs):
>         """ Signal handler to deal with a save on the User model """
>         try:
>                 sender.userprofile
>         except:
>                 profile = cc.models.UserProfile()

Given the above statement, I assume the "models.py" file you're
talking about is not the one where you define your UserProfile class.
If yes - you may have legitimate reasons to split this between
different apps -, are you sure the models.py file where you set up
this signal handler is correctly registered and imported ? (hint: is
the app containing this models.py in your settings.INSTALLED_APPS ?)

FWIW, you can insert print statements (poor man logging) in your
models.py file to make sure it's imported and check if the signal
handler is executed:

# wherever/models.py
from django.db.models.signals import post_save

print "in %s" % __name__

def profile_handler(sender, **kwargs):
""" Signal handler to deal with a save on the User model """
try:
p = sender.userprofile
print "in %s : for user %s, profile %s already exists" %
(__name__, sender, p)
except cc.models.UserProfile.DoesNotExist:
profile = cc.models.UserProfile(user=sender)
profile.save()
print "in %s : for user %s, created profile %s " % (__name__,
sender, p)
except Exception, e:
print "in %s : for user %s, got unexpected exception %s" %
(__name__, sender, e)
raise

print "in %s : connecting profile_handler to post_save signal" %
__name__
post_save.connect(profile_handler, sender=User)
print "in %s : connected profile_handler to post_save signal" %
__name__


Running this with the builtin dev server should provide some useful
informations about your problem.

While we're at it, the pythonic convention for indentations is 4-
spaces, no tabs

HTH

-- 
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: a rookie problem about 'Modules'

2011-03-02 Thread xie he
thanks sincerely

2011/3/2 bruno desthuilliers 

> On 1 mar, 16:30, Bill Liao  wrote:
> > On Tuesday, March 1, 2011, iRick  wrote:
> > > hi,i'm a freshman for python. i got a problem about "Modules"
>
> Python-related questions should go to comp.lang.python.
>
> > > this is my dir
> > > A/
> > >   a.py
> > >   __init__.py
> > >   B/
> > >   __init__.py
> > >   b.py
> > >   C/
> > >   __init__.py
> > >   c.py
> >
> > > and i wrote this as follows in c.py
> >
> > > from A.B import b
> > > blablabla
> >
> > > but the compiler warned like this:
>
> The interpreter, actually.
>
> > > Traceback (most recent call last):
> > >   File "H:\workspace\A\B\b.py", line 1, in 
> > > from A.C import c
> > > ImportError: No module named A.C
> >
> > >  so what's the matter ? should i do sth in sys.path or
> > > someelse?
>
> What you need is to have the directory *containing* A in your
> sys.path, but it's usually better not to mess with sys.path directly -
> setting your PYTHON_PATH environnment variable would be better.
>
> Also, remember that 1/ the current working directory is automagically
> inserted in your sys.path and 2/ Python now has relative imports.
>
>
>
> > > i hope sb can help me with it thanks
> >
> >
> > yes, add directory A to sys.path
>
> And this is why it's better to ask python-related questions on
> comp.lang.py. Nope, adding A to sys.path will NOT cure the problem -
> it's the directory containing A that needs to be in sys.path.
>
> --
> 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: a rookie problem about 'Modules'

2011-03-02 Thread xie he
thank you so much

2011/3/1 Bill Liao 

> On Tuesday, March 1, 2011, iRick  wrote:
> > hi,i'm a freshman for python. i got a problem about "Modules"
> > this is my dir
> > A/
> >   a.py
> >   __init__.py
> >   B/
> >   __init__.py
> >   b.py
> >   C/
> >   __init__.py
> >   c.py
> >
> > and i wrote this as follows in c.py
> >
> > from A.B import b
> > blablabla
> >
> > but the compiler warned like this:
> >
> > Traceback (most recent call last):
> >   File "H:\workspace\A\B\b.py", line 1, in 
> > from A.C import c
> > ImportError: No module named A.C
> >
> >
> >  so what's the matter ? should i do sth in sys.path or
> > someelse?
> >
> > i hope sb can help me with it 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.
> >
> >
>
> yes, add directory A to sys.path
>
> --
> *If the dream is BIG enough,the facts don't count!*
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: How to reduce DB queries?

2011-03-02 Thread galago
That's nice. I must check it.

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