Re: Django's decoupling apps but template should couple them together, right?
The point of decoupling the apps is so that you can share them with others without having to give them all of your site, and it make it ALOT easier to maintain since if you want to make changes to the way the menu works you dont have to read though hundred of lines of code dealing with the rest of your site, you just go right to the menu application. As for third party applications, they are (as long as they are designed properly) easy to integrate with your own site since they already have all the required code, you just need to write the template and CSS info to make it fit with your sites design. On Tue, Nov 4, 2008 at 2:14 AM, ilmarik <[EMAIL PROTECTED]> wrote: > > Thank you for all your elaborated answers > > However I still don't see the point to have decouped apps in my > project. Web page mainly is a program for serving some text or media > or for saving some user data under the hood. Having an app for > particular business logic AND another pool of views, tags and > processors to use it, feels like I have to create everything twice or > makes an app to be a directory with just models.py in it. > > I was realy happy when I read about apps, but now I feel a bit > disappointed. > what about using third party elements in my project? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Django's decoupling apps but template should couple them together, right?
Thank you for all your elaborated answers However I still don't see the point to have decouped apps in my project. Web page mainly is a program for serving some text or media or for saving some user data under the hood. Having an app for particular business logic AND another pool of views, tags and processors to use it, feels like I have to create everything twice or makes an app to be a directory with just models.py in it. I was realy happy when I read about apps, but now I feel a bit disappointed. what about using third party elements in my project? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Django's decoupling apps but template should couple them together, right?
bruno desthuilliers wrote: > > On 3 nov, 03:56, Steve Holden <[EMAIL PROTECTED]> wrote: > (snip) > >> You might also want to look into ContextManager objects, which are a way >> of providing information to all pages. >> > > I assume you meant 'Context processors' ?-) > > Are you some kind of a mind-reader? I suppose that would mean I had to have some kind of a mind ;-) Thanks, Bruno, I did indeed mean context processors. regards Steve --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Django's decoupling apps but template should couple them together, right?
On 3 nov, 03:56, Steve Holden <[EMAIL PROTECTED]> wrote: (snip) > You might also want to look into ContextManager objects, which are a way > of providing information to all pages. I assume you meant 'Context processors' ?-) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Django's decoupling apps but template should couple them together, right?
On Mon, Nov 3, 2008 at 2:48 AM, ilmarik <[EMAIL PROTECTED]> wrote: > I've got controllers made as logical apps (controllers named > particularly) and whenever I need f.e. menu inside base layout, I > simply put {#menus/show/1} which means - return here compiled > controllers(menus) method(show) of menu with id (1). > This gives me the power to return response to any template from any > controllers 'public' method. [snip] > custom tags are just to much fuss for me but if it IS django's way to > create full portal template, fine. > or mayby there is one, more intuitive, simple, better ? The controllers that you use for your current implementation would be the same thing as an inclusion tag in django. Generally what I do when developing a new inclusion tag is to create a new view, and get the view to display exactly what I want in an isolated manor. So from your example there are three sections I would create isolated views for. The left menu, the top menu, and the language change section. Once you get the views functional for those it is usually simple to migrate those to an inclusion tag, if your view requires the request or request.user etc, you just need to make sure you set your inclusion tags with takes_context=True, then you can access the request via context.request. All of the examples you gave seem rather simple to implement inclusion tags, though they do tend to get much more complex if you want the various other applications to be able to create their own sections of a menu instead of maintaining it all as manually entered DB entries. To get the hang of inclusion tags it actually took me about a month and a half of playing with it and creating different ones just testing their capabilities, and asking lots of questions in #django. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Django's decoupling apps but template should couple them together, right?
Am 03.11.2008 um 02:33 schrieb ilmarik: > It's just simple amazing that I waste another night to figure out how > to glue two and more apps together inside one template. > I read about custom tags and I thing it isn't (or at least it > shouldn't be) the way of doing it. too much fuss imho. > > Example: > I have home page with menu on one side, news on other side, greetings > article inside, footer menu on bottom and a survey somewere else. > everything on one page of course. > > Walking with the idea of decoupled apps, I should create News app, > Survey app, Menu app and so on... There are several ways to get data from apps into templates: Views: - With views you have the ability to tailor the data you want to display to the needs of a specific page. Views are not necessarily coupled to apps; most apps have them, but then the views deal with the pages that are tied to the app. Say, if you have a news app, it's most likely that the app contains some views to display the news on some specific pages like 'mysite/ news/', 'mysite/news/2008/11/' , 'mysite/news/2008/11/03/super-duper- great-news/'. If you would like to have the news displayed on other not-tied-to-the- news-app pages like your homepage, you wouldn't do this in the views.py file of the news app but in a more global file like the views.py in your project directory (at least this is how I do it...). In this file, you could wirte a view that gathers all the data you want to display on your home page, for example like this: def index(request): news = News.objects.all() surveys = Survey.objects.all() menu_items = MenuItem.objects.all() return render_to_response('home.html', { 'news': news, 'surveys': surveys, 'menu_items': menu_items, }, context_instance=RequestContext(request)) So views are a good thing if it comes to specific pages, but there are better ways if you have something you want to display on every page. Custom Tags: --- Custom tags are often tied to apps as well, wich makes sense. With custom tags, you can filter the app's data and provide this filtered data directly to the template, without wire up some views for it, and in the same step add functionality to the template language. You can do some other pretty sophisticated things with custom tags besides of just pulling data... Their main use case is in my oppinion to seperate business logic from presentation logic. With custom tags, the programmer can provide some special functionality for the template author. For example you could write a custom tag for your news app that is used in the template like this: {% get_news 4 1 as newslist %}, which would then be 'give me the four latest news items, but only if they are not older then one month, and make them available in the template as newslist'. So you could use custom tags when you have some things that you want to display on every page, but if you want to do only this, then you are right: It's a little bit to much fuss for such a simple task, custom tags can be used for much more complex things. Context processors: --- I think context processors the best way when it comes to just displaying some data on every single of your projects' pages. They are easy to write, and they do just one thing: Add some data to the context which gets passed to all templates. A (simple) example would be: def get_news(request): latest_news = News.objects.all()[:4] return {'lates_news': latest_news} And voilĂ , from now on 'latest_news' is available in every temlate, and you can do things like this: {% for news in latest_news %} Do some stuff with your news {% endfor %} Docs and tipps on context processors: http://docs.djangoproject.com/en/dev/ref/templates/api/#writing-your-own-context-processors http://www.b-list.org/weblog/2006/jun/14/django-tips-template-context-processors/ benjamin --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Django's decoupling apps but template should couple them together, right?
> A slightly fuller description of your intended page structure might let > people provide more accurate answers to your needs. Let http://pow.dzierzoniow.pl be my fuller explanation. This page is my old project written in php on Kohana framework. There is one 'app' used to generate both menus (i just need to point an id), then language changing mechanism is another 'app'. content display is another, news is another and so on... I made a special mechanizm as an addition to the generic parser to return any controller's method response inside template as a string, whenever I decide to generate and add some "app based(in django's meaning)" content from library of complited solutions. I've got controllers made as logical apps (controllers named particularly) and whenever I need f.e. menu inside base layout, I simply put {#menus/show/1} which means - return here compiled controllers(menus) method(show) of menu with id (1). This gives me the power to return response to any template from any controllers 'public' method. I'm not trying to find identical solution to feel satified with django. I'm trying to learn django's way to glue decoupled apps inside one template. But I persume, 'my way' from Kohana is quite logical so I used to think in that way. custom tags are just to much fuss for me but if it IS django's way to create full portal template, fine. or mayby there is one, more intuitive, simple, better ? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Django's decoupling apps but template should couple them together, right?
Yes exactly. http://dpaste.com/hold/88396/ is the inclusion tag that I use for my navigation menu @ http://www.gustafsonandassociates.com/ Dj Gilcrease OpenRPG Developer ~~http://www.openrpg.com On Sun, Nov 2, 2008 at 6:57 PM, ilmarik <[EMAIL PROTECTED]> wrote: > > are you saing this: > http://docs.djangoproject.com/en/dev/howto/custom-template-tags/#inclusion-tags > is an explanation to my question ? > > If yes, many thanks to you and... silly me. > > if not, could you point me some solution explained in detail? > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Django's decoupling apps but template should couple them together, right?
ilmarik wrote: > It's just simple amazing that I waste another night to figure out how > to glue two and more apps together inside one template. > I read about custom tags and I thing it isn't (or at least it > shouldn't be) the way of doing it. too much fuss imho. > > Example: > I have home page with menu on one side, news on other side, greetings > article inside, footer menu on bottom and a survey somewere else. > everything on one page of course. > > Walking with the idea of decoupled apps, I should create News app, > Survey app, Menu app and so on... > It was simple and fun for a newbe like me to do it but... > How in the name of God to put all these Views' responses into ONE > template ? > djangobook.com says nothing about it. djangoproject.com neighter. at > least not explicitly... > > I'm trying to google this problem out but without success. > > Can anybody point some simple explanation to me ? > or is Django blind for such fundamental and common task and isn't > simplifying it at all ? > Since a view is intended to provide a response to an HTTP request, if you want a single page that includes the output from multiple views you need a page structure that fills various sections by making HTTP requests in the manner of a portal. However, it's not clear that you really *do* want to use a separate view for each piece of output. In that case you need to write views that structure their output by making calls on function imported from the various apps, each of which renders the appropriate small portion of the final page, or provides the information tho be inserted into that part of the template. You might also want to look into ContextManager objects, which are a way of providing information to all pages. A slightly fuller description of your intended page structure might let people provide more accurate answers to your needs. regards Steve -- Steve Holden+1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Django's decoupling apps but template should couple them together, right?
are you saing this: http://docs.djangoproject.com/en/dev/howto/custom-template-tags/#inclusion-tags is an explanation to my question ? If yes, many thanks to you and... silly me. if not, could you point me some solution explained in detail? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Django's decoupling apps but template should couple them together, right?
Once you get each working individually, I would make inclusion tags for the items that will be on every page (Menu, NewsList, Footer, Survey). The contents in the middle is what is shown by a view (At least in my setup) Dj Gilcrease OpenRPG Developer ~~http://www.openrpg.com --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Django's decoupling apps but template should couple them together, right?
It's just simple amazing that I waste another night to figure out how to glue two and more apps together inside one template. I read about custom tags and I thing it isn't (or at least it shouldn't be) the way of doing it. too much fuss imho. Example: I have home page with menu on one side, news on other side, greetings article inside, footer menu on bottom and a survey somewere else. everything on one page of course. Walking with the idea of decoupled apps, I should create News app, Survey app, Menu app and so on... It was simple and fun for a newbe like me to do it but... How in the name of God to put all these Views' responses into ONE template ? djangobook.com says nothing about it. djangoproject.com neighter. at least not explicitly... I'm trying to google this problem out but without success. Can anybody point some simple explanation to me ? or is Django blind for such fundamental and common task and isn't simplifying it at all ? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---