コード例 #1
0
def preview(request):
    # TODO: POST method!
    text = request.GET['text']

    if len(text) > MAX_LENGTH:
        return HttpResponseBadRequest('Message too long.')

    return convert_to_html(text)
コード例 #2
0
    def render(self, quote=False):
        if self.html is None:
            from mathcontent.utils import convert_to_html
            print 'CONVERTING %d...' % self.id
            self.html = convert_to_html(self.text, self)
            self.no_html_reset = True
            self.save()
            print 'DONE!'

        return render_to_string('inc_mathcontent_render.html', {
            'content': self,
            # TODO: make a template tag
            # 'view_source': request.user.is_authenticated(),
            'view_source': True,
            'quote': quote,
        })
コード例 #3
0
ファイル: task_tags.py プロジェクト: ikicic/skoljka
def task_bulk_preview_single(task_info):
    """Renders a single task preview, given TaskInfo instance."""

    permissions = []
    for perm_id, groups in task_info.template_data["permissions"].iteritems():
        task_groups = mark_safe(", ".join([grouplink(x) for x in groups]))
        permissions.append((PERMISSION_NAMES[perm_id].upper(), task_groups))

    return {
        "content": mark_safe(convert_to_html(task_info.json["_content"])),
        "difficulty": task_info.json["_difficulty"],
        "folder": task_info.template_data["folder"],
        "folder_position": task_info.json["_folder_position"],
        "json": task_info.json,
        "permissions": permissions,
        "tags": tag_list_preview(task_info.json["_tags"]),
        "template_data": task_info.template_data,
    }
コード例 #4
0
ファイル: mathcontent_tags.py プロジェクト: ikicic/skoljka
def mathcontent_render(content, quote=False):
    if content.html is None:
        try:
            content.html = convert_to_html(content.text, content=content)
        except Exception:
            if getattr(settings, 'MATHCONTENT_DEBUG', False):
                raise
            # Leave content.html as None. If None, template will notify the
            # user about the error. No error details are provided.
            pass
        else:
            content._no_html_reset = True
            content.save()

    return {
        'content': content,
        # 'view_source': request.user.is_authenticated(),
        'view_source': True,
        'quote': quote,
    }