Re: Add an extra parameter to 'static' tag

2014-06-16 Thread Shai Berger
Hi Renato,

Sorry for being a little late to this party.

On Sunday 01 June 2014 17:36:43 Renato Oliveira wrote:
> 
> Yeah, i'm aware of this, and sorry for not being explicit. The goal of this
> improvement is to point to many places. For exampe, if I have a project
> with, bootstrap, jquery and angular. I can do this:
> 
> {% static 'path/to/my/angular.js' http://googlecdn/angular.js %}
> {% static 'path/to/bootstrap.css' http://bootstrapcdn/bootstrap.css %}
> 
> And If I have to write some css or js file,
> 
> {% static 'path/to/users.js' %}
> 
> And this would use Django storage or S3, whatever.

I suspect that your proposal could be acceptable, if, instead of adding HTTP 
sources into the templates, you added a "using=" argument that referenced a 
file-storage object -- similar to the one on the cache tag.

The problem with this idea is that, while caches are named in a settings 
entry, there is currently no such "registry" of file-storage objects. One could 
arguably be added to staticfiles' AppConfig, but that will probably only happen 
if there are more uses for named storages.

Anyway, doing it this way addresses Florian's concerns -- control of which 
named storage goes where stays at the project level, the templates only 
specify grouping of files; and I think it gives most of what you want. 

The only concern I have about it is, it may be over-engineered -- in practice, 
you don't usually have whole sets of files in different storages, and if you 
do, 
you can probably tell the right storage by path; so a simpler solution is a 
custom storage (as Florian pointed) which makes all the decisions.

YMMV,
Shai.

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/201406161812.34475.shai%40platonix.com.
For more options, visit https://groups.google.com/d/optout.


Re: Add an extra parameter to 'static' tag

2014-06-02 Thread Renato Oliveira
Thanks for the answers!





Renato Oliveira
@_renatooliveira 
Labcodes - www.labcodes.com.br



On Sun, Jun 1, 2014 at 8:26 PM, Florian Apolloner 
wrote:

> Hi Renato,
>
>
> On Sunday, June 1, 2014 4:36:55 PM UTC+2, Renato Oliveira wrote:
>>
>> On Sunday, June 1, 2014 3:26:06 AM UTC+2, Renato Oliveira wrote:

 I open sourced  the
 modification we did (4 or 5 lines plus tests), and was about to send it to
 pypi and wondered if it is an improvement to do on Django itself.

>>>
>>> I don't think so, since Django already provides a way to do what you are
>>> after: You can write your on static storage backend which the static-tag
>>> will then use, this way the backend will figure out what to do when
>>> DEBUG=False/True.
>>>
>>
>> Yeah, i'm aware of this, and sorry for not being explicit. The goal of
>> this improvement is to point to many places. For exampe, if I have a
>> project with, bootstrap, jquery and angular. I can do this:
>>
>> {% static 'path/to/my/angular.js' http://googlecdn/angular.js %}
>> {% static 'path/to/bootstrap.css' http://bootstrapcdn/bootstrap.css %}
>>
>
> I don't see any difference to the  DEBUG example here, a storage backend
> can still return different URLs, depending on the filename (eg angular vs
> bootstrap). Your proposal seems to remove the choice from the user and puts
> it into the template. FWIW, in my experience per project CDNs often
> introduce greater latency and less performance than a single (or more)
> keep-alive connections to one server fetching all the files (possible
> concatenated).
>
> Cheers,
> Florian
>
>>  --
> You received this message because you are subscribed to the Google Groups
> "Django developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-developers+unsubscr...@googlegroups.com.
> To post to this group, send email to django-developers@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-developers.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-developers/d7da3542-f64e-4aed-83c0-4d56070d9d01%40googlegroups.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/CAGPLouUU8c5zQn%2BPGZ3OnCw%3D0x85qKx1au3YN4OOtnQpa7iLbw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Add an extra parameter to 'static' tag

2014-06-01 Thread Florian Apolloner
Hi Renato,

On Sunday, June 1, 2014 4:36:55 PM UTC+2, Renato Oliveira wrote:
>
> On Sunday, June 1, 2014 3:26:06 AM UTC+2, Renato Oliveira wrote:
>>>
>>> I open sourced  the 
>>> modification we did (4 or 5 lines plus tests), and was about to send it to 
>>> pypi and wondered if it is an improvement to do on Django itself.
>>>
>>
>> I don't think so, since Django already provides a way to do what you are 
>> after: You can write your on static storage backend which the static-tag 
>> will then use, this way the backend will figure out what to do when 
>> DEBUG=False/True.
>>
>
> Yeah, i'm aware of this, and sorry for not being explicit. The goal of 
> this improvement is to point to many places. For exampe, if I have a 
> project with, bootstrap, jquery and angular. I can do this:
>
> {% static 'path/to/my/angular.js' http://googlecdn/angular.js %}
> {% static 'path/to/bootstrap.css' http://bootstrapcdn/bootstrap.css %}
>

I don't see any difference to the  DEBUG example here, a storage backend 
can still return different URLs, depending on the filename (eg angular vs 
bootstrap). Your proposal seems to remove the choice from the user and puts 
it into the template. FWIW, in my experience per project CDNs often 
introduce greater latency and less performance than a single (or more) 
keep-alive connections to one server fetching all the files (possible 
concatenated).

Cheers,
Florian

>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/d7da3542-f64e-4aed-83c0-4d56070d9d01%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Add an extra parameter to 'static' tag

2014-06-01 Thread Reinout van Rees

On 01-06-14 16:36, Renato Oliveira wrote:


{% static 'path/to/my/angular.js' http://googlecdn/angular.js %}
{% static 'path/to/bootstrap.css' http://bootstrapcdn/bootstrap.css %}


It seems to me that the core use case of the staticfiles app is to 
manage *local* css files well. This includes the scenario where the 
local files are copied off to a CDN. That CDN's base URL can then be 
used in production.



What you are proposing sounds to be a different problem:

- You want to use a CDN in production.

- You want to use local files as a fallback for when you're on a train 
without an internet connection to the CDN.



So... I don't think this change should go into staticfiles.

But... the basic use case is sound. Perhaps you could change your code 
into a template tag that looks like

{% cdn http://googlecdn/whatever.js %} ?

With a management command that would download all the relevant files to 
a local directory? (Assuming you can list the templates). Or that would 
do it on the fly when an internet connection is available when you use 
the template?


It works the other way around from your current approach, but that looks 
to me to be the right way around :-)




Reinout

--
Reinout van Reeshttp://reinout.vanrees.org/
rein...@vanrees.org http://www.nelen-schuurmans.nl/
"If you're not sure what to do, make something. -- Paul Graham"

--
You received this message because you are subscribed to the Google Groups "Django 
developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/lmg7nt%24og3%241%40ger.gmane.org.
For more options, visit https://groups.google.com/d/optout.


Re: Add an extra parameter to 'static' tag

2014-06-01 Thread Renato Oliveira
On Sun, Jun 1, 2014 at 6:52 AM, Florian Apolloner 
wrote:

> Hi Renato,
>

Hi Florian, thanks for answering

>
>
> On Sunday, June 1, 2014 3:26:06 AM UTC+2, Renato Oliveira wrote:
>>
>> I open sourced  the
>> modification we did (4 or 5 lines plus tests), and was about to send it to
>> pypi and wondered if it is an improvement to do on Django itself.
>>
>
> I don't think so, since Django already provides a way to do what you are
> after: You can write your on static storage backend which the static-tag
> will then use, this way the backend will figure out what to do when
> DEBUG=False/True.
>

Yeah, i'm aware of this, and sorry for not being explicit. The goal of this
improvement is to point to many places. For exampe, if I have a project
with, bootstrap, jquery and angular. I can do this:

{% static 'path/to/my/angular.js' http://googlecdn/angular.js %}
{% static 'path/to/bootstrap.css' http://bootstrapcdn/bootstrap.css %}

And If I have to write some css or js file,

{% static 'path/to/users.js' %}

And this would use Django storage or S3, whatever.

>
> Cheers,
> Florian
>

I looked for alternatives, and read about django custom storage backends,
and it doesn't seemed to me that it could do it.

If there is a way to do this without changing the template tag, this e-mail
must be on django-users, sorry :)

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/CAGPLouWmPt%2BVQNyuLy00o7P4-OLgVZR1JDvN_ZGH_6JCWsPFHw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Add an extra parameter to 'static' tag

2014-06-01 Thread Florian Apolloner
Hi Renato,

On Sunday, June 1, 2014 3:26:06 AM UTC+2, Renato Oliveira wrote:
>
> I open sourced  the 
> modification we did (4 or 5 lines plus tests), and was about to send it to 
> pypi and wondered if it is an improvement to do on Django itself.
>

I don't think so, since Django already provides a way to do what you are 
after: You can write your on static storage backend which the static-tag 
will then use, this way the backend will figure out what to do when 
DEBUG=False/True.

Cheers,
Florian 

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/1ecef89d-ec48-4ae0-bd97-95275bcd72f8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Add an extra parameter to 'static' tag

2014-05-31 Thread Renato Oliveira
Sorry if I gave the wrong impression, this e-mail isn't to publish a new
project, It's a feature proposal.



Renato Oliveira
@_renatooliveira 
Labcodes - www.labcodes.com.br



On Sat, May 31, 2014 at 10:20 PM, Renato Oliveira <
renatooliveira@gmail.com> wrote:

> Hi all,
>
> My name is Renato Oliveira and I'm a Brazilian Django user.
>
> Here at my company we use a small modification of static template tag.
>
> We added a parameter, URL, and the inside job is when DEBUG is True, the
> tag returns the local path for the static file, but when DEBUG is false,
> the URL is returned.
>
> So, why do we use it. We do a lot of projects using staticfiles that are
> already online, at CDNs for example, and there is no need for me to serve
> it. But when I'm writing code, I don't want useless requests (my internet
> is not so fast) and also, I want to be able to work offline. Also, if
> everyone who uses bootstrap, foundation and that kind of stuff, point to
> the same file, they will already be on cache, so a lot of happy people.
>
> I open sourced  the
> modification we did (4 or 5 lines plus tests), and was about to send it to
> pypi and wondered if it is an improvement to do on Django itself.
>
> Of course, I would need some help to find the best way to do it on Django.
> In our version, we just made it works.
>
> Best regards,
>
> Renato Oliveira
> @_renatooliveira 
> Labcodes - www.labcodes.com.br
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/CAGPLouXdGixPKTdoCdZE1MH9COSBc-CsgTzh%2B-e79UrXtw_wPA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Add an extra parameter to 'static' tag

2014-05-31 Thread Renato Oliveira
Hi all,

My name is Renato Oliveira and I'm a Brazilian Django user.

Here at my company we use a small modification of static template tag.

We added a parameter, URL, and the inside job is when DEBUG is True, the
tag returns the local path for the static file, but when DEBUG is false,
the URL is returned.

So, why do we use it. We do a lot of projects using staticfiles that are
already online, at CDNs for example, and there is no need for me to serve
it. But when I'm writing code, I don't want useless requests (my internet
is not so fast) and also, I want to be able to work offline. Also, if
everyone who uses bootstrap, foundation and that kind of stuff, point to
the same file, they will already be on cache, so a lot of happy people.

I open sourced  the
modification we did (4 or 5 lines plus tests), and was about to send it to
pypi and wondered if it is an improvement to do on Django itself.

Of course, I would need some help to find the best way to do it on Django.
In our version, we just made it works.

Best regards,

Renato Oliveira
@_renatooliveira 
Labcodes - www.labcodes.com.br

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/CAGPLouVLTv4CQC%3D0_iwAZudcDvzQPm22fcNG1vLNaKYWo%3Dhshg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.