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 <tblanch...@mac.com> 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 <tblanch...@mac.com> 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 <tblanch...@mac.com> 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 >> >>>>>> <html> >>>>>> <head> >>>>>> {{ media }} >>>>>> </head> >> >>>>>> 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 >>> 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.