Re: Rails-style form value deserializer?

2009-12-23 Thread Todd Blanchard
Yeah - I'm going to shelve django and see what is up with TG2 and its Geo 
extensions for awhile.

It has become very clear that it is "not a fit" for the kind of dynamic web 
application development I'm looking for.  I need effective and well integrated 
ajax out of the box and the ability to compose forms dynamically and quickly.

Thanks for the help.  I may pick it up again - but probably not for this 
project.

-Todd Blanchard

On Dec 20, 2009, at 1:06 AM, Russell Keith-Magee wrote:

> As for dynamically expanding forms - Django treats that as a client
> side problem. Django doesn't ship with any javascript dependencies in
> it's form library, so it doesn't provide dynamically expanding forms
> out of the box.
> 
> It's not that difficult to do, though. You just have to dynamically
> create form elements, and tweak the formset management fields [2] in
> the submitted form.

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Rails-style form value deserializer?

2009-12-19 Thread Todd Blanchard
I think what i actually want is a form set, but I don't find that all that well 
done either.

What I'm finding lacking is the ability to put a master/detail relationship in 
a single form.  For instance, Author/Books.  Furthermore, I don't see a nice 
way to work with dynamically expanding forms - IOW, allow the user to keep 
adding books to an Author using DHTML.

So far my impression of forms is - ick - lame.

-Todd Blanchard


On Dec 19, 2009, at 4:37 PM, Karen Tracey wrote:

> On Fri, Dec 18, 2009 at 7:27 PM, Todd Blanchard  wrote:
> One thing I'm keenly missing from rails is the form input naming convention 
> that causes the form values to be converted into a hierarchy.  For instance,
> 
> 
> 
> 
> will result in the request values being stored as { 'foo'  : {'bar' : 'one', 
> 'baz' : 'two' }}
> 
> this is very handy when updating multiple related objects in a single form 
> submit.
> 
> Is there a similar facility for django/python or will I need to write it?
> 
> 
> I think you might be looking for the form prefix argument:
> 
> http://docs.djangoproject.com/en/dev/ref/forms/api/#prefixes-for-forms
> 
> Karen
> 
> --
> 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Rails-style form value deserializer?

2009-12-19 Thread Todd Blanchard
Clear as mud.  Where does it show how I update two objects in one form?

On Dec 19, 2009, at 1:16 PM, Antoni Aloy wrote:

> 2009/12/19 Todd Blanchard :
>> How does this solve the problem of having two related objects that have the
>> same attribute name (like "name") on the same html form?  As I see it, it
>> doesn't.  There will be a conflict and it will be impossible to keep them
>> separate.
>> IOW,
>> 
>> {{ account_form }}
>> {{ contact_form }}
>> 
>> 
>> def update_account_and_contact
>> if(request.POST)
>> account_form = AccountForm(request.POST, instance=get_object_or_404(Account,
>> id=request.POST['id'])
>> contact_form = ContactForm(request.POST, instance=get_object_or_404(Contact,
>> id=request.POST['id'])
>> if(account_form.is_valid() && contact_form.is_valid())
>> account_form.save()
>> contact_form.save()
>> .
>> 
>> The rails solution is much superior.
>> 
> 
> Thi is clearly explained in the Django documentation about forms
> http://docs.djangoproject.com/en/dev/ref/forms/api/#ref-forms-api
> 
> Django documentation us much superior :-P
> 
> 
> -- 
> Antoni Aloy López
> Blog: http://trespams.com
> Site: http://apsl.net
> 
> --
> 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 
> 

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Rails-style form value deserializer?

2009-12-19 Thread Todd Blanchard
How does this solve the problem of having two related objects that have the 
same attribute name (like "name") on the same html form?  As I see it, it 
doesn't.  There will be a conflict and it will be impossible to keep them 
separate.

IOW,


{{ account_form }}
{{ contact_form }}



def update_account_and_contact
if(request.POST)
account_form = AccountForm(request.POST, 
instance=get_object_or_404(Account, id=request.POST['id'])
contact_form = ContactForm(request.POST, 
instance=get_object_or_404(Contact, id=request.POST['id'])
if(account_form.is_valid() && contact_form.is_valid())
account_form.save()
contact_form.save()
.


The rails solution is much superior.



On Dec 19, 2009, at 2:15 AM, Jani Tiainen wrote:

> 
> 
> 
> Result is stored in request.POST (or you can do same with get params, 
> ?foo=one&foo=two). 
> 
> for example request.POST.getlist('foo'). Default getitem implementation 
> returns only last occurence from list.
> 
> See: 
> http://docs.djangoproject.com/en/1.1/ref/request-response/#querydict-objects 
> for more info.
> 
> On Sat, Dec 19, 2009 at 2:27 AM, Todd Blanchard  wrote:
> One thing I'm keenly missing from rails is the form input naming convention 
> that causes the form values to be converted into a hierarchy.  For instance,
> 
> 
> 
> 
> will result in the request values being stored as { 'foo'  : {'bar' : 'one', 
> 'baz' : 'two' }}
> 
> this is very handy when updating multiple related objects in a single form 
> submit.
> 
> Is there a similar facility for django/python or will I need to write it?
> 
> -Todd Blanchard
> 
> --
> 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 
> 
> 
> 
> --
> 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.




Rails-style form value deserializer?

2009-12-18 Thread Todd Blanchard
One thing I'm keenly missing from rails is the form input naming convention 
that causes the form values to be converted into a hierarchy.  For instance,




will result in the request values being stored as { 'foo'  : {'bar' : 'one', 
'baz' : 'two' }}

this is very handy when updating multiple related objects in a single form 
submit.

Is there a similar facility for django/python or will I need to write it?

-Todd Blanchard

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.




attachments vs filebrowser

2009-12-18 Thread Todd Blanchard
I need users to attach arbitrary media files to database records.  Attachments 
seems to do what I need, except that its UI is utterly lame - it should figure 
out the media type of the file from the extension and display an appropriate 
thumbnail as well as a way to provide a viewer inline.  Also, it relies on a 
bunch of custom tags for django's template processor but I'm using jinja2.

filebrowser seems smarter this way, but seems targeted strictly at trusted 
users.  I need arbitrary users to be able to attach files.

Is there something else I ought to consider?  

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.




Stuck trying integrate jinja2 - need compatibility extensions

2009-12-09 Thread Todd Blanchard
OK, first let me start by saying I tried to live with the django template 
processor.  But I need more power.  I like jinja2's macros - much slicker than 
having to write a custom tag.

So I've downloaded jinja2 and installed it.  Good.

After trying a couple of integration recipes on the web that "almost but not 
quite worked" I've found and downloaded chouwa and started using that.  This 
works.  Good.

I have templates I want to inherit from that were written for the default 
template processor that use tags with names like 'url'.  Amazingly, jinja2 
lacks this and a few other commonly used tags.  So I'm looking for 
compatibility extensions.

I found: http://www.djangosnippets.org/snippets/1062/

Which looks like it might solve my problem - if I could get it recognized by 
jinja2's initialization.  I've copied this code to a file at the root level of 
myapp called tags.py

I've added the following to my settings.py file

JINJA_EXTS = (
'jinja2.ext.i18n',
'jinja2.ext.do',
'jinja2.ext.loopcontrols',
'from myapp.tags import *',
)


JINJA2_ENVIRONMENT_OPTIONS = {
'extensions': JINJA_EXTS,
}

I've tried half a dozen incantations trying to get these functions imported as 
extensions to jinja2 and nothing seems to work.  I've tried
'myapp.tags'
'myapp.tags.url' (this one produces a scary error 'no patterns in myapp.urls' 
and the entire app dies)

and a few others.  I'm stuck.  What's the trick to getting compatibility tags 
for django installed into jinja2?

-Todd Blanchard

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Sick of defining urls

2009-12-04 Thread Todd Blanchard
First, thanks for the critiques - I'm not surprised there are better ways to 
write this as I'm just learning python.

Second, url mapping for me is trivial.  Its a web app, not a web site.  I would 
be fairly happy with totally opaque urls ala seaside as long as I didn't have 
to think about them.  

But url mapping isn't enough of a factor to make me choose pylons.  I chose 
django because of the availability of geodjango, olwidigte, the admin, auth 
framework, and a number of other goodies.  I don't get those with pylons.

As I've already said, I'm happy with my solution.  If I decide I need something 
else, I can change it, later, right?  Development time drops exponentially with 
the number of files I have to edit to do a task.  

Bouncing over to urls.py every time I write another page view was a significant 
time sync (especially since I'm no regex maven - I use them seldom and always 
have to look them up and fiddle around with them for quite awhile to get them 
right).

So, no, I would not be happier with pylons.  I'm happy here with this 
modification, thanks.

-Todd Blanchard

On Dec 4, 2009, at 12:41 AM, bruno desthuilliers wrote:

>  If you really want routes and
> rails-like controllers, you'd be way happier with Pylons.

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Forms - readonly representation?

2009-12-03 Thread Todd Blanchard
I'd gotten nearly a dozen responses to a later question so I figured the 
threshold of awareness had passed on this one.

Anyhow, I'll check that one out.  Thanks.

On Dec 3, 2009, at 2:48 PM, Nick Arnett wrote:

> tempted not to respond due to the "deafening silence" comment... did you 
> imagine you're due an instant answer?

--

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




Re: What apps do besides provide views?

2009-12-03 Thread Todd Blanchard
Models?  Where do I find an example?

I've got Pro Django, Definitive Guide to Django, Python Essential Reference, 
and I've read the online django tutorial and a bunch of random docs.  I have 
yet to see an instance of mapping a url to a model.

Or, I don't know what you mean by model vs view (because when I say view - I 
mean just a function that takes a request, returns a response, and lives in a 
file called views.py).

What am I missing?

On Dec 3, 2009, at 11:58 AM, bruno desthuilliers wrote:

> On 3 déc, 20:42, Todd Blanchard  wrote:
>> On Dec 3, 2009, at 10:46 AM, Javier Guerra wrote:
>> 
>>> remember that an app can do a lot more than provide views.
>> 
>> Explain this one to me.  AFAICS, its just http request/response all the way 
>> down and this is basically done by getting a request to a view that spits 
>> out a response.  Side effects like updating the database sometimes occur.
> 
> An app can expose views, indeed. It can also expose models - one of
> the most important parts of an application -, templatetags, filters,
> forms, fields, widgets etc. FWIW, the views are perhaps one of the
> less important thing an app has to offer - and obviously the most easy
> to factor out, cf genericviews. Models, OTHO, are really the core. If
> you end up writing most of your code in views, then you more than
> probably failed to identify what belongs to the model and what belongs
> to the views. The fact that "views" are a mandatory part of the
> request-response cycle doesn't mean they are the most important part
> of the app.
> 
> --
> 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 
> 

--

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




What apps do besides provide views?

2009-12-03 Thread Todd Blanchard

On Dec 3, 2009, at 10:46 AM, Javier Guerra wrote:

> remember that an app can do a lot more than provide views.

Explain this one to me.  AFAICS, its just http request/response all the way 
down and this is basically done by getting a request to a view that spits out a 
response.  Side effects like updating the database sometimes occur.

> OTOH, a shortcut to deal with repeating code would be really welcomed.

Yeah, app integration right now seems very non-DRY and much too fiddly.  Stands 
to reason that including an app implies you include the app's urls and 
templates - or why include it?  I definitely cringe when copying an integrated 
app's templates into my project's template hierarchy.

-Todd Blanchard

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Forms - readonly representation?

2009-12-03 Thread Todd Blanchard
>From the deafening silence, I'm going to take this as a "no". 

Seems like a pretty basic enhancement - sometimes you want to display data in 
the same layout as a form, but not editable (checkboxes disabled, text fields 
just styled text).

And nobody thought of it?

On Dec 3, 2009, at 9:05 AM, Todd Blanchard wrote:

> Forms seem nifty, but sometimes I want to display the data in the same format 
> but readonly.  Is there a to do this?  I can't seem to find it.
> 
> -Todd Blanchard
> 
> --
> 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 
> 

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Sick of defining urls

2009-12-03 Thread Todd Blanchard
Oh, I've already come to terms with that.  So long as XCode makes indenting 
easy I'm OK. :-)

On Dec 3, 2009, at 11:19 AM, Alex Robbins wrote:

> If you start to complain about significant whitespace too, you aren't
> welcome to stay either. :)

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Sick of defining urls

2009-12-03 Thread Todd Blanchard
I'm quite aware how the amazon browse service works.  I also know it takes a 
whole team of people to manage it.  I'm one guy. :-)

On Dec 3, 2009, at 10:31 AM, Sean Perry wrote:

> Here is the page on Amazon for Learning Python:

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Sick of defining urls

2009-12-03 Thread Todd Blanchard
Not sure what you mean?  You mean something that looks through the code and 
generates/expands urls for the view methods it finds?

I don't see the point of that exactly.  The dynamic dispatch I'm doing does the 
same thing and I prefer dynamic dispatch to code generation (I abhor code 
generation).  

I do have one additional little complaint about url handling and application 
integration in general.

settings.py has a list of applications to include (INSTALLED_APPS).  Fine.  But 
then, in urls.py I have to repeat myself by importing each application's 
urls.py to add them.  (r'^admin/', include(admin.urls)),

And then I have to fiddle the template path so the templates in the application 
are found or create a symbolic link from my templates root folder to the 
templates folder in the app.

So enabling an application takes two or three steps, rather than one.  Not DRY 
at all.   Just adding an app to INSTALLED_APPS should make all this other stuff 
just happen.

-Todd Blanchard

On Dec 3, 2009, at 9:40 AM, Javier Guerra wrote:

> have you considered writing a url pattern generator? if it's handy
> enough, it would become quite popular...

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.




Forms - readonly representation?

2009-12-03 Thread Todd Blanchard
Forms seem nifty, but sometimes I want to display the data in the same format 
but readonly.  Is there a to do this?  I can't seem to find it.

-Todd Blanchard

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Sick of defining urls

2009-12-03 Thread Todd Blanchard
On Dec 3, 2009, at 6:34 AM, Javier Guerra wrote:

> first of all, if you want Rails, you know where to find it.  i (and
> several others, i guess) like Django in part because it's *not* Rails.
> :-)

Django has several superior features to rails that drive me to use it.  The 
admin is much better than active scaffold, there are a number of already 
written apps, geodjango postgis integration, scalability, etc.

That doesn't mean I have to think it is superior in every way and when its not, 
I'm apt to point them out.  No good idea should go unstolen IMO. 

I'm going to stick with preferring convention over configuration.  If I want to 
write boilerplate over and over I'll use J2EE. :-)

I've solved my urls problem for now (though I'm open to more elegant solutions) 
but I think not having a default url scheme is lame.  Rails has routes which 
means you can rearrange the url patterns anyway you like, just like django.  In 
practice this is mostly a waste of time and you just use the defaults.  That 
doesn't mean I have zero custom routes in all my apps, but I have very few 
because the defaults are so well chosen.  Django, OTOH, provides no sensible 
default url scheme at all out of the box.  I don't see that as a feature, its a 
pointless time drain.

I've read the little poem.  I disagree with about half of it.  If you can't 
take constructive criticism of your toolkit (I have plenty negative to say 
about rails and any of the other dozen web app development environments I know 
too) then you should maybe put down the kool-aid and walk away.  No environment 
is perfect.

I do thank everyone who has been so generous with help so far and thanks in 
advance for any future help.  I'm trying to learn python, django, postgis, and 
a whole other raft of technologies all at once.  Its a steep curve and I can 
use all the help I can get.  

-Todd Blanchard



--

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




Re: Using a form to UPDATE a record?

2009-12-03 Thread Todd Blanchard
That did it.  I figured if the form had a primary key it would do an update.  I 
guess that was wrong.

The url is the form you describe, but the dispatcher view method adds the id to 
the GET of the request to pass it on.  So the url for this is actually 
/incidents/edit/4.

Thanks. 

On Dec 3, 2009, at 1:59 AM, Daniel Roseman wrote:

> Note it's more Django-nic (that isn't a word, but it should be) to
> pass the ID to edit as part of the URL (eg edit/4/), rather than as a
> GET parameter.

--

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




Re: Using a form to UPDATE a record?

2009-12-03 Thread Todd Blanchard
K

def edit(request):
form = None
if request.method == 'GET':
try:
form = IncidentForm(instance = Incident.objects.get(id = 
request.GET['id']))
except ObjectDoesNotExist:
raise Http404
else:
form = IncidentForm(request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect('/incidents')

media = form.media
return render_to_response('incidents/new.html',{'form': form, 'media': 
media, 'view': 'Edit'},context_instance=RequestContext(request))


class IncidentForm(forms.ModelForm):

place = forms.CharField(widget=EditableMap(options={
'layers': ['google.hybrid', 'google.streets', 'google.physical', 
'google.satellite',  ],
'default_lat': 39.4421,
'default_lon': -100.0,
'default_zoom': 3,
'geometry': 'point',
'map_div_style': {'width': '400px', 'height': '300px'},
}))
when_occurred = forms.DateTimeField(widget=widgets.AdminSplitDateTime())
reporter = forms.ModelChoiceField(User.objects.all(), 
widget=forms.HiddenInput())
id = forms.CharField(widget=forms.HiddenInput())
 
class Meta:
model = Incident
fields = ('title', 'when_occurred', 'place', 'notes', 'what_type', 
'reporter', 'id')



On Dec 3, 2009, at 1:30 AM, Daniel Roseman wrote:

> On Dec 3, 8:53 am, Todd Blanchard  wrote:
>> Thanks, that makes the form show up populated.
>> But saving it creates a new record, despite making sure I have id in a 
>> hidden field on the form.  :-/
> 
> It does work, so you'll need to show us some code so we can see where
> you're going wrong.
> --
> DR.
> 
> --
> 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 
> 

--

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




Re: Using a form to UPDATE a record?

2009-12-03 Thread Todd Blanchard
Thanks, that makes the form show up populated.
But saving it creates a new record, despite making sure I have id in a hidden 
field on the form.  :-/

On Dec 3, 2009, at 12:26 AM, Rishabh Manocha wrote:

> On Thu, Dec 3, 2009 at 4:17 PM, Todd Blanchard  wrote:
>> All the tutorials on forms discuss creating a new record.
>> 
>> I've got a record in the database, I want to fetch it, plunk its values into 
>> a form, let the user edit it and save it.
>> 
>> I don't see how to conveniently put the model's values into the form.  It 
>> seems the form wants a dictionary of values, so how to convert a model 
>> object to a dict?
>> 
>> -Todd Blanchard
>> 
>> --
>> 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To post to this group, send email to django-us...@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.
>> 
>> 
>> 
> 
> Assuming you'd use a ModelForm[1] to update the records, all you need
> to do is something like the following:
> 
> my_record = Record.objects.get(id = 1)
> my_form = MyRecordModelForm(instance = my_record)
> 
> You will then have a form with the 'values' on the fields pre-set.
> Users can then edit the form to their hearts content, submit it and
> you can the process the form[2] as you would normally do with a
> ModelForm.
> 
> 
> [1] - http://docs.djangoproject.com/en/dev/topics/forms/modelforms/
> [2] - 
> http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#the-save-method
> 
> -- 
> 
> Best,
> 
> R
> 
> --
> 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 
> 

--

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




Using a form to UPDATE a record?

2009-12-03 Thread Todd Blanchard
All the tutorials on forms discuss creating a new record.

I've got a record in the database, I want to fetch it, plunk its values into a 
form, let the user edit it and save it.

I don't see how to conveniently put the model's values into the form.  It seems 
the form wants a dictionary of values, so how to convert a model object to a 
dict?

-Todd Blanchard

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Sick of defining urls

2009-12-02 Thread Todd Blanchard
,
> 'magic_view_handler'),
>)
> 
> "magic_view_handler" would then be a view that gets called, whose
> signature looks something like:
> 
>magic_view_handler(request, app, view, id):
>view_function = None
>try:
>view_function = import('%s.%s' % (app, view))
>except ImportError:
>raise Http404
>view_function(request, id)
> 
> It'd then be up to your *real* view to check to ensure that the id is
> legit.
> 
> I forget precise syntax on that import() function.  I don't use it
> often.  The idea is to import a dynamic module based on some string
> you've got handy.
> 
> I think that the reason why this latter suggestion doesn't have a
> reason to exist is because you've always got to validate all sorts of
> stuff very specific to the model.  By making one generic view, you're
> bound to never really allowing yourself any custom processing.  You'd
> always be passing your variably-defined model to the same template.
> How could the same template render entirely different models to the
> page?
> 
> Anyway, "sticky" the word for it, at best.  I'm totally curious, so
> could I ask that you give an example of your url conf?  If feels like
> there might be something missing that could simplify your task.
> 
> Tim
> 
> On Nov 25, 12:07 pm, Todd Blanchard  wrote:
>> It is mostly a waste of time and busy work.
>> 
>> I like the rails strategy of /controller/action/id
>> 
>> I'd like to define a similar one time couple rules in urls.py
>> 
>> Something like /application/view/id where view is the name of the function 
>> in the views.py in that application.
>> 
>> Anybody got a little snippet or recipe to do this generically once and for 
>> all?
>> 
>> -Todd Blanchard
> 
> --
> 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 
> 

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Forms ForeignKeyField does not populate with initial value

2009-11-26 Thread Todd Blanchard
OK, this did lead me to the solution though.

It seems that, for the ForeignKeyField the initial value should be the primary 
key of the record and not the object referenced.  So changing

>> form = IncidentForm(initial={
>>'reporter': request.user,


to 

>> form = IncidentForm(initial={
>>'reporter': request.user.id,


makes it work OK.  Seems counter-intuitive given the the ForeignKeyField wants 
to work with objects rather than keys though.



On Nov 26, 2009, at 12:33 PM, Todd Blanchard wrote:

> I want it to be possible to be changed.  But I also want the initial 
> selection to be the current user.
> 
> So this isn't really a solution.  Thanks anyway.
> 
> On Nov 26, 2009, at 10:27 AM, esatterwh...@wi.rr.com wrote:
> 
>> in your IncidentForm definition set reporter to a ModelChoiceField
>> (User.objects.all(), widget=forms.HiddenInput())
>> 
>> then it should work out ok. I usually hide fk fields to a user if i
>> want the current request.user object, because I don't want to allow
>> the possibility for it to be changed.
>> 
>> On Nov 25, 10:32 pm, Todd Blanchard  wrote:
>>> I have a (simplified) model
>>> 
>>> class Incident(models.Model):
>>>title = models.CharField(max_length=128)
>>>when_reported = models.DateTimeField(auto_now_add=True)
>>>reporter = models.ForeignKey(User)
>>> 
>>> Where User is from auth.  When used with a ModelForm, this creates a popup 
>>> button with a list of users.  I want it to default to the currently logged 
>>> in user so in my view I have:
>>> 
>>> def new_incident(request):
>>>   form = IncidentForm(initial={
>>>'reporter': request.user,
>>>'title': 'New Incident',
>>>'when_reported' : datetime.now(),
>>>})
>>> 
>>>media = form.media
>>>return render_to_response('incidents/new.html',{'form': form, 'media': 
>>> media},context_instance=RequestContext(request))
>>> 
>>> However the popup button's selection is never set to the current logged in 
>>> user.  I have rendered the current logged in user's name elsewhere on the 
>>> page, it is set.  But the popup selector isn't getting its selection set 
>>> right.  Any tips?  
>>> 
>>> -Todd Blanchard
>> 
>> --
>> 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To post to this group, send email to django-us...@googlegroups.com.
>> To unsubscribe from this group, send email to 
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at 
>> http://groups.google.com/group/django-users?hl=en.
>> 
>> 
> 
> --
> 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 
> 

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Forms ForeignKeyField does not populate with initial value

2009-11-26 Thread Todd Blanchard
I want it to be possible to be changed.  But I also want the initial selection 
to be the current user.

So this isn't really a solution.  Thanks anyway.

On Nov 26, 2009, at 10:27 AM, esatterwh...@wi.rr.com wrote:

> in your IncidentForm definition set reporter to a ModelChoiceField
> (User.objects.all(), widget=forms.HiddenInput())
> 
> then it should work out ok. I usually hide fk fields to a user if i
> want the current request.user object, because I don't want to allow
> the possibility for it to be changed.
> 
> On Nov 25, 10:32 pm, Todd Blanchard  wrote:
>> I have a (simplified) model
>> 
>> class Incident(models.Model):
>> title = models.CharField(max_length=128)
>> when_reported = models.DateTimeField(auto_now_add=True)
>> reporter = models.ForeignKey(User)
>> 
>> Where User is from auth.  When used with a ModelForm, this creates a popup 
>> button with a list of users.  I want it to default to the currently logged 
>> in user so in my view I have:
>> 
>> def new_incident(request):
>>form = IncidentForm(initial={
>> 'reporter': request.user,
>> 'title': 'New Incident',
>> 'when_reported' : datetime.now(),
>> })
>> 
>> media = form.media
>> return render_to_response('incidents/new.html',{'form': form, 'media': 
>> media},context_instance=RequestContext(request))
>> 
>> However the popup button's selection is never set to the current logged in 
>> user.  I have rendered the current logged in user's name elsewhere on the 
>> page, it is set.  But the popup selector isn't getting its selection set 
>> right.  Any tips?  
>> 
>> -Todd Blanchard
> 
> --
> 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 
> 

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.




Forms ForeignKeyField does not populate with initial value

2009-11-25 Thread Todd Blanchard
I have a (simplified) model

class Incident(models.Model):
title = models.CharField(max_length=128)
when_reported = models.DateTimeField(auto_now_add=True)
reporter = models.ForeignKey(User)


Where User is from auth.  When used with a ModelForm, this creates a popup 
button with a list of users.  I want it to default to the currently logged in 
user so in my view I have:

def new_incident(request):
   form = IncidentForm(initial={
'reporter': request.user,
'title': 'New Incident',
'when_reported' : datetime.now(),
})

media = form.media
return render_to_response('incidents/new.html',{'form': form, 'media': 
media},context_instance=RequestContext(request))

However the popup button's selection is never set to the current logged in 
user.  I have rendered the current logged in user's name elsewhere on the page, 
it is set.  But the popup selector isn't getting its selection set right.  Any 
tips?  

-Todd Blanchard

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: More media collection nightmares

2009-11-25 Thread Todd Blanchard
Actually, a widget required a js file that required core.js, but did not 
specify it.  So I added core.js to the form's media list - but apparently it 
renders the widget media, then the form media - so no good.

Your second suggestion was the best - I now just include the jsi18n and core.js 
on every page as part of the base template.

So far so good.  Hopefully I won't find any more widgets with surprise 
dependencies.

-Todd Blanchard

On Nov 25, 2009, at 12:14 PM, Tim Valenta wrote:

> Is it a widget that has the "core.js"?  I'd suggest putting that on
> the form instead, if that's the case.  Alternatively, if the page
> should always have this JS anyway, you could always insert it directly
> to the template, to avoid any ambiguity for any future eyeballs
> wondering how it all works.

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.




More media collection nightmares

2009-11-25 Thread Todd Blanchard
The latest is that the media collection strategy apparently has no concept of 
order dependence when specifying or loading javascript and in my form it seems 
to be sticking core.js somewhere in the middle which contains addEvent which is 
required by something being loaded sooner and thus it results in failure.

Is there some way to specify order dependency in js files using this mechanism? 
Otherwise I think it is worthless.

-Todd Blanchard

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.




Sick of defining urls

2009-11-25 Thread Todd Blanchard
It is mostly a waste of time and busy work.

I like the rails strategy of /controller/action/id

I'd like to define a similar one time couple rules in urls.py

Something like /application/view/id where view is the name of the function in 
the views.py in that application.

Anybody got a little snippet or recipe to do this generically once and for all?

-Todd Blanchard

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: calendar.js can't find variable gettext

2009-11-25 Thread Todd Blanchard
Did that, filed it.  Ticket #12264

-Todd Blanchard

On Nov 25, 2009, at 8:01 AM, Tim Valenta wrote:

> 
> 
> On Nov 24, 10:32 pm, Todd Blanchard  wrote:
>> Yep, I solved this by ripping and copying some code out of admin/sites.py
>> and adding a url conf for it.
>> 
>> It works now, but this should be included by default through the widget 
>> media dependency system.  Not very slick.  I tried filing a bug and the 
>> submission was rejected as spam.
> 
> I'd just sign up for the account.  It's pretty simple.  Filing bugs is
> how this thing gets better-- I'd urge you not to just let it drop.
> 
> Glad that that worked out for you.  I learned something about it,
> myself.  It had never struck me that it was a view :)
> 
> Tim
> 
>> 
>> -Todd Blanchard
>> 
>> On Nov 24, 2009, at 8:42 PM, Karen Tracey wrote:
>> 
>> 
>> 
>>> On Tue, Nov 24, 2009 at 8:56 PM, Todd Blanchard  wrote:
>>> I'm trying to use the date/time entry widgets from admin and I get this 
>>> javascript error and the controls don't render.
>> 
>>> Where is this supposed to come from?
>> 
>>> In annoyance, I have copied the head section precisely from an admin page 
>>> that work.  Still doesn't work in my page.
>> 
>>> 
>>> 
>>> 
>> 
>>> 
>> 
>>> This is the one gettext would be coming from and I'm guessing the relative 
>>> path here is causing a problem.  (gettext is internationalization support, 
>>> and jsi18n is javascript internationalization support, I'd guess)  jsi18n 
>>> is an admin view:
>> 
>>> http://code.djangoproject.com/browser/django/tags/releases/1.1.1/djan...
>>> http://code.djangoproject.com/browser/django/tags/releases/1.1.1/djan...
>> 
>>> It is not being pulled in via a form media definition but rather looks to 
>>> be hardcoded into the templates that depend on it, for example:
>> 
>>> http://code.djangoproject.com/browser/django/tags/releases/1.1.1/djan...
>> 
>>> It seems using the admin widgets that use the i18n javascript is a bit more 
>>> involved than just importing them and using them.  Maybe there is some 
>>> elegant way you're supposed to pull in this javascript, but I don't know it 
>>> (I don't know much when it comes to javascript).
>> 
>>> Karen
>> 
>>> --
>> 
>>> You received this message because you are subscribed to the Google Groups 
>>> "Django users" group.
>>> To post to this group, send email to django-us...@googlegroups.com.
>>> To unsubscribe from this group, send email to 
>>> django-users+unsubscr...@googlegroups.com.
>>> For more options, visit this group 
>>> athttp://groups.google.com/group/django-users?hl=en.
> 
> --
> 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 
> 

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: calendar.js can't find variable gettext

2009-11-24 Thread Todd Blanchard
Yep, I solved this by ripping and copying some code out of admin/sites.py
and adding a url conf for it.

It works now, but this should be included by default through the widget media 
dependency system.  Not very slick.  I tried filing a bug and the submission 
was rejected as spam.

-Todd Blanchard

On Nov 24, 2009, at 8:42 PM, Karen Tracey wrote:

> On Tue, Nov 24, 2009 at 8:56 PM, Todd Blanchard  wrote:
> I'm trying to use the date/time entry widgets from admin and I get this 
> javascript error and the controls don't render.
> 
> Where is this supposed to come from?
> 
> In annoyance, I have copied the head section precisely from an admin page 
> that work.  Still doesn't work in my page.
> 
> 
> 
> 
> 
> 
> 
> 
> 
> This is the one gettext would be coming from and I'm guessing the relative 
> path here is causing a problem.  (gettext is internationalization support, 
> and jsi18n is javascript internationalization support, I'd guess)  jsi18n is 
> an admin view:
> 
> http://code.djangoproject.com/browser/django/tags/releases/1.1.1/django/contrib/admin/sites.py#L213
> http://code.djangoproject.com/browser/django/tags/releases/1.1.1/django/contrib/admin/sites.py#L253
> 
> It is not being pulled in via a form media definition but rather looks to be 
> hardcoded into the templates that depend on it, for example:
> 
> http://code.djangoproject.com/browser/django/tags/releases/1.1.1/django/contrib/admin/templates/admin/change_list.html#L9
> 
> It seems using the admin widgets that use the i18n javascript is a bit more 
> involved than just importing them and using them.  Maybe there is some 
> elegant way you're supposed to pull in this javascript, but I don't know it 
> (I don't know much when it comes to javascript).
> 
> Karen
> 
> --
> 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.




calendar.js can't find variable gettext

2009-11-24 Thread Todd Blanchard
I'm trying to use the date/time entry widgets from admin and I get this 
javascript error and the controls don't render.

Where is this supposed to come from?

In annoyance, I have copied the head section precisely from an admin page that 
work.  Still doesn't work in my page.














http://openlayers.org/api/2.8/OpenLayers.js";>

http://openstreetmap.org/openlayers/OpenStreetMap.js";>

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Designing base template - how to include media properly?

2009-11-24 Thread Todd Blanchard
Thanks, I feel like I'm making progress.  

Widgets define media too.  I'm really fuzzy about how widgets get loaded and 
how their media declarations get collected into the media object list. (I'm 
using contrib.gis which has nifty map widgets and it "just works" in the admin 
but now I'm building my own UI).

In fact, I'm pretty fuzzy in general about how code like widgets gets "found" 
and loaded.

-Todd Blanchard


On Nov 24, 2009, at 3:52 PM, Tim Valenta wrote:

> Sorry-- I got out of sync with the replies.
> 
>> Or am I missing something.  Seems like I am getting very much NON-DRY here.
> 
> How many pages do you have dozens of forms on?  If ever, I find that
> I've got a single form on the page.  If you're writing an app complex
> enough to need such amazingly complicated nested forms should you
> use the admin, and let it do all that for you?
> 
> We're not really working with specifics here, so I'm unsure of what
> you're trying to accomplish.
> 
> How would you propose we get around this problem?  You've got a python
> list of form objects.  How on earth is Django supposed to know what
> variable you've got your forms in?  By forcing you to put all your
> forms in a single variable, it would make Django dictate too strongly
> "the one and only variable which can hold forms".  That exactly what
> it's trying not to do.
> 
> Just set up a template, perhaps "base.html".  Make it something like
> this:
> 
> 
> 
>blah
>{% block my_media %}
>{{ media }}
>{% endblock %}
> 
> 
>{% content %}{% endcontent %}
> 
> 
> 
> 
> Then, in your views, you'll render the actual template you want to use
> (as in, don't render "base.html", render the one that you'd normally
> render), but make sure it extends base:
> {# mytemplate.html #}
> {% extends "base.html" %}
> 
> {% block content %}
>my content goes here...
>
>{% for form in forms %}
>{{ form.as_p }}
>{% endfor %}
>
> {% endblock %}
> 
> 
> The idea is that the 'base.html' template will *always* try to grab
> the context variable "media" and render it.  That means that all you
> ever have to do is make sure that the context variable "media"
> contains the cumulative media of what you want to include.  Note,
> though, that when you want to use this "extends" approach, you become
> required to work in those blocks.  that's why I put a "content" block
> in the base template, and override it in the extended one.  Stuff
> outside of blocks in mytemplate.html won't get displayed.  This is a
> very common approach, though, so don't feel like you're getting
> cheated.
> 
> Then, if you ever want to for whatever reason add more media beyond
> the form media, you can either slap it into the 'media' context var in
> your view, or you can do that block override I kept using the first
> examples:
> 
> {# mytemplate.html #}
> {% block my_media %}
>{{ block.super }}
>
> {% endblock %}
> 
> {% block content %}
>{# continue as usual #}
> {% endblock %}
> 
> 
> 
> I hope I'm not spouting nonsense that you are already familiar with.
> Feel free to ask anything more, if you've got specifics that you're
> trying to nail down, design-wise.
> 
> Tim
> 
> On Nov 24, 4:36 pm, Todd Blanchard  wrote:
>> No no no, I really really appreciate the help.
>> 
>> But I'm definitely beginning to feel like my app is 80% boilerplate.
>> 
>> On Nov 24, 2009, at 3:35 PM, Tim Valenta wrote:
>> 
>> 
>> 
>>> PS -- I hope I don't sound like I'm insulting your intelligence--- I'm
>>> not.  I've often felt like there aren't enough policies in Django,
>>> myself.  But pick your battles.  This is an easy one.  I prefer Django
>>> over Rails, when it comes down to it.  Feel fortunate that Django has
>>> practically the best documentation on the planet.  I hate more open
>>> source docs, because it was written by a guy who don't know how to use
>>> proper english!
>> 
>>> I'm just trying to drive home the point that this isn't the worst
>>> thing that you could be stuck on.
>> 
>>> Sincerely hoping it helps,
>>> Tim
>> 
>>> On Nov 24, 4:28 pm, Tim Valenta  wrote:
>>>> Sorry it's not working out for you, but I'd disagree about the
>>>> comparison to X-Windows :)  I'd be defending Django, and no

Re: Designing base template - how to include media properly?

2009-11-24 Thread Todd Blanchard
No no no, I really really appreciate the help.

But I'm definitely beginning to feel like my app is 80% boilerplate.

On Nov 24, 2009, at 3:35 PM, Tim Valenta wrote:

> PS -- I hope I don't sound like I'm insulting your intelligence--- I'm
> not.  I've often felt like there aren't enough policies in Django,
> myself.  But pick your battles.  This is an easy one.  I prefer Django
> over Rails, when it comes down to it.  Feel fortunate that Django has
> practically the best documentation on the planet.  I hate more open
> source docs, because it was written by a guy who don't know how to use
> proper english!
> 
> I'm just trying to drive home the point that this isn't the worst
> thing that you could be stuck on.
> 
> Sincerely hoping it helps,
> Tim
> 
> On Nov 24, 4:28 pm, Tim Valenta  wrote:
>> Sorry it's not working out for you, but I'd disagree about the
>> comparison to X-Windows :)  I'd be defending Django, and not X-
>> windows, when I say that.
>> 
>> I'm serious.  Just add them together.  I'm not sure you're
>> appreciating the slick objects that have been crafted for this very
>> purpose.
>> 
>> Your view:
>> cumulative_media = form.media for form in forms
>> return render_to_response('mytemplate.html', {'media':
>> cumulative_media})
>> 
>> Your template:
>> {% block my_media_block %}
>> {{ block.super }}
>> {{ media }}
>> {% endblock %}
>> 
>> I fail to see what is so hard about this.
>> 
>> Tim
>> 
>> On Nov 24, 4:13 pm, Todd Blanchard  wrote:
>> 
>> 
>> 
>>> You know what, this is absolutely too much BS.  Why would one bother to use 
>>> the media declaration stuff at all if there is no mechanism to properly 
>>> consume it (a built in template tag for instance).
>> 
>>> I think I will just hardcode them in the head in the base template.  They 
>>> seldom change and browser caching being what it is having them never change 
>>> is just fine.
>> 
>>> After three weeks of seriously trying to get traction with django, my 
>>> conclusion is it has all of the elegance of X-windows.  It can do anything 
>>> but out of the box it does nothing except present a zillion confusing parts 
>>> to the programmer and it has too many mechanisms but no policies.
>> 
>>> I'm beginning to very much pine for rails.  At least it does something out 
>>> of the box.
>> 
>>> Very frustrated today - still haven't got a single record/entry form 
>>> working.  Too many little files and indirection to keep it all straight in 
>>> my head.
>> 
>>> -Todd Blanchard
>> 
>>> On Nov 24, 2009, at 2:05 PM, Tim Valenta wrote:
>> 
>>>> The idea is along the lines of what you initially guessed.
>> 
>>>> The admin accomplishes the non-duplicate effect in django/django/
>>>> contrib/admin/options.py, starting at line 770.  It loops over the
>>>> forms and combines the existing media with the media on each form
>>>> object.  It ends up using a series of objects to do it, including a
>>>> Media class, but it's not doing anything too special.  When an item
>>>> gets added, it checks to make sure that the path doesn't already exist
>>>> in the list.
>> 
>>>> So, short story: loop over your forms and add the media attributes
>>>> together.  The underlying Media class ought to be dropping duplicates.
>> 
>>>> Then just save a context variable with the result, and do the
>>>> following in your template:
>> 
>>>> {% block extrahead %} {# or whatever you call your header block #}
>>>>{{ block.super }}
>>>>{{ cumulative_media }}
>>>> {% endblock %}
>> 
>>>> Tim
>> 
>>>> On Nov 24, 12:30 pm, Todd Blanchard  wrote:
>>>>> What about de-duping?
>>>>> If two forms want the same js file, will it get included twice?
>>>>> It seems like this is the kind of thing that the framework should handle 
>>>>> and the current "solution" is kind of half baked.
>> 
>>>>> -Todd
>> 
>>>>> On Nov 23, 2009, at 2:40 PM, Mark (Nosrednakram) wrote:
>> 
>>>>>> Hello,
>> 
>>>>>> I have something like the following in my generic genericform.html.  I
>>>>>> think this is what you're looking for if 

Re: Designing base template - how to include media properly?

2009-11-24 Thread Todd Blanchard
What is annoying is I have to repeat this incantation in every view function 
ever, yes?.  If its got a form, I have to do this every time.

I thought the idea was to write less code?  Not the same code over and over 
again in every view.

Or am I missing something.  Seems like I am getting very much NON-DRY here.

On Nov 24, 2009, at 3:28 PM, Tim Valenta wrote:

> Sorry it's not working out for you, but I'd disagree about the
> comparison to X-Windows :)  I'd be defending Django, and not X-
> windows, when I say that.
> 
> I'm serious.  Just add them together.  I'm not sure you're
> appreciating the slick objects that have been crafted for this very
> purpose.
> 
> Your view:
>cumulative_media = form.media for form in forms
>return render_to_response('mytemplate.html', {'media':
> cumulative_media})
> 
> Your template:
>{% block my_media_block %}
>{{ block.super }}
>{{ media }}
>    {% endblock %}
> 
> I fail to see what is so hard about this.
> 
> Tim
> 
> On Nov 24, 4:13 pm, Todd Blanchard  wrote:
>> You know what, this is absolutely too much BS.  Why would one bother to use 
>> the media declaration stuff at all if there is no mechanism to properly 
>> consume it (a built in template tag for instance).
>> 
>> I think I will just hardcode them in the head in the base template.  They 
>> seldom change and browser caching being what it is having them never change 
>> is just fine.
>> 
>> After three weeks of seriously trying to get traction with django, my 
>> conclusion is it has all of the elegance of X-windows.  It can do anything 
>> but out of the box it does nothing except present a zillion confusing parts 
>> to the programmer and it has too many mechanisms but no policies.
>> 
>> I'm beginning to very much pine for rails.  At least it does something out 
>> of the box.
>> 
>> Very frustrated today - still haven't got a single record/entry form 
>> working.  Too many little files and indirection to keep it all straight in 
>> my head.
>> 
>> -Todd Blanchard
>> 
>> On Nov 24, 2009, at 2:05 PM, Tim Valenta wrote:
>> 
>> 
>> 
>>> The idea is along the lines of what you initially guessed.
>> 
>>> The admin accomplishes the non-duplicate effect in django/django/
>>> contrib/admin/options.py, starting at line 770.  It loops over the
>>> forms and combines the existing media with the media on each form
>>> object.  It ends up using a series of objects to do it, including a
>>> Media class, but it's not doing anything too special.  When an item
>>> gets added, it checks to make sure that the path doesn't already exist
>>> in the list.
>> 
>>> So, short story: loop over your forms and add the media attributes
>>> together.  The underlying Media class ought to be dropping duplicates.
>> 
>>> Then just save a context variable with the result, and do the
>>> following in your template:
>> 
>>> {% block extrahead %} {# or whatever you call your header block #}
>>>{{ block.super }}
>>>{{ cumulative_media }}
>>> {% endblock %}
>> 
>>> Tim
>> 
>>> On Nov 24, 12:30 pm, Todd Blanchard  wrote:
>>>> What about de-duping?
>>>> If two forms want the same js file, will it get included twice?
>>>> It seems like this is the kind of thing that the framework should handle 
>>>> and the current "solution" is kind of half baked.
>> 
>>>> -Todd
>> 
>>>> On Nov 23, 2009, at 2:40 PM, Mark (Nosrednakram) wrote:
>> 
>>>>> Hello,
>> 
>>>>> I have something like the following in my generic genericform.html.  I
>>>>> think this is what you're looking for if not hope you find a better
>>>>> answer. The extramedia block is back in my base.html  template and my
>>>>> form template extends it. I'm not sure if it's in the admin base.html
>>>>> but you can take a look at if for there media blocks I believe are
>>>>> something like extrastyle etc...
>> 
>>>>> {% block extramedia %}
>>>>> {% if forms %}
>>>>>{% for form in forms %}
>>>>>   {{ form.media }}
>>>>>{% endfor %}
>>>>> {% else %}
>>>>>   {{ form.media }}
>>>>> {% endif %}
>> 
>>>>> Mark
>> 
>>>>> On Nov 23, 1:31 pm, Todd Blanchard  wrote:
>>>>&g

Re: Designing base template - how to include media properly?

2009-11-24 Thread Todd Blanchard
You know what, this is absolutely too much BS.  Why would one bother to use the 
media declaration stuff at all if there is no mechanism to properly consume it 
(a built in template tag for instance).

I think I will just hardcode them in the head in the base template.  They 
seldom change and browser caching being what it is having them never change is 
just fine.

After three weeks of seriously trying to get traction with django, my 
conclusion is it has all of the elegance of X-windows.  It can do anything but 
out of the box it does nothing except present a zillion confusing parts to the 
programmer and it has too many mechanisms but no policies.

I'm beginning to very much pine for rails.  At least it does something out of 
the box.

Very frustrated today - still haven't got a single record/entry form working.  
Too many little files and indirection to keep it all straight in my head.

-Todd Blanchard

On Nov 24, 2009, at 2:05 PM, Tim Valenta wrote:

> The idea is along the lines of what you initially guessed.
> 
> The admin accomplishes the non-duplicate effect in django/django/
> contrib/admin/options.py, starting at line 770.  It loops over the
> forms and combines the existing media with the media on each form
> object.  It ends up using a series of objects to do it, including a
> Media class, but it's not doing anything too special.  When an item
> gets added, it checks to make sure that the path doesn't already exist
> in the list.
> 
> So, short story: loop over your forms and add the media attributes
> together.  The underlying Media class ought to be dropping duplicates.
> 
> Then just save a context variable with the result, and do the
> following in your template:
> 
> {% block extrahead %} {# or whatever you call your header block #}
>{{ block.super }}
>    {{ cumulative_media }}
> {% endblock %}
> 
> Tim
> 
> On Nov 24, 12:30 pm, Todd Blanchard  wrote:
>> What about de-duping?
>> If two forms want the same js file, will it get included twice?
>> It seems like this is the kind of thing that the framework should handle and 
>> the current "solution" is kind of half baked.
>> 
>> -Todd
>> 
>> On Nov 23, 2009, at 2:40 PM, Mark (Nosrednakram) wrote:
>> 
>> 
>> 
>> 
>> 
>>> Hello,
>> 
>>> I have something like the following in my generic genericform.html.  I
>>> think this is what you're looking for if not hope you find a better
>>> answer. The extramedia block is back in my base.html  template and my
>>> form template extends it. I'm not sure if it's in the admin base.html
>>> but you can take a look at if for there media blocks I believe are
>>> something like extrastyle etc...
>> 
>>> {% block extramedia %}
>>> {% if forms %}
>>>{% for form in forms %}
>>>   {{ form.media }}
>>>{% endfor %}
>>> {% else %}
>>>   {{ form.media }}
>>> {% endif %}
>> 
>>> Mark
>> 
>>> On Nov 23, 1:31 pm, Todd Blanchard  wrote:
>>>> I've read this:
>> 
>>>> http://docs.djangoproject.com/en/dev/topics/forms/media/
>> 
>>>> Nifty.  
>> 
>>>> Now, how exactly do I make sure that the media urls get spewed properly 
>>>> into the head section of the page?  This is apparently omitted everywhere 
>>>> I've looked.  The admin template seems to pull it off properly but I 
>>>> cannot figure out how.  Seems like I should be able to do something like
>> 
>>>> 
>>>> 
>>>> {{ media }}  
>>>> 
>> 
>>>> but I cannot figure out exactly how to properly aggregate all the forms' 
>>>> media's and get them spewed into the templates properly.
>> 
>>>> -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-us...@googlegroups.com.
>>> To unsubscribe from this group, send email to 
>>> django-users+unsubscr...@googlegroups.com.
>>> For more options, visit this group 
>>> athttp://groups.google.com/group/django-users?hl=.
> 
> --
> 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 
> 

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Designing base template - how to include media properly?

2009-11-24 Thread Todd Blanchard
What about de-duping?
If two forms want the same js file, will it get included twice?
It seems like this is the kind of thing that the framework should handle and 
the current "solution" is kind of half baked.

-Todd

On Nov 23, 2009, at 2:40 PM, Mark (Nosrednakram) wrote:

> 
> Hello,
> 
> I have something like the following in my generic genericform.html.  I
> think this is what you're looking for if not hope you find a better
> answer. The extramedia block is back in my base.html  template and my
> form template extends it. I'm not sure if it's in the admin base.html
> but you can take a look at if for there media blocks I believe are
> something like extrastyle etc...
> 
> {% block extramedia %}
> {% if forms %}
>{% for form in forms %}
>   {{ form.media }}
>{% endfor %}
> {% else %}
>   {{ form.media }}
> {% endif %}
> 
> Mark
> 
> 
> On Nov 23, 1:31 pm, Todd Blanchard  wrote:
>> I've read this:
>> 
>> http://docs.djangoproject.com/en/dev/topics/forms/media/
>> 
>> Nifty.  
>> 
>> Now, how exactly do I make sure that the media urls get spewed properly into 
>> the head section of the page?  This is apparently omitted everywhere I've 
>> looked.  The admin template seems to pull it off properly but I cannot 
>> figure out how.  Seems like I should be able to do something like
>> 
>> 
>> 
>> {{ media }}  
>> 
>> 
>> but I cannot figure out exactly how to properly aggregate all the forms' 
>> media's and get them spewed into the templates properly.
>> 
>> -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-us...@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=.
> 
> 

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.




Designing base template - how to include media properly?

2009-11-23 Thread Todd Blanchard
I've read this:

http://docs.djangoproject.com/en/dev/topics/forms/media/

Nifty.  

Now, how exactly do I make sure that the media urls get spewed properly into 
the head section of the page?  This is apparently omitted everywhere I've 
looked.  The admin template seems to pull it off properly but I cannot figure 
out how.  Seems like I should be able to do something like



{{ media }}  


but I cannot figure out exactly how to properly aggregate all the forms' 
media's and get them spewed into the templates properly.

-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-us...@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=.




Re: Any users groups around San Diego?

2009-11-21 Thread Todd Blanchard
Wow, thanks.  I can actually walk to that one!

-Todd

On Nov 21, 2009, at 11:34 AM, Donna Snow wrote:

> Todd,
>
> Have you tried Meetup? If you can't find one there.. start one :-)
>
> Found this Django San Diego - meeting December 1:
>
> http://djangosd.jottit.com/
>
> Django group was merged into here:
> http://www.kernel-panic.org/meetings/lpsg
>
> http://wiki.python.org/moin/LocalUserGroups#California
>
> If you are ever in the Bay Area feel free to join our ZPUG-Valley  
> meetup - we discuss python based web frameworks - (not just Django -  
> but it gets discussed a lot :-))
>
> Hope this helps!
>
> Happy Holidays!
>
> Best Regards,
> Donna 'SnowWrite' Snow
> card.ly/snowwrite
>
> Office Manager, Hacker Dojo
> hackerdojo.com
>
> Owner, C2E Training
> c2etraining.com
> (1/2 off Django training until 11/22/09 (2 tickets left!)
>
>
>
> On Sat, Nov 21, 2009 at 11:20 AM, Todd Blanchard  
>  wrote:
> I'm still kind of struggling to get off the ground with django and
> think I'd benefit from some face time with other developers.  I'm in
> San Diego.
>
> Any resources?
>
> -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-us...@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= 
> .
>
>
>
>
> --
>
> You received this message because you are subscribed to the Google  
> Groups "Django users" group.
> To post to this group, send email to django-us...@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= 
> .

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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=.




Any users groups around San Diego?

2009-11-21 Thread Todd Blanchard
I'm still kind of struggling to get off the ground with django and  
think I'd benefit from some face time with other developers.  I'm in  
San Diego.

Any resources?

-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-us...@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=.




Help a Rails refugee - how to do site specific layouts?

2009-11-12 Thread Todd Blanchard
I like the rails mechanism for specifying page layouts (boilerplate  
template that surrounds the currently rendered view).

Its simple and obvious.

I cannot, having read most of two books on django now along with the  
website stuff, figure out how to do the same thing in django.

Also, I'm building a multiple-domain site and using the sites module  
so I want different layouts for different sites.

Can someone point me an example or a module or something?

Thx

-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-us...@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=.




Re: Working the tutorial - and I'm stuck

2009-11-03 Thread Todd Blanchard
 From settings.py

MIDDLEWARE_CLASSES = (
 'django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.csrf.middleware.CsrfMiddleware',
)

I added the last line and restarted the server.  Same result.

On Nov 3, 2009, at 9:16 AM, Todd Blanchard wrote:

> As a total noob - I do that how?
>
> On Nov 3, 2009, at 9:14 AM, DrBloodmoney wrote:
>
>> Make sure that you have the CSRF middleware installed.
>>
>>
>>> On Nov 3, 2009 12:09 PM, "Todd Blanchard"   
>>> wrote:
>>>
>>> What did I screw up?
>>>
>>> TemplateSyntaxError at /polls/1/
>>> Invalid block tag: 'csrf_token'
>>> Request Method: GET
>>> Request URL:http://localhost:8000/polls/1/
>>> Exception Type: TemplateSyntaxError
>>> Exception Value:
>>> Invalid block tag: 'csrf_token'
>>> Exception Location: /Library/Python/2.6/site-packages/django/ 
>>> template/__init__.py in invalid_block_tag, line 335
>>> Python Executable:  /usr/bin/python
>>> Python Version: 2.6.1
>>>
>>>
>>> The forms bit.
>>>
>>> views.py:
>>>
>>> # Create your views here.
>>> from django.template import Context, loader
>>> from mysite.polls.models import Choice, Poll
>>> from django.http import HttpResponse
>>> from django.shortcuts import render_to_response, get_object_or_404
>>> from django.http import Http404
>>> from django.template import RequestContext
>>> # ...
>>>
>>> def index(request):
>>> latest_poll_list = Poll.objects.all().order_by('-pub_date')[:5]
>>> return render_to_response('polls/index.html',  
>>> {'latest_poll_list': latest_poll_list})
>>>
>>> def detail(request, poll_id):
>>> p = get_object_or_404(Poll, pk=poll_id)
>>> return render_to_response('polls/detail.html', {'poll': p},
>>>context_instance=RequestContext 
>>> (request))
>>>
>>> def results(request, poll_id):
>>> return HttpResponse("You're looking at the results of poll  
>>> %s." % poll_id)
>>>
>>> def vote(request, poll_id):
>>> p = get_object_or_404(Poll, pk=poll_id)
>>> try:
>>> selected_choice = p.choice_set.get(pk=request.POST 
>>> ['choice'])
>>> except (KeyError, Choice.DoesNotExist):
>>> # Redisplay the poll voting form.
>>> return render_to_response('polls/detail.html', {
>>> 'poll': p,
>>> 'error_message': "You didn't select a choice.",
>>> }, context_instance=RequestContext(request))
>>> else:
>>> selected_choice.votes += 1
>>> selected_choice.save()
>>> # Always return an HttpResponseRedirect after successfully  
>>> dealing
>>> # with POST data. This prevents data from being posted  
>>> twice if a
>>> # user hits the Back button.
>>> return HttpResponseRedirect(reverse 
>>> ('mysite.polls.views.results', args=(p.id,)))
>>>
>>> detail.html:
>>>
>>> {{ poll.question }}
>>>
>>> {% if error_message %}{{ error_message }} 
>>> {% endif %}
>>>
>>> 
>>> {% csrf_token %}
>>> {% for choice in poll.choice_set.all %}
>>> 
>>> {{ choice.choice }}>> label>
>>> {% endfor %}
>>> 
>>> 
>>>
>>>
>>>
>>>
>>
>>
>>
>
>
> >


--~--~-~--~~~---~--~~
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: Working the tutorial - and I'm stuck

2009-11-03 Thread Todd Blanchard
As a total noob - I do that how?

On Nov 3, 2009, at 9:14 AM, DrBloodmoney wrote:

> Make sure that you have the CSRF middleware installed.
>
>
>> On Nov 3, 2009 12:09 PM, "Todd Blanchard"  wrote:
>>
>> What did I screw up?
>>
>> TemplateSyntaxError at /polls/1/
>> Invalid block tag: 'csrf_token'
>> Request Method:  GET
>> Request URL: http://localhost:8000/polls/1/
>> Exception Type:  TemplateSyntaxError
>> Exception Value: 
>> Invalid block tag: 'csrf_token'
>> Exception Location:  /Library/Python/2.6/site-packages/django/ 
>> template/__init__.py in invalid_block_tag, line 335
>> Python Executable:   /usr/bin/python
>> Python Version:  2.6.1
>>
>>
>> The forms bit.
>>
>> views.py:
>>
>> # Create your views here.
>> from django.template import Context, loader
>> from mysite.polls.models import Choice, Poll
>> from django.http import HttpResponse
>> from django.shortcuts import render_to_response, get_object_or_404
>> from django.http import Http404
>> from django.template import RequestContext
>> # ...
>>
>> def index(request):
>> latest_poll_list = Poll.objects.all().order_by('-pub_date')[:5]
>> return render_to_response('polls/index.html',  
>> {'latest_poll_list': latest_poll_list})
>>
>> def detail(request, poll_id):
>> p = get_object_or_404(Poll, pk=poll_id)
>> return render_to_response('polls/detail.html', {'poll': p},
>>context_instance=RequestContext 
>> (request))
>>
>> def results(request, poll_id):
>> return HttpResponse("You're looking at the results of poll %s."  
>> % poll_id)
>>
>> def vote(request, poll_id):
>> p = get_object_or_404(Poll, pk=poll_id)
>> try:
>> selected_choice = p.choice_set.get(pk=request.POST['choice'])
>> except (KeyError, Choice.DoesNotExist):
>> # Redisplay the poll voting form.
>> return render_to_response('polls/detail.html', {
>> 'poll': p,
>> 'error_message': "You didn't select a choice.",
>> }, context_instance=RequestContext(request))
>> else:
>> selected_choice.votes += 1
>> selected_choice.save()
>> # Always return an HttpResponseRedirect after successfully  
>> dealing
>> # with POST data. This prevents data from being posted  
>> twice if a
>> # user hits the Back button.
>> return HttpResponseRedirect(reverse 
>> ('mysite.polls.views.results', args=(p.id,)))
>>
>> detail.html:
>>
>> {{ poll.question }}
>>
>> {% if error_message %}{{ error_message }}{%  
>> endif %}
>>
>> 
>> {% csrf_token %}
>> {% for choice in poll.choice_set.all %}
>> 
>> {{ choice.choice }}> label>
>> {% endfor %}
>> 
>> 
>>
>>
>>
>>
>
>
> >


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



Working the tutorial - and I'm stuck

2009-11-03 Thread Todd Blanchard
What did I screw up?

TemplateSyntaxError at /polls/1/
Invalid block tag: 'csrf_token'
Request Method: GET
Request URL:http://localhost:8000/polls/1/
Exception Type: TemplateSyntaxError
Exception Value:
Invalid block tag: 'csrf_token'
Exception Location: /Library/Python/2.6/site-packages/django/template/ 
__init__.py in invalid_block_tag, line 335
Python Executable:  /usr/bin/python
Python Version: 2.6.1


The forms bit.

views.py:

# Create your views here.
from django.template import Context, loader
from mysite.polls.models import Choice, Poll
from django.http import HttpResponse
from django.shortcuts import render_to_response, get_object_or_404
from django.http import Http404
from django.template import RequestContext
# ...

def index(request):
 latest_poll_list = Poll.objects.all().order_by('-pub_date')[:5]
 return render_to_response('polls/index.html',  
{'latest_poll_list': latest_poll_list})

def detail(request, poll_id):
 p = get_object_or_404(Poll, pk=poll_id)
 return render_to_response('polls/detail.html', {'poll': p},
context_instance=RequestContext 
(request))

def results(request, poll_id):
 return HttpResponse("You're looking at the results of poll %s." %  
poll_id)

def vote(request, poll_id):
 p = get_object_or_404(Poll, pk=poll_id)
 try:
 selected_choice = p.choice_set.get(pk=request.POST['choice'])
 except (KeyError, Choice.DoesNotExist):
 # Redisplay the poll voting form.
 return render_to_response('polls/detail.html', {
 'poll': p,
 'error_message': "You didn't select a choice.",
 }, context_instance=RequestContext(request))
 else:
 selected_choice.votes += 1
 selected_choice.save()
 # Always return an HttpResponseRedirect after successfully  
dealing
 # with POST data. This prevents data from being posted twice  
if a
 # user hits the Back button.
 return HttpResponseRedirect(reverse 
('mysite.polls.views.results', args=(p.id,)))

detail.html:

{{ poll.question }}

{% if error_message %}{{ error_message }}{%  
endif %}


{% csrf_token %}
{% for choice in poll.choice_set.all %}
 
 {{ choice.choice }}
{% endfor %}





--~--~-~--~~~---~--~~
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: Versionable Models?

2009-10-27 Thread Todd Blanchard


On Oct 27, 2009, at 6:09 PM, Tim Chase wrote:

>
>> There's quite a learning curve here.
>
> The learning curve doesn't have much to do with Django, but
> rather development in general -- any time you take on a new
> technology (or soup of technologies, in this case Python/HTML/CSS
> Django's templating language, and possibly SQL) there's a hill to
> climb, but this one's pretty gentle -- in fact the most gentle
> learning curve of all the frameworks I've toyed with.

I've not done any python before so I'm struggling with infrastructure  
concepts.  Where do I put my code that isn't necessarily model types?   
Ditto for cross application model relationships (if any).  I looked at  
pinax and the major obstacle to adoption is the virtualenv thing.  I  
tried the setup script and it wants to install its own python stack  
and everything else.  I just want to use the modules, I already got a  
python stack built (on Snow Leopard - no it hasn't been fun rebuilding  
every blessed open source lib I ever downloaded for binary  
compatibility).

And then the best practices of django.  I don't know any of the tools  
yet, but I've got a web app to build and I've judged django has more  
pre-built parts I need than anything else so here we go.

-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: how to store web page content values in client side?

2009-10-27 Thread Todd Blanchard

You shouldn't have to do that.  Most browsers cache form state so if a  
user jumps off your page, then hits back, the form values should all  
be restored.  Try doing nothing and see what the browser does.  I'll  
bet it is what you want.

-Todd

On Oct 27, 2009, at 4:37 PM, webbo wrote:

>
> Hi all,
>
> I am new to django and web design.  I might ask some non-sense
> questions.
>
> I want to store dropdown boxes values on client side by cookies.
>
> For example, any users open the web page and choose dropdown box
> value.
>
> If they jump to other page then go back, the web page will
> automatically show what they choose before.
>
> I tried session, but some weird things
>
> Please help and many thanks.
>
>
> >


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



Re: Versionable Models?

2009-10-27 Thread Todd Blanchard

Great, I was trying to decide between that and "The definitive guide"  
and guess which one I ordered

Back to Amazon... :-/

There's quite a learning curve here.

-Todd


On Oct 27, 2009, at 5:15 PM, Mike Dewhirst wrote:

>
> Todd Blanchard wrote:
>> Total django noob here.  Rails/PHP/WebObjects refugee here.
>>
>> I'm starting a project where some models need to be fully versioned.
>>
>> IOW, record update is forbidden - every save to a changed model  
>> should
>> result in a new record with a new version number or timestamp along
>> with identity pulled from the current authenticated user's session.
>> Queries/relationships should be specified as "fetch newest" or "fetch
>> history".  IOW sometimes I want to traverse a relationship and just
>> get the "current" record.  Sometimes I want to get the history of  
>> that
>> relationship.
>>
>> Anybody done this?  Got any tips?
>
> Marty Allchin has documented this very precisely and eloquently in
> chapter 11 of his Pro Django published recently by Apress.
>
> Highly recommended :)
>
> Cheers
>
> Mike
>>
>> Thanks,
>> -Todd Blanchard
>>
>>>
>>
>>
>
>
> >


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



Versionable Models?

2009-10-27 Thread Todd Blanchard

Total django noob here.  Rails/PHP/WebObjects refugee here.

I'm starting a project where some models need to be fully versioned.

IOW, record update is forbidden - every save to a changed model should  
result in a new record with a new version number or timestamp along  
with identity pulled from the current authenticated user's session.   
Queries/relationships should be specified as "fetch newest" or "fetch  
history".  IOW sometimes I want to traverse a relationship and just  
get the "current" record.  Sometimes I want to get the history of that  
relationship.

Anybody done this?  Got any tips?

Thanks,
-Todd Blanchard

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



Goflow

2009-10-02 Thread Todd Blanchard

Hi,

I have a workflow type app I need to do and was looking at django with  
goflow.  I'm a total django noob - mostly I've done rails, php, web  
objects, j2ee, and some other stuff.  I can't seem to get the demos  
working and the goflow mailing list is silent.  Is that project  
abandoned?  Is there another workflow lib for django?  I love the  
admin and am leaning heavily towards django just for this, but I am  
doing a system with a lot of different classes of users and events and  
handoffs.

-Thanks
-Todd Blanchard

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