Commit b032b613 by benjaoming

Merge branch 'master' of github.com:benjaoming/django-wiki

parents 38dc640d 8c453359
...@@ -261,6 +261,8 @@ class CreateForm(forms.Form, SpamProtectionMixin): ...@@ -261,6 +261,8 @@ class CreateForm(forms.Form, SpamProtectionMixin):
if settings.URL_CASE_SENSITIVE: if settings.URL_CASE_SENSITIVE:
already_existing_slug = models.URLPath.objects.filter(slug=slug, parent=self.urlpath_parent) already_existing_slug = models.URLPath.objects.filter(slug=slug, parent=self.urlpath_parent)
else: else:
slug = slug.lower()
slug = slug.replace('-', '_')
already_existing_slug = models.URLPath.objects.filter(slug__iexact=slug, parent=self.urlpath_parent) already_existing_slug = models.URLPath.objects.filter(slug__iexact=slug, parent=self.urlpath_parent)
if already_existing_slug: if already_existing_slug:
already_urlpath = already_existing_slug[0] already_urlpath = already_existing_slug[0]
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
// if downcode doesn't hit, the char will be stripped here // if downcode doesn't hit, the char will be stripped here
s = s.replace(/[^-\w\s]/g, ''); // remove unneeded chars s = s.replace(/[^-\w\s]/g, ''); // remove unneeded chars
s = s.replace(/^\s+|\s+$/g, ''); // trim leading/trailing spaces 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 s = s.toLowerCase(); // convert to lowercase
return s.substring(0, num_chars);// trim to first num_chars chars return s.substring(0, num_chars);// trim to first num_chars chars
} }
...@@ -30,10 +30,7 @@ ...@@ -30,10 +30,7 @@
var e = $("#id_slug")[0]; var e = $("#id_slug")[0];
if(!e._changed) { if(!e._changed) {
slug = URLify(this.value, 50); slug = URLify(this.value, 50);
wikislug = slug.replace(/\-/g, " "); e.value = slug;
wikislug = wikislug.replace(/\w\S*/gi, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1);});
wikislug = wikislug.replace(/\s*/g, "");
e.value = wikislug;
} }
}); });
}); });
......
...@@ -62,7 +62,15 @@ class Create(FormView, ArticleMixin): ...@@ -62,7 +62,15 @@ class Create(FormView, ArticleMixin):
initial['slug'] = self.request.GET.get('slug', None) initial['slug'] = self.request.GET.get('slug', None)
kwargs['initial'] = initial kwargs['initial'] = initial
form = form_class(self.request, self.urlpath, **kwargs) 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 return form
def form_valid(self, form): def form_valid(self, form):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment