def test_object_to_json(self): """ Simple test, the actual serialization happens in json.dumps and we don't wanna test this core module in depth. """ obj = [] response = object_to_json_response(obj) self.assertEqual(response.status_code, 200) self.assertEqual(response.content, b"[]")
def test_object_to_json(self): """ Simple test, the actual serialization happens in json.dumps and we don't wanna test this core module in depth. """ obj = [] response = object_to_json_response(obj) self.assertEqual(response.status_code, 200) self.assertEqual(response.content, b"[]")
def dispatch(self, request, article, *args, **kwargs): max_num = 20 query = request.GET.get('query', None) matches = [] if query: matches = search.filter_persons(query) matches = [ "[{name}]({url})".format(name=m.first_name + ' ' + m.last_name, url=m.url) for m in matches[:max_num] ] return object_to_json_response(matches)
def render_to_response(self, context, **response_kwargs): revision = self.get_object() other_revision = revision.previous_revision baseText = other_revision.content if other_revision is not None else "" newText = revision.content differ = difflib.Differ(charjunk=difflib.IS_CHARACTER_JUNK) diff = differ.compare( baseText.splitlines(keepends=True), newText.splitlines(keepends=True) ) other_changes = [] if not other_revision or other_revision.title != revision.title: other_changes.append((_('New title'), revision.title)) return object_to_json_response( {'diff': list(diff), 'other_changes': other_changes} )
def render_to_response(self, context, **response_kwargs): revision = self.get_object() other_revision = revision.previous_revision baseText = other_revision.content if other_revision is not None else "" newText = revision.content differ = difflib.Differ(charjunk=difflib.IS_CHARACTER_JUNK) diff = differ.compare(baseText.splitlines(keepends=True), newText.splitlines(keepends=True)) other_changes = [] if not other_revision or other_revision.title != revision.title: other_changes.append((_('New title'), revision.title)) return object_to_json_response({ 'diff': list(diff), 'other_changes': other_changes })
def diff(request, revision_id, other_revision_id=None): revision = get_object_or_404(models.ArticleRevision, id=revision_id) if not other_revision_id: other_revision = revision.previous_revision baseText = other_revision.content if other_revision else "" newText = revision.content differ = difflib.Differ(charjunk=difflib.IS_CHARACTER_JUNK) diff = differ.compare(baseText.splitlines(1), newText.splitlines(1)) other_changes = [] if not other_revision or other_revision.title != revision.title: other_changes.append((_('New title'), revision.title)) return object_to_json_response( dict(diff=list(diff), other_changes=other_changes))
def dispatch(self, request, article, *args, **kwargs): max_num = kwargs.pop('max_num', 20) query = request.GET.get('query', None) matches = [] if query: matches = models.URLPath.objects.can_read( request.user).active().filter( article__current_revision__title__contains=query, article__current_revision__deleted=False, ) matches = matches.select_related_common() matches = [ "[{title:s}](wiki:{url:s})".format( title=m.article.current_revision.title, url='/' + m.path.strip("/")) for m in matches[:max_num] ] return object_to_json_response(matches)
def diff(request, revision_id, other_revision_id=None): revision = get_object_or_404(models.ArticleRevision, id=revision_id) if not other_revision_id: other_revision = revision.previous_revision baseText = other_revision.content if other_revision else "" newText = revision.content differ = difflib.Differ(charjunk=difflib.IS_CHARACTER_JUNK) diff = differ.compare(baseText.splitlines(1), newText.splitlines(1)) other_changes = [] if not other_revision or other_revision.title != revision.title: other_changes.append((_('New title'), revision.title)) return object_to_json_response( dict(diff=list(diff), other_changes=other_changes) )
def dispatch(self, request, article, *args, **kwargs): max_num = kwargs.pop('max_num', 20) query = request.GET.get('query', None) matches = [] if query: matches = models.URLPath.objects.can_read( request.user).active().filter( article__current_revision__title__contains=query, article__current_revision__deleted=False, ) matches = matches.select_related_common() matches = [ "[{title:s}](wiki:{url:s})".format( title=m.article.current_revision.title, url='/' + m.path.strip("/") ) for m in matches[:max_num] ] return object_to_json_response(matches)
def dispatch(self, request, article, *args, **kwargs): max_num = kwargs.pop('max_num', 20) # TODO: Move this import when circularity issue is resolved # https://github.com/django-wiki/django-wiki/issues/23 query = request.GET.get('query', None) matches = [] if query: matches = models.URLPath.objects.can_read( request.user).active().filter( article__current_revision__title__contains=query, article__current_revision__deleted=False, ) matches = matches.select_related_common() matches = [ "[{title:s}](wiki:{url:s})".format( title=m.article.current_revision.title, url='/' + m.path.strip("/")) for m in matches[:max_num] ] return object_to_json_response(matches)
def dispatch(self, request, article, *args, **kwargs): max_num = kwargs.pop('max_num', 20) # TODO: Move this import when circularity issue is resolved # https://github.com/django-wiki/django-wiki/issues/23 query = request.GET.get('query', None) matches = [] if query: matches = models.URLPath.objects.can_read( request.user).active().filter( article__current_revision__title__contains=query, article__current_revision__deleted=False, ) matches = matches.select_related_common() matches = [ "[{title:s}](wiki:{url:s})".format( title=m.article.current_revision.title, url='/' + m.path.strip("/") ) for m in matches[:max_num] ] return object_to_json_response(matches)