Commits

Oben Sonne  committed 873a76f

Update

  • Participants
  • Parent commits 32e7f31

Comments (0)

Files changed (12)

+\.pyc$
+~$

File dingeling/models.py

+from django.db import models
+
+class Label(models.Model):
+    
+    name = models.CharField(max_length=200, unique=True)
+
+class Page(models.Model):
+    
+    name = models.CharField(max_length=200, unique=True)
+    summary = models.CharField(max_length=200)
+    content = models.TextField()
+    labels = models.ManyToManyField(Label)
+
+    

File dingeling/settings.py

 # Django settings for dingeling project.
 
+import os.path
+BASEDIR = os.path.dirname(__file__)
+
+# =============================================================================
+
+WIKIFILES = os.path.join(os.path.expanduser("~"), "tmp", "dw")
+
+# =============================================================================
+
 DEBUG = True
 TEMPLATE_DEBUG = DEBUG
 
 
 DATABASES = {
     'default': {
-        'ENGINE': 'django.db.backends.', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
-        'NAME': '',                      # Or path to database file if using sqlite3.
+        'ENGINE': 'django.db.backends.sqlite3',
+        'NAME': os.path.join(WIKIFILES, 'wiki.db'),
         'USER': '',                      # Not used with sqlite3.
         'PASSWORD': '',                  # Not used with sqlite3.
         'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
 
 # Absolute path to the directory that holds media.
 # Example: "/home/media/media.lawrence.com/"
-MEDIA_ROOT = ''
+MEDIA_ROOT = WIKIFILES
 
 # 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).
 MIDDLEWARE_CLASSES = (
     'django.middleware.common.CommonMiddleware',
     'django.contrib.sessions.middleware.SessionMiddleware',
-    'django.middleware.csrf.CsrfViewMiddleware',
+    #'django.middleware.csrf.CsrfViewMiddleware',
     'django.contrib.auth.middleware.AuthenticationMiddleware',
     'django.contrib.messages.middleware.MessageMiddleware',
 )
 ROOT_URLCONF = 'dingeling.urls'
 
 TEMPLATE_DIRS = (
+    os.path.join(BASEDIR, 'templates').replace(os.path.sep, "/"),
     # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
     # Always use forward slashes, even on Windows.
     # Don't forget to use absolute paths, not relative paths.
 )
 
 INSTALLED_APPS = (
-    'django.contrib.auth',
+    #'django.contrib.auth',
     'django.contrib.contenttypes',
     'django.contrib.sessions',
     'django.contrib.sites',
     'django.contrib.messages',
     # Uncomment the next line to enable the admin:
     # 'django.contrib.admin',
+    'dingeling',
 )
+

File dingeling/templates/edit.html

+<div id="edit">
+<h1>{{ name }}</h1>
+
+{% if not page %}
+<div id="new-page-note">
+<p>This page does not yet exist.</p>
+</div>
+{% endif %}
+
+<form action="/edit/{{ name }}" method="POST">
+<input type="text" name="summary" value="page.summary" />
+<input type="text" name="content" value="page.content" />
+<input type="text" name="labels" value="{% for label in page.labels %}{{ label.name }} {% endfor %}" />
+<input type="submit" value="Save"> 
+</form>

File dingeling/templates/label.html

+<h1>Pages labeled <em>{{ label.name }}</em></h1>
+
+<div id="page-list">
+<ul>
+{% for page in label.page_set.all %}
+<li><a href="/page/{{ page.name }}">{{ page.name }}</a></li>
+{% endfor %}
+</ul>
+</div>
+

File dingeling/templates/labels.html

+<h1>Labels</h1>
+
+<div id="meta-labels">
+<ul>
+{% for label in labels %}
+<li><a href="/label/{{ label.name }}">{{ label.name }}</a></li>
+{% endfor %}
+</ul>
+</div>
+

File dingeling/templates/lost.html

+<div id="lost">
+<h1>Ooops ...</h1>
+<p>{% if message %}{{ message }}{% else %}Nothing to see here.{% endif %}</p>
+<p>Go to <a href="/">main page</a>.</p>
+</div>

File dingeling/templates/main.html

+<div id="main">
+</div>

File dingeling/templates/page.html

+<div id="page">
+<h1>{{ page.name }}</h1>
+
+<div id="summary">
+<strong>{{ page.summary }}</strong>
+</div>
+
+<div id=labels>
+<ul>
+{% for label in page.labels.all %}
+<li>{{ label.name }}</li>
+{% endfor %}
+</ul>
+</div>
+
+<div id="content">
+</div>
+</div>

File dingeling/templates/pages.html

+<div id="meta-pages">
+<h1>Pages</h1>
+
+<ul>
+{% for page in pages %}
+<li><a href="/page/{{ page.name }}">{{ page.name }}</a></li>
+{% endfor %}
+</ul>
+</div>
+<div>

File dingeling/urls.py

 from django.conf.urls.defaults import *
 
-# Uncomment the next two lines to enable the admin:
-# from django.contrib import admin
-# admin.autodiscover()
+urlpatterns = patterns('dingeling.views',
 
-urlpatterns = patterns('',
-    # Example:
-    # (r'^dingeling/', include('dingeling.foo.urls')),
-
-    # Uncomment the admin/doc line below and add 'django.contrib.admindocs' 
-    # to INSTALLED_APPS to enable admin documentation:
-    # (r'^admin/doc/', include('django.contrib.admindocs.urls')),
-
-    # Uncomment the next line to enable the admin:
-    # (r'^admin/', include(admin.site.urls)),
+    (r'^$', 'main'),
+    (r'^labels$', 'labels'),
+    (r'^pages$', 'pages'),
+    (r'^files$', 'files'),
+    (r'^page/(?P<name>\w+)$', 'page'),
+    (r'^edit/(?P<name>\w+)$', 'edit'),
+    (r'^label/(?P<name>\w+)$', 'label'),
+    (r'^.*$', 'lost'),
+    
+    
 )

File dingeling/views.py

+import os.path
+import re
+
+from django.http import HttpResponse, HttpResponseRedirect
+from django.shortcuts import render_to_response
+from django.core.exceptions import ObjectDoesNotExist
+from django.core.urlresolvers import reverse
+
+from dingeling.settings import WIKIFILES
+from dingeling.models import Page, Label
+
+def main(request):
+    
+    return HttpResponse("Hello")
+
+def labels(request):
+    
+    labels = Label.objects.all()
+    
+    return render_to_response('labels.html', {'labels': labels})
+
+def pages(request):
+    
+    pages = Page.objects.all()
+    
+    return render_to_response('pages.html', {'pages': pages})
+
+def label(request, name):
+    
+    try:
+        label = Label.objects.get(name=name)
+    except ObjectDoesNotExist:
+        return render_to_response('lost.html', {'message': "No such label: %s." % name})
+    
+    return render_to_response('label.html', {'label': label})
+
+def files(request):
+    
+    return HttpResponse("files")
+
+def page(request, name):
+    
+    try:
+        page = Page.objects.get(name=name)
+    except ObjectDoesNotExist:
+        return HttpResponseRedirect(reverse('dingeling.views.edit', args=(name,)))
+
+    print name, type(name), repr(name)
+    
+    return render_to_response('page.html', {'page': page})
+
+def edit(request, name):
+
+    try:
+        page = Page.objects.get(name=name)
+    except ObjectDoesNotExist:
+        page = None
+    
+    if request.method == 'POST':
+        
+        summary = request.POST['summary']
+        
+        
+    return render_to_response('edit.html', {'page': page, 'name': name})
+
+def lost(request):
+    
+    return render_to_response('lost.html')
+