1. Jannis Leidel
  2. django-vcstorage

Commits

Jannis Leidel  committed 9f9b866

Added example project to show how to use vcstorage

  • Participants
  • Parent commits 47dc7fc
  • Branches default

Comments (0)

Files changed (9)

File example/__init__.py

Empty file added.

File example/blog/__init__.py

Empty file added.

File example/blog/admin.py

View file
+from django.contrib import admin
+from example.blog.models import Entry, Topic, Link
+
+admin.site.register(Entry)
+admin.site.register(Topic)
+admin.site.register(Link)

File example/blog/models.py

View file
+import os
+from django.db import models
+from vcstorage.fields import VcFileField
+from vcstorage.storage import VcStorage, GitStorage, BazaarStorage
+
+def handle_attachment(instance, filename):
+    return os.path.join(instance.title.lower(), filename)
+
+class Entry(models.Model):
+    "Example model that uses the VCSTORAGE_DEFAULT_BACKEND 'hg'"
+    title = models.CharField(max_length=100)
+    content = models.TextField()
+    attachment = VcFileField(upload_to=handle_attachment)
+
+    class Meta:
+        verbose_name = 'entry'
+        verbose_name_plural = 'entries'
+
+class Topic(models.Model):
+    "Example model that uses the Git storage backend"
+    title = models.CharField(max_length=100)
+    content = models.TextField()
+    attachment = VcFileField(storage=GitStorage())
+
+    class Meta:
+        verbose_name = 'topic'
+        verbose_name_plural = 'topics'
+
+class Link(models.Model):
+    "Example model that uses the Bazaar storage backend"
+    title = models.CharField(max_length=100)
+    url = models.URLField()
+    attachment = VcFileField(storage=BazaarStorage())
+
+    class Meta:
+        verbose_name = 'link'
+        verbose_name_plural = 'links'

File example/blog/views.py

View file
+# Create your views here.

File example/development.py

View file
+
+from example.settings import *
+DEBUG=True
+TEMPLATE_DEBUG=DEBUG

File example/production.py

View file
+
+from example.settings import *

File example/settings.py

View file
+import os
+PROJECT_ROOT = os.path.realpath(os.path.dirname(__file__))
+
+ADMINS = (
+    # ('Your Name', 'your_email@domain.com'),
+)
+
+MANAGERS = ADMINS
+
+DATABASE_ENGINE = 'sqlite3'    # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
+DATABASE_NAME = 'example.db'
+DATABASE_USER = ''             # Not used with sqlite3.
+DATABASE_PASSWORD = ''         # Not used with sqlite3.
+DATABASE_HOST = ''             # Set to empty string for localhost. Not used with sqlite3.
+DATABASE_PORT = ''             # Set to empty string for default. Not used with sqlite3.
+
+TIME_ZONE = 'America/Chicago'
+
+LANGUAGE_CODE = 'en-us'
+
+# Absolute path to the directory that holds media.
+# Example: "/home/media/media.lawrence.com/"
+#MEDIA_ROOT = os.path.join(PROJECT_ROOT, 'media')
+MEDIA_ROOT = os.path.join(os.path.expanduser("~"), "repos")
+
+# URL that handles the media served from MEDIA_ROOT. Make sure to use a
+# trailing slash if there is a path component (optional in other cases).
+# Examples: "http://media.lawrence.com", "http://example.com/media/"
+MEDIA_URL = '/media/'
+
+# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
+# trailing slash.
+# Examples: "http://foo.com/media/", "/media/".
+ADMIN_MEDIA_PREFIX = '/admin_media/'
+
+# Don't share this with anybody.
+SECRET_KEY = 'd%-)1sa0rp&quum@&=da_v-5+w7$cuntc($1oi%ndrl6t^n9qj'
+
+MIDDLEWARE_CLASSES = (
+    'django.middleware.common.CommonMiddleware',
+    'django.contrib.sessions.middleware.SessionMiddleware',
+    'django.contrib.auth.middleware.AuthenticationMiddleware',
+    'django.middleware.doc.XViewMiddleware',
+)
+
+ROOT_URLCONF = 'example.urls'
+
+INSTALLED_APPS = (
+    'django.contrib.auth',
+    'django.contrib.contenttypes',
+    'django.contrib.sessions',
+    'django.contrib.admin',
+    'example.blog',
+)
+
+TEMPLATE_LOADERS = (
+    'django.template.loaders.filesystem.load_template_source',
+    'django.template.loaders.app_directories.load_template_source',
+)
+
+TEMPLATE_DIRS = (
+    os.path.join(PROJECT_ROOT, "templates"),
+)
+
+VCSTORAGE_DEFAULT_BACKEND = 'hg'

File example/urls.py

View file
+
+from django.conf.urls.defaults import patterns, include, handler500
+from django.conf import settings
+from django.contrib import admin
+admin.autodiscover()
+
+handler500 # Pyflakes
+
+urlpatterns = patterns(
+    '',
+    (r'^admin/(.*)', admin.site.root),
+    (r'^accounts/login/$', 'django.contrib.auth.views.login'),
+)
+
+if settings.DEBUG:
+    urlpatterns += patterns('',
+        (r'^media/(?P<path>.*)$', 'django.views.static.serve', 
+         {'document_root': settings.MEDIA_ROOT}),
+    )