Commits

Oben Sonne committed 62e3ade

Edit, delete, main page, templates

Comments (0)

Files changed (11)

dingeling/models.py

     summary = models.CharField(max_length=200)
     content = models.TextField()
     labels = models.ManyToManyField(Label)
+    links = models.ManyToManyField("self", symmetrical=True)
+    modified = models.DateTimeField("last modified", auto_now=True)
 
-    
+    def friends(self):
+        friends = []
+        for other in Page.objects.all():
+            if other != self:
+                for label in self.labels.all():
+                    if label in other.labels.all():
+                        friends.append(other)
+                        break
+        print "friends:", friends
+        return friends
+    
+    def referrers(self):
+        
+        referrers = []
+        for other in Page.objects.all():
+            if self in other.links.all():
+                referrers.append(other)
+        return referrers
+        

dingeling/templates/base.html

+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<title>Dingeling</title>
+</head>
+<body>
+<div id="wrap">
+<div id="header">
+<ul>
+<li><a href="/pages">Pages</a></li>
+<li><a href="/changes">Changes</a></li>
+<li><a href="/labels">Labels</a></li>
+<li><a href="/files">Files</a></li>
+</ul>
+<h1>{% block title %}{% endblock %}</h1>
+</div>
+<div id="content">
+{% block content %}{% endblock %}
+</div>
+<div id="footer">
+Footer
+</div>
+</div> <!-- wrap -->
+</body>
+</html>

dingeling/templates/changes.html

+{% extends "base.html" %}
+
+{% block title %}Changes{% endblock %}
+
+{% block content %}
+<div id="changes">
+<ul>
+{% for page in pages %}
+<li>
+  <a href="/page/{{ page.name }}">{{ page.name }}</a>
+  <span class="change-age">- {{ page.modified|timesince }} ago</span>
+</li>
+{% endfor %}
+</ul>
+</div>
+{% endblock %}
+

dingeling/templates/delete.html

+{% extends "base.html" %}
+
+{% block title %}Deleting page {{ page.name }}{% endblock %}
+
+{% block content %}
+<div id="delete">
+<form action="/delete/{{ page.name }}" method="POST">
+<p>
+  Sorry, I don't want to get in your way. I just want to make sure you know
+  what you are doing.
+</p>
+<p>
+  <input type="submit" value="Delete page {{ page.name }}">
+</p>
+<p>
+  Er, <a href="/page/{{ page.name }}">no thanks.</a>
+</p>
+</form>
+</div>
+{% endblock %}
+   

dingeling/templates/edit.html

+{% extends "base.html" %}
+
+{% block title %}{% if page %}Editing{% else %}Creating{% endif %} page {{ name }}{% endblock %}
+
+{% block content %}
 <div id="edit">
-<h1>{{ name }}</h1>
-
-{% if not page %}
-<div id="new-page-note">
-<p>This page does not yet exist.</p>
+<form action="/edit/{{ name }}" method="POST">
+<p>
+  <label for="id-summary">Summary</label><br />
+  <input id="id-summary" type="text" name="summary" size="80"
+    value="{{ page.summary }}" />
+</p>
+<p>
+  <label for="id-content">Content</label><br />
+  <textarea id="id-content" rows="30" cols="80" name="content">{{ page.content }}</textarea>
+</p>
+<p>
+  <label for="id-labels">Labels <span class="known-labels">(Known: {% for label in labels %}<a href="/label/{{ label }}">{{ label }}</a>{% if not forloop.last %} &middot; {% endif %}{% endfor %})</span></label><br />
+  <input id="id-labels" type="text" name="labels" size="80"
+	value="{% for label in page.labels.all %}{{ label.name }} {% endfor %}" />
+</p>
+<p>
+  <input type="submit" value="Save">
+</p>
+</form>
 </div>
-{% endif %}
-
-<form action="/edit/{{ name }}" method="POST">
-<p><label for="id-summary">Summary</label><br />
-<input id="id-summary" type="text" name="summary" size="80"
-	value="{{ page.summary }}" /></p>
-<p><label for="id-content">Content</label><br />
-<textarea id="id-content" rows="30" cols="80" name="content">{{ page.content }}</textarea></p>
-<p><label for="id-labels">Labels</label><br />
-<input id="id-labels" type="text" name="labels" size="80"
-	value="{% for label in page.labels.all %}{{ label.name }} {% endfor %}" /></p>
-<p><input type="submit" value="Save"></p>
-</form>
+{% endblock %}

dingeling/templates/labels.html

-<h1>Labels</h1>
+{% extends "base.html" %}
 
-<div id="meta-labels">
+{% block title %}Labels{% endblock %}
+
+{% block content %}
+<div id="labels">
 <ul>
 {% for label in labels %}
 <li><a href="/label/{{ label.name }}">{{ label.name }}</a></li>
 {% endfor %}
 </ul>
 </div>
-
+{% endblock %}

dingeling/templates/main.html

+{% extends "base.html" %}
+
+
+{% block title %}Wiki{% endblock %}
 <div id="main">
+
+<div class="main-pages">
+<h2>Main pages</h2>
+<ul>
+	{% for page in mpages %}
+	<li><a href="/page/{{ page.name }}">{{ page.name }}</a></li>
+	{% endfor %}
+</ul>
+</div>
+
+<div class="recent-pages">
+<h2>Last changed pages</h2>
+<ul>
+	{% for page in rpages %}
+	<li><a href="/page/{{ page.name }}">{{ page.name }}</a> <span
+		class="change-age">- {{ page.modified|timesince }} ago</span></li>
+	{% endfor %}
+</ul>
+</div>
+
 </div>

dingeling/templates/page.html

+{% extends "base.html" %}
+
+{% block title %}{{ page.name }}{% endblock %}
+
+
+{% block content %}
 <div id="page">
-<h1>{{ page.name }}</h1>
 
-<div id="summary">
+<div class="summary">
 <strong>{{ page.summary }}</strong>
 </div>
 
-<div id=labels>
+<div class="content">
+{{ page.content }}
+</div>
+
+<div class=labels>
 <ul>
 {% for label in page.labels.all %}
-<li>{{ label.name }}</li>
+<li><a href="/label/{{ label.name }}">{{ label.name }}</a></li>
 {% endfor %}
 </ul>
 </div>
 
-<div id="content">
-{{ page.content }}
+<div class="friends">
+<p>Friends:</p>
+<ul>
+{% for friend in page.friends %}
+<li><a href="/page/{{ friend.name }}">{{ friend.name }}</a></li>
+{% endfor %}
+</ul>
 </div>
 
+<div class="referrers">
+<p>Referrers:</p>
+<ul>
+{% for ref in page.referrers %}
+<li><a href="/page/{{ ref.name }}">{{ ref.name }}</a></li>
+{% endfor %}
+</ul>
+</div>
+
+<div class="edit">
 <a href="/edit/{{ page.name }}">Edit</a>
-
-</div>
+<a href="/delete/{{ page.name }}">Delete</a>
+</div>
+</div>
+{% endblock %}

dingeling/templates/pages.html

-<div id="meta-pages">
-<h1>Pages</h1>
+{% extends "base.html" %}
 
+{% block title %}Pages{% endblock %}
+
+{% block content %}
+<div id="all-pages">
 <ul>
 {% for page in pages %}
 <li><a href="/page/{{ page.name }}">{{ page.name }}</a></li>
 {% endfor %}
 </ul>
-</div>
-<div>
+<div>
+{% endblock %}

dingeling/urls.py

     (r'^$', 'main'),
     (r'^labels$', 'labels'),
     (r'^pages$', 'pages'),
+    (r'^changes$', 'changes'),
     (r'^files$', 'files'),
     (r'^page/(?P<name>\w+)$', 'page'),
     (r'^edit/(?P<name>\w+)$', 'edit'),
-    (r'^label/(?P<name>\w+)$', 'label'),
+    (r'^delete/(?P<name>\w+)$', 'delete'),
+    (r'^label/(?P<name>[\w-]+)$', 'label'),
     (r'^.*$', 'lost'),
     
     

dingeling/views.py

+import datetime
 import os.path
 import re
 
 
 def main(request):
     
-    return HttpResponse("Hello")
+    mpages = [p for p in Page.objects.all() if p.labels.filter(name="main")]
+    
+    rcmp = lambda a,b: cmp(a.modified, b.modified)
+    rpages = sorted(Page.objects.all(), cmp=rcmp, reverse=True)[:10]
+    
+    return render_to_response('main.html', {'mpages': mpages, 'rpages': rpages})
 
 def labels(request):
     
     
     return render_to_response('label.html', {'label': label})
 
+def changes(request):
+    
+    lcmp = lambda a,b: cmp(a.modified, b.modified)
+    pages = sorted(Page.objects.all(), cmp=lcmp, reverse=True)
+    
+    return render_to_response('changes.html', {'pages': pages})
+
 def files(request):
     
     return HttpResponse("files")
     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):
         page = None
     
     if request.method == 'POST':
-        
+        print request.POST
         page = page or Page.objects.create(name=name)
         page.summary = request.POST['summary']
         page.content = request.POST['content']
             print lname
             label = Label.objects.get_or_create(name=lname)[0]
             page.labels.add(label)
+        page.modified = datetime.datetime.now()
         page.save()
         return HttpResponseRedirect(reverse('dingeling.views.page', args=(name,)))
-        
-    return render_to_response('edit.html', {'page': page, 'name': name})
+    
+    labels = [l.name for l in Label.objects.all()]
+    
+    return render_to_response('edit.html', {'page': page, 'name': name, 'labels': labels})
+
+def delete(request, name):
+
+    try:
+        page = Page.objects.get(name=name)
+    except ObjectDoesNotExist:
+        return render_to_response('lost.html', {'message': "No such page: %s." % name})
+    
+    if request.method == 'POST':
+        page.delete()
+        #page.save()
+        print "going to", reverse('dingeling.views.main')
+        return HttpResponseRedirect(reverse('dingeling.views.main'))
+
+    return render_to_response('delete.html', {'page': page})
 
 def lost(request):