示例#1
0
from django.http import HttpResponseRedirect
from django.template import loader, RequestContext
from django.utils.encoding import force_text
from django.utils.html import escape
from django.utils.six.moves.urllib_parse import unquote

from fiber.app_settings import LOGIN_STRING, EXCLUDE_URLS, EDITOR, PERMISSION_CLASS
from fiber.models import ContentItem, Page
from fiber.utils.import_util import import_element, load_class

try:
    from django.utils.deprecation import MiddlewareMixin
except ImportError:
    MiddlewareMixin = object

perms = load_class(PERMISSION_CLASS)


def is_html(response):
    """
    Returns True if the response is either `text/html` or `application/xhtml+xml`
    """
    content_type = response.get('Content-Type', None)
    return bool(content_type and content_type.split(';')[0]
                in ('text/html', 'application/xhtml+xml'))


class AdminPageMiddleware(MiddlewareMixin):
    LOGIN_SESSION_KEY = 'show_fiber_login'
    body_re = re.compile(
        r'<head>(?P<HEAD>.*)</head>(?P<AFTER_HEAD>.*)<body(?P<BODY_ATTRS>.*?)>(?P<BODY>.*)</body>',
示例#2
0
import json
import operator
from copy import copy

from django import template
from django.contrib.auth.models import AnonymousUser
from django.template import TemplateSyntaxError
from django.utils.html import escape

import fiber
from fiber.models import Page, ContentItem
from fiber.utils.urls import get_admin_change_url
from fiber.app_settings import PERMISSION_CLASS, AUTO_CREATE_CONTENT_ITEMS
from fiber.utils.import_util import load_class

PERMISSIONS = load_class(PERMISSION_CLASS)

register = template.Library()


class MenuHelper(object):
    """
    Helper class for show_menu tag, for convenience/clarity
    """
    def __init__(self,
                 context,
                 menu_name,
                 min_level=1,
                 max_level=999,
                 expand=None):
        self.context = copy(context)
示例#3
0
from django.template import loader, RequestContext
from django.utils.encoding import force_text
from django.utils.html import escape
from django.utils.six.moves.urllib_parse import unquote

from fiber.app_settings import LOGIN_STRING, EXCLUDE_URLS, EDITOR, PERMISSION_CLASS
from fiber.models import ContentItem, Page
from fiber.utils.import_util import import_element, load_class

try:
    from django.utils.deprecation import MiddlewareMixin
except ImportError:
    MiddlewareMixin = object


perms = load_class(PERMISSION_CLASS)


def is_html(response):
    """
    Returns True if the response is either `text/html` or `application/xhtml+xml`
    """
    content_type = response.get('Content-Type', None)
    return bool(content_type and content_type.split(';')[0] in ('text/html', 'application/xhtml+xml'))


class AdminPageMiddleware(MiddlewareMixin):
    LOGIN_SESSION_KEY = 'show_fiber_login'
    body_re = re.compile(
        r'<head>(?P<HEAD>.*)</head>(?P<AFTER_HEAD>.*)<body(?P<BODY_ATTRS>.*?)>(?P<BODY>.*)</body>',
        re.DOTALL)
示例#4
0
from rest_framework import generics
from rest_framework import renderers
from rest_framework.decorators import api_view, renderer_classes, permission_classes
from rest_framework.response import Response
from rest_framework.reverse import reverse
from rest_framework import views
from rest_framework import status
from rest_framework import permissions

from fiber.models import Page, PageContentItem, ContentItem, File, Image
from fiber.app_settings import API_RENDER_HTML, PERMISSION_CLASS
from fiber.utils.import_util import load_class

from .serializers import PageSerializer, MovePageSerializer, PageContentItemSerializer, MovePageContentItemSerializer, ContentItemSerializer, FileSerializer, ImageSerializer, FiberPaginationSerializer

PERMISSIONS = load_class(PERMISSION_CLASS)

API_RENDERERS = (renderers.JSONRenderer, )
if API_RENDER_HTML:
    API_RENDERERS = (renderers.BrowsableAPIRenderer, renderers.JSONRenderer)

_403_FORBIDDEN_RESPONSE = Response(
    {
    'detail': 'You do not have permission to access this resource. ' +
    'You may need to login or otherwise authenticate the request.'
    },
    status.HTTP_403_FORBIDDEN)


class PlainText(renderers.BaseRenderer):
    media_type = 'text/plain'
 def test_load_class_with_kwargs(self):
     """Import and instantiate TestClass by name with kwargs"""
     path = '.'.join([self.__module__, 'TestClass'])
     instance = load_class(path, foo='bar')
     self.assertEqual(instance.foo, 'bar')
 def test_load_class(self):
     """Import and instantiate TestClass by name"""
     path = '.'.join([self.__module__, 'TestClass'])
     self.assertIsInstance(load_class(path), TestClass)
示例#7
0
 def test_load_class_with_kwargs(self):
     """Import and instantiate TestClass by name with kwargs"""
     path = '.'.join([self.__module__, 'TestClass'])
     instance = load_class(path, foo='bar')
     self.assertEqual(instance.foo, 'bar')
示例#8
0
 def test_load_class(self):
     """Import and instantiate TestClass by name"""
     path = '.'.join([self.__module__, 'TestClass'])
     self.assertIsInstance(load_class(path), TestClass)
示例#9
0
 def test_load_class_with_kwargs(self):
     """Import and instantiate TestClass by name with kwargs"""
     path = ".".join([self.__module__, "TestClass"])
     instance = load_class(path, foo="bar")
     self.assertEqual(instance.foo, "bar")