Convenient way to get dynamic names for formset fields?

2009-03-08 Thread Todd O'Bryan

I'm trying to create multiple choice questions with variable numbers
of answers. I have a Question model and an Answer model with a
ForeignKey back to Question.

I'd like to display the question in a form as:

Text : ___
A: ___
B: ___
C: ___
D: ___
E: ___

where each blank represent the text of the question and the text of
each of the possible answers.

If I use formsets, I can't see any way to override the display of the
field name for A-E, so I get

Text: __
Answer text: ___
Answer text: ___
Answer text: ___
Answer text: ___
Answer text: ___

I know that I can fix this in the template, but that's brittle in the
sense that calling formset.as_p or formset.as_table won't pick up the
behavior.

Is there any way to do this, or am I trying to follow DRY so
religiously that I'm going to end up wandering in the desert instead
of getting something done?

Thanks,
Todd

--~--~-~--~~~---~--~~
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: trouble with Django and javascript

2009-02-01 Thread Todd O'Bryan

In addition to displaying the message, it's also submitting the form,
so you see the text for a second and then the form reloads.

Change the  instead of "submit" and see if that helps.

Todd

On Sun, Feb 1, 2009 at 6:05 PM, min  wrote:
>
> First I  have a form:
>
> class TestForm(forms.Form):
>  name = forms.CharField( max_length=30 )
>  age = forms.CharField( max_length=30 )
>
> Then in the views.py:
>
> def Test_page(request):
>
>  form = TestForm()
>  variables = RequestContext(request, {
>'form': form,
>  })
>  return render_to_response('Test.html', variables)
>
> In the temlates file, I want to add a iframe and a submit button. When
> the submit button was clicked, some word will appear in the iframe.
> The following code is the Test.html:
>
> 
> Test Result Page
> 
>  
>  function test(){
>  var iframe = document.getElementById
> ("test");
>  var d = iframe.contentDocument;
>  d.body.innerHTML = "This is a test";
>  }
>  
> 
> 
>   
>Name:{{form.name}}
>age: {{form.age}}
>
>
>   
> 
> 
>
> Now, the problem is that, when I clicked the submit button, the text
> of "This is a test" will display in the iframe for one second, and
> then disappear. Is there any one know what's wrong with my code?
>
> thanks
> min
> >
>

--~--~-~--~~~---~--~~
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 question: filtering objects by date

2009-02-01 Thread Todd O'Bryan

How about:

items = Item.objects.filter(categories=category, expire_date__gt=today)

?

Todd

On Sun, Feb 1, 2009 at 2:04 PM, KJ  wrote:
>
> Hi, I want to filter objects based on whether they have expired or
> not. Each object has an expiration date. Right now, I am getting all
> the objects via this line:
>items = Item.objects.filter(categories=category)
>
> However, I only want to get the "items" which have not expired
> (expire_date > today). How can I add that check to the filter command?
>
> I recently started with Django, so be kind :)
>
> KJ
>
> >
>

--~--~-~--~~~---~--~~
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: Session Variables as Default Form Values

2009-01-30 Thread Todd O'Bryan

You can pass data to a form class as a dictionary, so just save a
dictionary of the values in your session under some name that you'll
know to use.

On Fri, Jan 30, 2009 at 5:04 PM, Tyler Brownell  wrote:
> http://groups.google.com/group/django-users/browse_thread/thread/ed74391560c762bb
>
> On Fri, Jan 30, 2009 at 5:03 PM, Ty  wrote:
>>
>> I've went through the documentation for "modelforms" and "forms" but I
>> couldn't figure our how someone would set the default value for a form
>> field to a session variable.
>>
>> I have a checkbox in my comment form that says "remember my
>> information". After a comment is submitted and if the checkbox is
>> checked I'm saving the persons name, email address, and website in
>> session variables.
>>
>> Now I'm just trying to figure out how to get these session variables
>> to load as the default values in the form fields, if they exist.
>>
>> Can anyone point me in the right direction?
>
> >
>

--~--~-~--~~~---~--~~
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: reason for missing readline() in uploaded files?

2009-01-29 Thread Todd O'Bryan

On Thu, Jan 29, 2009 at 9:28 PM, Malcolm Tredinnick
 wrote:
>
> On Thu, 2009-01-29 at 15:40 -0500, Todd O'Bryan wrote:
>> I'm trying to validate an uploaded csv file, so I want to read the
>> first line of text and if it's not the right format, send an error
>> message. Unfortunately, neither InMemoryUploadedFile nor
>> TemporaryUploadedFile have the readline() method.
>>
>> Was that an oversight (in which case I'll create a two-line patch and
>> submit it--both StringIO and temp files support the method) or a
>> design decision with a good reason?
>
> It's a flaw in Python: what an object needs to be "file-like" is not
> well defined. Different users require different things. A file doesn't
> really need a readlines() method, except when it does, etc.
>
> There's about half a dozen tickets open for "add X, Y or Z" to the file
> stuff, so look through those first.
>
> Regards,
> Malcolm
>

OK. I proxied every file-like object method or attribute listed in the
Python docs. If something doesn't work now it's because the object
that backs the UploadedFile doesn't support it, not because we forgot
to provide a proxy to it.

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

Todd

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



reason for missing readline() in uploaded files?

2009-01-29 Thread Todd O'Bryan

I'm trying to validate an uploaded csv file, so I want to read the
first line of text and if it's not the right format, send an error
message. Unfortunately, neither InMemoryUploadedFile nor
TemporaryUploadedFile have the readline() method.

Was that an oversight (in which case I'll create a two-line patch and
submit it--both StringIO and temp files support the method) or a
design decision with a good reason?

Thanks,
Todd

--~--~-~--~~~---~--~~
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: Three table Lookup Question

2009-01-29 Thread Todd O'Bryan

I'm not sure I understand what you're asking, but

projs = Project.objects.filter(campaign__industry=x)

where x is one of 1-6 should do what you want, I think.

Is that what you were asking?

On Thu, Jan 29, 2009 at 9:54 AM, Kyle  wrote:
>
> Hello!
>
> I am trying to get a list of "Projects" based on certain "Industry".
> (My naming convention, not django's)
>
> My models look like this:
> http://dpaste.com/114308/
>
> "Project" has a foreign key to "Campaign".
>
> "Industry" also has a foreign key to "Campaign".
>
> Does it matter if both relationships are pointing to the center model
> in the data route I am trying to setup?  Like this:
>
> Project -> Campaign <- Industry
>
> If Industry = 3, and a handful of Campaigns are returned, I would like
> a list of all the Projects contained in each of the Campaigns
> returned.
>
> How do I do this with django models?
>
> >
>

--~--~-~--~~~---~--~~
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: absolute_import, app names, dots, and a bug

2009-01-29 Thread Todd O'Bryan

On Wed, Jan 28, 2009 at 11:49 PM, Malcolm Tredinnick
 wrote:
>
> On Wed, 2009-01-28 at 22:50 -0500, Karen Tracey wrote:
>>
>> No, I don't think that's an accurate representation of the status.
>> The triage state is Accepted and furthermore Malcolm even assigned it
>> to himself, meaning he's intending to fix it.  Per this comment:
>>
>> http://code.djangoproject.com/ticket/8193#comment:20
>>
>> working on the fix has revealed other problems so it is not as simple
>> as one might hope.  So it's in the queue to be fixed, probably (I'm
>> just guessing) prioritized behind some 1.1 feature work.
>
> That's correct. Also, this particular thread has provided the first
> example of standard behaviour causing a problem, which is something
> that's been requested a few times in that ticket and related threads.
>
> It will be fixed for 1.1. Since we now have a case of normal Python
> usage triggering a problem, it will also be back-ported to the 1.0
> branch. All in good time.
>
> For now, not using "from __future__ ..." is an acceptable workaround.
> Live in the present, not the future for a little while. :-)

I misspoke. I should have said, "...people think it's a bug without
consequences."

I also realize my message could have been read in a demanding, annoyed
way rather than in the teasing, needling way in which I meant it. I'm
okay with living in the present. Especially since I've had four whole
days to work on Django stuff since my school district (I teach CS at
the high school level.) is closed all week because of an ice storm
that has knocked out power at about 1/3 of the schools.

Todd

P.S. One of my former students has made a few thousand dollars writing
Django sites since he graduated last May. Best advertising for my
advanced classes I've ever had. :-)

--~--~-~--~~~---~--~~
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: absolute_import, app names, dots, and a bug

2009-01-28 Thread Todd O'Bryan

On Sun, Jan 25, 2009 at 7:13 PM, Karen Tracey  wrote:
> On Sun, Jan 25, 2009 at 7:03 PM, Todd O'Bryan  wrote:
>>
>> I've been trying to convert my apps to use the relative imports from
>> __future__ and have noticed a problem. I think it may be something
>> Django is doing, but I'm not sure.
>>
>> In the __init__.py module inside an app, I have
>>
>> from __future__ import absolute_import
>>
>> from ..another_app.models import blah
>>
>> This causes an error when I try to load a page that uses it, with the
>> error message:
>>
>> No module named another_app.models
>>
>> I looked up the absolute_import PEP, and it uses the __name__ value to
>> figure out relative imports. So I tried printing __name__. When the
>> file is first imported, the name is 'project.app', but later on, after
>> the server starts running (and when it causes the error in
>> page-loading) the name has changed to 'project.app.' with an extra dot
>> at the end.
>>
>> Is Django doing this or is it happening in the bowels of my code
>> somewhere? If Django is doing this, does it have to since it will mess
>> up absolute_import users?
>
> Sounds related to:
>
> http://code.djangoproject.com/ticket/8193
>
> Karen
>

That's exactly what it is, and that hasn't been fixed because people
don't think it's really a bug.

OK, just note that it will be a bug at some point in the future,
because it  doesn't work with absolute_import. Especially if we want
apps to be self-contained (i.e., be able to do relative imports rather
than absolute imports), this will eventually become an issue.

Thanks for pointing out the issue, Karen. I just decided to hold off
on absolute_import, even though I think it makes imports much
prettier. :-)

Todd

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



absolute_import, app names, dots, and a bug

2009-01-25 Thread Todd O'Bryan

I've been trying to convert my apps to use the relative imports from
__future__ and have noticed a problem. I think it may be something
Django is doing, but I'm not sure.

In the __init__.py module inside an app, I have

from __future__ import absolute_import

from ..another_app.models import blah

This causes an error when I try to load a page that uses it, with the
error message:

No module named another_app.models

I looked up the absolute_import PEP, and it uses the __name__ value to
figure out relative imports. So I tried printing __name__. When the
file is first imported, the name is 'project.app', but later on, after
the server starts running (and when it causes the error in
page-loading) the name has changed to 'project.app.' with an extra dot
at the end.

Is Django doing this or is it happening in the bowels of my code
somewhere? If Django is doing this, does it have to since it will mess
up absolute_import users?

Thanks,
Todd

--~--~-~--~~~---~--~~
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: Speeding up the tests, what am I missing?

2009-01-06 Thread Todd O'Bryan

On Tue, Jan 6, 2009 at 6:23 PM, Russell Keith-Magee
 wrote:
>
> On Wed, Jan 7, 2009 at 4:51 AM, Todd O'Bryan  wrote:
>>
>> So, I've been trying to speed up tests. Surprise. I came across a
>> fairly easy solution, so I'm sure I must be missing something. If
>> someone could tell me what I'm missing, I'd really appreciate it.
> ...
>> MyTestCaseSubclass.dirties_db = True
> ...
>> So, what am I missing? I know this doesn't deal with doctests--the db
>> gets cleaned for all of those, but does anyone see when this is just
>> going to blow up in my face?
>
> This approach will (clearly) speed up tests. I have three objections
> to the technique.
>
> The first objection is a relatively minor syntactical wart. Using a
> normal assignment to set the dirty bit means your test code is mixing
> test code with setup code. I'd rather see this sort of thing as a
> decorator, so that the test i
>
I shan't argue with you. It is less than elegant.

> The second objection is more significant: the technique is entirely
> manual, and prone to error. If you get all the dirties_db markers
> correct, your tests will be much faster; however, if you get one
> wrong, you could get all sorts of unexpected consequences, and the
> problems won't be reported in the test that actually has the incorrect
> dirty marker. The order in which tests doesn't necessarily match the
> order in which they are defined in the test case; if you run a subset
> of tests, all bets on predictable test output are off.
>
You're right, of course. But the only thing you can do wrong is mark a
test that actually dirties the database as dirties_db = False.
Changing the superclass from MyTestCase back to django.test.TestCase
should be able to determine if that's the problem. And it's not like
writing tests is that easy to begin with. I find that I screw up a
significant percentage the first time I write them, so I have to debug
my test cases just like I have to debug my code.

> The third objection is that in my experience, genuine 0-write test
> cases aren't actually that common. This will, of course, vary wildly
> depending on your particular project, but I seem to recall looking at
> this sort of change and came to the conclusion that it wouldn't
> actually speed up the Django test suite that much. Feel free to prove
> me wrong.
>
As I mentioned in the reply to Malcolm, there are some writes that I
don't care about. Since it's only within a single TestCase class, I
shouldn't need to worry about changes to the session and last_login
and such if I know I'm not testing those things. Clearly this requires
more thinking than I should have to do, but at this point I'm willing
to try the trade-off. I'll probably be back in a few weeks to tell you
it wasn't worth it. :-)

> There are some plans in place to speed up test cases using
> transactions; I'm hoping to be able to look at this once I put the
> aggregation and F() code to bed, in the next week or so.
>
This does sound exciting. I look forward to it.

Thanks for the input!
Todd

--~--~-~--~~~---~--~~
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: Speeding up the tests, what am I missing?

2009-01-06 Thread Todd O'Bryan

On Tue, Jan 6, 2009 at 6:05 PM, Malcolm Tredinnick
 wrote:
>
> On Tue, 2009-01-06 at 14:51 -0500, Todd O'Bryan wrote:
> [...]
>
>> So, what am I missing? I know this doesn't deal with doctests--the db
>> gets cleaned for all of those, but does anyone see when this is just
>> going to blow up in my face?
>
> For that to work reliably, you would need to deeply know the internals
> of Django to know which calls are going to dirty the database in some
> way. For example, if your tests simulate a user's interactions at all,
> there will be changes to the session.
>
Right. For example, every time a user logs in, the last_login gets
updated. I would say dirties_db = False in most of those cases,
because I just don't check the last_login time in my tests.

> So, sure, it's possible, although duplicates a lot of code, but it's
> also a bit fragile. Russell Keith-Magee and I have had a number of
> conversations over the past couple of years about speeding up the tests
> for Django itself and we keep looking at this one. But, at the end of
> the day, every set of non-significant tests touch the database in some
> way, with very, very few exceptions (template rendering being one such
> exception).
>
> If it works for you, sure, keep going. But when things suddenly start
> failing in interesting ways down the track (when you have 500 tests in
> your suite), expect to set aside time to debug your testing harness
> setup, rather than your tests.
>
Forewarned is forearmed. The worst that could happen is that I have to
switch from extending MyTestCase to django.test.TestCase if I can't
figure out what's causing the problem. I agree it's a little hacky,
but I have such a short attention span... :-)

> There are other plans moving along slowly to speed up the tests for some
> databases (capable databases with proper transaction support :-) ),
> wherein a lot of tests can just run inside a transaction and roll back
> at the end. But there are a few corner cases still to work out there, so
> it's not quite ready yet.
>
Looking forward to it. Thanks for the warnings--I'm sure I will get
bitten at some point.

Todd

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



Speeding up the tests, what am I missing?

2009-01-06 Thread Todd O'Bryan

So, I've been trying to speed up tests. Surprise. I came across a
fairly easy solution, so I'm sure I must be missing something. If
someone could tell me what I'm missing, I'd really appreciate it.

So, first I created my own subclass of django.test.TestCase:

class MyTestCase(django.test.TestCase):
# see code below

Then I wrote unit tests, subclassing MyTestCase

class TestParticularThing(MyTestCase):
fixtures = ['mydata', 'myotherdata.json']
dirties_db = True

def test_something(self):
TestParticularThing.dirties_db = False
resp = self.client.get('/some/url')
self.assertContains(resp, 'blah')

def test_something_else(self):
TestParticularThing.dirties_db = True
resp = self.client.post('/another/url', {'var': 'value'})
self.assertRedirects(resp, '/redirect/url')

So here's the code for MyTestCase. I just overrode the _pre_setup
method so that it checks the dirties_db attribute of the class. If it
both exists and is set to False, flushing and repopulating the db is
skipped, otherwise the db is cleaned as usual.

class MyTestCase(django.test.TestCase):
def _pre_setup(self):
"""Performs any pre-test setup. This includes:
* Flushing the database.
* If the Test Case class has a 'fixtures' member, installing the
  named fixtures.
* If the Test Case class has a 'urls' member, replace the
  ROOT_URLCONF with it.
* Clearing the mail test outbox.
"""
if not hasattr(self.__class__, 'dirties_db') or
self.__class__.dirties_db:
print "Cleaning db"
call_command('flush', verbosity=0, interactive=False)
if hasattr(self, 'fixtures'):
# We have to use this slightly awkward syntax due to the fact
# that we're using *args and **kwargs together.
call_command('loaddata', *self.fixtures, **{'verbosity': 0})
if hasattr(self.__class__, 'dirties_db'):
self.__class__.dirties_db = True
if hasattr(self, 'urls'):
self._old_root_urlconf = settings.ROOT_URLCONF
settings.ROOT_URLCONF = self.urls
clear_url_caches()
mail.outbox = []

So, to use this, add a class attribute dirties_db = True to your own
subclass of MyTestCase. In any test methods that don't dirty the db,
add:

MyTestCaseSubclass.dirties_db = False

and the next test method that's run in that class won't bother to
flush and repopulate the database. To be explicit, you can set

MyTestCaseSubclass.dirties_db = True

in methods that dirty the database, but if you forget to explicitly
set the value to False, it will be True and the db will be cleaned.

Just trying it on some model and request/response tests, I got a
speed-up from nearly a minute to less than 20 seconds for 13 tests.

So, what am I missing? I know this doesn't deal with doctests--the db
gets cleaned for all of those, but does anyone see when this is just
going to blow up in my face?

Thanks,
Todd

--~--~-~--~~~---~--~~
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: ManyToManyField contains

2008-08-18 Thread Todd O'Bryan

I seem to keep making this mistake, even though I know better.

contains only works for strings. In other words, it checks to see if a
string field contains the substring you provide. You want to use the
reverse relationship from the user, rather than a query:

myUser = User.objects.get(username='thisUsername')
classes = myUser.class_set.all()

Todd

On Sun, Aug 17, 2008 at 8:11 PM, Robert <[EMAIL PROTECTED]> wrote:
>
> Hi all,
> I'm trying to query a ManyToManyField to see whether or not it
> contains a specific type of object.
> My query is as follows:
> MyUser = User.objects.get(username='thisUsername')
> theQuery = Class.objects.filter(users__contains=myUser)
>
> but when I try to run that, i get the following error:Related Field
> has invalid lookup: contains
> Any thoughts?
> Thank you so much, any help is greatly appreciated.
> -Robert
> >
>

--~--~-~--~~~---~--~~
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 learning management application

2008-05-14 Thread Todd O'Bryan

My students and I are working on a Django system for online quizzes.
It should be finished sometime this summer. I'll post a link when we
finish it.

Todd

On Wed, May 14, 2008 at 10:35 PM, Ariel Mauricio Nunez Gomez
<[EMAIL PROTECTED]> wrote:
> Moodle and Django can coexist happily (Using same database and writing
> django models for some of the tables), That way you can take advantage of
> all the moodle functionality (Quizzes, lessons, forums) and have some
> business related code on django (Class scheduling, CRM, Billing).
>
> If you like the idea, I can post some details, I did it once.
>
> Moodle quizz module is _very_ complete, I wish we had something similar
> written by django.
>
> BTW, there was a django_quizz app post like 8 months ago on this list,
> search the archives.
>
> Regards,
> Ariel.
>
> >
>

--~--~-~--~~~---~--~~
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: files xls

2008-04-09 Thread Todd O'Bryan
There's also xlrd:

http://www.lexicon.net/sjmachin/xlrd.htm

On Wed, Apr 9, 2008 at 1:23 PM, Claudio Escudero <[EMAIL PROTECTED]> wrote:

> Thanks,
>
> I liked it.
> =)
>
> I did that tips for using pyExcelerator with the django
> Http://www.developer.com/lang/other/article.php/3727616
>
> On Wed, Apr 9, 2008 at 2:05 PM, Alex Ezell <[EMAIL PROTECTED]> wrote:
>
> >
> > On Wed, Apr 9, 2008 at 12:02 PM, Claudio Escudero <[EMAIL PROTECTED]>
> > wrote:
> >
> > > Anyone knows there is a script to do with manipulation files xls
> > (Excel)?
> >
> > Hi Claudio,
> > This is not Django specific, but there is a python module called
> > pyExcelerator, that while old, seems to work for me.
> >
> > http://sourceforge.net/projects/pyexcelerator
> >
> > /alex
> >
> >
> >
>
>
> --
> Claudio Escudero
>
> >
>

--~--~-~--~~~---~--~~
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: middleware that works with Ajax

2008-04-09 Thread Todd O'Bryan
On Wed, Apr 9, 2008 at 6:54 AM, Russell Keith-Magee <[EMAIL PROTECTED]>
wrote:

>
> On Wed, Apr 9, 2008 at 1:47 AM, andy baxter
> <[EMAIL PROTECTED]> wrote:
> >
> >  Do you mean middleware specifically written for django? If so not sure,
> >  but it might be worth looking at dojo (http://www.dojotoolkit.org/). It
> >  is a javascript toolkit which provides an API to make cross platform
> >  programming easier, and also supports ajax and a variety of widgets. I
> >  think it will be the official javascript toolkit of django at some
> point
> >  as well.
>
> No, it won't. The Core devs have said on a number of occasions that we
> aren't in the business of recommending JS toolkits, and I don't think
> that position will change any time soon.
>


Isn't some JS toolkit getting used in newforms-admin?

--~--~-~--~~~---~--~~
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: Using Django for Teaching

2008-03-31 Thread Todd O'Bryan
On Mon, Mar 31, 2008 at 12:46 AM, Kenneth Gonsalves <[EMAIL PROTECTED]>
wrote:

>
>
> On 31-Mar-08, at 9:58 AM, Todd O'Bryan wrote:
>
> > Sorry this is two weeks late (it's been a bear of a two weeks), but
> > I use Django with high school students who've done the equivalent
> > of a year of college programming--the AP Computer Science AB
> > curriculum.
>
> what age would these students be?


16- 18. Most are going to university next fall, but a few have one more year
of high school.


>
> >
> >
> > You have to be careful and you have to lead students by the nose,
> > making sure that students get HTML and basic concepts of databases,
> > but Django is a great way to get a class working together on a
> > project.
>
> do you use version control and teach them to use it? How are they at
> finding solutions through the docs, mailing lists and IRC?
>

Yes, we use version control and we've all kind of learned how to use it
together. Our SVN repository has seen some "interesting" merges. I think we
finally have a handle on how it's supposed to work, though.

They're pretty good at the docs, but have mostly stayed away from the list
and IRC. When they hit a problem and the more advanced students and I can't
figure it out either, I tend to post a question to the list or ask on IRC
myself.

Todd

--~--~-~--~~~---~--~~
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: Using Django for Teaching

2008-03-30 Thread Todd O'Bryan
Sorry this is two weeks late (it's been a bear of a two weeks), but I use
Django with high school students who've done the equivalent of a year of
college programming--the AP Computer Science AB curriculum.

We've been working on a webapp for two years that has evolved into something
with 8 apps, tens of thousands of lines of view code, several hundred
templates, and has already saved the school over $1000 by providing
functionality the administration was prepared to buy commercial software
for.

You have to be careful and you have to lead students by the nose, making
sure that students get HTML and basic concepts of databases, but Django is a
great way to get a class working together on a project.

As to taking things live, just don't. Show everyone how to run things using
the development server and only think about taking the product live at
certain milestone events.

If you'd like more info, feel free to email me.

Todd

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



GSoC idea for Django-friendly static checkers

2008-03-29 Thread Todd O'Bryan
Sorry I'm so late suggesting this, but...

Do people have a desire/see a need for a way to make Pylint or PyChecker
handle Django code more robustly? Because so many of the attributes of
Django model and form objects are given as class objects or are
auto-generated in instance creation, using a static checker on Django code
is a mess.

Would a good GSoC project involve modifying one or both of the standard
Python code checkers so that they're smarter about Django?

Or maybe everybody thinks static checking is for wimps and I should just
stop misspelling things...

Todd

P.S. I'm not a student, but I teach students who might be interested in
applying.

--~--~-~--~~~---~--~~
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: IE error when clicking the back button after a POST

2008-01-21 Thread Todd O'Bryan
Generally, you use GET when you're retrieving information from the server
and POST when you're sending information to the server (as when you're
submitting a form).

Django is designed so that, if you have GETs and POSTs for a form go to the
same URL, you can display the form on the GET branch and deal with the form
submission on the POST branch. If you then return an HttpResponseRedirect
after dealing with the submission, pressing back will not re-submit the POST
and you'll avoid lots of these problems.

In short, use GET as a default and only use POST when you're submitting a
form. (There are probably more subtle rules, but stick with these unless you
have a good reason to break them.)

Todd

On Jan 20, 2008 5:58 PM, Greg <[EMAIL PROTECTED]> wrote:

>
> Hello,
> I have a form submission where people can search by properties of my
> product (color, size, price, etc...).  We'll when they do a search a
> bunch of products are returned.  When they click on a product and then
> try to click on the back button.  In IE they receive an error:
> 'Webpage has expired'.  In looking around it seems that if I used a
> GET instead of a POST...my problem should be solved.  Does anybody
> have any experience with this problem?  Would there be any problems
> with using GET instead of POST?
>
>
> >
>

--~--~-~--~~~---~--~~
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: How to bind data to a form, and not make the validation fire

2008-01-06 Thread Todd O'Bryan

On Jan 6, 2008 11:27 AM, shabda <[EMAIL PROTECTED]> wrote:
>
> But I need the initial data to be dynamic, so I can't just do
> text = forms.CharField(widget = forms.Textarea, initial = 'sometext')
>
> I assume I can do some thing along the lines of overriding __init__
> for this form, passing the requored value from the view function and
> then using something like
> text = forms.CharField(widget = forms.Textarea, initial =
> self.page.text)
> I just can't get this to work? Any place where I can look for dynamic
> values to initial?
>
Not exactly what you're looking for, but in the neighborhood:

http://code.djangoproject.com/wiki/CookBookNewFormsDynamicFields

You want to do something like

def __init__(...):
 ...
 self.fields['text'].initial = function_to_get_my_initial_value()

HTH,
Todd

--~--~-~--~~~---~--~~
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: Can I use a underscore in my url to separate variables?

2008-01-02 Thread Todd O'Bryan

Try downloading Kodos and sticking in your regex and the string you
want to match it and see what it says.

Todd

On Jan 2, 2008 12:59 AM, Greg <[EMAIL PROTECTED]> wrote:
>
> ocgstyles,
> Tried it...still no good
>
> (r'^(?P[a-zA-Z]+)_(?P[a-zA-Z]+)/$', 'showline'),
>
>
> On Jan 1, 11:23 pm, ocgstyles <[EMAIL PROTECTED]> wrote:
> > I'm confused now too...  :-/
> >
> > Try taking out the hyphen and see what happens...
> >
> > On Jan 1, 11:45 pm, Greg <[EMAIL PROTECTED]> wrote:
> >
> > > Todd,
> > > My app works fine.  When I have the following line in my url file then
> > > everything works fine
> >
> > > (r'^(?P[\w-]+)/(?P[\w-]+)/$', 'showline'),
> >
> > > /
> >
> > > It just doesn't work with I take out the '/' and replace it with the
> > > '_'
> >
> > > On Jan 1, 10:25 pm, "Todd O'Bryan" <[EMAIL PROTECTED]> wrote:
> >
> > > > Have you added the app to your INSTALLED_APPS ?
> >
> > > > Maybe you should paste in your site's urls.py as well as the app's.
> >
> > > > On Jan 1, 2008 11:09 PM, Greg <[EMAIL PROTECTED]> wrote:
> >
> > > > > ocgstyles,
> > > > > I've tried the following combinations however I still get the Page Not
> > > > > Found error:
> >
> > > > > (r'^(?P[a-zA-Z-]+)_(?P[a-zA-Z-]+)/$', 'showline'),
> > > > > (r'^(?P[-a-zA-Z]+)_(?P[-a-zA-Z]+)/$', 'showline'),
> > > > > (r'^(?P[a-zA-Z\-]+)_(?P[a-zA-Z\-]+)/$',
> > > > > 'showline'),
> > > > > (r'^(?P[a-zA-Z_]+)_(?P[a-zA-Z_]+)/$', 'showline'),
> >
> > > > > On Jan 1, 9:52 pm, ocgstyles <[EMAIL PROTECTED]> wrote:
> > > > > > I thought you wanted to capture either words or hyphens, so I just
> > > > > > replaced \w, which also consumes underscores, with [a-zA-Z], which
> > > > > > doesn't consume the underscores.  So the new regex
> >
> > > > > > [a-zA-Z-]+
> >
> > > > > > will consume one or more letters or hyphens.  The one I replaced it
> > > > > > with should work for sprint-phone_cellphone.
> >
> > > > > > On Jan 1, 10:36 pm, Greg <[EMAIL PROTECTED]> wrote:
> >
> > > > > > > ocgstyles,
> > > > > > > I'm not sure what's going on.  What does the last '-' mean in the
> > > > > > > following code [a-zA-Z-]?  Occasionally I'm going to have the a 
> > > > > > > url
> > > > > > > that is going to have a '-' in the variable.  For 
> > > > > > > examplehttp://mysite.com/sprint-phone_cellphone.  So I'm not sure 
> > > > > > > if [a-zA-
> > > > > > > Z-] is going to work.
> >
> > > > > > > On Jan 1, 8:51 pm, ocgstyles <[EMAIL PROTECTED]> wrote:
> >
> > > > > > > > worked for me using the following:
> >
> > > > > > > > [urls.py] (i removed the single quotes around the view)
> > > > > > > > from myapp.views import showline
> > > > > > > > (r'^(?P[a-zA-Z-]+)_(?P[\w-]+)/$', showline),
> >
> > > > > > > > [views.py]
> > > > > > > > def showline(request, manufacturer, line):
> > > > > > > >return HttpResponse('manu = ' + manufacturer + 'line = 
> > > > > > > > ' +
> > > > > > > > line)
> >
> > > > > > > > Maybe the error is being generated from somewhere else?
> >
> > > > > > > > On Jan 1, 9:42 pm, Greg <[EMAIL PROTECTED]> wrote:
> >
> > > > > > > > > ocgstyles,
> > > > > > > > > I tried the following however I'm still getting a page not 
> > > > > > > > > found
> > > > > > > > > error:
> >
> > > > > > > > > (r'^(?P[a-zA-Z-]+)_(?P[\w-]+)/$', 
> > > > > > > > > 'showline'),
> >
> > > > > > > > > On Jan 1, 8:23 pm, ocgstyles <[EMAIL PROTECTED]> wrote:
> >
> > > > > > > > > > Hi Greg,
> &g

Re: Can I use a underscore in my url to separate variables?

2008-01-01 Thread Todd O'Bryan

Have you added the app to your INSTALLED_APPS ?

Maybe you should paste in your site's urls.py as well as the app's.

On Jan 1, 2008 11:09 PM, Greg <[EMAIL PROTECTED]> wrote:
>
> ocgstyles,
> I've tried the following combinations however I still get the Page Not
> Found error:
>
> (r'^(?P[a-zA-Z-]+)_(?P[a-zA-Z-]+)/$', 'showline'),
> (r'^(?P[-a-zA-Z]+)_(?P[-a-zA-Z]+)/$', 'showline'),
> (r'^(?P[a-zA-Z\-]+)_(?P[a-zA-Z\-]+)/$',
> 'showline'),
> (r'^(?P[a-zA-Z_]+)_(?P[a-zA-Z_]+)/$', 'showline'),
>
>
>
>
> On Jan 1, 9:52 pm, ocgstyles <[EMAIL PROTECTED]> wrote:
> > I thought you wanted to capture either words or hyphens, so I just
> > replaced \w, which also consumes underscores, with [a-zA-Z], which
> > doesn't consume the underscores.  So the new regex
> >
> > [a-zA-Z-]+
> >
> > will consume one or more letters or hyphens.  The one I replaced it
> > with should work for sprint-phone_cellphone.
> >
> > On Jan 1, 10:36 pm, Greg <[EMAIL PROTECTED]> wrote:
> >
> > > ocgstyles,
> > > I'm not sure what's going on.  What does the last '-' mean in the
> > > following code [a-zA-Z-]?  Occasionally I'm going to have the a url
> > > that is going to have a '-' in the variable.  For 
> > > examplehttp://mysite.com/sprint-phone_cellphone.  So I'm not sure if 
> > > [a-zA-
> > > Z-] is going to work.
> >
> > > On Jan 1, 8:51 pm, ocgstyles <[EMAIL PROTECTED]> wrote:
> >
> > > > worked for me using the following:
> >
> > > > [urls.py] (i removed the single quotes around the view)
> > > > from myapp.views import showline
> > > > (r'^(?P[a-zA-Z-]+)_(?P[\w-]+)/$', showline),
> >
> > > > [views.py]
> > > > def showline(request, manufacturer, line):
> > > >return HttpResponse('manu = ' + manufacturer + 'line = ' +
> > > > line)
> >
> > > > Maybe the error is being generated from somewhere else?
> >
> > > > On Jan 1, 9:42 pm, Greg <[EMAIL PROTECTED]> wrote:
> >
> > > > > ocgstyles,
> > > > > I tried the following however I'm still getting a page not found
> > > > > error:
> >
> > > > > (r'^(?P[a-zA-Z-]+)_(?P[\w-]+)/$', 'showline'),
> >
> > > > > On Jan 1, 8:23 pm, ocgstyles <[EMAIL PROTECTED]> wrote:
> >
> > > > > > Hi Greg,
> >
> > > > > > The problem is that "\w" is consuming the underscore.  Instead of
> > > > > > using [\w-], use [a-zA-Z-].  The pattern would then look like:
> >
> > > > > > (r'^(?P[a-zA-Z-]+)_(?P[\w-]+)/$', 'showline')
> >
> > > > > > Hope that helps.
> >
> > > > > > Keith
> >
> > > > > > On Jan 1, 9:05 pm, Greg <[EMAIL PROTECTED]> wrote:
> >
> > > > > > > Hello,
> > > > > > > I orginially had my url like this:
> >
> > > > > > > (r'^(?P[\w-]+)/(?P[\w-]+)/$', 'showline')
> >
> > > > > > > Which would work fine when going to the url 
> > > > > > > 'www.mysite.com/sprint/
> > > > > > > cellphone/'
> >
> > > > > > > //
> >
> > > > > > > However, I want to change my url structure so that all of my 
> > > > > > > pages are
> > > > > > > as close to the root as possible.  So I replaced my '/' in the url
> > > > > > > with a '_'.  Like so:
> >
> > > > > > > (r'^(?P[\w-]+)_(?P[\w-]+)/$', 'showline')
> >
> > > > > > > However, I now get a page not found whenever I view the following 
> > > > > > > url
> > > > > > > 'www.mysite.com/sprint_cellphone/'
> >
> > > > > > > 
> >
> > > > > > > Can I not replace the / with a _ in my url?
> >
> > > > > > > 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Can I use a underscore in my url to separate variables?

2008-01-01 Thread Todd O'Bryan

No, because he doesn't want it to match the underscore. I think this works:

[-a-zA-Z]

because a hyphen in the first position matches a literal hyphen.
However, to be sure, you can use a backslash

[a-zA-Z\-]

For all regex questions, I highly recommend the Kodos app. It lets you
enter Python regexes and strings and will show you exactly how they
match or don't.

http://kodos.sourceforge.net/

HTH,
Todd

On Jan 1, 2008 10:39 PM,  <[EMAIL PROTECTED]> wrote:
>
> I think that should be an underscore: [a-zA-Z_]
> Owen
>
>
> -Original Message-
> From: Greg <[EMAIL PROTECTED]>
> Sent: Tuesday, January 1, 2008 10:36pm
> To: Django users 
> Subject: Re: Can I use a underscore in my url to separate variables?
>
>
> ocgstyles,
> I'm not sure what's going on.  What does the last '-' mean in the
> following code [a-zA-Z-]?  Occasionally I'm going to have the a url
> that is going to have a '-' in the variable.  For example
> http://mysite.com/sprint-phone_cellphone.  So I'm not sure if [a-zA-
> Z-] is going to work.
>
> On Jan 1, 8:51 pm, ocgstyles <[EMAIL PROTECTED]> wrote:
> > worked for me using the following:
> >
> > [urls.py] (i removed the single quotes around the view)
> > from myapp.views import showline
> > (r'^(?P[a-zA-Z-]+)_(?P[\w-]+)/$', showline),
> >
> > [views.py]
> > def showline(request, manufacturer, line):
> >return HttpResponse('manu = ' + manufacturer + 'line = ' +
> > line)
> >
> > Maybe the error is being generated from somewhere else?
> >
> > On Jan 1, 9:42 pm, Greg <[EMAIL PROTECTED]> wrote:
> >
> > > ocgstyles,
> > > I tried the following however I'm still getting a page not found
> > > error:
> >
> > > (r'^(?P[a-zA-Z-]+)_(?P[\w-]+)/$', 'showline'),
> >
> > > On Jan 1, 8:23 pm, ocgstyles <[EMAIL PROTECTED]> wrote:
> >
> > > > Hi Greg,
> >
> > > > The problem is that "\w" is consuming the underscore.  Instead of
> > > > using [\w-], use [a-zA-Z-].  The pattern would then look like:
> >
> > > > (r'^(?P[a-zA-Z-]+)_(?P[\w-]+)/$', 'showline')
> >
> > > > Hope that helps.
> >
> > > > Keith
> >
> > > > On Jan 1, 9:05 pm, Greg <[EMAIL PROTECTED]> wrote:
> >
> > > > > Hello,
> > > > > I orginially had my url like this:
> >
> > > > > (r'^(?P[\w-]+)/(?P[\w-]+)/$', 'showline')
> >
> > > > > Which would work fine when going to the url 'www.mysite.com/sprint/
> > > > > cellphone/'
> >
> > > > > //
> >
> > > > > However, I want to change my url structure so that all of my pages are
> > > > > as close to the root as possible.  So I replaced my '/' in the url
> > > > > with a '_'.  Like so:
> >
> > > > > (r'^(?P[\w-]+)_(?P[\w-]+)/$', 'showline')
> >
> > > > > However, I now get a page not found whenever I view the following url
> > > > > 'www.mysite.com/sprint_cellphone/'
> >
> > > > > 
> >
> > > > > Can I not replace the / with a _ in my url?
> >
> > > > > 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Getting related data...

2007-12-31 Thread Todd O'Bryan

There's probably an easier/more efficient way to do it, but you can do

services = []
for p in Profile.objects.all():
services += p.service_set.all()

Todd

On Dec 31, 2007 7:07 PM, ocgstyles <[EMAIL PROTECTED]> wrote:
>
> Hi All,
>
> I'm trying to figure out how to accomplish something using Django's
> database API, that I can easily do with SQL.  Here's my models:
>
> class Service(models.Model):
>name = models.CharField(max_length=50)
>
> class Profile(models.Model):
>user = models.ForeignKey(User)
>service = models.ManyToManyField(Service)
>
> So, I could have hundreds of Services, but I'm only interested in
> listing the Services that have been listed in any Profile.  In regards
> to the base tables, this would look like:
>
> select * from app_profile_services;
>
> How can I accomplish this using Django's database API?
>
> Keith
> >
>

--~--~-~--~~~---~--~~
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: hide fields using newforms

2007-12-30 Thread Todd O'Bryan

On Dec 30, 2007 11:11 AM, l5x <[EMAIL PROTECTED]> wrote:
>
> On Dec 30, 5:04 pm, Florian Lindner <[EMAIL PROTECTED]> wrote:
> > Hello,
> > using newforms how can I set fields to be hidden (the hidden="hidden"
> > attribute)?
>
> Did you mean type="hidden" ?
> http://www.djangoproject.com/documentation/newforms/#widgets
>
> You can create your own widget if you need to.
>

Or you can just use the HiddenInput widget that already exists. Here's
how you'd declare a hidden text field:

class SomeForm(forms.Form):
my_text = forms.CharField(max_length=20, widget=forms.HiddenInput)

HTH,
Todd

--~--~-~--~~~---~--~~
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: newforms tricks

2007-12-29 Thread Todd O'Bryan

On Dec 29, 2007 4:39 AM, David Larlet <[EMAIL PROTECTED]> wrote:
>
> Thanks for those useful tricks. Here are some typo corrections, hope
> it helps:
>
> > [4]: http://code.djangoproject.com/wiki/CookBookNewFormsDynamicFields
>
> [4]: http://code.djangoproject.com/wiki/CookBookNewFormsFieldOrdering
>
Whoops!

> In DynamicFields, you forgot to add 'self' as first argument of
> __init__.
> In the same function you use range(len(iterable)) which is not really
> pythonic, I prefer this solution:
>
> for i, question in enumerate(questions):
>  self.fields['question_%d' % i] =
> forms.ChoiceField(label=questions, ...)
>
Thanks for pointing this out. I didn't even know about the enumerate function!

Both fixed.

Todd

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



newforms tricks

2007-12-28 Thread Todd O'Bryan

After wrestling with newforms to get it to do things I thought it was
never intended to do, I decided that either it was really intended to
do such things or it's just such a clean design that getting it to do
weird things isn't that hard.

That said, I spent a lot of time fiddling around to find the right
incantations, so I added a section to the Cookbook[1] called
newforms[2] and included instructions for creating form fields
dynamically[3] and altering the default order[4]. If anyone sees any
obvious stupidness or this duplicates information available elsewhere,
please let me know.

Todd

[1]: http://code.djangoproject.com/wiki/CookBook
[2]: http://code.djangoproject.com/wiki/CookBookNewForms
[3]: http://code.djangoproject.com/wiki/CookBookNewFormsDynamicFields
[4]: http://code.djangoproject.com/wiki/CookBookNewFormsDynamicFields

--~--~-~--~~~---~--~~
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: How to create an "iffirst" tag?

2007-12-28 Thread Todd O'Bryan

On Dec 28, 2007 2:46 PM, Ned Batchelder <[EMAIL PROTECTED]> wrote:
>
> I'm making a list of objects, and only including some of them in the output:
>
> {% for thing in mylist %}
>{% if thing.test %}
>   {{thing}}
>{% endif %}
> {% endfor %}
>

Is there a compelling reason not to do the filtering in the view
before you even hit the template?

Todd

--~--~-~--~~~---~--~~
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: no one on the IRC?

2007-12-25 Thread Todd O'Bryan

If you can ever log on and not find Magus there, I'd be surprised. I
think the IRC channel has a direct link to his brain. Which is, by the
way, a good thing. He (and all the other people on the channel) are an
amazing resource.

Todd

On Dec 24, 2007 9:32 AM, Empty <[EMAIL PROTECTED]> wrote:
>
> > I have from time to time tried to bump into someone on the #django IRC.
> > Unfortunately, I always get a blank.
> > It seems the french and german #django channels are more active?
> > or maybe its my timezone (africa/lagos)?
> > can someone plese give me a hand on when i am likely to meet people on
> > #django?
> > btw - have been using it for 3 months now and am having the time of my
> > life...
> > Thanks Guys (and the occassional Gals (Carole Zieler))

--~--~-~--~~~---~--~~
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: Fwd: Break with Django SVN r6718

2007-12-10 Thread Todd O'Bryan

Hmm. What you said about not having Django installed in site-packages
makes me think...

What does your PYTHONPATH environment variable have in it?

Do you possibly have the current directory listed before the path to
Django? Because if you try to

from django.conf import settings

before your settings module has been identified, weird things might
happen. (I don't know what exactly...I'm grasping at straws at the
moment.)

Thanks,
Todd

--~--~-~--~~~---~--~~
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: Check if in query set...

2007-12-09 Thread Todd O'Bryan

s = Student.objects.get(pk=student_id)
if user in s.parents.all():
 // the user is legit
else:
 // user is not s's guardian

On Dec 9, 2007 6:11 PM, radioflyer <[EMAIL PROTECTED]> wrote:
>
> I have a m2m relationship between users (guardians) and students.
>
> I want to check if the currently logged in user has permission to edit
> a particular student.
>
> s = Student.objects.get(pk=student_id)
> parents = s.parents.all()
>
> And then check if logged in user.id matches against any of the parent
> ids.
>
> Is there a query set method for this? If not, what would the Python
> look like? (Learning Python as I learn Django.)
>
> 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Noob question: Which Linux distribution is "best" for Django?

2007-12-09 Thread Todd O'Bryan

If you decide to use Ubuntu, here's a link to how to set it up for
developing Django using PyDev on Eclipse. The steps have been tested
by several high school students, so they're fairly straightforward.
(That doesn't mean you won't find a problem, however.)

https://www.dupontmanual.org/wikis/spectops//HOWTO:_Install_Ubuntu_Linux/HOWTO%3A_Install_Ubuntu_Linux

There are some parts of the how-to you should skip, obviously. (Trying
to set up an account on our server, for one.)

HTH,
Todd

On Dec 9, 2007 10:14 AM, Horst Gutmann <[EMAIL PROTECTED]> wrote:
>
> IMO the differences between the distributions out there shouldn't
> really matter when it comes to GNU/Linux as a development environment.
> You should always have the option to install whatever you want from
> source. You might face some problems with some distros that use for
> example very old version of whatever database system you want to use,
> but again: Nothing that would completely keep you from developing
> using Django.
>
> That said, the more popular a distro, the more help you will get from
> other people, so you should focus on the big ones like Ubuntu, Fedora
> etc. :-)
>
> - Horst
>
>
> On Dec 9, 2007 3:57 PM, Andreas Pfrengle <[EMAIL PROTECTED]> wrote:
> >
> > Hello,
> >
> > till now I've been experimenting with Django (development version)
> > under Win2k. But Windows sucks. So I dare to make my first steps with
> > Linux. Most of you will surely say I won't regret this decision ;-).
> > But since I haven't any experience with Linux yet, I want to choose a
> > distribution that is best suited for someone coming from the Windows-
> > world AND suited to establish a Django development environment. Well,
> > I'm not even sure if there will be any great difference between
> > several distributions regarding these aspects. Any comment is welcome.
> >
> > Regards,
> > Andreas
> > >
> >
>
> >
>

--~--~-~--~~~---~--~~
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: Fwd: Break with Django SVN r6718

2007-12-09 Thread Todd O'Bryan

Crapola.

r6718 was a patch I wrote. Without the patch you only get app-defined
commands if you use manage.py. With django-admin.py, you don't get
app-defined commands, even if you specify a --settings=path module.

I just tried the steps you mentioned and everything works fine, both
in Python 2.4 and 2.5:

[EMAIL PROTECTED]:~/Desktop/mysite$ python2.4
Python 2.4.4 (#2, Oct  4 2007, 22:02:31)
[GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
[EMAIL PROTECTED]:~/Desktop/mysite$ python2.4 manage.py runserver
Validating models...
0 errors found

Django version 0.97-pre-SVN-6718, using settings 'mysite.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
42
[09/Dec/2007 09:11:40] "GET / HTTP/1.1" 404 2053
[EMAIL PROTECTED]:~/Desktop/mysite$ python
Python 2.5.1 (r251:54863, Oct  5 2007, 13:36:32)
[GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
[EMAIL PROTECTED]:~/Desktop/mysite$ python manage.py runserver
Validating models...
0 errors found

Django version 0.97-pre-SVN-6718, using settings 'mysite.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
42
[09/Dec/2007 09:12:17] "GET / HTTP/1.1" 404 2053

Can you provide any other debugging information that might help me
narrow down the problem?

Adrian, what errors were you seeing that caused the revert?

Todd
(Sorry it took me so long to get to this--teaching has been a bear recently.)

On Dec 4, 2007 5:37 PM, Josh Stone <[EMAIL PROTECTED]> wrote:
>
> I just found that commit 6871 fixed the problem by reverting 6718:
> "Undid [6718], as it broke 'django-admin.py runserver' for a
> reason I haven't figured out yet"
>
> But since there still seems to be some mystery, I went on with some
> debugging on 6718 anyway below.
>
> On Dec 2, 6:53 am, Malcolm Tredinnick <[EMAIL PROTECTED]>
> wrote:
> > Try to reduce the problem to something a bit simpler, since there's a
> > large package involved here (that I, and probably a lot of other people
> > on this list, know nothing about).
>
> I'm sorry, you're right, I should have pared down the problem first.
>
> > Does just creating a simple Django project from scratch work for you
> > (e.g. the tutorial application)?
>
> I started a new 'mysite' as described in the beginning of the
> tutorial, and verified that I could get the "Welcome to Django" page.
> Then I made the following simple changes:
>
>   Add to settings.py:
> FOOBAR = 42
>
>   Add to urls.py:
> from django.conf import settings
> print settings.FOOBAR
>
> Then when I visit the site, I get an ImproperlyConfigured exception,
> "Error while importing URLconf 'mysite.urls': 'Settings' object has no
> attribute 'FOOBAR'".  But if I add "--settings=mysite.settings" to the
> manage.py command line, then it works fine.
>
> > What operating system are you running on (there could well be Windows
> > vs. Mac vs. Linux vs. OS/2 differences)? What exceptions do you get?
> > Just the standard "can't find settings" exception, or something else?
>
> This is RHEL5.1, with python-2.4.3-19.el5.  The exception is always
> the same, as quoted above.
>
> Let me know if I should try anything else.  Otherwise I'll just use
> Django after 6718 was reverted, where things are fine for me.
>
> Josh
>
> >
>

--~--~-~--~~~---~--~~
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's doctest clashes with coverage.py

2007-11-24 Thread Todd O'Bryan

On Nov 24, 2007 9:58 PM, Russell Keith-Magee <[EMAIL PROTECTED]> wrote:

> If the licensing issue can't be resolved, it may be worth starting a
> standalone project to handle coverage tests. We recently added the
> ability for external projects to define new management commands
> specifically so that end-users could contribute features like this
> without the need to modify the Django core.

I believe the author of coverage.py, Ned Batchelder, is on the list.
Has he said whether he's willing to have Django include it without
much hoop jumping?

Todd

--~--~-~--~~~---~--~~
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: validating fields with newforms - part 2

2007-11-23 Thread Todd O'Bryan

How do you clean a field that's supposed to be a date or a number, for
example, if the user doesn't provide a legal date or number? If you're
not allowed to throw validation errors during cleaning, you could find
yourself in a situation where your later cleaning code makes
assumptions that aren't true. Better to realize that, in the process
of cleaning, you may discover validation problems that require errors.

Todd

On Nov 23, 2007 8:59 AM, Wolfram Kriesing <[EMAIL PROTECTED]> wrote:
>
> We discussed this here again, and it looks like newforms currently
> mixes cleaning and validating data in a not so ideal way.
>
> Actually the clean and validation process should be separated, there
> should be clean-methods and validate-methods. The process should work
> in the following way, to allow full flexibility:
>
> 1) call Field.clean() - to clean the data, NOT throw any errors, just
> do basic data cleaning if necessary.
> 2) call Form.clean_() - provide _all_form_ data to this method,
> so it can also clean the data depending on other form data
> 3) call Form.clean() - stuff that needs to be done _after_ every
> single field had been cleaned
>
> 4) call Field.validate() - use the cleaned data to validate the fields
> 5) call Form.validate_()
> 6) call Form.validate()
>
> looks cleaner in my eyes. opinions please!
>
> wolfram
>
>
> On Nov 23, 2007 2:45 PM, Wolfram Kriesing <[EMAIL PROTECTED]> wrote:
> > On Nov 23, 2007 2:41 PM, Matthias Kestenholz <[EMAIL PROTECTED]> wrote:
> > >
> > >
> > > On Fri, 2007-11-23 at 14:30 +0100, Wolfram Kriesing wrote:
> > > > :-) yep we also discussed that here
> > > > still it seems "wrong" that it needs to be done with such a hacky way 
> > > > around
> > > >
> > >
> > > I don't think that's hacky at all, really. If you want an URLField, you
> > > get a field that guarantees that it really contains an URL. Otherwise it
> > > should get called fields.MaybeURLField, and what would be the difference
> > > between that and a plain CharField?
> > >
> > > You can even validate the URL in clean_url()
> > >
> > > But take whatever works for you...
> >
> > sounds right too :-). thx for the help!
> > but see the other two drawbacks i wrote in the other mail
> >
> > wolfram
> >
> > >
> > > --
> > >
> > > http://spinlock.ch/blog/
> > >
> > >
> > > > >
> > >
> >
> >
> >
> > --
> > cu
> >
> > Wolfram
> >
>
>
>
> --
> cu
>
> Wolfram
>
> >
>

--~--~-~--~~~---~--~~
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: Python Question - How to show the last few elements in a list

2007-11-20 Thread Todd O'Bryan

Have you tried request.session['prod'][-7:] ?

If that doesn't work, try list(request.session['prod'])[-7:]

Todd

On Nov 20, 2007 10:52 PM, Greg <[EMAIL PROTECTED]> wrote:
>
> Hello,
> I have a session variable.  Whenever anybody adds a product to this
> session variable it gets stored like so:
>
> request.session['prod'].append(b)
>
> This can make my session variable look like this:
>
> [, , , ]
>
> //
>
> I want to show the last 7 elements in my list,  Occassionally my list
> will only contain less than 7 elements...like above.  So in this case
> only 4 elements will be shown.  However, I'm getting errors with how I
> currently have it setup:
>
> request.session['prod'][len(request.session['prod']) -
> 6:len(request.session['prod'])]
>
> It doesn't work correctly when I have less than 7 elements in the
> list.  I guess it's because I have
>
> 'len(request.session['prod']) - 6'
>
> ///
>
> Does anybody know how I can show the last 7 elements in my list, and
> if my list has less than 7 elements then it shows all of the elements?
> >
>

--~--~-~--~~~---~--~~
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: url tag difficulties

2007-11-09 Thread Todd O'Bryan

I've also been a little frustrated with the {% url %} tag. It's very
easy to mess it up, and very hard to figure out what's messed up. I
wonder if we couldn't provide some debugging information if DEBUG is
set to true.

Todd

On Nov 9, 2007 10:54 PM,  <[EMAIL PROTECTED]> wrote:
>
> I really hope this isn't embarrassingly obvious but...
>
> My {% url %} tags aren't producing anything -- no error and no url. My
> current setup is so bare-bones I can't imagine what's gone wrong. Here
> are the basics:
>
> ROOT_URLCONF = Project.urls
>
> In Project.urls:
> (r'^$', 'app1.views.index'),
> (r'^(?Pauthors|books|publishers)/$', 'app2.views.browse'),
>
> The app2.views.browse view uses a render_to_response, with a
> RequestContext. I've got no TEMPLATE_CONTEXT_PROCESSORS set, so I'm
> using default.
>
> app2.views.browse renders the app2/browse.html template, with no
> context variables passed in except what the RequestContext puts in
> there. I thought the problem was that ROOT_URLCONF wasn't available in
> the template, but I imported that specifically and passed it in, with
> the same result.
>
> In app2/browse.html template:
> Home
> (I've also tried Project.app1.views.index, and other variations, with
> the same result)
>
> All I want is a link to the homepage, but nothing is output. This is
> the simplest case but the I get the same result in all my views and
> templates. I'm using the development version of Django, and the
> development server.
>
> Can anyone see where I've got wrong? I tried setting the
> TEMPLATE_STRING_IF_INVALID variable to '%s', but I guess this doesn't
> actually count as an invalid template tag.
>
> I'd be very grateful for any help!
>
> 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: spam

2007-11-07 Thread Todd O'Bryan

Does anyone know if those of us with gmail clicking the Report Spam
button connects back to Google Groups, or are we just protecting
ourselves?

On Nov 7, 2007 4:52 PM, Jacob Kaplan-Moss <[EMAIL PROTECTED]> wrote:
>
> Hi folks --
>
> I'm a bit late to this discussion; sorry!
>
> There actually is something you can do to help out with spam on this
> list: become a moderator, and give spammers the boot.
>
> I'll happily make you into a moderator if you're someone whose name I
> recognize as someone with proven history on this list of being calm,
> considerate, and generally trustworthy.
>
> Email me privately if you want to help out.
>
> Jacob
>
>
> >
>

--~--~-~--~~~---~--~~
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: keeping SECRET_KEY secret

2007-11-01 Thread Todd O'Bryan

I then point to production_settings as my DJANGO_SETTINGS_MODULE for
mod_python and the production settings overwrite the settings that I
use for production.

Of course, the last word should be "development," not "production."

Todd

--~--~-~--~~~---~--~~
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: keeping SECRET_KEY secret

2007-11-01 Thread Todd O'Bryan

I actually have a production_settings.py file that only exists on my
server, is not part of version control, and is only readable by the
Apache user.

It consists of:

from settings import *

DEBUG = False

DATABASE_NAME = blah
DATABASE_USER = blah
DATABASE_PASSWORD = blah
SECRET_KEY = blah

where the latter two are constructed using a random password generator
and, in my case, are 20 and 50 characters each.

I then point to production_settings as my DJANGO_SETTINGS_MODULE for
mod_python and the production settings overwrite the settings that I
use for production.

Todd

On 11/1/07, Carl Karsten <[EMAIL PROTECTED]> wrote:
>
> Given that some settings.py files get shared/posted/uploaded to code.google,
> etc. it seems this should not be in there by default:
>
> # Make this unique, and don't share it with anybody.
> SECRET_KEY = 'foo!'
>
> I am sure there are already a dozen or so good solutions to this problem, 
> plus mine:
>
> SECRET_KEY_file_name = os.path.expanduser('~/.secret')
> try:
>  SECRET_KEY_file = open(SECRET_KEY_file_name,'r')
>  SECRET_KEY = SECRET_KEY_file.read().strip()
> except IOError:
>  # if the file doesn't exist, gen a key and save it to the file.
>  from random import choice
>  SECRET_KEY_file = open(SECRET_KEY_file_name,'w')
>  SECRET_KEY =
> ''.join([choice('[EMAIL PROTECTED]&*(-_=+)') for i in
> range(50)])
>  SECRET_KEY_file.write( SECRET_KEY )
> finally:
>  SECRET_KEY_file.close()
>
> let the code war begin.
>
> Carl K
>
> >
>

--~--~-~--~~~---~--~~
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: elance'in django programmers

2007-10-28 Thread Todd O'Bryan

The other complication is that, in the United States, contractors have
to include in their hourly rate the employer's portion of payroll
taxes as well as enough money to pay for health insurance and other
benefits that might be provided by virtue of citizenship in other
countries, but which the contractor has to pay for him/herself. That
tends to inflate the hourly rate of contractors compared with
employees.

Todd

On 10/25/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> Well the more skills you have as a programmer... the more work is
> available to you... but also the more skills you have...the more you
> expect to be paid.
>
> Someone that knows only PHP ... or only knows Flash Actionscript,
> etc shouldn't expect to get paid as much as a developer who is
> knowledgeable in many languages.  Similarly, a newbie programmer with
> only a few months experience, or no 'professional' experience,
> shouldn't expect to be paid the same as a developer with many years of
> software/web application development experience under their belt.
>
> On Oct 25, 10:42 pm, Roboto <[EMAIL PROTECTED]> wrote:
> > That's true, I didn't think about this at first - it's difficult to
> > make it as a programmer with market dilution.
> >
> > On Oct 25, 10:38 pm, "Marty Alchin" <[EMAIL PROTECTED]> wrote:
> >
> > > Speaking as someone who's tried their hand at both sides of the coin,
> > > I definitely agree with you, Ross. I'm currently employed, but when I
> > > was trying to make it as a contractor (because a job fell through), I
> > > couldn't land a single job because of the market dillution. Working in
> > > PHP as I was, I found that I was competing against high school and
> > > college students, whose bills are paid by their parents, and can
> > > afford to spend weeks on end getting paid next to nothing. And yes,
> > > the quality of their work showed.
> >
> > > The trouble with most good developers is that they're not willing to
> > > work for cheap change. And it often has little to do with getting paid
> > > appropriately for their skill level. For me, and many others, the high
> > > price is necessary because we have families and mortgages to support.
> > > Contracting for a low price is only good for a certain type of people,
> > > and that pool doesn't contain very many quality developers.
> >
> > > Just keep in mind that contractors don't have an endless pool of jobs
> > > to choose from, where they can just pick whatever price they feel
> > > like. They have to make sure that each job can sustain them until they
> > > secure another job. It's not a fun way to live unless you're already
> > > very well established.
> >
> > > -Gul
>
>
> >
>

--~--~-~--~~~---~--~~
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: Looping through a list in a template?

2007-10-09 Thread Todd O'Bryan

You probably want to look at this:

http://www.djangoproject.com/documentation/models/pagination/

On Tue, 2007-10-09 at 21:02 -0700, Greg wrote:
> Hello,
> I'm trying to create a way for people to navigate through their search
> results.  Depending on how specific they are in their search they
> could have 1 to 1,000 products get returned.  I want to develop
> something where my page will list 10 links at a time that when clicked
> shows those 10 elements from my list.  So there could be one number or
> 100 depending on how many products were returned.
> 
> I'm sending a template a variable that contains the length of a list.
> I want to be able to create a link for each group of ten elements in
> the list.  So let's say that my length variable that is sent to the
> template is 100.  In my template I would need to have something like:
> 
> {% for #notsure# %}
> http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Add a permission to a production db

2007-10-02 Thread Todd O'Bryan

On Wed, 2007-10-03 at 07:58 +0800, Russell Keith-Magee wrote:
> On 10/3/07, Todd O'Bryan <[EMAIL PROTECTED]> wrote:
> >
> > How should I add a permission to an app/model that already exists in a
> > production db? The docs say to use syncdb, but that doesn't work (I
> > don't think) when the db tables already exist. Also, sqlall doesn't show
> > the SQL that's used to create the permissions.
> >
> > I'm just really worried that I'll accidentally hose my db.
> 
> My reading of this code is that it should add the permissions for your
> pre-existing table. create_permissions() calls get_or_create for all
> permissions on all models in a given app, and the handler will be
> called for all installed apps. If you have a pre-existing table, it
> won't have a permissions, so they should be created without any drama.
> 
Thanks! I feel much better, now.

Todd


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



Add a permission to a production db

2007-10-02 Thread Todd O'Bryan

How should I add a permission to an app/model that already exists in a
production db? The docs say to use syncdb, but that doesn't work (I
don't think) when the db tables already exist. Also, sqlall doesn't show
the SQL that's used to create the permissions.

I'm just really worried that I'll accidentally hose my db.

Thanks,
Todd

P.S. We just deployed a Django site entirely written by me and my high
school students that we're hoping will evolve into a cool way for the
school to exchange information. We just added over 2000 users and
parents and teachers are using the system to schedule conferences.



--~--~-~--~~~---~--~~
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: Help installing Psycopg2 and/or MySQL-python on OS X

2007-09-02 Thread Todd O'Bryan

Looks like you're missing some header files...

On Sun, 2007-09-02 at 16:14 -0700, Brandon Taylor wrote:
> Hi Todd,
> 
> Here is a copy of my terminal session:
> 
> running install
> running build
> running build_py
> running build_ext
> Warning: /bin/sh: line 1: pg_config: command not found

Maybe postgres didn't put everything where it needed to be. You also may
need the dev packages for postgres.

> building 'psycopg2._psycopg' extension
> gcc -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -
> fno-strict-aliasing -Wno-long-double -no-cpp-precomp -mno-fused-madd -
> fno-common -dynamic -DNDEBUG -g -O3 -DPY_MAJOR_VERSION=2 -
> DPY_MINOR_VERSION=5 -DHAVE_PYBOOL=1 -DHAVE_DECIMAL=1 -
> DHAVE_PYDATETIME=1 -DPSYCOPG_DEFAULT_PYDATETIME=1 -
> DPSYCOPG_VERSION="2.0.6 (dec dt ext pq3)" -DPSYCOPG_EXTENSIONS=1 -
> DPSYCOPG_DISPLAY_SIZE=1 -DPSYCOPG_NEW_BOOLEAN=1 -DHAVE_PQFREEMEM=1 -
> DHAVE_PQPROTOCOL3=1 -I/Library/Frameworks/Python.framework/Versions/
> 2.5/include/python2.5 -I. -c psycopg/psycopgmodule.c -o build/
> temp.macosx-10.3-fat-2.5/psycopg/psycopgmodule.o
> In file included from psycopg/psycopgmodule.c:29:
> ./psycopg/connection.h:27:22: error: libpq-fe.h: No such file or
> directory

This looks like a missing library and all the warnings below could be
problems with incompatibility between versions of gcc.

Have you tried fink?




--~--~-~--~~~---~--~~
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: Help installing Psycopg2 and/or MySQL-python on OS X

2007-09-02 Thread Todd O'Bryan

On Sun, 2007-09-02 at 16:04 -0700, Brandon Taylor wrote:
> Hi everyone,
> 
> I have Python 2.5.1 and Django installed and running on OS X 10.4.10,
> but can't seem to get either the Psycopg2 or MySQL-python bindings
> installed so I can actually use a database with Django.
> 
> I have the latest version of PostgreSQL and MySQL5 installed and
> running. Can someone please get me pointed in the right direction?!
> 
> Many thanks in advance,
> Brandon

On my Mac, the main problem with Python is that I can't tell which
version it's using. I assume you've tried downloading psycopg2 and
running

$ sudo python setup.py install

from the terminal in the correct directory? If you have, what errors do
you get?

Todd


--~--~-~--~~~---~--~~
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: Adding permissions in a fixture

2007-08-13 Thread Todd O'Bryan

On Tue, 2007-08-14 at 08:27 +0800, Russell Keith-Magee wrote:
> On 8/14/07, Todd O'Bryan <[EMAIL PROTECTED]> wrote:
> >
> > I asked this before and no one answered, but after having to do this
> > manually in the shell for about the fifteenth time, I'm going to ask
> > again.
> 
> Can't say I remember seeing this question the first time round.
> Apologies for missing it.
> 
> > Let me outline what I'm doing and see if I'm doing something wrong:
> ...
> > This last step changes the id of the old permissions and my serialized
> > test data no longer sets the permissions it's supposed to. Now I have to
> > remake my test data.
> >
> > Is this a real problem, or am I just making it up?
> 
> This could be a real problem. Permissions are all based on
> ContentTypes, and the ID's assigned to contenttypes will depend on the
> order in which applications are installed. The same problem will
> potentially exist with GenericRelations, or anything else relying on
> ContentType references.
> 
> Changing the order of the INSTALLED_APPS shouldn't cause this problem
> (if you can demonstrate that it does, there might be another issue at
> work here). Adding a new application by itself shouldn't cause a
> problem either - the new permission ID's should be added with
> sequential IDs at the end of the existing IDs.
> 
> However, the following sequence will cause problems:
> - Add two applications, and sync
> - Write a fixture that uses permissions for those apps
> - Add a third application
> - Write a fixture that uses permissions on the third app
> - Destroy and recreate the database
> 
> In this case, there is no guarantee that the permissions will be
> recreated in the same order   as they were in the first instance -
> hence, serialization problems.
> 
> Does this correspond with the use case you are seeing? Or are your
> serialization problems more widespread than this example?
> 
I'm only actually talking about test cases where you start from a fresh
database each time. I assume that as you evolve your production database
you're smart enough not to, say, serialize the data, rebuild the
database willy-nilly, and then cross your fingers and hope the data goes
back where it was supposed to. :-)

> > If it's a real problem, is there a way around it? Since fixtures are
> > such an easy way to create test data, it would seem a really good idea
> > if they supported the ability to create data that wouldn't break
> > unnecessarily as a result of a project just evolving.
> 
> I agree that this is annoying.
> 
> One possible way around the problem is to serialize your ContentTypes.
> This will ensure that the content types in any new database correspond
> to their original values. This will require your to rebuild your
> contenttype fixture every time you add an new application, but this is
> fairly easy to do with ./manage.py dumpdata contenttype
> 
> The only permanent solution I can think of would be to introduce some
> sort of query language into the fixtures, which is a road I'd rather
> not travel down. Any other suggestions are welcome.

That's something I hadn't thought of, but do you run into trouble
because Django creates the content-types itself and then you try to load
yours afterward? I was getting weird errors and discovered that the way
to solve the problem was to *not* dumpdata auth or any other of Django's
own apps.

Here's something I considered. What if fixtures were a Python module
instead of just a folder and you could include a function as part of a
fixture. For example, in addition to test.json, I could include a
function called test in fixtures/__init__.py that added stuff to the
database using the ORM. Most things would still be done through
serialization, because it's so handy, but generic relations and
permissions and such could be set with a few lines of Python code. Does
that seem like too big a hammer for such a small nail?

Todd


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



Adding permissions in a fixture

2007-08-13 Thread Todd O'Bryan

I asked this before and no one answered, but after having to do this
manually in the shell for about the fifteenth time, I'm going to ask
again.

Is there a way to add user permissions to a test fixture that isn't
brittle?

Let me outline what I'm doing and see if I'm doing something wrong:

1. I serialize the database with permission data and the permission is
stored as a foreign key, which means the serialized data just includes
its id.
2. I use the test data for a while, very happily.
3. I add a new app to my project, which has its own permissions (or even
maybe just change the order my apps appear in INSTALLED_APPS).

This last step changes the id of the old permissions and my serialized
test data no longer sets the permissions it's supposed to. Now I have to
remake my test data.

Is this a real problem, or am I just making it up?

If it's a real problem, is there a way around it? Since fixtures are
such an easy way to create test data, it would seem a really good idea
if they supported the ability to create data that wouldn't break
unnecessarily as a result of a project just evolving.

Hoping for some way to avoid "from django.contrib.auth.models import
User, Permission" over and over again in the shell,
Todd


--~--~-~--~~~---~--~~
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: Access request while cleaning fields

2007-08-05 Thread Todd O'Bryan

I'm going to answer my own question in case anyone searches in the
future. And, eventually, I'll start thinking in Python and figure out
these things before sending a message to the list. I'm afraid too much
Java has warped me forever.

I just added the request object as an attribute on the form before
calling the is_valid method. In other words:

if request.method == 'POST':
form = ChangePasswordForm(request.POST)
form.request = request
if form.is_valid():

Now all of the clean methods can access the request object as
self.request inside the form class.

Todd

On Sun, 2007-08-05 at 10:08 -0400, Todd O'Bryan wrote:
> I'm trying to translate a Change Password page I wrote using oldforms
> into newforms and have hit a snag. I need to validate that the user
> types in his/her current password correctly and it seems like writing a
> clean_current_password() method in the form class is the easiest way to
> do that, since errors and such will appear where they should, without me
> having to worry much about them.
> 
> Unfortunately, I can't figure out how to access the request object when
> I'm cleaning the form data. Is there a way to get to it, or do I have to
> do this kind of validation in the view and handle all the errors
> manually?



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



Access request while cleaning fields

2007-08-05 Thread Todd O'Bryan

I'm trying to translate a Change Password page I wrote using oldforms
into newforms and have hit a snag. I need to validate that the user
types in his/her current password correctly and it seems like writing a
clean_current_password() method in the form class is the easiest way to
do that, since errors and such will appear where they should, without me
having to worry much about them.

Unfortunately, I can't figure out how to access the request object when
I'm cleaning the form data. Is there a way to get to it, or do I have to
do this kind of validation in the view and handle all the errors
manually?

Thanks,
Todd


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



How do you set user permissions in test data?

2007-08-03 Thread Todd O'Bryan

I've been using fixtures to create test data, but how do I set user
permissions that aren't brittle? If I use

./manage.py dumpdata

it dumps the user_permissions as a list of ids of permissions the user
has. The problem is, as I add more apps/permissions to my project, those
ids are likely to change and my test data will end up invalid.

Is there some way to specify a permission by name in a fixture or some
easier way to do this that I'm missing?

Todd


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



equality weirdness

2007-08-01 Thread Todd O'Bryan

I was writing some unit tests for a model in which I'd written a custom
__cmp__ method and got a strange result. Is it a bug, feature, or just
something to warn people about.

django.db.models.Model defines __eq__ and __ne__ based on  PK identity.
That means that all model objects are == to one another until they've
been saved in the database because their PKs don't get set until they're
saved.

In my case,

>>> name1 < name2 and name2 > name1
True
>>> name1 != name2
False

Is it worth it to check if the PK exists in the equality check, or have
I just hit something that's not likely to ever surface in the real
world?

Todd


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



Is this a test? Is this only a test?

2007-07-30 Thread Todd O'Bryan

Some of my pages fetch data based on user input. It obviously doesn't
make sense to do the actual fetch in test cases, since I should know
what is going to be returned and should be checking for what I do with
the data.

Is there an easy way to tell if something is running as a test so that I
can mock that behavior? I'm thinking of something like

def fetch_data_for(input):
if TEST:
return mock_data(input)
else:
#do the production stuff

Or maybe this isn't the right approach at all and I'm missing something
that would make this easier.

Thanks,
Todd


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



Adding permission in admin causes error

2007-07-20 Thread Todd O'Bryan

In the most recent from trunk, I get the following error when I try to
add a permission (either default or custom) to a user. Is this a bug or
am I doing something wrong?

Todd

TypeError at /dmi/admin/auth/user/2/
Cannot resolve keyword 'name' into field. Choices are: groups,
user_permissions, logentry, message, info, labelqueueset, checkout, id,
username, first_name, last_name, email, password, is_staff, is_active,
is_superuser, last_login, date_joined
  Request Method:
POST
Request URL:
http://localhost:8000/dmi/admin/auth/user/2/
  Exception Type:
TypeError
  Exception Value:
Cannot resolve keyword 'name' into
field. Choices are: groups,
user_permissions, logentry, message,
info, labelqueueset, checkout, id,
username, first_name, last_name,
email, password, is_staff,
is_active, is_superuser, last_login,
date_joined
Exception Location:
/usr/lib/python2.5/site-packages/django/db/models/query.py in lookup_inner, 
line 1026
 Python Executable:
/usr/bin/python
  Python Version:
2.5.1




















--~--~-~--~~~---~--~~
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: Looking for 2 great python/django developers in Atlanta area

2007-07-13 Thread Todd O'Bryan

On Sat, 2007-07-14 at 13:46 +1000, Malcolm Tredinnick wrote:

> Umm... the world is a fairly big place. Where in it are you located?
> 
> Malcolm

See subject. :-)


--~--~-~--~~~---~--~~
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: Do FormFields know which Model Field they're from?

2007-07-12 Thread Todd O'Bryan

Just ignore me!

The callback function is called on the MODEL fields, not the FORM
fields. (Although, given that they have the same names, please don't be
too cross with me for not noticing the difference. You can see how much
work I did trying to figure it out before I turned to the list.)

Thanks Russ! Now back to your program...

Todd


On Thu, 2007-07-12 at 23:22 -0400, Todd O'Bryan wrote:
> On Fri, 2007-07-13 at 09:53 +0800, Russell Keith-Magee wrote:
> 
> > 
> > Check the attributes of field - amongst many others, there is
> > field.name, the name of the field on the form. So, you can do the
> > following:
> > 
> > if isinstance(field, models.DateField) and field.name == 'appointment':
> >...
> 
> Could have sworn I'd checked that. Here's what I get with the latest
> from trunk:
> 
> >>> from django.newforms.models import form_for_instance
> >>> FormClass = form_for_instance(Title.objects.all()[0])
> >>> form = FormClass()
> >>> form.fields
> {'name': ,
> 'author': ,
> 'publisher': ,
> 'isbn': ,
> 'num_pages': ,
> 'dimensions': ,
> 'weight': ,
> 'picture_url': }
> >>> dir(form.fields['name'])
> ['__class__', '__delattr__', '__dict__', '__doc__', '__getattribute__',
> '__hash__', '__init__', '__module__', '__new__', '__reduce__',
> '__reduce_ex__', '__repr__', '__setattr__', '__slotnames__', '__str__',
> '__weakref__', 'clean', 'creation_counter', 'help_text',
> 'hidden_widget', 'initial', 'label', 'max_length', 'min_length',
> 'required', 'widget', 'widget_attrs']
> 
> No name in there...
> 
> Todd
> 
> 
> > 


--~--~-~--~~~---~--~~
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: Do FormFields know which Model Field they're from?

2007-07-12 Thread Todd O'Bryan

On Fri, 2007-07-13 at 09:53 +0800, Russell Keith-Magee wrote:

> 
> Check the attributes of field - amongst many others, there is
> field.name, the name of the field on the form. So, you can do the
> following:
> 
> if isinstance(field, models.DateField) and field.name == 'appointment':
>...

Could have sworn I'd checked that. Here's what I get with the latest
from trunk:

>>> from django.newforms.models import form_for_instance
>>> FormClass = form_for_instance(Title.objects.all()[0])
>>> form = FormClass()
>>> form.fields
{'name': ,
'author': ,
'publisher': ,
'isbn': ,
'num_pages': ,
'dimensions': ,
'weight': ,
'picture_url': }
>>> dir(form.fields['name'])
['__class__', '__delattr__', '__dict__', '__doc__', '__getattribute__',
'__hash__', '__init__', '__module__', '__new__', '__reduce__',
'__reduce_ex__', '__repr__', '__setattr__', '__slotnames__', '__str__',
'__weakref__', 'clean', 'creation_counter', 'help_text',
'hidden_widget', 'initial', 'label', 'max_length', 'min_length',
'required', 'widget', 'widget_attrs']

No name in there...

Todd


--~--~-~--~~~---~--~~
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: Using Django without database

2007-07-12 Thread Todd O'Bryan

On Fri, 2007-07-13 at 01:40 +, Patrick wrote:

> Unfortunately, I can't give you more details about the security aspect, 
> except that it has to do with prolonged physical storage of large amounts 
> of data online, which is "insecure". The exact details are not known to 
> me yet. I'm a developer that has been told to make a web app instead of a 
> desktop program that works with a pretty old system :)
> 
> I know it sounds a bit contradictory, but at this point I'm exploring 
> possibilities. It might be that a database would be the best option in 
> the end. It would be so much easier.

What if you mocked up your own backend to connect to whatever storage
solution they have in mind. You could use models internally and only
have to worry about storing and retrieving. Also, chances are that you
wouldn't have to implement all the bells and whistles of the other
backends but could get by with a subset based on what you're accessing
and storing.


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



Do FormFields know which Model Field they're from?

2007-07-12 Thread Todd O'Bryan

The docs for newforms say how to override a field if you wish:

http://www.djangoproject.com/documentation/newforms/#overriding-the-default-field-types

> For example, if you wanted to use MyDateFormField for any DateField
> field on the model, you could define the callback:
> 
> >>> def my_callback(field, **kwargs):
> ... if isinstance(field, models.DateField):
> ... return MyDateFormField(**kwargs)
> ... else:
> ... return field.formfield(**kwargs)
> 
> >>> ArticleForm = form_for_model(formfield_callback=my_callback)
> 
> Note that your callback needs to handle all possible model field
> types, not just the ones that you want to behave differently to the
> default. That's why this example has an else clause that implements
> the default behavior.

But what if I only want to override the appointment field in my model
with a form field that limits people to choosing weekdays, but leave the
birth_date field as a normal DateField?

Any way to do that?

Todd


--~--~-~--~~~---~--~~
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 keyword argument when calling a function

2007-07-07 Thread Todd O'Bryan

According to the code I have, this should be working. Try changing it
to 

def showcollection(request, manufacturer_id=None, collection_id=None):

and see if that makes any difference.

On Sat, 2007-07-07 at 16:07 -0700, Greg wrote:
> Hello,
> I have the following line in my urls.py file
> 
> r'^(?P\d+)/(?P\d+)/styles/$',
> 'mysite.rugs.views.showcollection'),
> 
> //
> 
> I have the following function defined in my views.py file
> 
> def showcollection(request, manufacturer_id, collection_id):
>   s = Style.objects.filter(collection=collection_id)
>   return render_to_response('thecollectionpage.html', {'coll': s})
> 
> //
> 
> When I go to that url I get the following error:
> 
> TypeError at /rugs/2/1/styles/
> showcollection() got an unexpected keyword argument 'collection_id'
> Request Method:   GET
> Request URL:  http://127.0.0.1:8000/rugs/2/1/styles/
> Exception Type:   TypeError
> Exception Value:  showcollection() got an unexpected keyword argument
> 'collection_id'
> Exception Location:   c:\Python24\lib\site-packages\django\core\handlers
> \base.py in get_response, line 77
> 
> 
> 
> I done this before with just one variable and it's always been (?
> P\d+).  Can I change the name from object_id to
> manufacturer_id and collection_id?  And can I send two variables
> (three including request)?
> 
> 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Building forms by hands

2007-07-07 Thread Todd O'Bryan

On Sat, 2007-07-07 at 12:36 +, Alexander Solovyov wrote:
> On 5 июл, 14:19, "Russell Keith-Magee" <[EMAIL PROTECTED]> wrote:
> 
> > Can you explain your problem another way, possibly with a more
> > complete example?
> 
> Ok, I'll try.
> 
> I want to enter HTML by hands, but can't determine which radio must be
> selected. Form is built with form_for_instance, so it contains values.
> 
> Sorry if my description is unclear.

If you don't want to use a to output the form HTML that Django gives
you, you'll need to store some kind of value in the context to let you
know which radio button is selected.

Can I ask why, if you're using form_for_instance, you don't want to use
the form's HTML output as well?

Todd


--~--~-~--~~~---~--~~
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: cross-table unique_together?

2007-07-06 Thread Todd O'Bryan

On Fri, 2007-07-06 at 21:50 +, Nathan Ostgard wrote:
> You would either have to duplicate the Title foreign key in the Copy
> model or write a custom check in the save method.
> 
> To enforce uniqueness over several columns you would use the
> "unique_together" field of the Meta class for your Copy model. (see:
> http://www.djangoproject.com/documentation/model-api/#unique-together)
> This creates the appropriate unique index for your table. However,
> this means you can only enforce uniqueness for fields within an
> individual model.
> 
Thanks. That's what I was afraid of, but the idea of duplicating the
title ForeignKey never occurred to me.

On the other hand, I guess that would require overriding __setattr__
method to set the title whenever the purchase_group is set, so it might
just be easier to put the constraint in the save method.

Todd


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



cross-table unique_together?

2007-07-06 Thread Todd O'Bryan

I'm writing an app to deal with checking out textbooks to students. The
models are

Title:
the book
PurchaseGroup:
when purchased and how much they cost, foreign key to Title
Copy:
number, foreign key to PurchaseGroup

I'd like to make it so that no two copies have the same number and
title, i.e. copies #1 and #2 of The Django Book are legal as is copy #1
of The Mythical Man-Month, but having two copy #1's of the same book
would be forbidden.

Will the ORM do that, or do I have to just write a check in the Copy
class's save method?

Thanks!
Todd


--~--~-~--~~~---~--~~
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: TextField in newforms

2007-07-06 Thread Todd O'Bryan

On Fri, 2007-07-06 at 11:00 -0500, James Bennett wrote:
> On 7/6/07, Todd O'Bryan <[EMAIL PROTECTED]> wrote:
> > Is there any reason there's not a TextField in newforms that defaults to
> > use a TextArea widget other than the fact that no one has written one
> > yet?
> 
> http://groups.google.com/group/django-users/browse_frm/thread/b3dc5cc742f3f068/
> 
> 
D'oh! Thanks for not throwing something at me, James. :-)


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



TextField in newforms

2007-07-06 Thread Todd O'Bryan

Is there any reason there's not a TextField in newforms that defaults to
use a TextArea widget other than the fact that no one has written one
yet?

Todd


--~--~-~--~~~---~--~~
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: YUI tags

2007-07-05 Thread Todd O'Bryan

Thanks! I'd actually thought about how to do this, but it's nice to have
real code...

On Thu, 2007-07-05 at 13:50 -0500, Jacob Kaplan-Moss wrote:
> Hi Todd --
> 
> You might find writing those "nested" template tags a bit tricky;
> there's a not-very-well-documented method you'll need to pull out the
> sub-tags.
> 
> I've got an example of how you can do these types of nested tags here:
> http://www.djangosnippets.org/snippets/300/
> 
> Good luck!
> 
> Jacob



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



YUI tags

2007-07-04 Thread Todd O'Bryan

I just looked at YUI yesterday and am pretty impressed. What I'm not
impressed by is how complicated it is to write the markup in HTML for
things like menus so that they'll work in non-JavaScript environments.

I'm considering trying to develop a yuitags app that would just consist
of template tags that compartmentalize YUI widgets in a form that would
make them easy to enter in a Django template. For example, to do a
menubar, you'd do something like

{% menubar %}
{% menu %}
{% menuitem %}Menu One{% endmenuitem %}
{% menuitem %}Item One.1{% endmenuitem %}
{% menuitem %}Item One.2{% endmenuitem %}
{% endmenu %}
{% menu %}
etc.
{% endmenu %}
{% endmenubar %}

The other thing is that you could include a

{{ yui_links }}

variable in the head section of your base template, and each tag would
include the imports it would need to be displayed in the context so that
they'd be loaded automatically.

Does such a thing already exist? If not, is this something people see a
use for? Any gotchas I'm missing that would make this impossible instead
of just tricky?

Thanks,
Todd


--~--~-~--~~~---~--~~
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: Using reverse() in your urlpatterns

2007-06-26 Thread Todd O'Bryan

On Tue, 2007-06-26 at 19:58 +, Justin wrote:
> On Jun 26, 12:12 pm, Justin <[EMAIL PROTECTED]> wrote:
> > I'm wondering though, is it possible to use reverse() and pass it some
> > args, to use it as the post_save_redirect in generic views?
> 
> On second thought, this is kind of a stupid thing to do in the first
> place... why would I want to avoid hard coding urls in the very same
> file where they are defined? That's a silly thing to do. I think I was
> getting a little too anal there. :)

It's actually not that stupid. If you have urls hard-coded in the
template, you have to make sure that you change them if you change the
url patterns of your app. If you use the {% url %} tag, you can change
the url patterns willy-nilly and only have to make changes if you rename
the patterns or the view functions.

Following this pattern would seem to make it easier to make apps
portable.

Todd


--~--~-~--~~~---~--~~
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: error after updating from svn (v5479): unexpected keyword argument 'max_digits'

2007-06-15 Thread Todd O'Bryan

On Fri, 2007-06-15 at 22:40 +, hotani wrote:
> Full error:
> [__init__() got an unexpected keyword argument 'max_digits']
> 
> Just updated from svn today and when I tried a syncdb that is what
> happened. Is 'max_digits' not allowed anymore?
> 
> Here is an example straight from the model:
> fine = models.FloatField(max_digits=9, decimal_places=2, blank=True,
> null=True, default='0.00')
> 
> It is a currency field.

Learn to love the new DecimalField:

http://www.djangoproject.com/documentation/model-api/#decimalfield

FloatField now just represents a float in all its glorious imprecision.

Todd


--~--~-~--~~~---~--~~
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: why won't my wildcard url work?

2007-06-15 Thread Todd O'Bryan

On Fri, 2007-06-15 at 11:44 -0700, [EMAIL PROTECTED] wrote:
> I've got urls that could be /section/foo/slug/, /section/bar/slug/, /
> section/whatever/slug/, so I'm trying to use a wildcard selector
> (http://www.djangobook.com/en/beta/chapter03/#s-wildcard-urlpatterns)
> 
> I've tried lots of different ways, but the most promising seems to be
> 
> (r'^section/[^/]+/(?P[-w]+)/$', ... ),
> 
> If I'm reading right, that should match everything up to the next
> slash, but no matter what I seem to try, I 404.

It does. It's the slug that's not matching. [-w] will only match "-" or
"w".

Try:

(r'^section/[^/]+/(?P(\w|-)+)/$, ...),

and see if that works.

Todd


--~--~-~--~~~---~--~~
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: Path problems

2007-06-15 Thread Todd O'Bryan

I figured out the problem. I had missed adding the top-level module to
one of my

import settings

lines. The problem was that even with the debugging output, the actual
problem line never showed up in the exception trace. I actually found it
by using django-admin.py shell and then importing one of the views
modules that was giving me grief. Bingo, the evil import statement
appeared.

On Fri, 2007-06-15 at 09:33 -0400, Todd O'Bryan wrote:
> Hey all,
> 
> I'm trying to deploy a project I've been developing for a long time and,
> in preparation, have tried to move everything (including settings.py,
> etc.) into one overarching module. So, here's my setup: 
> [snip]
> django-admin.py validate --pythonpath=/home/tobryan1/workspace/dmi/src/
> --settings=dmi.settings
> 
> I get
> 
> dmi.orgs: No module named settings
> dmi.recommendations: No module named settings
> dmi.shared: No module named settings
> dmi.calendar: No module named settings
> dmi.assignments: No module named settings
> 5 errors found.



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



Path problems

2007-06-15 Thread Todd O'Bryan

Hey all,

I'm trying to deploy a project I've been developing for a long time and,
in preparation, have tried to move everything (including settings.py,
etc.) into one overarching module. So, here's my setup:

/dmi
__init__.py
manage.py (which I realize I now can't use)
settings.py
urls.py
/assignments
/calendar
/orgs
/recommendations
/shared

This is all inside a src folder in my Eclipse workspace.

When I run

django-admin.py validate --pythonpath=/home/tobryan1/workspace/dmi/src/
--settings=dmi.settings

I get

dmi.orgs: No module named settings
dmi.recommendations: No module named settings
dmi.shared: No module named settings
dmi.calendar: No module named settings
dmi.assignments: No module named settings
5 errors found.

I'm sure the problem must be something to do with my path and
where Django apps expect their settings to come from, but I can't
figure out what's going on. I've searched for explicit mention of
settings in my apps, but don't see anything. I thought maybe I
needed to use configure() or something, but I thought the --settings
option to django-admin.py would handle that.

Does anyone see the problem?

Todd


--~--~-~--~~~---~--~~
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: Doing query with 'ne' terms.

2007-06-14 Thread Todd O'Bryan

You can do a custom SQL query. I don't think you'd *have* to for this,
but someone else will have to provide the correct translation.

Todd

On Fri, 2007-06-15 at 11:50 +0800, Nicholas Ding wrote:
> but I wanna 'where column1 <> %s and column2 <> %s'
> If I were using exclude, the SQL must be 'where not (column1 = %s and
> column2 = %s), that's different.
> 
> On 6/15/07, Todd O'Bryan <[EMAIL PROTECTED]> wrote:
> 
> Django uses different functions for this. To get the opposite
> of this
> (the ne version)
> 
> Foo.objects.filter(bar__exact='something')
> 
> do
> 
> Foo.objects.exclude(bar__exact='something')
> 
> HTH,
> Todd
> 
> On Fri, 2007-06-15 at 11:37 +0800, Nicholas Ding wrote:
> > I found Django can not do '<>' operation in SQL, such as
> "where column
> > <> %s".
> > While diving into the source code, it seems easy to add a
> 'ne' to 
> > existing query terms.
> > But why Django doesn't include this, it's confuse me a lot.
> >
> > Best Regards.
> > --
> > Nicholas @ Nirvana Studio
> > http://www.nirvanastudio.org
> > >
> 
> 
> 
> 
> 
> 
> 
> -- 
> Nicholas @ Nirvana Studio
> http://www.nirvanastudio.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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Doing query with 'ne' terms.

2007-06-14 Thread Todd O'Bryan

Django uses different functions for this. To get the opposite of this
(the ne version)

Foo.objects.filter(bar__exact='something')

do

Foo.objects.exclude(bar__exact='something')

HTH,
Todd

On Fri, 2007-06-15 at 11:37 +0800, Nicholas Ding wrote:
> I found Django can not do '<>' operation in SQL, such as "where column
> <> %s".
> While diving into the source code, it seems easy to add a 'ne' to
> existing query terms.
> But why Django doesn't include this, it's confuse me a lot.
> 
> Best Regards.
> -- 
> Nicholas @ Nirvana Studio
> http://www.nirvanastudio.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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: sleep for 30 minutes?

2007-06-10 Thread Todd O'Bryan

On Sun, 2007-06-10 at 18:03 +, MartinWinkler wrote:
> Hi all,
> 
> I have implemented a captcha solution for django (because the already
> available approaches did not fit my needs), and came to this problem:
> 
> An image is created for every captcha-enabled form that is being
> displayed. Wen the user submits the form, the image is being deleted
> automatically. 

Why actually create a file for the image? Just create the image in
memory and send the stream to the client instead of linking to a real
file on the filesystem. You could also encrypt the response you expect
from the user and include it as a hidden field in the form and then
you're basically stateless (at least as far as the form is concerned).

Todd


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



Date and time formats

2007-06-08 Thread Todd O'Bryan

Is there an easy way to convert from the format strings the template
language uses for the date filter and the strings Python's strftime
method uses?

Here's where this comes up. We're pre-populating a value in a form with
datetime.now() and then using form.as_table() in the template. The time
is shown with microseconds which (probably rightly) won't pass
validation. So we need to reformat the value we're inserting in the
form.

We have three date formats defined for the project--time only, short,
and longer--and it would be nice to be able to use those to format
anything we're sticking in a form to achieve some consistency. But to do
that, we have to define two strings for each format, one for Python and
one for the templating language.

Or do we?

Also, somewhat relatedly, how do DateFields, TimeFields, and
DateTimeFields decide which format to display their contents in when you
use form_for_instance?

Thanks,
Todd


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



limit_choices_to confusion

2007-05-30 Thread Todd O'Bryan

I was trying to use limit_choices_to in what I thought was an intuitive
way.

class Organization(models.Model):
members = ManyToManyField(User)

class Committee(models.Model):
org = ForeignKey(Organization)
chair = ForeignKey(
User,
limit_choices_to={ 'organization_set__contains' : org })

What I want to do is limit the choices for the chair to only people who
are members of the organization. (What I realize now is that the
CONTAINS clause appears in the actual SQL WHERE clause and is trying to
do a text match, so I see why it doesn't work.)

Is there an easy and natural way to do this with the database API?

Thanks,
Todd


--~--~-~--~~~---~--~~
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: ManyRelatedManager object is not iterable

2007-05-30 Thread Todd O'Bryan

On Tue, 2007-05-29 at 21:38 -0400, Todd O'Bryan wrote:
> Template error
> In
> template 
> /home/tobryan1/workspace/dmi/src/dmi/orgs/templates/obligationList.html, 
> error at line 18
> 
> 
> Caught an exception while rendering: 'ManyRelatedManager' object is not
> iterable
> 
> 18 {% for obligation in oblig_list %}
> 
OK. I figured out the problem. Russ was right that I had forgotten
a .all--the problem is that it wasn't here. There was another for-loop
nested in this one, and that was where the problem was. It's a mystery
to me why the error was reported with this line instead of the line
where it actually occurred. Is that maybe a bug?

Todd


--~--~-~--~~~---~--~~
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: ManyRelatedManager object is not iterable

2007-05-29 Thread Todd O'Bryan

On Wed, 2007-05-30 at 09:50 +0800, Russell Keith-Magee wrote:
> On 5/30/07, Todd O'Bryan <[EMAIL PROTECTED]> wrote:
> >
> > Caught an exception while rendering: 'ManyRelatedManager' object is not
> > iterable
> >
> > 18 {% for obligation in oblig_list %}
> >
> > Any ideas what's going on?
> 
> The Manager isn't iterable, but the query sets it produces are.
> 
> You're looking for:
> 
> {% for obligation in oblig_list.all %}
> 
But didn't I already do that in the view? Or am I not allowed to do
that?

def obligation_list(request, org_name):
org = Organization.objects.get(slug=org_name)
--> oblig_list = org.obligation_set.all()
return render_to_response('obligationList.html',
  {'oblig_list': oblig_list, 'organization':
org},
  RequestContext(request))

Todd


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



ManyRelatedManager object is not iterable

2007-05-29 Thread Todd O'Bryan

With the latest from SVN, I'm getting an error in a template, but I
can't figure out why...

def obligation_list(request, org_name):
org = Organization.objects.get(slug=org_name)
oblig_list = org.obligation_set.all()
return render_to_response('obligationList.html',
  {'oblig_list': oblig_list, 'organization':
org},
  RequestContext(request))

Here's the (relevant part of the) model:

class Obligation(models.Model):
organization = models.ForeignKey(Organization, editable=False)

And the (relevant part of the) error I get in the browser:

Template error
In
template 
/home/tobryan1/workspace/dmi/src/dmi/orgs/templates/obligationList.html, error 
at line 18


Caught an exception while rendering: 'ManyRelatedManager' object is not
iterable

18 {% for obligation in oblig_list %}

Any ideas what's going on?

Thanks,
Todd



--~--~-~--~~~---~--~~
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: My Learning Path

2007-05-19 Thread Todd O'Bryan

Check out How to Think Like a Computer Scientist (Python version). It's
an intro CS text, so it may be a little basic, but it does a very good
job of introducing all of the important Python concepts in a very
easy-to-understand way. Dive Into Python is a terrific book, but it
assumes considerable experience with some other language and PHP may not
not provide enough of that to make it easily accessible.

Here's the link:

http://www.ibiblio.org/obp/thinkCSpy/

Todd

On Sat, 2007-05-19 at 01:52 -0700, chell wrote:
> Thanks for the reply. I think I'll do the following (as I can't afford
> books at the moment):
> 
> 1. Dive into Python
> 2. Django Tutorial
> 3. Django Book
> 4. A first project (maybe a blog) using the Django documentation if I
> have to
> 
> Does that sound good?
> 
> 
> On 19 Mai, 10:24, Kelvin Nicholson <[EMAIL PROTECTED]> wrote:
> > chell wrote:
> > > Hello,
> >
> > > I'm a beginner to Python and Djano. I have some experience with PHP,
> > > but that's all.
> >
> > Be ready to be blown away with blissfulness:)
> >
> > To get your feet wet with python you can check out Dive Into Python,
> > freely available online:http://www.diveintopython.org/
> >
> > While you can maybe "get by" writing Django apps without an in-depth
> > knowledge of python, to do anything useful will be difficult.  Plus, in
> > my opinion, python is pretty fun.
> >
> > I guess I would recommend flipping through the DIP site while going
> > through the Django tutorial and Django book.
> >
> > My learning path was:
> >
> > 1) Beginning Python - From Novice To Professional (2005)
> > 2) Django tutorial
> > 3) Django book (http://www.djangobook.com)
> > 1/2/3) Django documentation (which is mostly pretty darn good) when
> > needed, and either the python docs or the DIP site if I run into
> > something I am unsure about.
> >
> > You can consider jumping into IRC as well if you haven't already.
> >
> > Cheers,
> >
> > Kelvin
> >
> > --
> > Kelvin Nicholson
> > Voice: +886 9 52152 336
> > Voice: +1 503 715 5535
> > GPG Keyid: 27449C8C
> > Data: [EMAIL PROTECTED]
> > Skype: yj_kelvin
> > Site:http://www.kelvinism.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: excel import

2007-05-14 Thread Todd O'Bryan

Check out Xlrd. It will import Excel files and change them into a list
of lists.

http://cheeseshop.python.org/pypi/xlrd/0.5.2

Todd

On Mon, 2007-05-14 at 11:25 +0200, Aidas Bendoraitis wrote:
> Hello, Dmitry!
> 
> You could save the excel sheet as comma separated values and then read
> and parse them line-by-line using python.
> 
> For each category (which is one of the columns) you can get_or_create
> a category record in the database and assign that as a foreign key or
> many to many relationship to the record of the main item.
> 
> All the further details depend on your models and business requirements.
> 
> Regards,
> Aidas Bendoraitis aka Archatas
> 
> 
> 
> On 5/12/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> >
> > Hello, everyone!
> >
> > I want to implement some sort of importing data into my database from
> > excel. And i have a problem: this xls tables are huge and needs to be
> > normalized to relation structure, in other words i want to torn one
> > excel table to many with FK relationships between them, but i dunno
> > how to do this: in my python import function, or some kind of SQL
> > procedure, or there are software, which can do that. Please, advice
> >
> > Regards, Dmitry Shevchenko.
> >
> >
> > >
> >
> 
> > 


--~--~-~--~~~---~--~~
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: Recommended Editor/IDE

2007-04-30 Thread Todd O'Bryan

Does anybody have a sense of how hard it would be to add code completion
support for Django to Pydev? I think the problem is that there are some
many instance variables and functions that are computed on the fly,
rather than being declared in the classes' init functions.

Todd

On Mon, 2007-04-30 at 10:10 -0700, raminf wrote:
> I've been using a mix of Eclipse with PyDev to do Django work. It
> works well except for Django code completion (none of the IDEs seem to
> support it well enough to be useful). I've also had pretty good luck
> with Komodo, but with Eclipse you can also do front-end javascript
> development with Aptana installed. The latest Komodo is supposed to
> have that support as well, but I haven't played with it yet.
> 
> HTH.
> 
> 
> On Apr 29, 7:32 pm, Sat <[EMAIL PROTECTED]> wrote:
> > Hi,
> >
> > Is there a recommended editor or IDE for windows that is django savvy?
> > Ideally, I am looking for one that handles bundles/snippets for django
> > as well as syntax highlighting and code completion for django and
> > python.
> >
> > Thanks in advance for your help.
> >
> > Sat
> 
> 
> > 


--~--~-~--~~~---~--~~
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 comparison

2007-04-17 Thread Todd O'Bryan

On Tue, 2007-04-17 at 21:03 -0500, M Harris wrote:
> On Monday 16 April 2007 11:09, James Bennett wrote:
> > A CMS like Joomla is a house, pre-built. A framework like Django is a
> > toolbox and some raw materials.
>   Thank you for your responses folks.  This is helpful.  Are there 
> packages of 
> Django templates available... as in your analogy... a restaurant template... 
> an office building template... etc.

Not really. Although there are substantial numbers of parts of
things..fields to hold email addresses, phone numbers, etc. But not a
whole project that you could just customize and make into your own
contact application, alas.

>   The other question I have for the community is this:  Django ships with 
> a 
> "simple" web server.  Is this server designed for Django development /testing 
> only?  Can it be safely put on-line, or is it better to run on Apache, etc.?

Run under Apache. The Django server would be slower and would be more
likely to fail once you got any kind of load on the server.

Todd


--~--~-~--~~~---~--~~
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: Dumb URL question

2007-04-14 Thread Todd O'Bryan

Just a guess, but if the admin is enabled, that pattern is probably
checked first. It's never getting to your pattern because it's matching
the admin pattern.

Todd

On Sat, 2007-04-14 at 09:34 -0500, Mike Hostetler wrote:
> I've been looking at this for a couple of hours and I have no idea
> what is happening.
> 
> In my urls.py I have this:
> 
> urlpatterns = patterns('',
>  (r'^admin/myapp/mymodel/', ',myapp.views.viewmodels'),
>   
> 
> When I go to http://localhost:8000/admin/myapp/mymodel
> it has ignored my pattern and went to the default admin change_list view.
> 
> How do I know this?  There is no views.pyc file, and I put in an error
> in the myapp.views to make sure I knew if I hit it.
> 
> Anyone please let me know what did wrong . .


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [EMAIL PROTECTED]
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: Simple python question

2007-04-10 Thread Todd O'Bryan

On Tue, 2007-04-10 at 18:03 -0500, Jeremy Dunck wrote:
> On 4/10/07, Todd O'Bryan <[EMAIL PROTECTED]> wrote:
> ...
> > The key is that he wanted to use the string name of the class, not the
> > class itself. Assuming that Foo is available (i.e., is local to the code
> > you're running or has been imported), this should work:
> >
> > o = locals()['Foo']()
> 
> Oh.  In that case, you also want to make sure the string is trust-worthy.
> 
> I hope you're not creating a class instance from a request parameter. :)

What he said! (I'm inclined to be so trusting...)



--~--~-~--~~~---~--~~
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: Simple python question

2007-04-10 Thread Todd O'Bryan

On Tue, 2007-04-10 at 17:50 -0500, Jeremy Dunck wrote:
> On 4/10/07, Grupo Django <[EMAIL PROTECTED]> wrote:
> >
> > I know this is not the right place for asking about python, but it's a
> > simple question.
> > I need to load an object given in a string. Example:
> >
> > #I have a class called foo
> > class foo:
> > def Hello():
> > return "Hello World"
> >
> > object = 'foo'
> >
> > print object.Hello()
> 
> You probably don't really want to use the variable name "object",
> since that's also the name of Python's base class.
> 
> But just to follow your example, these lines (almost) do what you want:
> 
> object = foo()
> print object.Hello()
> 
> Now I'll rewrite it using better Python conventions and correct a small bug:
> 
> class Foo(object):
> def hello(self):
> return "Hello World"
> 
> o = Foo()
> print o.hello()
> 
The key is that he wanted to use the string name of the class, not the
class itself. Assuming that Foo is available (i.e., is local to the code
you're running or has been imported), this should work:

o = locals()['Foo']()

The locals() function returns a dictionary with all currently defined
names as keys mapped to their current values. Since 'Foo' is mapped to a
class, the code above gets the class and then makes an instance by
calling it like a function.

Todd


--~--~-~--~~~---~--~~
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: Global model/view best practice help

2007-04-10 Thread Todd O'Bryan

On Tue, 2007-04-10 at 22:21 +, Dave wrote:

> I could add to the Context object in each view, but that's a lot of
> repeat code (urgh). Also, if I were to take that route, I'd need the
> Model to be available between multiple apps within a project and I've
> not seen how to do that.

You want a TEMPLATE_CONTEXT_PROCESSOR. Write a function that takes a
request and returns a dictionary with the name you want for your
included model. Then add that function to TEMPLATE_CONTEXT_PROCESSORS in
your settings.py file. Voila.

Todd


--~--~-~--~~~---~--~~
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: Which ajax framework django will support in the upcoming 1.0, prototype/dojo/jquery?

2007-04-10 Thread Todd O'Bryan

On Tue, 2007-04-10 at 18:11 +, Steve Bergman wrote:
> But Django definitely has a preferred ORM and a preferred templating
> engine.  Why be so set on complete agnosticism when it comes to
> javascript?
> 
I agree. I don't have time to weigh the benefits of various libraries.
As someone mentioned, we have stuff that translates to various
databases. Why not factor out the important stuff and create interfaces
to the JavaScript libraries people are interested in.

Todd


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



Drop-down choice or create new; how to handle?

2007-04-10 Thread Todd O'Bryan

We've discovered in a couple of places that we need the ability for
people to choose something from a list or to create a new item. In the
admin, creating a new item involves having a pop-up open, but we'd like
to avoid that, if possible.

We've kind of decided on a "Create new..." item in the list that would
cause a text field to appear via JavaScript magic. Moving away from
"Create new..." to one of the other choices would cause the text field
to disappear.

First question: Does this seem reasonable/intuitive/clean?

Second question: Right now, we think the easiest way to implement this
is by creating a new Field class that combines the drop-down field and
text field and includes the JavaScript necessary to combine them
together. Is that the right approach or should we be looking for
something less complicated?

Thanks,
Todd



--~--~-~--~~~---~--~~
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: Announcing Django 0.96!

2007-03-24 Thread Todd O'Bryan

Django gets installed in your Python version's site-packages
folder--/usr/lib/python2.x/site-packages is typical for Linux. Probably
the easiest thing to do is delete the django folder you find there and
re-install.

Todd

On Sat, 2007-03-24 at 13:14 -0700, mariuss wrote:
> On Mar 23, 5:13 pm, "mariuss" <[EMAIL PROTECTED]> wrote:
> > I downloaded 0.96 and installed it using "python setup.py install"
> >
> > But it is still Django 0.95.1 (previously installed) that shows up.
> > How can I uninstall the old version?
> 
> Any suggestions? Pointers to some documentation?
> 
> The answer could be trivial, but since I am not familiar with
> setuptools I can't figure this out. Checked the setuptools site, could
> not find anything related to uninstall. Probably I am looking for the
> wrong thing.
> 
> Thanks,
> Marius



--~--~-~--~~~---~--~~
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 problem with view/model interaction

2007-03-24 Thread Todd O'Bryan

What is it you want to do with the ones they've voted on vs. haven't? If
you're going to hide the ones they've already voted on, just write a
query in the view method that only returns those and pass that to the
context. (Note: the view method, not the template. See Ivan's response.)

If they have to be in alphabetical order by title and you're going to
show all of them, add something to each one that indicates whether
they've been voted on. Your list could morph into a list of tuples where
the first item is a paper and the second item is a boolean indicating
whether the current user has voted.

Something like:

def display_votes(request):
all_papers = Paper.objects.all()
tuple_list = [(p, p.has_voted(request.user)) for p in all_papers]
...

Then in the template:

{% for paper_voted in tuple_list %}
{% if paper_voted.1 %}
   stuff if they voted, paper is accessible as paper_voted.0
{% else %}
   stuff if they haven't
{% endif %}

HTH,
Todd

On Sat, 2007-03-24 at 07:55 -0700, Ross Burton wrote:

> My initial implementation was split across the template and the
> model.  In my model:
> 
> class Paper (models.Model):
> ...
> def has_voted(paper, user):
> return paper.vote_set.filter(user__exact = user).count() != 0
> 
> then in the view:
> 
> {% for paper in object_list|dictsort:"title" %}
>   {% if paper.has_voted( TODO ) %}
> 
> 
> I then discovered that you can't pass arguments to methods in
> templates, so I can't ask the model if the current user has voted.
> 
> Can anyone give any hints on how I can fix this?
> 
> Thanks,
> Ross



--~--~-~--~~~---~--~~
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: How to handle a preview page

2007-03-24 Thread Todd O'Bryan

On Sat, 2007-03-24 at 08:41 +1100, Malcolm Tredinnick wrote:

> Quite often, preview and edit are combined on the same form, so you see
> the preview version at the top and the editable fields lower down. If
> you do this, your single form (for edit/create) just needs a block at
> the top that contains the optional "static preview" version.

Yeah. I don't mind this much in wikis, but it feels ugly to me in
general, especially if the form is rather long.

> Another way is to layout the form fields as you normally would and then
> use CSS to hide them (feels ugly to me, but technically possible).

That's an idea, but probably not great for text readers. And you're
right--using CSS for what is basically content formatting is just as
bad, IMHO, as using HTML for presentation.

> If you don't want to do either of these and truly want to store the
> information in hidden fields the second time around, then, yes, you are
> going to have to specify all the hidden fields, or provide a way to
> alter the "type" of your original fields between their editable type and
> "hidden". So there will be some repetition, whether you generate them
> programmatically or by hand. That really can't be avoided because you
> *are* repeating the information.

Let me ask a silly question before I go off and do something radical,
just to make sure I won't hit a brick wall later.

I'm trying to model every conceivable kind of question in a way that
won't involve changing the database later. To do this, my Question model
has some meta-information and has a OneToMany mapping to a DataBit
model. A DataBit has fields for type and one piece each of textual and
numeric data. If I want a true/false question, it has two DataBit
objects: a bit containing the statement and a bit indicating whether
it's true or false. If I want a fill-in-the-blank question, it has one
DataBit instance for the statement and one for each answer that belongs
in the blanks. For a multiple-choice question, there are several bits:
the question, each possible answer, and a bit saying which answer is
correct.

Obviously, trying to represent these things directly from the database
is a bit of a pain, so I have non-model classes that translate from the
representation in the database to a more natural representation and vice
versa. These classes also create the forms (as in django.newforms) that
I display.

Could I pickle one of these non-model objects and use the pickled value
in a hidden field to store everything all at once and then get it back
really easily? I've never used pickle, so I'm a little apprehensive that
there are gotchas I don't know about, but, if it works the way it's
advertised, it seems an easy way to dump something into the preview and
then reconstruct it on the way out. Are there any gotchas I should be
aware of before I start?

Thanks for reading all of that,
Todd


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



How to handle a preview page

2007-03-23 Thread Todd O'Bryan

I'm trying to create the following workflow for a website where teachers
can create questions for their students:

1. The teacher click a link to create a new question.
2. A form appears where the teacher can enter information, including
formatting information in some kind of wiki-like language. At the bottom
of the form, the teacher clicks Cancel (to discard what they were
working on) or Preview (to see the question formatted).
3. After clicking Preview, the question is shown in HTML glory, with
three buttons at the bottom: Save, Edit, or Cancel.

Here's my question: how do I keep track of the information while the
teacher is previewing it so that I can have access to it when I want to
edit or save it? The obvious answer is to stick in a form filled with
hidden fields, but I can't figure out any way to do that without
defining a completely new form that's exactly the same as the original
except that all the fields are hidden, and that just seems silly.

Any brilliant ideas that avoid violation of DRY?

Thanks,
Todd


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



IRC

2007-03-19 Thread Todd O'Bryan

I'm trying to use XChat to connect to the IRC channel, but I can only
find #django-br and #django-fr on FreeNode.

What am I stupidly doing?

Todd


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



Wiki account

2007-03-16 Thread Todd O'Bryan

I just edited a Wiki page and maybe I'm dense, but I couldn't figure out
how to create an account, so I had to do it anonymously.

Is there a way to get a Trac account or are those reserved for the
nobility?

Todd


--~--~-~--~~~---~--~~
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: newforms with no pre-set number of fields

2007-03-16 Thread Todd O'Bryan

On Fri, 2007-03-16 at 17:41 +, Rubic wrote:
> Just use a ChoiceField with a radio or checkbox widget.
> 
>   http://www.djangosnippets.org/snippets/26/
> 
> --
> Jeff Bauer
> Rubicon, Inc.

Sorry, wasn't clear. I know how to do it if the question has already
been created. My problem is how to create the form to create the
question in the first place, since each possible answer has to have its
own textarea input widget.

I guess what I want is some way to create a form with a variable number
of fields rather than a fixed number.

Todd


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



newforms with no pre-set number of fields

2007-03-16 Thread Todd O'Bryan

I'm trying to design a form for multiple choice questions:

Question: 
Answer A: 
Answer B: 
Answer C: 

Correct Answer: 
   A
   B
   C...


Explanation: 

The problem is that I don't want to fix the number of possible answers
so that I can use the same form for questions with 3, 4, 5, or more
choices.

Is there an easy way to do that with newforms or am I out of luck?

Todd


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



  1   2   3   >