Skip to content

Commit

Permalink
Merge branch 'master' of github.com:benjaoming/django-wiki
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaoming committed May 17, 2014
2 parents 38dc640 + 8c45335 commit b032b61
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
2 changes: 2 additions & 0 deletions wiki/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ def clean_slug(self):
if settings.URL_CASE_SENSITIVE:
already_existing_slug = models.URLPath.objects.filter(slug=slug, parent=self.urlpath_parent)
else:
slug = slug.lower()
slug = slug.replace('-', '_')
already_existing_slug = models.URLPath.objects.filter(slug__iexact=slug, parent=self.urlpath_parent)
if already_existing_slug:
already_urlpath = already_existing_slug[0]
Expand Down
7 changes: 2 additions & 5 deletions wiki/templates/wiki/create.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// if downcode doesn't hit, the char will be stripped here
s = s.replace(/[^-\w\s]/g, ''); // remove unneeded chars
s = s.replace(/^\s+|\s+$/g, ''); // trim leading/trailing spaces
s = s.replace(/[-\s]+/g, '-'); // convert spaces to hyphens
s = s.replace(/[-\s]+/g, '_'); // convert spaces and hyphens to underscores
s = s.toLowerCase(); // convert to lowercase
return s.substring(0, num_chars);// trim to first num_chars chars
}
Expand All @@ -30,10 +30,7 @@
var e = $("#id_slug")[0];
if(!e._changed) {
slug = URLify(this.value, 50);
wikislug = slug.replace(/\-/g, " ");
wikislug = wikislug.replace(/\w\S*/gi, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1);});
wikislug = wikislug.replace(/\s*/g, "");
e.value = wikislug;
e.value = slug;
}
});
});
Expand Down
10 changes: 9 additions & 1 deletion wiki/views/article.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,15 @@ def get_form(self, form_class):
initial['slug'] = self.request.GET.get('slug', None)
kwargs['initial'] = initial
form = form_class(self.request, self.urlpath, **kwargs)
form.fields['slug'].widget = forms.TextInputPrepend(prepend='/'+self.urlpath.path)
form.fields['slug'].widget = forms.TextInputPrepend(
prepend='/'+self.urlpath.path,
attrs={
# Make patterns force lowercase if we are case insensitive to bless the user with a
# bit of strictness, anyways
'pattern': '[a-z0-9_]+' if not settings.URL_CASE_SENSITIVE else '[a-zA-Z0-9_]+',
'title': 'Lowercase letters, numbers, and underscores' if not settings.URL_CASE_SENSITIVE else 'Letters, numbers, and underscores',
}
)
return form

def form_valid(self, form):
Expand Down

0 comments on commit b032b61

Please sign in to comment.