Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Digital Labels Installation

richbs edited this page · 1 revision

You'll probably want a Python or Django developer to help you through this and or have some experience with developing Django. At least, a run through of the tutorials will be essential before grokking some of this:

https://docs.djangoproject.com/en/1.4/

Get our source code from Github and clone it into local directory called DigitalLabels

$ git clone -b pip-bundle git@github.com:vanda/DigitalLabels.git ./DigitalLabels

Hop in to the directory:

$ cd ./DigitalLabels

Install DigitalLabels and its requirements:

$ pip install -r requirements.txt .

Hop out of the clone directory and clean it up:

$ cd ..
$ rm -rf ./DigitalLabels

Start your own Django project for your labels, called mylabels:

$ django-admin.py startproject mylabels

Brilliant! You've started your project. Hop into the project folder and let's look at the settings file in your favourite text editor (unless it's emacs).

$ vim ./mylabels/mylabels/settings.py

Here are some lines to add to the stock settings to get us up and running.

Filesystem and database

Let's give Django easy access to our local project folder. Stick this at the top of your settings.py:

# Useful variable for quick local setup
import os
BASE_PATH = os.path.dirname(__file__)

Now we can set up the database and media folders. First, the database—find the DATABASES dictionary in your settings.py and edit it too look a bit like this:

'ENGINE': 'django.db.backends.sqlite3',  # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': BASE_PATH + '/digitallabels.db',  # Or path to database file if using sqlite3.

Here we are saying we want to get started with a little sqlite database, which is part of Python core, and create the file in the project directory.

Assets

Next thing to do is make sure we're able to deal with all the nice images we're going to upload into our digital labels.

First, the media root to which the images will be uploaded:

MEDIA_ROOT = BASE_PATH + '/media/'

Next, the URL path from which the images will be served:

MEDIA_URL = '/media/'

We add a new setting for the thumbnailing system, where all the variants of your uploaded images will be kept:

# Absolute filesystem path to the directory that will hold thumbnail files.
MEDIA_CACHE_ROOT = BASE_PATH + '/media/cache/'

Also, we need to set up a directory from where your CSS, JavaScript etc will be served, including the admin eye-candy. Find and edit these lines thus:

STATIC_ROOT = BASE_PATH + '/static/'

# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'

ADMIN_MEDIA_PREFIX = STATIC_URL + "grappelli/"

Plugging in the apps

Next we edit the INSTALLED_APPS tuple to include the required Django apps to make this whole show rock.

First, enable the admin. Where it says…

# Uncomment the next line to enable the admin:
# 'django.contrib.admin',

Do so…

# Uncomment the next line to enable the admin:
'django.contrib.admin',

Then insert the following lines before the admin line:

'labels',
'reversion',
'sorl.thumbnail',
'grappelli',

Your INSTALLED_APPS setting could look as good as this:

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'labels',
    'reversion',
    'sorl.thumbnail',
    'grappelli',
    # Uncomment the next line to enable the admin:
    'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    # 'django.contrib.admindocs',
)

Miscellaneous settings

Stick these at the bottom of settings.py

Ensure your thumbnails are padded square to fit the square templates:

THUMBNAIL_ENGINE = 'labels.thumbs.PadEngine'

Give your admin site a custom heading:

GRAPPELLI_ADMIN_TITLE = "MyLabels Administration" 

If you want to hide the mouse cursor on the front end:

KIOSK_MODE = True # optional

Create appropriate media directories

In your mylabels project directory (cd mylabels) create the media directory:

$ mkdir mylabels/media

Create the database and superuser (follow the generated instructions):

$ python ./manage.py syncdb

Hook up the URLS

Now we need to route the URLs to the appropriate views:

$ vim mylabels/urls.py

Enable, the admin interface by uncommenting the lines as indicated:

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

And also the appropriate urlpatterns:

# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),

Insert the grappelli urlpatterns above the admin ones (for a fancy admin interface):

(r'^grappelli/', include('grappelli.urls')),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),

Next, hook up the front end patterns for the labels. Insert after the admin patterns. Your urlpatterns tuple should look something like this:

urlpatterns = patterns('',
    (r'^grappelli/', include('grappelli.urls')),
    url(r'^admin/', include(admin.site.urls)),
    (r'^', include('labels.urls')),
)

Finally, during development, we need to serve up any images that are added to the system by administrators. Add these lines to the end of urls.py

from django.conf import settings
from django.contrib.staticfiles.urls import staticfiles_urlpatterns

urlpatterns += staticfiles_urlpatterns()
if settings.DEBUG:
    urlpatterns += patterns('',
        url(r'^media/(?P<path>.*)$', 'django.views.static.serve', {
            'document_root': settings.MEDIA_ROOT,
        }),
   )

Finally, you should be able to start this whole shooting match:

$ python manage.py runserver

Then, you can hit up the URL:

http://127.0.0.1:8000

Not much to see here. So, log in to the back end with the superuser you created.

http://127.0.0.1:8000/admin/

From here, you can follow the user instructions in the README:

https://github.com/vanda/DigitalLabels
Something went wrong with that request. Please try again.