Moved htmldiff function to utils.py. Fixed travis build error (pep8).
This commit is contained in:
parent
49765bbe6e
commit
3f4df58807
@ -544,12 +544,6 @@ class MotionVersion(models.Model):
|
|||||||
"""Return True, if the version is the active version of a motion. Else: False."""
|
"""Return True, if the version is the active version of a motion. Else: False."""
|
||||||
return self.active_version.exists()
|
return self.active_version.exists()
|
||||||
|
|
||||||
def make_htmldiff(self, rev1, rev2):
|
|
||||||
"""Return string of html diff between two strings (rev1 and rev2)"""
|
|
||||||
|
|
||||||
diff = difflib.HtmlDiff(wrapcolumn=60)
|
|
||||||
return diff.make_table(rev1.splitlines(), rev2.splitlines())
|
|
||||||
|
|
||||||
|
|
||||||
class MotionSubmitter(models.Model):
|
class MotionSubmitter(models.Model):
|
||||||
"""Save the submitter of a Motion."""
|
"""Save the submitter of a Motion."""
|
||||||
|
@ -25,7 +25,7 @@ from openslides.utils.views import (
|
|||||||
TemplateView, RedirectView, UpdateView, CreateView, DeleteView, PDFView,
|
TemplateView, RedirectView, UpdateView, CreateView, DeleteView, PDFView,
|
||||||
DetailView, ListView, FormView, QuestionMixin, SingleObjectMixin)
|
DetailView, ListView, FormView, QuestionMixin, SingleObjectMixin)
|
||||||
from openslides.utils.template import Tab
|
from openslides.utils.template import Tab
|
||||||
from openslides.utils.utils import html_strong
|
from openslides.utils.utils import html_strong, htmldiff
|
||||||
from openslides.poll.views import PollFormView
|
from openslides.poll.views import PollFormView
|
||||||
from openslides.projector.api import get_active_slide
|
from openslides.projector.api import get_active_slide
|
||||||
from openslides.projector.projector import Widget, SLIDE
|
from openslides.projector.projector import Widget, SLIDE
|
||||||
@ -264,8 +264,8 @@ class VersionDiffView(GetVersionMixin, DetailView):
|
|||||||
rev2 = int(self.request.GET['rev2'])
|
rev2 = int(self.request.GET['rev2'])
|
||||||
version_rev1 = self.object.version.motion.versions.get(version_number=self.request.GET['rev1'])
|
version_rev1 = self.object.version.motion.versions.get(version_number=self.request.GET['rev1'])
|
||||||
version_rev2 = self.object.version.motion.versions.get(version_number=self.request.GET['rev2'])
|
version_rev2 = self.object.version.motion.versions.get(version_number=self.request.GET['rev2'])
|
||||||
diff_text = self.object.version.make_htmldiff(version_rev1.text, version_rev2.text)
|
diff_text = htmldiff(version_rev1.text, version_rev2.text)
|
||||||
diff_reason = self.object.version.make_htmldiff(version_rev1.reason, version_rev2.reason)
|
diff_reason = htmldiff(version_rev1.reason, version_rev2.reason)
|
||||||
except (KeyError, ValueError, MotionVersion.DoesNotExist):
|
except (KeyError, ValueError, MotionVersion.DoesNotExist):
|
||||||
messages.error(self.request, _('At least one version number was not valid.'))
|
messages.error(self.request, _('At least one version number was not valid.'))
|
||||||
version_rev1 = None
|
version_rev1 = None
|
||||||
@ -274,10 +274,10 @@ class VersionDiffView(GetVersionMixin, DetailView):
|
|||||||
diff_reason = None
|
diff_reason = None
|
||||||
context = super(VersionDiffView, self).get_context_data(**kwargs)
|
context = super(VersionDiffView, self).get_context_data(**kwargs)
|
||||||
context.update({
|
context.update({
|
||||||
'version_rev1': version_rev1,
|
'version_rev1': version_rev1,
|
||||||
'version_rev2': version_rev2,
|
'version_rev2': version_rev2,
|
||||||
'diff_text': diff_text,
|
'diff_text': diff_text,
|
||||||
'diff_reason': diff_reason,
|
'diff_reason': diff_reason,
|
||||||
})
|
})
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
@ -154,3 +154,10 @@ def encodedict(dict):
|
|||||||
|
|
||||||
def html_strong(string):
|
def html_strong(string):
|
||||||
return u"<strong>%s</strong>" % string
|
return u"<strong>%s</strong>" % string
|
||||||
|
|
||||||
|
|
||||||
|
def htmldiff(self, rev1, rev2):
|
||||||
|
"""Return string of html diff between two strings (rev1 and rev2)"""
|
||||||
|
|
||||||
|
diff = difflib.HtmlDiff(wrapcolumn=60)
|
||||||
|
return diff.make_table(rev1.splitlines(), rev2.splitlines())
|
Loading…
Reference in New Issue
Block a user