Warning: Can't synchronize with repository "(default)" (/home/git/ome.git does not appear to be a Git repository.). Look in the Trac log for more information.
Notice: In order to edit this ticket you need to be either: a Product Owner, The owner or the reporter of the ticket, or, in case of a Task not yet assigned, a team_member"

Task #7274 (closed)

Opened 12 years ago

Closed 12 years ago

DOC: Development examples documentation

Reported by: atarkowska Owned by: cxallan
Priority: critical Milestone: OMERO-4.4
Component: Documentation Version: n.a.
Keywords: n.a. Cc: cxallan, wmoore, cneves
Resources: n.a. Referenced By: n.a.
References: n.a. Remaining Time: 0.0d
Sprint: n.a.

Description

This ticket should include examples how to configure, use and add own static files and their handler

Change History (7)

comment:1 Changed 12 years ago by atarkowska

Using STATICS in the template

django.contrib.staticfiles collects static files from each of your applications (and any other places you specify) into a single location that can easily be served in production.

By default, static files should be put within static/ subdirectories of apps in INSTALLED_APPS. Some projects will probably also have static assets that aren’t tied to a particular app. The STATICFILES_DIRS setting is a tuple of filesystem directories to check when loading static files.

  • GENERAL: In order to refer to these files in templates use the included context processor which allows template code like:
<link rel="stylesheet" href="{% static "YOUR_APP/path_to_media" %}" type="text/css" />

for example:

<script type="text/javascript" src="{% static "3rdparty/jquery-1.7.2.js" %}"></script>

http://host:port/static/3rdparty/jquery_1.4.2.js

and less fabulous way:

{% load static %}
<img src="{{ STATIC_URL }}YOUR_APP/image/logo.jpg" />

http://host:port/static/YOUR_APP/image/logo.jpg

WARNING: In every inherited template any code outside blocks redefinitions is not executed. So in this case {% load webclient_tags %} has to be called inside each block.

or use context processor for setting "global" variable.



Using STATICS in views methods:

Developer might be also interested in using static prefix directly in the python code such as views, forms, etc.

from django.conf import settings
'<script type="text/javascript" src="%s3rdparty/jquery-1.7.2.js"></script>' % settings.STATIC_URL



Serving static files:

The static files tools are mostly designed to help with getting static files successfully deployed into production. This usually means a separate, dedicated static file server, which is a lot of overhead to mess with when developing locally. Thus, the staticfiles app ships with a quick and dirty helper view that you can use to serve files locally in development. This will only work if DEBUG is True.

$ bin/omero config set omero.web.debug True

That's because this view is grossly inefficient and probably insecure. This is only intended for local development, and should never be used in production.



Config changes:

  1. STATICFILES_DIRS should be configurable from omero config command line by
$ bin/omero config set omero.web.staticfile_dirs '[["alias", "/home/example.com/static/"], ["/opt/webfiles/common"]'
  1. DATABASES: "omero.web.databases": ["DATABASES", {}, json.loads],

Deprecated:

  • DATABASE_ENGINE - This setting has been replaced by ENGINE in DATABASES. The database backend to use. The built-in database backends are:
    • 'django.db.backends.postgresql_psycopg2'
    • 'django.db.backends.postgresql'
    • 'django.db.backends.mysql'
    • 'django.db.backends.sqlite3'
    • 'django.db.backends.oracle'
  • DATABASE_HOST - This setting has been replaced by HOST in DATABASES.
  • DATABASE_NAME - This setting has been replaced by NAME in DATABASES.
  • DATABASE_OPTIONS - This setting has been replaced by OPTIONS in DATABASES.
  • DATABASE_PASSWORD - This setting has been replaced by PASSWORD in DATABASES.
  • DATABASE_PORT - This setting has been replaced by PORT in DATABASES.
  • DATABASE_USER - This setting has been replaced by USER in DATABASES.

New OMERO config command:

bin/omero config set omero.web.databases '{"default": {"ENGINE": "django.db.backends.sqlite3","NAME": "mydatabase"}}'
  1. CACHES: "omero.web.caches": ["CACHES", {}, json.loads],

Deprecated:

  • CACHE_BACKEND - This setting has been replaced by BACKEND in CACHES. The cache backend to use. The built-in cache backends are:

New OMERO config command:

bin/omero config set omero.web.caches '{"default": {"BACKEND": "django.core.cache.backends.filebased.FileBasedCache","LOCATION": "file://C:/windows/temp/"}}'
Last edited 12 years ago by atarkowska (previous) (diff)

comment:2 Changed 12 years ago by atarkowska

  • Cc cxallan wmoore added

comment:3 Changed 12 years ago by atarkowska

  • Cc cneves-x added

comment:4 Changed 12 years ago by cxallan

  • Owner changed from atarkowska to cxallan

comment:5 Changed 12 years ago by wmoore

If I do this:

$ omero config set omero.web.staticfile_dirs '[["alias", "/Users/will/Desktop/static"], ["blah", "/Users/will/Desktop/static"]]'

It seems to have no effect on where static files are copied on web start

Copying '/Users/will/Desktop/OMERO/dist/lib/python/omeroweb/webstart/static/webstart/img/icon-omero-web.png'

735 static files copied to '/Users/will/Desktop/OMERO/dist/lib/python/omeroweb/static'.
Starting OMERO.web... Validating models...

0 errors found
Django version 1.3.1, using settings 'omeroweb.settings'
Development server is running at http://0.0.0.0:4080/
Quit the server with CONTROL-C.

comment:6 Changed 12 years ago by wmoore

Ah - OK, I get it. omero.web.staticfile_dirs simply specifies additional source dirs for static files. Do we provide any way to change the location that they are copied to? Or it is Always lib/python/omeroweb/static

comment:7 Changed 12 years ago by cxallan

  • Remaining Time changed from 1 to 0
  • Resolution set to fixed
  • Status changed from new to closed

Completed.

Note: See TracTickets for help on using tickets. You may also have a look at Agilo extensions to the ticket.

1.3.13-PRO © 2008-2011 Agilo Software all rights reserved (this page was served in: 0.80272 sec.)

We're Hiring!