Tuesday, September 6, 2011

Re: Static images for use in admin widget



> Inside the widget's render() function, I have a formatted string that
> contains embedded JS, and within that string I have a JS function that
> looks like:
>
> function showCrossHair(divId) {
>        ...
>        div.innerHTML = '<img src="...">';
>        ...
> };

this looks awful to me. Can't you stick that into a .js file and include that?

With that over, you can use djangodocs-Form Widget Media and you can define a js-script somewhere inside your app/static/js/ directory. I think hardcoding the 'app/' directory is the usual way to do this, you should be the one naming your /static/app/ directory anyways, and you should be doing your imports with absolute paths, but in case you still don't want to, you can do something like

from django.conf import settings
import os
settings.<MY_APP_NAME>_DIR = os.path.dirname(__file__)


inside your app's root __init__.py file, and then do

from django.conf import settings
...
...
class MyWidget:
  class Media:
     js = ('%s/myfile.js'%settings.<MY_APP_NAME>_DIR)


I think

I'm pulling this up pretty straight out of my.. the blue, and it's really too late, but I think this or something along this lines would work


--
"The whole of Japan is pure invention. There is no such country, there are no such people" --Oscar Wilde

|_|0|_|
|_|_|0|
|0|0|0|

(\__/)
(='.'=)This is Bunny. Copy and paste bunny 
(")_(") to help him gain world domination.

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment