Skip to content

Commit

Permalink
allow save without change in the body. fix #85
Browse files Browse the repository at this point in the history
  • Loading branch information
mgaitan committed Apr 12, 2015
1 parent c922c3c commit eac598e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 22 deletions.
16 changes: 9 additions & 7 deletions tests/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,16 +179,18 @@ def test_commit_page_with_no_changes(self):

response = self.client.get(self.edit_url)
data = response.context[0]['form'].initial
data['title'] = 'new title'
data['raw'] = self.page.raw
data['message'] = 'testing :)'
response = self.client.post(self.edit_url, data)
self.assertEqual(response.status_code, 200)
self.assertFalse(response.context['form'].is_valid())
self.assertIn('raw', response.context['form'].errors)
self.assertContains(response, _('There were no changes in the page to commit.'))

self.assertEqual(self.page.raw, 'lala')
self.assertEqual(Git().version(self.page, 'HEAD'), 'lala')
self.assertRedirects(response, self.page.get_absolute_url())
page = Page.objects.get(id=self.page.id) # refresh
self.assertEqual(page.raw, 'lala') # same body
self.assertEqual(page.title, 'new title') # different title
response = self.client.get(reverse('waliki_history', args=(self.page.slug,)))
history = response.context[0].get('history')
self.assertEqual(len(history), 1)
self.assertEqual(history[0]['message'], u'previous commit')

def test_history_log(self):
self.page.raw = 'line\n' * 10
Expand Down
13 changes: 0 additions & 13 deletions waliki/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ def clean(self):
return cleaned_data





class NewPageForm(forms.ModelForm):

def __init__(self, *args, **kwargs):
Expand All @@ -60,13 +57,10 @@ def clean_slug(self):
if Page.objects.filter(slug=slug).exists():
raise forms.ValidationError(_("There is already a page with this slug"))



return slug




class PageForm(forms.ModelForm):
raw = forms.CharField(label="", widget=forms.Textarea)
# Translators: log message
Expand Down Expand Up @@ -98,13 +92,6 @@ def __init__(self, *args, **kwargs):
for field in self.fields.values():
field.widget = forms.HiddenInput()

def clean_raw(self):
if self.instance.raw == self.cleaned_data['raw']:
raise forms.ValidationError(
_('There were no changes in the page to commit.')
)
return self.cleaned_data['raw']

def save(self, commit=True):
instance = super(PageForm, self).save(commit)
if commit:
Expand Down
4 changes: 2 additions & 2 deletions waliki/git/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def commit(self, page, message='', author=None, parent=None, extra_path=None):
kwargs['i'] = True

git.add(path)
git_commit_cmd = git.commit.bake(allow_empty_message=True, m=message, **kwargs)
git_commit_cmd = git.commit.bake(allow_empty=True, allow_empty_message=True, m=message, **kwargs)
git_commit_cmd('--', *paths_to_commit)
last = self.last_version(page)
if parent and status != "UU":
Expand All @@ -65,7 +65,7 @@ def commit(self, page, message='', author=None, parent=None, extra_path=None):
error = e.stdout.decode('utf8')
if 'CONFLICT' in error:
# For '-i' attribute see http://stackoverflow.com/q/5827944/811740
git_commit_cmd = git.commit.bake(allow_empty_message=True, m=_('Merged with conflict'), i=True, **kwargs)
git_commit_cmd = git.commit.bake(allow_empty=True, allow_empty_message=True, m=_('Merged with conflict'), i=True, **kwargs)
git_commit_cmd('--', *paths_to_commit)
raise Page.EditionConflict(_('Automatic merge failed. Please, fix the conflict and save the page.'))
else:
Expand Down

0 comments on commit eac598e

Please sign in to comment.