check for errors in JS and stop form changing the slug (bug 625779)
This commit is contained in:
Родитель
4f480baa06
Коммит
4e448a9fd5
|
@ -50,6 +50,10 @@ class AddonFormBasic(AddonFormBase):
|
|||
max_length=250)
|
||||
tags = forms.CharField(required=False)
|
||||
|
||||
class Meta:
|
||||
model = Addon
|
||||
fields = ('name', 'slug', 'summary', 'tags')
|
||||
|
||||
def __init__(self, *args, **kw):
|
||||
super(AddonFormBasic, self).__init__(*args, **kw)
|
||||
self.fields['tags'].initial = ', '.join(tag.tag_text for tag in
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
{% from "devhub/includes/macros.html" import tip, empty_unless, select_cats, trans_readonly %}
|
||||
|
||||
<form method="post" action="{{ url('devhub.addons.section', addon.slug, 'basic', 'edit') }}"
|
||||
id="addon-edit-basic" data-baseurl="{{ url('devhub.addons.edit', addon.slug) }}">
|
||||
<form method="post" action="{{ url('devhub.addons.section', valid_slug, 'basic', 'edit') }}"
|
||||
id="addon-edit-basic" data-baseurl="{{ url('devhub.addons.edit', valid_slug) }}">
|
||||
<h3>
|
||||
{{ _('Basic Information') }}
|
||||
{% if not editable %}
|
||||
<a href="#" data-editurl="{{ url('devhub.addons.section', addon.slug, 'basic', 'edit') }}" class="button">
|
||||
<a href="#" data-editurl="{{ url('devhub.addons.section', valid_slug, 'basic', 'edit') }}" class="button">
|
||||
{{ _('Edit') }}</a>
|
||||
{% endif %}
|
||||
</h3>
|
||||
|
|
|
@ -1057,6 +1057,20 @@ class TestEdit(test_utils.TestCase):
|
|||
|
||||
eq_([unicode(t) for t in addon.tags.all()], sorted(self.tags))
|
||||
|
||||
def test_edit_slug_invalid(self):
|
||||
old_edit = self.get_url('basic', True)
|
||||
data = self.get_dict(name='', slug='invalid')
|
||||
r = self.client.post(self.get_url('basic', True), data)
|
||||
doc = pq(r.content)
|
||||
eq_(doc('form').attr('action'), old_edit)
|
||||
|
||||
def test_edit_slug_valid(self):
|
||||
old_edit = self.get_url('basic', True)
|
||||
data = self.get_dict(slug='valid')
|
||||
r = self.client.post(self.get_url('basic', True), data)
|
||||
doc = pq(r.content)
|
||||
assert doc('form').attr('action') != old_edit
|
||||
|
||||
def test_edit_summary_escaping(self):
|
||||
data = self.get_dict()
|
||||
data['summary'] = '<b>oh my</b>'
|
||||
|
|
|
@ -246,6 +246,7 @@ def edit(request, addon_id, addon):
|
|||
data = {
|
||||
'page': 'edit',
|
||||
'addon': addon,
|
||||
'valid_slug': addon.slug,
|
||||
'tags': addon.tags.not_blacklisted().values_list('tag_text', flat=True),
|
||||
'previews': addon.previews.all()}
|
||||
|
||||
|
@ -574,6 +575,8 @@ def addons_section(request, addon_id, addon, section, editable=False):
|
|||
previews = forms.PreviewFormSet(request.POST or None,
|
||||
prefix='files', queryset=addon.previews.all())
|
||||
|
||||
# Get the slug before the form alters it to the form data.
|
||||
valid_slug = addon.slug
|
||||
if editable:
|
||||
if request.method == 'POST':
|
||||
form = models[section](request.POST, request.FILES,
|
||||
|
@ -594,6 +597,8 @@ def addons_section(request, addon_id, addon, section, editable=False):
|
|||
|
||||
if cat_form:
|
||||
cat_form.save()
|
||||
|
||||
valid_slug = addon.slug
|
||||
else:
|
||||
form = models[section](instance=addon, request=request)
|
||||
else:
|
||||
|
@ -604,7 +609,8 @@ def addons_section(request, addon_id, addon, section, editable=False):
|
|||
'editable': editable,
|
||||
'tags': tags,
|
||||
'cat_form': cat_form,
|
||||
'preview_form': previews}
|
||||
'preview_form': previews,
|
||||
'valid_slug': valid_slug,}
|
||||
|
||||
return jingo.render(request,
|
||||
'devhub/includes/addon_edit_%s.html' % section, data)
|
||||
|
|
|
@ -232,7 +232,7 @@ function addonFormSubmit() {
|
|||
$.post(parent_div.find('form').attr('action'),
|
||||
$(this).serialize(), function(d) {
|
||||
parent_div.html(d).each(addonFormSubmit);
|
||||
if (old_baseurl && old_baseurl !== baseurl()) {
|
||||
if (!parent_div.find(".errorlist").length && old_baseurl && old_baseurl !== baseurl()) {
|
||||
document.location = baseurl();
|
||||
}
|
||||
$(document).scrollTop($(document).height() - scrollBottom);
|
||||
|
|
Загрузка…
Ссылка в новой задаче