If you are interested, here is a simple Wiki I threw together a few
weeks ago that allows html markup. I am still somewhat of an amateur,
so there are probably a thousand better ways to do this, but feel free
to use it as an example.

URLs

urlpatterns += patterns('project.wiki.views',
     (r'^wiki/create/$', 'create'),
     (r'^wiki/update/(?P<wikipage>\w+)/$', 'update'),
     (r'^wiki/$', 'wikipage', {'wikipage': "main"}),
     (r'^wiki/(?P<wikipage>\w+)/$', 'wikipage'),
)

Models

class Wikipage(models.Model):
    title = models.SlugField(primary_key=True)
    creator = models.CharField(maxlength=25, editable=False)
    post_date = models.DateTimeField(auto_now_add=True)
    class Admin:
        list_display = ('title', 'creator', 'post_date')
    def __unicode__(self):
        return self.title

class Pageversion(models.Model):
    page = models.ForeignKey(Wikipage, edit_inline=models.TABULAR,
num_in_admin=1)
    content = models.TextField(core=True)
    editor = models.CharField(maxlength=25, editable=False)
    update_date = models.DateTimeField(default=datetime.datetime.now,
editable=False)


Views

def wikipage(req, wikipage):
    pages=Wikipage.objects.all()
    page=Wikipage.objects.get(title=wikipage)
    versions=Pageversion.objects.filter(page=wikipage)
    version=versions.latest('update_date')
    return render_to_response('wiki/wiki_page.html', {'pages': pages,
'page': page, 'version': version})

<h2 class="title">{{page.title|title}}</h2>
        <p>{{version.content|safe}}</p>
        <p>[ <a href="/wiki/update/{{page.title}}/">Update This Page</a> ]
        [ <a href="/wiki/create/">Create New Page</a> ]
        [ <select onChange="DropDownMenu(this)">
                <option selected>Go To Page</option>
                {% for page in pages %}
                        <option 
value="/wiki/{{page.title|escape}}/">{{page.title|escape}}</
option>
                {% endfor %}
        </select> ]</p>

def create(req):
    pages=Wikipage.objects.all()
    pages=Wikipage.objects.all()
    if req.POST.has_key('title') and req.POST.has_key('content'):
        p=Wikipage(title=req.POST['title'],
creator=req.POST['creator'])
        p.save()
        v=Pageversion(page_id=req.POST['title'],
content=req.POST['content'], editor=req.POST['creator'])
        v.save()
        page=req.POST['title']
        address="/wiki/"+page
        return HttpResponseRedirect(address)
    return render_to_response('wiki/create_page.html', {'pages':
pages})

<h2 class="title">Create a New Page</h2>
        <form action="" method="POST" onsubmit="return validate_form(this)">
                <input type="hidden" name="creator" value="{{ reader }}">
                <p><input type="text" name="title"></p>
                <p><textarea name="content" cols=85 rows=60></textarea><input
type="submit" value="Submit"></p>
        </form>

def update(req, wikipage):
    page=Wikipage.objects.get(title=wikipage)
    versions=Pageversion.objects.filter(page=wikipage)
    version=versions.latest('update_date')
    if req.POST.has_key('content'):
        v=Pageversion(page_id=req.POST['title'],
content=req.POST['content'], editor=req.POST['creator'])
        v.save()
        page=req.POST['title']
        address="/wiki/"+page
        return HttpResponseRedirect(address)
    return render_to_response('wiki/update_page.html', {'page': page,
'version': version})

<h2 class="title">Update Page Content</h2>
        <form action="" method="POST">
                <input type="hidden" name="creator" value="{{ reader }}">
                <input type="hidden" name="title" value="{{ page.title }}">
                <h4>{{ page.title|title }}</h4>
                <p><textarea name="content" cols=85 
rows=60>{{version.content}}</
textarea></p>
                <p><input type="submit" value="Submit"></p>
        </form>


On Nov 27, 7:27 pm, walterbyrd <[EMAIL PROTECTED]> wrote:
> I like wikis for quickly editing and organizing documents online. I
> hate everything else about wikis - especially markup languages that
> are not compatible with anything else.
>
> Would it be difficult to develop a django app that could edit an
> online document, or a part of that document, and easily create and
> organize new docuemnts?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to