Skip to content

Commit

Permalink
[bug 758783] /kb/new?title=foo should prepopulate the title (and slug…
Browse files Browse the repository at this point in the history
…) field
  • Loading branch information
tobbi authored and rlr committed Jun 27, 2012
1 parent b19bf19 commit 7f916a2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
8 changes: 8 additions & 0 deletions apps/wiki/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import re

from django import forms
from django.template.defaultfilters import slugify
from django.utils.encoding import smart_str
from django.utils.safestring import mark_safe

Expand Down Expand Up @@ -51,9 +52,16 @@ def __init__(self, *args, **kwargs):
# Quasi-kwargs:
can_create_tags = kwargs.pop('can_create_tags', False)
can_archive = kwargs.pop('can_archive', False)
initial_title = kwargs.pop('initial_title', '')

super(DocumentForm, self).__init__(*args, **kwargs)

title_field = self.fields['title']
title_field.initial = initial_title

slug_field = self.fields['slug']
slug_field.initial = slugify(initial_title)

# Set up tags field, which is instantiated deep within taggit:
tags_field = self.fields['tags']
tags_field.widget.can_create_tags = can_create_tags
Expand Down
3 changes: 2 additions & 1 deletion apps/wiki/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ def new_document(request):
"""Create a new wiki document."""
if request.method == 'GET':
doc_form = DocumentForm(
can_create_tags=request.user.has_perm('taggit.add_tag'))
can_create_tags=request.user.has_perm('taggit.add_tag'),
initial_title=request.GET.get('title'))
rev_form = RevisionForm()
return jingo.render(request, 'wiki/new_document.html',
{'document_form': doc_form,
Expand Down

0 comments on commit 7f916a2

Please sign in to comment.