コード例 #1
0
ファイル: views.py プロジェクト: adminus/banyan-web
def read_story(request, story_id=None, piece_id=None, slug=None):
    """
    Read Story

    Templates: :"banyan/inner.html"
    """
    template_name = "banyan/inner.html"

    res = StoryResource()
    request_bundle = res.build_bundle(request=request)

    try:
        storyObj = res.cached_obj_get(request_bundle,
                                      **{"bnObjectId": story_id})
        bundle = res.build_bundle(obj=storyObj, request=request)
        story_json = res.serialize(None,
                                   res.full_dehydrate(bundle, for_list=False),
                                   "application/json")
        story = json.loads(story_json)
    except:
        raise Http404
    ''' TO DO: Permission error seperately '''
    #     if story is None or story.get('read', False) is not True:
    #         return  render_to_response( "banyan/permission_error.html", context_instance = RequestContext( request ) )

    pieces = story.get('pieces', [])
    piece = None
    next_piece = None
    previous_piece = None
    if len(pieces):
        if piece_id is None:
            next_piece = pieces[0]
        else:
            piece_id = int(piece_id)
            # This is a piece view
            for index, piece in enumerate(pieces):
                if piece.get('bnObjectId') == piece_id:
                    if index > 0:
                        previous_piece = pieces[index - 1]
                    if index < len(pieces) - 1:
                        next_piece = pieces[index + 1]
                    break

    return render_to_response(template_name, {
        'story': story,
        'previous_piece': previous_piece,
        'piece': piece,
        'next_piece': next_piece,
    },
                              context_instance=RequestContext(request))
コード例 #2
0
ファイル: views.py プロジェクト: adminus/banyan-web
def read_story(request, story_id=None, piece_id=None, slug=None):
    """
    Read Story

    Templates: :"banyan/inner.html"
    """
    template_name = "banyan/inner.html"

    res = StoryResource()
    request_bundle = res.build_bundle(request=request)
    
    try:
        storyObj = res.cached_obj_get(request_bundle, **{"bnObjectId":story_id})
        bundle = res.build_bundle(obj=storyObj, request=request)
        story_json = res.serialize(None, res.full_dehydrate(bundle, for_list=False), "application/json")
        story = json.loads(story_json)
    except:
        raise Http404

    ''' TO DO: Permission error seperately '''
#     if story is None or story.get('read', False) is not True:
#         return  render_to_response( "banyan/permission_error.html", context_instance = RequestContext( request ) )

    pieces = story.get('pieces', [])
    piece = None
    next_piece = None
    previous_piece = None
    if len(pieces):
        if piece_id is None:
            next_piece = pieces[0]
        else:
            piece_id = int(piece_id)
            # This is a piece view
            for index, piece in enumerate(pieces):
                if piece.get('bnObjectId') == piece_id:
                    if index > 0:
                        previous_piece = pieces[index-1]
                    if index < len(pieces)-1:
                        next_piece = pieces[index + 1]
                    break
        
    return render_to_response(template_name,
        {'story': story, 'previous_piece':previous_piece, 'piece': piece, 'next_piece':next_piece,},
        context_instance=RequestContext(request))
コード例 #3
0
ファイル: views.py プロジェクト: adminus/banyan-web
def home(request):
    template_name = "banyan/index.html"
    res = StoryResource()
    request_bundle = res.build_bundle(request=request)
    queryset = res.cached_obj_get_list(request_bundle)
    bundles = []
    for obj in queryset.iterator():
        bundle = res.build_bundle(obj=obj, request=request)
        bundles.append(res.full_dehydrate(bundle, for_list=True))

    list_json = res.serialize(None, bundles, "application/json")
    list_json = json.loads(list_json)

    paginator = Paginator(list_json, settings.API_DEFAULT_ITEMS_PER_PAGE)
    page = request.GET.get('page')
    try:
        stories = paginator.page(page)
    except PageNotAnInteger:
        stories = paginator.page(1)
    except EmptyPage:
        stories = paginator.page(paginator.num_pages)

    return render_to_response( template_name, {'stories':stories},
                               context_instance = RequestContext( request ) )
コード例 #4
0
ファイル: views.py プロジェクト: adminus/banyan-web
def home(request):
    template_name = "banyan/index.html"
    res = StoryResource()
    request_bundle = res.build_bundle(request=request)
    queryset = res.cached_obj_get_list(request_bundle)
    bundles = []
    for obj in queryset.iterator():
        bundle = res.build_bundle(obj=obj, request=request)
        bundles.append(res.full_dehydrate(bundle, for_list=True))

    list_json = res.serialize(None, bundles, "application/json")
    list_json = json.loads(list_json)

    paginator = Paginator(list_json, settings.API_DEFAULT_ITEMS_PER_PAGE)
    page = request.GET.get('page')
    try:
        stories = paginator.page(page)
    except PageNotAnInteger:
        stories = paginator.page(1)
    except EmptyPage:
        stories = paginator.page(paginator.num_pages)

    return render_to_response(template_name, {'stories': stories},
                              context_instance=RequestContext(request))