Re: Parsing / Deserializing a JSON String

2009-09-06 Thread J. Clifford Dyer



On Sat, 2009-09-05 at 16:12 -0700, Eric wrote:
> Thank you for your input.  I tried what you suggested by first just
> trying to loop through the data like so:
> 
> "
> test_output = 0
> for obj in serializers.deserialize('json', gantt_data)['ganttgroups']:
> test_output = test_output + 1
> "
> 
> This generated the following error:
> 
>  "'generator' object is unsubscriptable"
> 

Huh.  Okay.  I didn't realize deserialize would return a generator.

> I tried changing it slightly,  moving "['ganttgroups']" inside the
> brackets, to this:
> 
> "
> test_test_output = 0
> for obj in serializers.deserialize('json', gantt_data['ganttgroups']):
> test_output = test_output + 1
> "
> 
> This generated the error I originally received:
> 
> "string indices must be integers"
> 

Yes.  Now you're trying to subscript gantt_data before you deserialize
it.  As you know, gantt_data is a json string.  Hence the error.

> I am just so new to this that I'm not sure where to go from here. Do
> you have any other suggestions as to what I may be doing wrong?
> Again, any help with this would be greatly appreciated.
> 

Well, the first thing you need to do is figure out what you have to work
with.  You know now that deserializer returns a generator, so try
looping over it to see what it yields each time around: 

for obj in serializers.deserialize('json', gantt_data):
print '---'
print type(obj) 
print obj

That should give you a hint how to proceed.  If you need more clues,
then add:

print dir(obj)
print help(obj)

That will give you some hints as to what you can do with obj.


> 
> 
> 
> On Sep 3, 1:09 pm, "J. Cliff Dyer"  wrote:
> > I suspect your error is hiding in .  What do you expect
> > obj to be?  Your JSON should return a big dictionary with one key
> > ("ganttgroups").  When you iterate over a dictionary in python, you get
> > the keys of that dictionary.  In this case, the string "ganttgroups".
> > You may be doing the following:
> >
> > for obj in serializers.deserialize("json", gantt_data):
> > do_something_to(obj['gantts'])
> >
> > which returns an error, because it evaluates to "ganttgroups"['gantts']
> > (which would give you the error you see.
> >
> > What you want is more like:
> >
> > for obj in serializers.deserialize('json', gantt_data)['ganttgroups']:
> > start = obj['start']
> > for gantt in obj['gantts']:
> > for row in gantt['rows']:
> > print row['own']
> >
> > In short, you're getting your dicts and lists mixed up, or your keys and
> > values.
> >
> > Cheers,
> > Cliff
> >
> > On Wed, 2009-09-02 at 10:40 -0700, Eric wrote:
> > > I forgot to mention that I am trying to deserialize the data as
> > > follows:
> >
> > > "
> > > ...
> > > gantt_data = request.POST.get('ganttdata')
> >
> > > for obj in serializers.deserialize("json", gantt_data):
> > > 
> > > ...
> > > "
> >
> > > On Sep 2, 10:37 am, Eric  wrote:
> > > > Hi,
> > > > I am attempting to parse a json string passed to my view via a form
> > > > post.   A simple example of my json structure is as follows (indented
> > > > for readability):
> >
> > > > {
> > > > "ganttgroups":[
> > > > {
> > > > "gantts":[
> > > > {
> > > > "rows":[
> > > > {"stt":1, "end":2, "ttl":"test row - gr1 ga1
> > > > ta1",  "own":"Tim Johnson"},
> > > > {"stt":2, "end":3, "ttl":"my row (g1 t2)",
> > > > "own":"John Doe"},
> > > > {"stt":1, "end":2, "ttl":"test row - gr1 ga1
> > > > ta3", "own":"Mary Smith"}
> > > > ]
> > > > },
> > > > {
> > > > "rows":[
> > > > {"stt":1, "end":2, "ttl":"My 4th task",
> > > > "own":"Eric Johnson"},
> > > > {"stt":1, "end":2, "ttl":"my row (g2 t2)",
> > > > "own":"Jeff Smith"},
> > > > {"stt":1, "end":2, "ttl":"test row - gr1 ga2
> > > > t3", "own":"Bill Baker"}
> > > > ]
> > > > }
> > > > ],
> > > > "start":"2009-1-01"
> > > > }
> > > > ,{
> > > > "gantts":[
> > > > {
> > > > "rows":[
> > > > {"stt":1, "end":2, "ttl":"row - gr2 ga1 t1",
> > > > "own":"Ted Tillman"},
> > > > {"stt":1, "end":2, "ttl":"row - gr2 ga1 t2",
> > > > "own":"Kim Crane"},
> > > > {"stt":1, "end":2, "ttl":"row - gr2 ga1 t3",
> > > > "own":"Bob Barker"}
> > > > ]
> > > > }
> > > > ],
> > > > "start":"2009-1-01"
> > > > }
> > > > ]
> >
> > > > }
> >
> > > > I would like to parse it so that I can loop over the pairs/arrays to
> > > > access the data. When I try to deserialize the data, I get the django
> > > > error "string indices must be integers". Can anybo

Re: Unit testing views.

2009-07-11 Thread J. Clifford Dyer

Woot!  Thank you.  I'll be pestering my sysadmins about that starting
with our Tuesday meeting this week. :)

Cheers,
Cliff


On Sat, 2009-07-11 at 22:32 +0800, Russell Keith-Magee wrote:
> On Fri, Jul 10, 2009 at 1:02 PM, J. Clifford Dyer 
> wrote:
> >
> > On Fri, 2009-07-10 at 07:58 +0800, Russell Keith-Magee wrote:
> >> On Fri, Jul 10, 2009 at 3:23 AM, J. Cliff Dyer wrote:
> >> >
> > I am using the django testcase, but without fixtures, because loading
> > fixtures is busted when you use a m2m relationship defined with an
> > explicit through table.  Ticket #11107 addresses this, and I've written
> > a patch for it which is marked ready for checkin, but with the push to
> > 1.1, it hasn't gotten patched.  We will backport the patch, but for
> > various reasons, mostly having to do with support and funding, I'm loath
> > to get my sysadmins to patch it until it's in trunk somewhere.
> >
> > So in the meantime, the DB just has one object in it, which I'm creating
> > manually in setUp.
> 
> Since you asked so nicely, and since you've done a great job making
> the ticket easy to understand, I've slipped your fix for #11107 into
> trunk as of [11215], and the 1.0.X branch as of [11216] (and, for good
> measure, your name into the AUTHORS file).
> 
> Now you don't have an excuse for not upgrading :-)
> 
> Yours,
> Russ Magee %-)
> 
> > 


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



Re: Unit testing views.

2009-07-09 Thread J. Clifford Dyer

On Fri, 2009-07-10 at 07:58 +0800, Russell Keith-Magee wrote:
> On Fri, Jul 10, 2009 at 3:23 AM, J. Cliff Dyer wrote:
> >
> > I'm trying to get my django site under tests.  I've started testing my
> > pages using Client('url/to/my/page'), but I noticed that each test takes
> > about a second to run (just to get a response code for the page--very
> > basic tests).
> 
> Are you using Django v1.1 or v1.0, and are you using Django's TestCase
> or the native unittest TestCase? The reason I ask is that the delay
> may be caused by the flushing of the database at the start of the
> test, rather than the client view invocation itself. Django v1.1
> improved this flushing time for databases that support transactions
> and rollbacks, but it will still be observable.
> 

I'm using 1.0.  I'll upgrade to 1.1 when I can, but for now I'm stuck
here.

> Python native unittests will always run much faster, since they have
> no setup/teardown overhead - but you also lose the nice fruit that
> Django's TestCase provides. However, you can reproduce that fruit -
> manually configure test fixtures, the client, etc - if test speed is a
> particular concern.
> 

I am using the django testcase, but without fixtures, because loading
fixtures is busted when you use a m2m relationship defined with an
explicit through table.  Ticket #11107 addresses this, and I've written
a patch for it which is marked ready for checkin, but with the push to
1.1, it hasn't gotten patched.  We will backport the patch, but for
various reasons, mostly having to do with support and funding, I'm loath
to get my sysadmins to patch it until it's in trunk somewhere.  

So in the meantime, the DB just has one object in it, which I'm creating
manually in setUp.

> > First of all, it seems like the client go through all the usual
> > apparatus of the django framework, including URLs, views, middlewares,
> > and templates.  Is this the case?
> 
> Correct. The test client is an attempt to validate the full stack for
> an installed view.
> 
> > This is useful, but also more of a functional test than a unit test.
> > I'd like to get tests going that can run faster, and properly test only
> > the view in question.  Does django provide any conveniences for this?
> 
> There isn't one built in right now, but there is an open ticket [1]
> that references a snippet that can help create mock Request objects.
> This snippet has been integrated as part of the GSoC project on
> testing, so it should be in trunk in the 1.2 timeframe.
> 
> [1] http://code.djangoproject.com/ticket/9002
> 

Oh cool.  That might be just the thing.  I'll take a closer look in the
morning.  And at the related snippet as well.

> > Failing that, I can probably manually instantiate a Request object, just
> > call the view function, and test the condition of the response object,
> > but I wanted to get some feedback on what others are doing, too.
> 
> This approach is also plausible.
> 
> Yours,
> Russ Magee %-)
> 
> > 


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



Re: Basic concept for templatetag using node and parser

2008-11-14 Thread J. Clifford Dyer

On Fri, 2008-11-14 at 16:59 +0530, suganthi saravanan wrote:
> Here i have customized the class in the templatetags folder and i have
> render too. Using the function also i have called the parser function
> and return the node object...
> 
> I have created the template also
> 
> How to call in the urls.py 
> 
> 
Do you mean to say that your trouble is not with the template tag, but
in rendering a template?  That is no different with or without a
templatetag.
> 
> Suggest me.
> 
http://docs.djangoproject.com/en/dev/intro/tutorial03/#intro-tutorial03

In particular, read the section titled "Design your URLs" and read the
code snippet under "Write views that actually do something."


If that doesn't help, you'll need to post some code, particularly, your
template, your view, and your urls.py file.

Cheers,
Cliff




--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: a problem with djikiki

2008-05-25 Thread J. Clifford Dyer

That might be a problem with your urls.py file.  An extra comma
somewhere, perhaps.

Also, what version of django are you using?

Cheers,
Cliff


On Sat, 2008-05-24 at 06:53 -0700, Qiang wrote:
> anyone have used the djikiki,a django wiki engine?
> i want to write a wiki engine with django like the djikiki.i installed
> the Djikiki.but i encounter a problem.
> i execute manage.py runserver there is no error.then i check the
> http://127.0.0.1:8000/admin. the django give me a trackback like this
> below. i want konw what wrong with it? how can i fix it? thanks
> 
> 
> TypeError at /admin/
> __init__() takes at most 4 arguments (5 given)
> Request Method:   GET
> Request URL:  http://127.0.0.1:8000/admin/
> Exception Type:   TypeError
> Exception Value:  __init__() takes at most 4 arguments (5 given)
> Exception Location:   D:\Python\Lib\site-packages\django\conf\urls
> \defaults.py in patterns, line 18
> > 


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: alternative to (r'^house/edit/(\d+)/$',ediHouse)?

2008-04-12 Thread J. Clifford Dyer

Heh.  It should also be pointed out that security is not obfuscation.
If your slug is a social security number, I don't care if you're using a
one time pad for authentication, you're still going to have social
security numbers in your browser history for the world to see.  :)  A
mix of obfuscation and security is a wise course of action.

Cheers,
Cliff

On Sat, 2008-04-12 at 11:28 -0700, ydjango wrote:
> Agreed, for MLS records, newspaper stories, blogs entries etc. most
> likely there is no security issue with incrementing db ids in url, and
> might actually be useful in some cases as you pointed out.
> But substitute MLS for accounts, health records, employee records with
> salary information etc, and potential issue appears for sites not
> having strong data/object level authorization.
> 
> I fully agree with other people (Cliff and Ned) on this thread that
> obfuscation should not mistaken for real security. and I thank them
> for pointing this out as I might have made that mistake.
> 
>  But in my case, my decision is to go with both obfuscation of id in
> url and security through proper authentication and authorization.
>  Security - more levels you have , harder and costlier it is to break.
> 
> thank
> Ashish
> 
> On Apr 12, 10:03 am, "James Bennett" <[EMAIL PROTECTED]> wrote:
> > On Fri, Apr 11, 2008 at 6:28 PM, ydjango <[EMAIL PROTECTED]> wrote:
> > >  currently I am using constructing url as /house/edit/123/
> > >  where 123 is house data base primary key for that house.
> >
> > >  Can exposing the primary key in url be any security issue?
> >
> > >  (r'^house/edit/(\d+)/$',editHouse)
> >
> > >  Is there alternative way without exposing the primary key in url?
> >
> > There is no security issue unless you care about people knowing how
> > many houses are in your system.
> >
> > However, if you're looking for an alternative, and if you have access
> > to an MLS[1] or similar database, the listing number will be unique
> > within a given MLS database. This makes for a useful identifier,
> > particularly if your users are realtors or work in the real-estate
> > industry since they'll already be familiar with the system and telling
> > them to just visit "/house//" is easy ;)
> >
> > [1]http://en.wikipedia.org/wiki/Multiple_Listing_Service
> >
> > --
> > "Bureaucrat Conrad, you are technically correct -- the best kind of 
> > correct."
> > 


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: alternative to (r'^house/edit/(\d+)/$',ediHouse)?

2008-04-12 Thread J. Clifford Dyer

If your concern is people randomly (or intentionally) hitting your URLs,
you might try creating a checksum of some kind on your primary key
concatenated with a hidden salt string.  Just make sure you keep that
checksum in an index to your DB, so performance doesn't suffer as a
result.  There is a benefit in having clean readable memorable URLs
(like using street addresses for real estate listings), but there's also
times when obfuscation is called for.  (but don't mistake it for real
security!)

Cheers,
Cliff


On Fri, 2008-04-11 at 21:24 -0700, ydjango wrote:
> Thanks, I will use Slug, which will be unique and alphanumeric but
> will not be sequential.
> 
> I agree best protection is proper authorization, and that I check on
> each page/request if the user is authorized to view this data or not.
> 
> I just hate the idea of some user just incrementing ids in url and
> trying to view the data, he is not supposed to. (eg. putting boss's
> employee id in url to see his salary)
> 
> I am restricting the data viewed through use of restrictive parameters
> in queries  which can be defeated by changing the ids in url, if I use
> primary ids.
> 
> thanks
> Ashish
> 
> 
> On Apr 11, 8:06 pm, Ned Batchelder <[EMAIL PROTECTED]> wrote:
> > Strictly speaking, exposing the primary key is not a security issue.
> > Primary keys are not a secret, just an id.  You need to secure your data
> > based on authenticated credentials and some sort of authorization system
> > that controls who can do what with each piece of data.
> >
> > Some people don't like using sequential primary keys because they are
> > exposing information about their system.  For example, with your system,
> > I can tell how many houses you have in your database by probing URLs.  I
> > guess you might consider that a security concern.  If so, use a
> > randomized slug as others have suggested.
> >
> > --Ned.http://nedbatchelder.com/blog
> >
> >
> >
> > ydjango wrote:
> > > I am displaying a list of houses and on clicking on one of the houses
> > > I want to show/edit details
> >
> > > currently I am using constructing url as /house/edit/123/
> > > where 123 is house data base primary key for that house.
> >
> > > Can exposing the primary key in url be any security issue?
> >
> > > (r'^house/edit/(\d+)/$',editHouse)
> >
> > > Is there alternative way without exposing the primary key in url?
> >
> > > Ashish
> >
> > --
> > Ned Batchelder,http://nedbatchelder.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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Unexpected TypeError in m2m relationship

2008-03-30 Thread J. Clifford Dyer

On Wed, 2008-03-26 at 19:11 -0400, Karen Tracey wrote:
> On Wed, Mar 26, 2008 at 5:16 PM, J. Cliff Dyer <[EMAIL PROTECTED]>
> wrote:
> 
> 
> So it did.  I had stripped down my original one to get rid of
> a couple
> hundred lines of unimportant cruft, but accidentally created
> some
> inconsistencies.  However, I ran it again before submitting
> and didn't
> get any errors except the one I mentioned before.  I just now
> went in
> and deleted all my .pyc files and tried again, and still got
> the
> TypeError I reported originally.
> 
> However, just to be sure, I cleaned up the models, deleted the
> pyc
> again, and re-dpasted my models and a fresh interactive
> session.
> 
> http://dpaste.com/41467/ -- models.py
> http://dpaste.com/41468/ -- complete interactive session (via
> django's
> manage.py shell)
> 
> Python 2.3.4 (#1, Nov 20 2007, 15:18:15)
> 
> >>> django.VERSION
> (0, 96, None)
> 
> Running on RHEL5 with a MySQL db.
> 
> Thanks for your patience.
> 
> Well I can still take your posted model file, simply add "class Admin:
> pass" to the models so I can dummy up some data in the admin, and then
> run your interactive session without error.  But, I am using Python
> 2.5, not 2.3.  Searching for problems like this in Django's tracker
> revealed this:
> 
> http://code.djangoproject.com/ticket/3894
> 
> which looks pretty similar and mentions Python 2.3 specifically as a
> problem.  It was closed as a dup of this:
> 
> http://code.djangoproject.com/ticket/1796
> 
> which has a looong history but ultimately seems to have been
> fixed by changeset 5919.  Unfortunately since you are running 0.96
> (tagged around revision 4810), you don't have that fix.  Can you
> consider upgrading either to a later Python or the SVN version of
> Django?
> 
> Karen

Karen,

Thanks for the pointer.  I think that bug is the issue here.  I'm not
sure if I can get trunk installed or not.  It's not impossible, but it
will be a challenge, persuading the sysadmins.  I'll give that a shot,
and if it doesn't work, I don't think it'll kill me to explicitly define
an association table with FKs back to each of the other tables.  If I do
it in such a way that it uses the same table and column names as a m2m,
it should save me some work if we do use many to many later.



Cheers,
Cliff




--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: SQL Join

2008-02-13 Thread J. Clifford Dyer

The type field on Membership rules out m2m.  There's a patch in the
works (6095) to address this, and it could use testing, if you'd like to
try it out.

Alternatively, set up a many to one from membership to user, and from
membership to group, and call the backrefs "groups" and "users"
respectively.

User.groups.group.all() gives you the groups associated with the user
table.
Group.users.user.all() gives you the users associated with the group
table.

It looks like Message should have a foreign key to Membership rather
than separate ones to User and Group, if I'm reading your intentions
correctly.

Cheers,
Cliff



On Tue, 2008-02-12 at 23:48 -0600, Alex Ezell wrote:
> This doesn't answer your question directly, but wouldn't many-to-many
> fields help a bit here?
> 
> http://www.djangoproject.com/documentation/model-api/#many-to-many-relationships
> 
> Sorry if you've already thought about this and dismissed it.
> 
> /alex
> 
> On Feb 12, 2008 11:41 PM, Gus <[EMAIL PROTECTED]> wrote:
> >
> > Hi all,
> > I have something like:
> >
> > Class User
> >  id
> >
> > Class Group
> >  id
> >
> > Class Membership
> >  id
> >  group fk
> >  user fk
> >  type char1
> >
> > Class Message
> >  id
> >  group fk
> >  user fk
> >
> > I'm a little confused about how to do this join from the django db
> > api:
> >
> > select message.* from message, membership
> >  where message.group_id = membership.group_id
> >  AND message.user_id = membership.user_id
> >  AND membership.type <> 'B'
> >
> > I basically want all the messages where the related membership type is
> > not 'B'...
> >
> > any help would be much appreciated
> >
> > >
> >
> 
> > 


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: template UnicodeDecodeError at / 'utf8' codec can't decode byte 0xa9 in position 1393: unexpected code byte

2008-02-13 Thread J. Clifford Dyer

0xA9 is the codepoint for the copyright symbol, but in UTF-8, characters
above 0x7F are not encoded with their codepoint value.  That means your
documents are probably encoded in ISO-8859-1 or ISO-8859-15.  So as per
Malcolm's advice, you should either re-save your templates in UTF-8, or
tell Django to expect ISO-8859-1 or -15, depending on your needs.

Cheers,
Cliff

On Tue, 2008-02-12 at 16:18 -0800, Steve wrote:
> Hi,
> I get this error:
> UnicodeDecodeError at / 'utf8' codec can't decode byte 0xa9 in
> position 1393: unexpected code byte
> The string that could not be encoded/decoded was: ight � 2006
> 
> The part of the static template it is complaining about is the ©
> character:
> 
> Copyright © 2006-2008 .. 
> 
> How do I get the © character translated correctly?
> 
> Thanks
> Steve
> > 


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Database?

2008-02-10 Thread J. Clifford Dyer


On Sat, 2008-02-09 at 23:19 -0800, waltbrad wrote:
> Hi there. I'm a python novice, getting into the Mark Lutz tome. I'm
> pretty enthusiastic about python and when I found out that it could be
> used in website development I had to look into to Django, (mainly
> because of the Satchmo project).  So, I actually got Django installed
> and got the webserver running, but then the tutorial started talking
> about a database.
> 
> I learned a dab of SQL a few months ago, but haven't used it since. Am
> I going to have to put learning Django on hold until I re-familiarize
> myself with SQL?  If so, do you know a good tutorial? The one that I
> used was mixed in with PHP, a language that really gave me a headache.
> 
> Or, can I go ahead with your tutorial without SQL and learn something
> about how Django helps with HTML and scripting?
> 

You will find much in the tutorial about Django's DB-API, which
translates DB queries into python syntax.  You can certainly get started
without brushing up your SQL, and much more easily if you have some
acquaintance with the basic concepts of SQL from before.  In
django-land, SQL isn't needed until your needs get more complicated than
the DB-API can reasonably handle.

> Thanks.

Cheers,
Cliff


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Newbie Question

2008-01-30 Thread J. Clifford Dyer


On Wed, 2008-01-30 at 23:01 +, Tim Sawyer wrote:
> Thanks everyone, I've been reading my Python In a Nutshell ("covers python 
> 2.2!") and it's reminded me of what I've forgotten!
> 
> Any suggestions for good books?  Was going to get the django book and the 
> O'Reilly Python Cookbook.
> 
> On Tuesday 29 Jan 2008, Ivan Illarionov wrote:
> > or, better:
> >def name(self):
> > return '%s %s' % (self.forenames, self.surname)
> 
> why is this "better"?  Performance or just clearer code?

"Better" because, for one thing, it's more robust.  

py>>> a = 'Hello'
py>>> b = 'World'
py>>> a + ' ' + b
'Hello World'
py>>> '%s %s' % (a, b)
'Hello World'
py>>> b = 4
py>>> a + ' ' + b
Traceback (most recent call last):
  File "", line 1, in 
a + ' ' + b
TypeError: cannot concatenate 'str' and 'int' objects
py>>> '%s %s' % (a, b)
'Hello 4'



--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: multilingual projects in django...

2008-01-26 Thread J. Clifford Dyer


On Sat, 2008-01-26 at 04:40 -0800, halukdogan wrote:
> hello
> 
> i'm trying to develop a multilingual web app with django. i've
> acchieved making django translate the messages in the views.py but it
> does not translate the messages in the template files.
> my message file for English is:
> 
> #: html/anasayfa.html:9
> #, fuzzy
> msgid "Hatali Giris"
> msgstr "Not Authorized"
> 
> and my template is:
> {% trans "Hatali Giris" %}
> 
> when i test it, I see that it doesn't translate the original message
> to "Not Authorized". what's wrong here?
> 
> thanks.

Did you: 

1) Compile your .mo files to .po files?
2) {% load i18n %} at the top of your template?
3) Restart your server?

Cheers,
Cliff



--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Form validation and clean_data

2008-01-23 Thread J. Clifford Dyer


On Wed, 2008-01-23 at 22:53 +, Andrew Doades wrote:
> Cheers,
> 
> That was basically the question, what do i put in that to field so the 
> what I email address I enter to the to field is where the message is 
> sent to!
> 
> Rajesh Dhawan wrote:
> >
> > On Jan 23, 5:11 pm, Andrew Doades <[EMAIL PROTECTED]> wrote:
> >   
> >> I now have this as the view:
> >> if request.method == 'POST':
> >> form = ContactForm(request.POST)
> >> if form.is_valid():
> >> topic = form.cleaned_data['topic']
> >> message = form.cleaned_data['message']
> >> to = form.cleaned_data.get('to')
> >> sender = form.cleaned_data.get('sender')
> >> send_mail(
> >> 'message, topic: %s' % topic,
> >> message, sender,
> >> ['to']
> >> )
> >>
> >> I need to have to bottom fields to read what is entered into the ' to '
> >> field, I thought something like % to   or something would do the trick!?
> >> 
> >
> > I am not sure I understand the question. However, that ['to'] should
> > instead be [to] in the send_mail() call.
> > >
> >   

Your emails are very difficult to understand.  Please proofread them
before hitting the send button, and adjust your formatting and/or code
to make it clear when you are referring to code, and when you are just
writing.  The ambiguous use of the word/variable "to" in your message
from 5:11 would be cleared up if you renamed the variable "recipient",
or something similar.  Your more recent contains one run on sentence
that doesn't even make sense if you correct the run on.  Rajesh's answer
should help with your problem.  Remove the quotes from your variable
name (to) in the list you pass to send_mail().

Cheers,
Cliff


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Question re: defining nature of relationship with ManyToManyFields

2008-01-05 Thread J. Clifford Dyer

See ticket #6095.  

There's been quite a bit of discussion about it, including a bit on
django-dev.

Cheers,
Cliff

On Sat, 2008-01-05 at 00:32 -0800, Topher wrote:
> Okay, I found one workaround in the archives (http://groups.google.com/
> group/django-users/browse_thread/thread/11d4a135c929ab7d).  The
> workaround is to instantiate the mapping as a model class in and of
> itself, e.g.:
> 
> class MappingAlbumSong(models.Model):
>song = models.ForeignKey(Song)
>album = models.ForeignKey(Album)
>track_number = models.IntegerField()
> 
> However, this seems clunky and inelegant -- at this point it's just an
> exact duplication of the database tables, and the application loses
> some of the nice abstraction of many-to-many relationships that I saw
> as the point of using Django's model system in the first place.  It
> also makes more work on the code side since (I think) I would have to
> modify both the Album and Song models to contain a MappingAlbumSong
> field, complicating queries for data like an album's tracklist ordered
> by track number (which is the primary task I want to accomplish).
> 
> Does anyone else have ideas or suggestions?  Any help would be
> appreciated!
> 
> On Jan 4, 11:58 pm, Topher <[EMAIL PROTECTED]> wrote:
> > Hi, I am new to Django, so please forgive me if my question is very
> > basic and/or stupid.
> >
> > I would like to keep track of Song and Album models, with a many-to-
> > many relationship between the two (albums contain multiple songs, and
> > songs can appear on multiple albums).
> >
> > class Song(models.Model):
> >title = models.CharField(max_length=300)
> >
> > class Album(models.Model):
> >title = models.CharField(max_length=300)
> >tracks = models.ManyToManyField(Song)
> >
> > What I'd like to do is have the ManyToManyField have some notion of
> > what track number a song is on an album.  This isn't information that
> > can be contained in the Song model since songs are assigned different
> > track numbers on different items.  When I've dealt with such matters
> > in the past, I would set up a MySQL table with fields 'song_id',
> > 'album_id', 'track_number', and would thereby be able to do tasks like
> > getting a song's track number on any given album and getting a list of
> > songs sorted by track number.for a given album.  Is there a way to
> > accomplish these tasks in Django?  I expected some sort of ability to
> > add extra fields to the relationship table when declaring a
> > ManyToManyField, but so far have not been able to find any
> > documentation on anything like that.
> >
> > Thank you for the help!  Again, I'm new to all this, so I apologize if
> > this is covered in some bit of documentation I missed; if that's the
> > case, a link to the right page would be much appreciated.
> > 


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django... False promises?

2008-01-03 Thread J. Clifford Dyer


On Thu, 2008-01-03 at 16:07 -0800, LRP wrote:
> Ah, Django promises much, but so far has delivered nothing but Mal de
> Mar. Please tell me that there is smoother sailing beyond this patch
> of troubled waters.
> 
> 1) Picked as my nautical chart The Django Book... Must be
> authoritative, right?
> 

Should be a pretty good choice.  I haven't received my copy yet, though,
so I can't say for sure.

> 2) We've barely cast moorings and into Chapter 2 when The Book tells
> me to pick a database. Fine. I have an affinity for Postgres. Tells me
> to find and install pyscopg. OK, I find it, try to install it
> according to instructions. Get mysterious error message. Double check
> all my work. No help. Post problem to this fine forum. No response.
> 
> Now that's nervous making. On two counts.
> 

Subtract one count for the helpful reply you received from Karen Tracey
on Wed, 2 Jan 2008 at 07:35:38 -0500.  Subtract the other count, because
the seaworthiness of your DB installation ought not to reflect on the
fine developers of Django.

If you didn't see the reply, maybe your spam blocker trapped it.  But
you can check the google group if you like:
http://groups.google.com/group/django-users/

> 3) Ah, the clouds part! Further digging leads me to discover that
> pyscopg is available as python-psycopq2 in the Debian etch
> repository.  Excellent! Aptitude loads it up in a jiffy and the sea is
> calm again!
> 
> Why didn't The Book steer me right to begin with?
> 

Did you tell the book you were running Debian Etch?  Maybe it thought
you were on Windows. ;)

> 4) I create a project. Launch the built-in web server. Success! See
> the friendly blue banner. Feeling good.
> 
Yay!

> 5) But... We sail on to Chapter 3. Create the view
> current_datetime(request) in views.py. Done. and map the view to the
> URL in urls.py as follows:
> 
> urlpatterns = patterns(",
> (r'^time/$' , current_datetime),
> )
> 
> I follow the instructions meticulously.  Double-check the code. Enter
> the URL...
> 
> Shipwreck!
> 
> 6) I get the error message 'function' object has no attribute 'rindex'
> Exception location: /var/lib/python-support/python2.4/django/core/
> resolvers.py in get_mod_func, line 23
> 
> Who ordered up this "rindex?"
> 

Clearly, django/core/resolvers.py ordered up this rindex. :)  Your URL
pattern passes in the function current_datetime, while the urls.py file
calls for a string naming a function.  (rindex is a method of string
objects).  Try changing current_datetime to 'current_datetime', and make
sure the first argument to patterns is two single quotes, rather than
one double quote, as it appears above.  (or two double quotes.  It
doesn't really matter.)

> Am I expected to flounder around in the bowls of django to make this
> tub seaworthy? This newbie is beginning to feel like Django may not be
> all that seaworthy. Or maybe the chart has steered me wrong? Or could
> it be my novice seamanship? Whatever. We're barely out of harbor and
> the good ship is leaking like a sieve.
> 

Nope.  Just ask when you get stuck.  Folks are pretty friendly.

> And so, I put this note in a bottle and cast it to the waves. Please
> tell me how I can caulk the leaky seams, continue afloat, and earn my
> sea legs.
> 
> And please reassure me that it's worth it.
> 

It's worth it.  A couple error messages in getting the configuration
right are most assuredly worth it.

> Many thanks,
> 
> Lloyd
> 
> 

No trouble at all.  I'm fairly new to Django myself, so don't assume my
advice is authoritative either, but hopefully it'll point you in the
right direction.  If it doesn't, come on back, and ask again.

Cheers,
Cliff



--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: stuck with tutorial 3 at - Write views that actually do something

2007-12-14 Thread J. Clifford Dyer

On Fri, Dec 14, 2007 at 01:01:37PM -0800, haver wrote regarding stuck with 
tutorial 3 at - Write views that actually do something:
> 
> 
> Hi All,
> 
> I started with django and went through 2.5 tutorials relatively
> painless, but nevertheless I stuck on tutorial #3. I tried to modify
> regular expression, but error getting more complecated.
> help needed fixed the urls.py (my guess)
> thanks,
> 
> Vadim
> 
> Error message:
> Request Method: GET
> Request URL: http://localhost:8000/polls/index.html
> 
> Using the URLconf defined in mysite.urls, Django tried these URL
> patterns, in this order:
> 
> ^polls/$
> ^polls/(?P\d+)/$
> ^polls/(?P\d+)/results/$
> ^polls/(?P\d+)/vote/$
> The current URL, polls/index.html, didn't match any of these.
> 

The $ means match the end of the url.  So

^foo/$ 

means match a url that begins and ends with "foo/".  

Which of your URL regular expressions would you expect to match 
polls/index.html? 

Assuming you want your index to show the list of polls, drop index.html from 
the URL in your browser.  If you need index.html there for legacy reasons, 
change your urls.py file to include index.html before the $.  For example:

^polls/index.html$

But then you won't match unless you have index.html in your URL, which is 
probably even worse.

If you aren't dealing with a legacy site, I would just drop the index.html.  It 
just makes your URLs uglier, and less accurate (because you aren't actually 
serving up flat HTML).

Cheers,
Cliff


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



x|add:-1 in templates doesn't work as I expect.

2007-12-06 Thread J. Clifford Dyer

Hello.  

I'm trying to get a template to render previous and next links on a series of 
pages, as follows.

Previous | 
Next

And I've come across some unexpected behavior.  The first line does not work 
(add:-1), while the second line does.  The first line throws a 
TemplateSyntaxError ("add requires 1 arguments, 0 provided").  It works if I 
change it to {{ position|add:"-1" }}, but that strikes me as vaguely crappy, 
especially since the positive version works as an int.  Also curious if this is 
the same issue as the one had by ifequal and ifnotequal in ticket #3670.  

Anybody else seen this issue?

Cheers,
Cliff

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: making two-column table from one-column data

2007-12-02 Thread J. Clifford Dyer


On Sun, 2007-12-02 at 03:05 -0800, andrej kesely wrote:
> hi,
> i have small question:
> suppose i have data in QuerySet - ['A', 'B', 'C', 'D', 'E', 'F',
> 'G'].
> I want make from this set two-column table in my template:
> 
>   AB
>   CD
>   EF
>   G
> 
> What is the fastest way to do it? I don't want split the QuerySet in
> my views to something like this: [(A, B), (C, D)...] etc.
> 
> Thanks,
> Andrej Kesely

Can you just pass in QuerySet[::2] and QuerySet[1::2]?

Cheers,
Cliff



--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Many to many column naming in 1.0?

2007-11-30 Thread J. Clifford Dyer

On Fri, Nov 30, 2007 at 08:16:17AM -0600, Malcolm Tredinnick wrote regarding 
Re: Many to many column naming in 1.0?:
> 
> On Fri, 2007-11-30 at 07:07 -0500, J. Clifford Dyer wrote:
> > Hey all,
> > 
> > Does anyone know if there are plans to include this patch (or similar
> > functionality) in Django 1.0?
> > 
> > http://code.djangoproject.com/ticket/785
> > 
> > It's a relatively simple change, breaking no backwards compatibility,
> > and it goes a long way to making it easier to integrate legacy DBs into
> > django projects.  
> 
> It's probably not unreasonable. The concept has always been sound; it's
> only the implementation that has needed a little work. Looking at the
> recent comments there, it's getting closer.
> 
> Malcolm
> 
> 


Looking at that patch and the surrounding code is my first sally into the guts 
of django, so I may not know what I'm talking about. 


In addition to defining attributes db_self_column and db_related_column to 
explicitly name the columns in a ManyToManyField table, would there need to be 
a third attribute for explicitly naming the primary key column?  

More generally, what needs to be done on the existing patch?  I may try to do 
something with it during the sprint, if there's any way I could be helpful.

Cheers,
Cliff

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Many to many column naming in 1.0?

2007-11-30 Thread J. Clifford Dyer

Hey all,

Does anyone know if there are plans to include this patch (or similar
functionality) in Django 1.0?

http://code.djangoproject.com/ticket/785

It's a relatively simple change, breaking no backwards compatibility,
and it goes a long way to making it easier to integrate legacy DBs into
django projects.  

Cheers,
Cliff


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---