[gsoc-dev] GWM Questions - Switching to new layout

Piotr Banaszkiewicz piotr at banaszkiewicz.org
Tue Jul 16 23:41:19 UTC 2013


Re: (A)
As long as Django project uses
``django.contrib.staticfiles.finders.AppDirectoriesFinder`` static
file finder [1] (and it usually does), the discovery of applications'
static files takes into account their ``static`` directory. More [2]

[1] https://docs.djangoproject.com/en/dev/ref/settings/#staticfiles-finders
[2] https://docs.djangoproject.com/en/dev/howto/static-files/

The same applies to applications' templates. Thanks to
``django.template.loaders.app_directories.Loader`` template loader,
Django searches for templates within installed applications
``templates`` directories.

More information [3], [4].
[3] https://docs.djangoproject.com/en/dev/ref/settings/#template-loaders
[4] https://docs.djangoproject.com/en/dev/ref/templates/api/#loader-types

Generally speaking, ``TEMPLATE_DIRS`` contains additional, often
global or external, paths containing templates.


Re: (B)
I don't think Django applications make use of per-application ``settings.py``.
Look for example here [5] to see how others deal with pluggable
applications and their settings.

[5] https://github.com/django-debug-toolbar/django-debug-toolbar/blob/master/debug_toolbar/middleware.py#L53


Re: (C)
You don't have to collect the templates, but, as you said, to collect
static files in one place we use ``./manage.py collecstatic``


I'm happy to answer any further questions :) cheers!

On Tue, Jul 16, 2013 at 7:04 PM, pranjal mittal
<mittal.pranjal at gmail.com> wrote:
> Hey Peter,
>
> [Adding the gsoc-dev alias so that everyone could see these questions /
> help.]
>
> Thank you for the previous answers. :)
> I have some further queries (which are more related to Django in itself,
> actually)
>
> (A)
> Assuming the case that I want to to build a pluggable app. (Though I am
> still a bit loath to do so now)
>
> I add the static, template files of "ganetiviz" respectively into-
> ganetiviz/static
> ganetiviz/templates
>
> Now even if I plug this application in as a separate app as I see in your
> changes. [1]
> How will GWM know where the static, template files for "ganetiviz" are
> located?
>
> TEMPLATE_DIRS setting needs to be defined for this app itself.
> => need for  creating  ganetiviz/settings.py
> And whether we can do that or not, comes from an answer to (B)
>
> Further, static files will also have to be collected to a central place for
> serving. (C)
>
> (B)
>  When I plugin an external app like in [1] , is the settings.py file of each
> app automatically included into the main Django Application
> Main Django Application - Defined as the app whose settings.py file is
> referenced by the manage.py, used to run the server.
>
>
> (C)
> Are you aware of any kind of  built-in Django feature that automatically
> imports the
>
> new_app/templates
> new_app/settings
>
> into the main Django application automatically. (for the case of static
> files, the per app static files being collected into the STATIC_ROOT defined
> by the MAIN app on giving collect-static command.)
>
>
> Cheers,
>
> [1]
> https://github.com/pbanaszkiewicz/ganeti_webmgr/blob/enhancement/13599/ganeti_web/ganeti_web/settings/local.py#L96
>
>
> On Tue, Jul 16, 2013 at 12:38 PM, Piotr Banaszkiewicz
> <piotr at banaszkiewicz.org> wrote:
>>
>> Hi! :)
>>
>> In my opinion you should
>>
>> 1. put your static files into ganeti_web/static and your templates
>> into ganeti_web/templates/ganetiviz/*
>> (unless you want your application to be pluggable everywhere, not only
>> into GWM, then create templates subdir in ganetiviz application and
>> store templates there)
>>
>> 2. it's actually possible to have "old" imports with new, refactored
>> code. Note that ganeti_web/models.py currently imports all three:
>> Node, Cluster and VirtualMachine:
>>
>> https://github.com/pbanaszkiewicz/ganeti_webmgr/blob/enhancement/13599/ganeti_web/ganeti_web/models.py#L39
>>
>> I think you can use "old-style" imports just to make ganetiviz work,
>> even if this is a little bit ugly.  Just leave a note in comments near
>> that imports.
>>
>> It's 9AM here and I'm asleep as well...
>>
>> On Tue, Jul 16, 2013 at 12:26 AM, pranjal mittal
>> <mittal.pranjal at gmail.com> wrote:
>> > Hi Peter,
>> >
>> > I had a look at your pull request nicely and the changes you made.
>> > Though I
>> > am relatively new to GWM as a developer, but I can imagine how things
>> > will
>> > be much better now for all the gwm developers now. :)
>> >
>> > Now, I am trying to modularize the code I have been writing into a
>> > separate
>> > app called "ganetiviz" [1], as per your scheme.
>> > Check the link [1] which shows my progress with the modularization.
>> >
>> > Following this, I have some blockers-
>> >
>> > (1) Where should I add the template files ganetiviz is supposed to
>> > render?
>> >
>> > (2) Where do I add the static files? For now I added them to a js
>> > subdirectory within "ganetiviz"
>> >
>> > (3) I was making use of Node, Cluster, VM models. Should I import them
>> > from
>> > the old location or the new location.
>> >
>> >
>> >
>> > P.S: Some of my questions might seem silly / incomplete? I am already
>> > half
>> > asleep. 3:55 am here. ^_-
>> >
>> >
>> > Cheers,
>> >
>> > [1]
>> >
>> > https://github.com/pramttl/ganeti_webmgr/tree/dev_feature/13569/ganeti_web/ganetiviz
>> >
>> > --
>> > Best Regards,
>> > Pranjal Mittal
>> > B.Tech.  2014
>> > Indian Institute of Technology,BHU
>> > Varanasi, U.P,
>> > India
>> >
>> > Github | LinkedIn | Blog
>
>
>
>
> --
> Best Regards,
> Pranjal Mittal
> B.Tech.  2014
> Indian Institute of Technology,BHU
> Varanasi, U.P,
> India
>
> Github | LinkedIn | Blog


More information about the gsoc-dev mailing list