Exemplo n.º 1
0
def get_media_urls():
    #~ print "20121110 get_urls"
    urlpatterns = []
    from os.path import exists, join, abspath, dirname
    
    logger.info("Checking /media URLs ")
    prefix = settings.MEDIA_URL[1:]
    assert prefix.endswith('/')
    
    def setup_media_link(short_name,attr_name=None,source=None):
        target = join(settings.MEDIA_ROOT,short_name)
        if exists(target):
            return
        if attr_name:
            source = getattr(settings.LINO,attr_name)
            if not source:
                raise Exception(
                  "%s does not exist and LINO.%s is not set." % (
                  target,attr_name))
        if not exists(source):
            raise Exception("LINO.%s (%s) does not exist" % (attr_name,source))
        if is_devserver():
            urlpatterns.extend(patterns('django.views.static',
            (r'^%s%s/(?P<path>.*)$' % (prefix,short_name), 
                'serve', {
                'document_root': source,
                'show_indexes': False })))
        else:
            logger.info("Setting up symlink %s -> %s.",target,source)
            symlink = getattr(os,'symlink',None)
            if symlink is not None:
                symlink(source,target)
        
    if not settings.LINO.extjs_base_url:
        setup_media_link('extjs','extjs_root')
    if settings.LINO.use_bootstrap:
        setup_media_link('bootstrap','bootstrap_root')
    if settings.LINO.use_jasmine:
        setup_media_link('jasmine','jasmine_root')
    if settings.LINO.use_extensible:
        setup_media_link('extensible','extensible_root')
    if settings.LINO.use_tinymce:
        setup_media_link('tinymce','tinymce_root')
    if settings.LINO.use_eid_jslib:
        setup_media_link('eid-jslib','eid_jslib_root')
        
    setup_media_link('lino',source=join(dirname(lino.__file__),'..','media'))

    if is_devserver():
        urlpatterns += patterns('django.views.static',
            (r'^%s(?P<path>.*)$' % prefix, 'serve', 
              { 'document_root': settings.MEDIA_ROOT, 
                'show_indexes': True }),
        )

    return urlpatterns
Exemplo n.º 2
0
 def setup_media_link(short_name,attr_name=None,source=None):
     target = join(settings.MEDIA_ROOT,short_name)
     if exists(target):
         return
     if attr_name:
         source = getattr(settings.LINO,attr_name)
         if not source:
             raise Exception(
               "%s does not exist and LINO.%s is not set." % (
               target,attr_name))
     if not exists(source):
         raise Exception("LINO.%s (%s) does not exist" % (attr_name,source))
     if is_devserver():
         urlpatterns.extend(patterns('django.views.static',
         (r'^%s%s/(?P<path>.*)$' % (prefix,short_name), 
             'serve', {
             'document_root': source,
             'show_indexes': False })))
     else:
         logger.info("Setting up symlink %s -> %s.",target,source)
         symlink = getattr(os,'symlink',None)
         if symlink is not None:
             symlink(source,target)