from django import forms
-from wiki.models import Document, storage
+from wiki.models import Document, getstorage
class DocumentForm(forms.Form):
self.fields['name'].initial = document.name
self.fields['text'].initial = document.text
self.fields['revision'].initial = document.revision()
-
- def get_storage(self):
- return storage
def save(self, document_author = 'anonymous'):
- document = Document(self.get_storage(), name=self.cleaned_data['name'], text=self.cleaned_data['text'])
+ storage = getstorage()
+
+ document = Document(storage, name=self.cleaned_data['name'], text=self.cleaned_data['text'])
storage.put(document,
author = document_author,
from django.http import HttpResponse, Http404
from django.utils import simplejson as json
-from wiki.models import storage, Document, DocumentNotFound
+from wiki.models import Document, DocumentNotFound, getstorage
from wiki.forms import DocumentForm
from datetime import datetime
from django.utils.encoding import smart_unicode
def document_list(request, template_name = 'wiki/document_list.html'):
# TODO: find a way to cache "Storage All"
return direct_to_template(request, template_name, extra_context = {
- 'document_list': storage.all(),
+ 'document_list': getstorage().all(),
'last_docs': sorted(request.session.get("wiki_last_docs", {}).items(),
key=operator.itemgetter(1), reverse = True)
})
def document_detail(request, name, template_name = 'wiki/document_details.html'):
print "Trying to get", repr(name)
try:
- document = storage.get(name)
+ document = getstorage().get(name)
except DocumentNotFound:
raise Http404
raise Http404
@never_cache
-def document_diff(request, name, revA, revB):
+def document_diff(request, name, revA, revB):
+ storage = getstorage()
docA = storage.get(name, int(revA))
docB = storage.get(name, int(revB))
@never_cache
def document_history(request, name):
+ storage = getstorage()
+
return HttpResponse(
json.dumps(storage.history(name), cls=DateTimeEncoder),
mimetype='application/json')
@never_cache
def document_publish(request, name, version):
+ storage = getstorage()
+
# get the document
try:
document = storage.get(name, revision = int(version))